Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use mimir APIs to get balances #36

Merged
merged 2 commits into from
May 22, 2024
Merged

Conversation

boscohyun
Copy link
Member

@boscohyun boscohyun commented May 21, 2024

@boscohyun boscohyun requested review from moreal, Atralupus and a team May 21, 2024 04:05
@boscohyun boscohyun self-assigned this May 21, 2024
ticker: CURRENCIES[index].ticker,
amount: parseFloat(resp.stateQuery.balance.quantity),
ticker: CURRENCY_TICKERS[index],
amount: resp === null ? 0 : parseFloat(resp.quantity),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about -1? 0 really means my value is zero, but -1 is like "An error occurred."
or handling rest api response error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, the existing logic is returning 0 for balance query for non-existent currencies.
If you query a balance of a currency that doesn't exist in the blockchain state,

query {
 stateQuery {
    balance(
      address: "0x6132331720a774274d6e51caead375068cc00505",
    	currency: {
        ticker: "FAKE_CRYSTAL",
        decimalPlaces: 18,
        minters: null,
      }) {
      __typename
      currency {
        ticker
      }
      quantity
    }
  }
}

and it returns "quantity": "0" like below.

{
  "data": {
    "stateQuery": {
      "balance": {
        "__typename": "FungibleAssetValueWithCurrencyType",
        "currency": {
          "ticker": "FAKE_CRYSTAL"
        },
        "quantity": "0"
      }
    }
  },
  "extensions": {}
}

So I wrote it to use 0 even if resp is null.

The cases where resp becomes null are as follows.

Since CURRENCY_TICKERS is currently a fully manageable value in the 9c-board project, I think it's fine to treat quantity as 0 when resp is null unless the specification of the mimir API changes.
And after the REST API provided by mimir is switched to GraphQL, it would be nice to have a front-end handling of networking failures on the 9c-board.
Thanks!

@boscohyun boscohyun merged commit 4025835 into main May 22, 2024
3 checks passed
@boscohyun boscohyun deleted the use-mimir-for-avatar branch May 22, 2024 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants