Skip to content

Commit

Permalink
Merge pull request #227 from rainlanguage/2024-02-12-gui-take-orders
Browse files Browse the repository at this point in the history
2024 02 12 gui take orders
  • Loading branch information
thedavidmeister authored Feb 15, 2024
2 parents ed47ca7 + ab297fe commit 80f8abd
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 534 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/vaultBalanceChangesList.graphql > crates/subgraph/src/types/vault_list_balance_changes.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderClearsList.graphql > crates/subgraph/src/types/order_clears_list.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderTakesList.graphql > crates/subgraph/src/types/order_takes_list.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderTakeDetail.graphql > crates/subgraph/src/types/order_take_detail.rs
```

2. Prepend each generated types file with the following:
Expand Down
30 changes: 30 additions & 0 deletions crates/cli/src/commands/order_take/detail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::{execute::Execute, subgraph::CliSubgraphArgs};
use anyhow::Result;
use clap::Args;

use rain_orderbook_common::subgraph::SubgraphArgs;

use tracing::info;

#[derive(Args, Clone)]
pub struct CliOrderTakeDetailArgs {
#[arg(short = 'i', long, help = "ID of the Order Take")]
id: String,

#[clap(flatten)]
pub subgraph_args: CliSubgraphArgs,
}

impl Execute for CliOrderTakeDetailArgs {
async fn execute(&self) -> Result<()> {
let subgraph_args: SubgraphArgs = self.subgraph_args.clone().into();
let order_take = subgraph_args
.to_subgraph_client()
.await?
.order_take_detail(self.id.clone().into())
.await?;
info!("{:#?}", order_take);

Ok(())
}
}
6 changes: 6 additions & 0 deletions crates/cli/src/commands/order_take/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
mod detail;
mod list;

use crate::execute::Execute;
use anyhow::Result;
use clap::Parser;
use detail::CliOrderTakeDetailArgs;
use list::CliOrderTakesListArgs;

#[derive(Parser)]
pub enum OrderTake {
#[command(about = "View an Order Take", alias = "view")]
Detail(CliOrderTakeDetailArgs),

#[command(about = "List takes for an Order", alias = "ls")]
List(CliOrderTakesListArgs),
}

impl Execute for OrderTake {
async fn execute(&self) -> Result<()> {
match self {
OrderTake::Detail(detail) => detail.execute().await,
OrderTake::List(list) => list.execute().await,
}
}
Expand Down
40 changes: 40 additions & 0 deletions crates/subgraph/queries/orderTakeDetail.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
query OrderTakeDetailQuery($id: ID!) {
takeOrderEntity(id: $id) {
id
transaction {
id
}
sender {
id
}
timestamp
order {
id
}
IORatio
input
inputDisplay
inputToken {
id
name
symbol
decimals
}
inputIOIndex
output
outputDisplay
outputToken {
id
name
symbol
decimals
}
outputIOIndex
context {
callingContext
calculationsContext
vaultInputsContext
vaultOutputsContext
}
}
}
19 changes: 19 additions & 0 deletions crates/subgraph/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::types::{
order_clears_list::{OrderClearsListQuery, OrderClearsListQueryVariables},
order_detail,
order_detail::{OrderDetailQuery, OrderDetailQueryVariables},
order_take_detail,
order_take_detail::{OrderTakeDetailQuery, OrderTakeDetailQueryVariables},
order_takes_list,
order_takes_list::{OrderTakesListQuery, OrderTakesListQueryVariables},
orders_list,
Expand Down Expand Up @@ -177,6 +179,23 @@ impl OrderbookSubgraphClient {

Ok(data.take_order_entities)
}

pub async fn order_take_detail(
&self,
id: Id,
) -> Result<order_take_detail::TakeOrderEntity, OrderbookSubgraphClientError> {
let data = self
.query::<OrderTakeDetailQuery, OrderTakeDetailQueryVariables>(
self.url.clone(),
OrderTakeDetailQueryVariables { id: &id },
)
.await?;
let order_take = data
.take_order_entity
.ok_or(OrderbookSubgraphClientError::Empty)?;

Ok(order_take)
}
}

pub struct VaultListBalanceChangesPageQueryClient {
Expand Down
1 change: 1 addition & 0 deletions crates/subgraph/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod flattened;
pub mod order_clears_list;
pub mod order_detail;
pub mod order_detail_traits;
pub mod order_take_detail;
pub mod order_takes_list;
pub mod orders_list;
pub mod vault_balance_change;
Expand Down
85 changes: 85 additions & 0 deletions crates/subgraph/src/types/order_take_detail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use crate::schema;
use serde::Serialize;
use typeshare::typeshare;

#[derive(cynic::QueryVariables, Debug)]
pub struct OrderTakeDetailQueryVariables<'a> {
pub id: &'a cynic::Id,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "OrderTakeDetailQueryVariables")]
pub struct OrderTakeDetailQuery {
#[arguments(id: $id)]
pub take_order_entity: Option<TakeOrderEntity>,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Serialize)]
pub struct TakeOrderEntity {
pub id: cynic::Id,
pub transaction: Transaction,
pub sender: Account,
pub timestamp: BigInt,
pub order: Order,
#[cynic(rename = "IORatio")]
pub ioratio: BigDecimal,
pub input: BigInt,
pub input_display: BigDecimal,
pub input_token: Erc20,
#[cynic(rename = "inputIOIndex")]
pub input_ioindex: BigInt,
pub output: BigInt,
pub output_display: BigDecimal,
pub output_token: Erc20,
#[cynic(rename = "outputIOIndex")]
pub output_ioindex: BigInt,
pub context: Option<ContextEntity>,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Serialize)]
pub struct Transaction {
pub id: cynic::Id,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Serialize)]
pub struct Order {
pub id: cynic::Id,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Serialize)]
#[cynic(graphql_type = "ERC20")]
pub struct Erc20 {
pub id: cynic::Id,
pub name: String,
pub symbol: String,
pub decimals: i32,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Serialize)]
pub struct ContextEntity {
pub calling_context: Option<Vec<BigInt>>,
pub calculations_context: Option<Vec<BigInt>>,
pub vault_inputs_context: Option<Vec<BigInt>>,
pub vault_outputs_context: Option<Vec<BigInt>>,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Serialize)]
pub struct Account {
pub id: Bytes,
}

#[derive(cynic::Scalar, Debug, Clone)]
pub struct BigDecimal(pub String);

#[derive(cynic::Scalar, Debug, Clone)]
pub struct BigInt(pub String);

#[derive(cynic::Scalar, Debug, Clone)]
pub struct Bytes(pub String);
15 changes: 15 additions & 0 deletions crates/subgraph/tests/order_take_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use cynic::Id;
use insta::assert_snapshot;
use rain_orderbook_subgraph_client::types::order_take_detail::{
OrderTakeDetailQuery, OrderTakeDetailQueryVariables,
};

#[test]
fn vaults_query_gql_output() {
use cynic::QueryBuilder;

let id = Id::new("1234");
let request_body = OrderTakeDetailQuery::build(OrderTakeDetailQueryVariables { id: &id });

assert_snapshot!(request_body.query);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
source: crates/subgraph/tests/order_take_test.rs
expression: request_body.query
---
query OrderTakeDetailQuery($id: ID!) {
takeOrderEntity(id: $id) {
id
transaction {
id
}
sender {
id
}
timestamp
order {
id
}
IORatio
input
inputDisplay
inputToken {
id
name
symbol
decimals
}
inputIOIndex
output
outputDisplay
outputToken {
id
name
symbol
decimals
}
outputIOIndex
context {
callingContext
calculationsContext
vaultInputsContext
vaultOutputsContext
}
}
}


1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
typeshare crates/subgraph/src/types/orders_list_for_vault.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/ordersListForVault.ts;
typeshare crates/subgraph/src/types/order_clears_list.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/orderClearsList.ts;
typeshare crates/subgraph/src/types/order_takes_list.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/orderTakesList.ts;
typeshare crates/subgraph/src/types/order_take_detail.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/orderTakeDetail.ts;
typeshare tauri-app/src-tauri/src/toast.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/toast.ts;
typeshare tauri-app/src-tauri/src/transaction_status.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/transactionStatus.ts;
Expand Down
Loading

0 comments on commit 80f8abd

Please sign in to comment.