rango_sdk/client/
check.rs

1use crate::{
2    check::{
3        balance::{BalanceRequest, BalanceResponse},
4        is_approved::{CheckApprovalResponse, IsApprovedRequest},
5        status::{StatusRequest, StatusResponse},
6    },
7    error::SdkErr,
8};
9
10impl super::Client {
11    /// In some blockchains (like evm), before sending the swap transaction, user is needing to give a approval to the conttact. This method will track and check the approval transcation.
12    pub async fn is_approved(
13        &self,
14        request: IsApprovedRequest,
15    ) -> Result<CheckApprovalResponse, SdkErr> {
16        let qs = request.into_qs()?;
17
18        let url = format!(
19            "{}/{}?apiKey={}&{}",
20            self.config.api_url, "basic/is-approved", self.config.api_key, qs
21        );
22
23        let body: CheckApprovalResponse = ureq::get(&url).call()?.into_json()?;
24        Ok(body)
25    }
26    /// After signing the transaction by the user and receiving transaction hash,
27    /// you could periodically call Rango check-status API to track the transaction status.
28    pub async fn status(&self, request: StatusRequest) -> Result<StatusResponse, SdkErr> {
29        let qs = request.into_qs()?;
30
31        let url = format!(
32            "{}/{}?apiKey={}&{}",
33            self.config.api_url, "basic/status", self.config.api_key, qs
34        );
35
36        let body: StatusResponse = ureq::get(&url).call()?.into_json()?;
37        Ok(body)
38    }
39
40    /// Getting wallet's balance by giving blockchain and address.
41    pub async fn balance(&self, request: BalanceRequest) -> Result<BalanceResponse, SdkErr> {
42        let qs = request.into_qs()?;
43
44        let url = format!(
45            "{}/{}?apiKey={}&{}",
46            self.config.api_url, "basic/balance", self.config.api_key, qs
47        );
48
49        let body: BalanceResponse = ureq::get(&url).call()?.into_json()?;
50        Ok(body)
51    }
52}