keplr-wallet icon indicating copy to clipboard operation
keplr-wallet copied to clipboard

Wrong available balance in extension

Open greedyboi opened this issue 3 years ago • 10 comments

Describe the bug Several users of our wallet have issues with their extension. On mintscan, our wallet or our explorer users have their correct balance showing but not on the extension leading to a blocking point for any transaction. We have investigated with the team to see if it was an API problem on our REST endpoint as it seems keplr uses this to fetch wallet informations but nothing weird, good balances are fetched but remains at 0 in the available part in the extension.

Note: No errors logged from all API calls, no errors in the extension console and this issue concern only available balance, not staked tokens.

To Reproduce Not all users have this problem and we don't know how to reproduce this.

Expected behavior Same available balance on mintscan, explorer or wallet and the extension itself

Screenshots

keplr_issue

Device details (please complete the following information):

  • OS: OS X and Windows
  • Browser: a user is on Chrome Version 104.0.5112.79 (Official Build)
  • Keplr Version: this same user is on 0.10.16 but this issue seems to come since 0.8

greedyboi avatar Aug 31 '22 14:08 greedyboi

What is your account address?

Thunnini avatar Aug 31 '22 14:08 Thunnini

In my personnal account I don't have the issue, this is from a user's account.

greedyboi avatar Aug 31 '22 14:08 greedyboi

[UPDATE: the below problem is unrelated to Keplr, I just leave this here if ever someone misguides himself the same way I did]

+1 here: Keplr shows 0 token as balances, whereas a call to http://0.0.0.0:1317/bank/balances/trust15cd8mlzj2j9ydl4mwzttpd3m00f7xh2ych42zx outputs: {"height":"7959","result":[ { "denom": "TRUST", "amount": "10" } ]}

As you can see from the url, I am developing locally, but maybe the precise outputs will help.

Http request sniffer tells me: image Copy-paste-proof query output: { "balances": [{ "denom": "TRUST", "amount": "10" }], "pagination": { "next_key": null, "total": "0" } } while my account's balance stays at 0 (I double checked as much as I could, and the local chain parameters suggested to Keplr are correct): image

My address is trust15cd8mlzj2j9ydl4mwzttpd3m00f7xh2ych42zx, but I don't think it'll help you, as I am developing a Cosmos chain locally.

Keplr extension version: 0.10.21 Issue reproduced both on Brave Browser and Chrome MacOs 12.3.1

Hope this helps.

blarsy avatar Sep 05 '22 11:09 blarsy

@blarsy How did you set ChainInfo when suggesting the localnet to keplr?

Thunnini avatar Sep 06 '22 07:09 Thunnini

@Thunnini Here the method used:

export async function connect(keplr: Keplr): Promise<string> {
  if (keplr.experimentalSuggestChain) {
      try {
          // Keplr v0.6.4 introduces an experimental feature that supports the feature to suggests the chain from a webpage.
          // cosmoshub-3 is integrated to Keplr so the code should return without errors.
          // The code below is not needed for cosmoshub-3, but may be helpful if you’re adding a custom chain.
          // If the user approves, the chain will be added to the user's Keplr extension.
          // If the user rejects it or the suggested chain information doesn't include the required fields, it will throw an error.
          // If the same chain id is already registered, it will resolve and not require the user interactions.
          await keplr.experimentalSuggestChain({
              // Chain-id of the Regen chain.
              chainId: CHAIN_ID,
              // The name of the chain to be displayed to the user.
              chainName: CHAIN,
              // RPC endpoint of the chain.
              rpc: RPC_ENDPOINT,
              // REST endpoint of the chain.
              rest: REST_ENDPOINT,
              // Staking coin information
              stakeCurrency: {
                // Coin denomination to be displayed to the user.
                coinDenom: COIN_ABV.toUpperCase(),
                // Actual denom (i.e. uatom, uscrt) used by the blockchain.
                coinMinimalDenom: `u${COIN_ABV}`,
                // # of decimal points to convert minimal denomination to user-facing denomination.
                coinDecimals: 6,
                // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided.
                // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed.
                // coinGeckoId: ""
              },
              // (Optional) If you have a wallet webpage used to stake the coin then provide the url to the website in `walletUrlForStaking`.
              // The 'stake' button in Keplr extension will link to the webpage.
              // walletUrlForStaking: "",
              // The BIP44 path.
              bip44: {
                // You can only set the coin type of BIP44.
                // 'Purpose' is fixed to 44.
                coinType: 118,
              },
              // Bech32 configuration to show the address to user.
              bech32Config: {
                bech32PrefixAccAddr: COIN_ABV,
                bech32PrefixAccPub: `${COIN_ABV}pub`,
                bech32PrefixValAddr: `${COIN_ABV}valoper`,
                bech32PrefixValPub: `${COIN_ABV}valoperpub`,
                bech32PrefixConsAddr: `${COIN_ABV}valcons`,
                bech32PrefixConsPub: `${COIN_ABV}valconspub`,
              },
              // List of all coin/tokens used in this chain.
              currencies: [
                {
                  // Coin denomination to be displayed to the user.
                  coinDenom: COIN_ABV.toUpperCase(),
                  // Actual denom (i.e. uatom, uscrt) used by the blockchain.
                  coinMinimalDenom: `u${COIN_ABV}`,
                  // # of decimal points to convert minimal denomination to user-facing denomination.
                  coinDecimals: 6,
                  // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided.
                  // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed.
                  // coinGeckoId: ""
                },
              ],
              // List of coin/tokens used as a fee token in this chain.
              feeCurrencies: [
                {
                  // Coin denomination to be displayed to the user.
                  coinDenom: COIN_ABV.toUpperCase(),
                  // Actual denom (i.e. uatom, uscrt) used by the blockchain.
                  coinMinimalDenom: `u${COIN_ABV}`,
                  // # of decimal points to convert minimal denomination to user-facing denomination.
                  coinDecimals: 6,
                  // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided.
                  // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed.
                  // coinGeckoId: ""
                },
              ],
              // (Optional) The number of the coin type.
              // This field is only used to fetch the address from ENS.
              // Ideally, it is recommended to be the same with BIP44 path's coin type.
              // However, some early chains may choose to use the Cosmos Hub BIP44 path of '118'.
              // So, this is separated to support such chains.
              //coinType: 118,

              // (Optional) This is used to set the fee of the transaction.
              // If this field is not provided, Keplr extension will set the default gas price as (low: 0.01, average: 0.025, high: 0.04).
              // Currently, Keplr doesn't support dynamic calculation of the gas prices based on on-chain data.
              // Make sure that the gas prices are higher than the minimum gas prices accepted by chain validators and RPC/REST endpoint.
              gasPriceStep: {
                low: 0.01,
                average: 0.025,
                high: 0.04,
              },
              features: ['stargate'],
            })
          
            await keplr.enable(CHAIN_ID)
            //Returning empty string means success (as we return an error message)
            return ""
      } catch(e) {
          return `Failed to suggest the chain: ${e}`
      }
  } else {
      return "Please use the recent version of keplr extension"
  }
}

At runtime, the actual value passed to experimentalSuggestChain is

{
    "chainId": "local",
    "chainName": "local Truststore chain",
    "rpc": "http://0.0.0.0:26657",
    "rest": "http://0.0.0.0:1317",
    "stakeCurrency": {
        "coinDenom": "TRUST",
        "coinMinimalDenom": "utrust",
        "coinDecimals": 6
    },
    "bip44": {
        "coinType": 118
    },
    "bech32Config": {
        "bech32PrefixAccAddr": "trust",
        "bech32PrefixAccPub": "trustpub",
        "bech32PrefixValAddr": "trustvaloper",
        "bech32PrefixValPub": "trustvaloperpub",
        "bech32PrefixConsAddr": "trustvalcons",
        "bech32PrefixConsPub": "trustvalconspub"
    },
    "currencies": [
        {
            "coinDenom": "TRUST",
            "coinMinimalDenom": "utrust",
            "coinDecimals": 6
        }
    ],
    "feeCurrencies": [
        {
            "coinDenom": "TRUST",
            "coinMinimalDenom": "utrust",
            "coinDecimals": 6
        }
    ],
    "gasPriceStep": {
        "low": 0.01,
        "average": 0.025,
        "high": 0.04
    },
    "features": [
        "stargate"
    ]
}

blarsy avatar Sep 06 '22 08:09 blarsy

My bad, my problem is not related to the current issue. Feel free to remove my interactions here, but if ever it stays, here's my advice to anyone coming here for the same reason as me: Make sure you understand correctly how to insert "denom_metadata" in the Genesis of the Cosmos SDK "Bank" module.

One thing that helped me a lot is a working configuration, which is the REGEN token of the Regen Network at http://redwood.regen.network:1317/cosmos/bank/v1beta1/denoms_metadata

Its output was, at the time of this writing:

{
  "metadatas": [
    {
      "description": "This is a test NCT basket",
      "denom_units": [
        {
          "denom": "eco.uC.NCT",
          "exponent": 0,
          "aliases": [
          ]
        },
        {
          "denom": "eco.C.NCT",
          "exponent": 6,
          "aliases": [
          ]
        }
      ],
      "base": "eco.uC.NCT",
      "display": "eco.C.NCT",
      "name": "NCT",
      "symbol": "NCT"
    },
    {
      "description": "tyler's basket",
      "denom_units": [
        {
          "denom": "eco.uC.TYLER",
          "exponent": 0,
          "aliases": [
          ]
        },
        {
          "denom": "eco.C.TYLER",
          "exponent": 6,
          "aliases": [
          ]
        }
      ],
      "base": "eco.uC.TYLER",
      "display": "eco.C.TYLER",
      "name": "TYLER",
      "symbol": "TYLER"
    },
    {
      "description": "this is a test rNCT basket",
      "denom_units": [
        {
          "denom": "eco.uC.rNCT",
          "exponent": 0,
          "aliases": [
          ]
        },
        {
          "denom": "eco.C.rNCT",
          "exponent": 6,
          "aliases": [
          ]
        }
      ],
      "base": "eco.uC.rNCT",
      "display": "eco.C.rNCT",
      "name": "rNCT",
      "symbol": "rNCT"
    },
    {
      "description": "The native staking token of Regen Network",
      "denom_units": [
        {
          "denom": "uregen",
          "exponent": 0,
          "aliases": [
            "microregen"
          ]
        },
        {
          "denom": "mregen",
          "exponent": 3,
          "aliases": [
            "milliregen"
          ]
        },
        {
          "denom": "regen",
          "exponent": 6,
          "aliases": [
          ]
        }
      ],
      "base": "uregen",
      "display": "regen",
      "name": "Regen",
      "symbol": "REGEN"
    }
  ],
  "pagination": {
    "next_key": null,
    "total": "4"
  }
}

blarsy avatar Sep 07 '22 11:09 blarsy

@blarsy Your first case is because you mistakenly set the coinDenom and coinMinimalDenom of the currencies incorrectly. And adding currencies through bank metadata is not yet supported in Keplr.

In this case, the Lum chain is not supported by keplr, but is supported through the suggest chain. In this way, the exact setting is not known because the Lum chain can be added from any website. In my case, there is no problem when I add Lum chain from app.osmosis.zone. If I can't reproduce this problem, it's hard to solve...

Thunnini avatar Sep 08 '22 05:09 Thunnini

@Thunnini Thank you for your time. I found out about the denom_metadata and corrected it already (see my update above).

I believe the second part of you comment was intended for @greedyboi

blarsy avatar Sep 08 '22 06:09 blarsy

In this case, the Lum chain is not supported by keplr, but is supported through the suggest chain. In this way, the exact setting is not known because the Lum chain can be added from any website. In my case, there is no problem when I add Lum chain from app.osmosis.zone. If I can't reproduce this problem, it's hard to solve...

This is why this bug is kinda annoying as we can't really know where the problem is. Is there any information (not sensitive of course) I can share that may help you ?

greedyboi avatar Sep 08 '22 09:09 greedyboi

Hello @Thunnini @blarsy we finally fixed that issue on the Lum Network Wallet.

The relevant commit is here https://github.com/lum-network/wallet/commit/a20f5dc767a7a90163746e48b65cdc0180564f67

When looking at the extension network calls for an affected wallet, I noticed that the call that query the network supply for a coin was sent with the "ULUM" denom when the network one is actually "ulum". Thus the call answered with an empty supply.

I don't know why this affect the display / usage of the balance on Keplr, but might be worth to ensure that the denoms are always sent lower case.

Cheers

Segfaultd avatar Sep 29 '22 12:09 Segfaultd