Skip to content

fix: register correct coin decimals when suggesting chain to wallets#672

Closed
Ehsan-saradar wants to merge 18 commits into
ping-pub:masterfrom
Ehsan-saradar:fix/keplr-coin-decimals
Closed

fix: register correct coin decimals when suggesting chain to wallets#672
Ehsan-saradar wants to merge 18 commits into
ping-pub:masterfrom
Ehsan-saradar:fix/keplr-coin-decimals

Conversation

@Ehsan-saradar
Copy link
Copy Markdown
Contributor

Summary

  • When the explorer suggests a chain to Keplr / Metamask Snap / Unisat, it was registering coinDecimals: 6 for QBTC even though the chain uses 8 decimals — wallets then rendered balances 100× too large (e.g. an actual 0.01 QBTC showed as 1.000000 QBTC).
  • Root cause: the lookup denom_units.find(x => x.denom === symbol.toLowerCase())?.exponent || 6 matches the base unit (which has exponent: 0) when the chain's base denom equals its lowercased symbol — as with QBTC where base = "qbtc" and symbol = "QBTC". The result 0 then falls through 0 || 6 to 6.
  • Fixed by reading the asset's exponent field directly (already attached to the asset by the local-config converter in useDashboard.ts) in all four call sites: src/libs/keplr.ts, the Keplr/Metamask Snap suggest screen, and the Unisat suggest screen.
  • Extended the local Asset interface with the optional exponent field so TypeScript reflects the runtime shape.

Test plan

  • yarn type-check passes.
  • Suggest QBTC mainnet to Keplr and confirm the registered chain reports balances in QBTC with 8-decimal precision (e.g. 0.01 QBTC displays as 0.01, not 1.000000).
  • Suggest QBTC to Metamask Snap and verify decimals.
  • Re-suggest at least one non-QBTC chain (where base !== symbol.toLowerCase()) to make sure decimals there still match the chain config.

🤖 Generated with Claude Code

Ehsan-saradar and others added 18 commits May 6, 2026 13:15
- add qbtc mainnet and testnet configs pointing to odindex.io endpoints
- add qbtc logo asset
- remove other chains (axelar, cosmos, neutron, nolus, osmosis, xion, bfhevm, crossfi) since this fork is dedicated to qbtc

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Rewrite all non-asset paths to / so the Vue Router can handle deep links
like /qbtc directly without Vercel returning 404.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Visiting / now 308-redirects to /qbtc so users land on the qbtc explorer
directly instead of the chain list page.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When Keplr lacks a chain in its modular registry, calling enable/getKey
throws "There is no modular chain info for {chainId}" and the connect
modal surfaces the error inline without ever opening a popup. Wire the
ping-connect-wallet keplr-config event to call experimentalSuggestChain
directly so Keplr prompts the user to add the chain, instead of routing
to a separate manual /wallet/keplr page. Falls back to the manual page
if Keplr is missing or the suggestion rejects.

Extracts the ChainInfo builder from modules/wallet/keplr.vue into a
shared libs/keplr.ts helper to avoid duplicating the payload shape.
ping-widget@0.3.8's <ping-connect-wallet> only emits keplr-config when
the user clicks the gear icon, not when CONNECT fails — so the prior
walletStore.suggestChain() patch alone didn't reach the inline error
path. Its built-in "Suggest a chain to Keplr" fallback link is also
gated by error.search('no chain info'), which doesn't match Keplr's
new "no modular chain info" message.

Watch chainStore.current and call experimentalSuggestChain proactively
once Keplr is available. The call is idempotent — Keplr no-ops if the
chain is already registered — so a one-time approval popup eliminates
the inline error for all subsequent visits.
fix: auto-suggest chain to Keplr on connect
Replaces the placeholder ping-dashboard-five.vercel.app logo with the
official qBTC svg from vultisig/vultisig-windows.
chore: update qbtc logo to vultisig-hosted svg
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
chore: point mainnet qbtc logo to vultisig-hosted svg
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
docs: rewrite README for qbtc-explorer fork
- public/logo.svg → 256×256 qbtc logo (rendered from vultisig-hosted SVG;
  kept .svg extension so index.html reference is unchanged — browsers
  sniff the PNG content)
- public/favicon.ico → multi-size ICO (16/32/48) of the qbtc logo
- .gitattributes pins both files to merge=ours so upstream syncs from
  ping-pub do not silently revert qbtc branding

Note: collaborators must run once per clone for merge=ours to take effect:
  git config merge.ours.driver true

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
chore: replace logo and favicon with qbtc branding
The default formatToken format string '0,0.[0]' rounds amounts to a
single decimal place, so a 0.989925 QBTC balance rendered as "1 QBTC"
and amounts under 0.05 collapsed to "0". Pass '0,0.[000000]' explicitly
on the account page assets card and the chain home wallet card so
sub-unit balances are displayed accurately.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The coinDecimals lookup matched a denom_unit by symbol against the
runtime-built denom_units list, but for chains where base equals
symbol.toLowerCase() (e.g. QBTC) both entries share the same denom and
.find() returns the base entry with exponent 0 — which then falls
through `0 || 6` to 6. Suggested chains end up registered with 6
decimals while the chain actually uses 8, so balances render 100x off.

Read the asset exponent directly instead. Applied to keplr.ts, the
Keplr/Metamask suggest screens, and the Unisat suggest screen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Ehsan-saradar
Copy link
Copy Markdown
Contributor Author

Closing — opened in the wrong repo by mistake. Re-opening on the fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant