Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ninokeldishvili committed Nov 19, 2024
1 parent e28ec75 commit dd70122
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/cli/src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use rain_orderbook_subgraph_client::types::order::OrdersListQuery;
use reqwest::Client;
use serde_json::Value;

async fn fetch_vault_balance(url: &str, variables: OrdersListQueryVariables) -> Result<Value> {
/// Fetches data from subgraph
async fn fetch_order_details(url: &str, variables: OrdersListQueryVariables) -> Result<Value> {
let client = Client::new();

// Build the GraphQL query with the provided variables.
let query = OrdersListQuery::build(variables);

let req = client
Expand All @@ -19,12 +21,14 @@ async fn fetch_vault_balance(url: &str, variables: OrdersListQueryVariables) ->

let text = req.text().await?;

// Parse the response JSON.
let response: Value = serde_json::from_str(&text)?;
Ok(serde_json::from_str(&text)?)
}

/// Retrieves data from subgraph and checks for errors in the response.
async fn get_data(url: &str, variables: OrdersListQueryVariables) -> Result<Value> {
let data = fetch_vault_balance(url, variables).await?;
let data = fetch_order_details(url, variables).await?;
if let Some(errors) = data.get("errors") {
return Err(anyhow::anyhow!("Error(s) occurred: {:?}", errors));
}
Expand Down

0 comments on commit dd70122

Please sign in to comment.