Skip to content

adds support to GBP, JPY and CNY - #463

Merged
bordalix merged 4 commits into
masterfrom
add_more_fiat_currencies
Mar 23, 2026
Merged

bordalix merged 4 commits into
masterfrom
add_more_fiat_currencies

Conversation

@bordalix

@bordalix bordalix commented Mar 23, 2026 •

Copy link
Copy Markdown
Collaborator

@tiero please review
closes #451

Big change because JPY and CNY are non decimal currencies, and all our code assumed 2 decimal places for all fiat currencies.

Summary by CodeRabbit

  • New Features

    • Added JPY, GBP, and CNY as selectable fiat currencies
    • Introduced a configurable fiat-decimal provider (e.g., 0 decimals for JPY)
  • UX / Formatting

    • Fiat displays now use dynamic decimal precision across the app so converted amounts respect the selected currency
  • Style

    • Minor visual tweaks (no-fade styling applied to some screens/components)

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 23, 2026 •

Copy link
Copy Markdown

Deploying wallet-mutinynet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3049354
Status: ✅  Deploy successful!
Preview URL: https://eb1f0bff.arkade-wallet.pages.dev
Branch Preview URL: https://add-more-fiat-currencies.arkade-wallet.pages.dev

View logs

@coderabbitai

coderabbitai Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 43415fca-4b59-49be-9e5d-2b09a37fd8c6

📥 Commits

Reviewing files that changed from the base of the PR and between e99e6ea and 3049354.

📒 Files selected for processing (2)
  • src/components/Keyboard.tsx
  • src/providers/fiat.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Keyboard.tsx

Walkthrough

Adds JPY, GBP, and CNY fiat support, exposes a new fiatDecimals() provider function, and replaces hardcoded 2-decimal fiat formatting with dynamic precision across UI, provider, formatter, and settings. Minor styling additions: className='no-fade' on some FlexCol wrappers.

Changes

Cohort / File(s) Summary
Fiat currency infrastructure
src/lib/types.ts, src/lib/fiat.ts, src/providers/fiat.tsx
Added JPY/GBP/CNY to Fiats; extended FiatPrices with jpy/gbp/cny; populate new price fields; added per-currency from/to helpers; introduced fiatDecimals(): number (0 for JPY, 2 otherwise); updated context default and emptyFiatPrices.
Formatting utilities
src/lib/format.ts
Extended prettyAmount(amount, suffix?, decimals = 2) to accept an optional decimals parameter and use it for suffixed fiat formatting.
Components consuming fiatDecimals
src/components/Balance.tsx, src/components/InputAmount.tsx, src/components/Keyboard.tsx, src/components/TransactionsList.tsx
Consume fiatDecimals() from FiatContext; replace hardcoded 2 with fiatDecimals() for fiat displays; Keyboard adds className='no-fade' to amount/error wrapper.
Wallet screens consuming fiatDecimals
src/screens/Wallet/Notes/Success.tsx, src/screens/Wallet/Receive/Amount.tsx, src/screens/Wallet/Receive/Success.tsx, src/screens/Wallet/Send/Form.tsx, src/screens/Wallet/Send/Success.tsx
Consume fiatDecimals(); pass it into prettyAmount() and use it for maximumFractionDigits where applicable.
Fiat settings UI
src/screens/Settings/Fiat.tsx
Added Fiats.GBP, Fiats.JPY, Fiats.CNY to the currency selection options.
UI styling updates
src/screens/Apps/Assets/Detail.tsx, src/screens/Apps/Assets/MintSuccess.tsx
Added className='no-fade' to FlexCol containers.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant UI as UI Component
participant FProv as FiatContext Provider
participant Prices as PriceFeed (src/lib/fiat.ts)
participant Fmt as format.prettyAmount / prettyNumber

UI->>FProv: read fiatDecimals(), toFiat(), fromFiat()
FProv->>Prices: access current fiat prices (usd, eur, chf, jpy, gbp, cny)
Prices-->>FProv: return latest price values
FProv-->>UI: conversion helpers & fiatDecimals()
UI->>Fmt: prettyAmount(value, fiatCode, fiatDecimals())
Fmt-->>UI: formatted string rendered

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • tiero
  • pietro909
  • Kukks
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'adds support to GBP, JPY and CNY' directly and specifically describes the main objective: adding three new fiat currencies.
Linked Issues check ✅ Passed The PR fulfills all core requirements from issue #451: added JPY/GBP/CNY to Fiats enum [#451], extended FiatPrices and getPriceFeed() [#451], implemented conversion helpers and dispatch logic [#451], updated Settings UI [#451], and added fiatDecimals() for zero-decimal handling [#451].
Out of Scope Changes check ✅ Passed All changes are directly aligned with adding JPY/GBP/CNY support; CSS class additions (className='no-fade') appear tangential but are related to the zero-decimal currency display concern noted in the issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add_more_fiat_currencies

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ghost

ghost commented Mar 23, 2026

Copy link
Copy Markdown

🔍 Review — wallet#463 adds GBP, JPY, CNY support

Clean implementation. The fiatDecimals() abstraction is the right approach — previously hardcoded to 2 everywhere. A few things:

Bug: CNY should use 2 decimal places, not 0

const fiatDecimals = () => {
  return [Fiats.JPY, Fiats.CNY].includes(config.fiat) ? 0 : 2
}

JPY is correctly zero-decimal (no subunit in practice). But CNY has 2 decimal places — 1 CNY = 100 fen. Grouping it with JPY will truncate user balances. Should be:

const fiatDecimals = () => {
  return [Fiats.JPY].includes(config.fiat) ? 0 : 2
}

Minor: unrelated className="no-fade" additions

Keyboard.tsx, Detail.tsx, MintSuccess.tsx add className="no-fade" — not related to fiat currencies. Not blocking, but worth noting for commit hygiene.

Division by zero (pre-existing)

fromJPY / fromGBP / fromCNY follow the same pattern as existing converters — Decimal.div(fiat, price) will produce Infinity if the price feed returns 0. Not new to this PR, but worth a guard eventually.

Looks good otherwise

  • Price feed integration follows existing pattern
  • fiatDecimals threaded through all display paths consistently
  • Settings screen updated with new options

TL;DR: Fix CNY decimal count (2, not 0) and this is good to go.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/fiat.ts (1)

3-10: ⚠️ Potential issue | 🟡 Minor

Add fallback values to match the interface type declaration.

The FiatPrices interface declares all fields as number, but the API response mapping uses optional chaining (json.JPY?.last). While blockchain.info's ticker API does return JPY, GBP, and CNY data, the code lacks defensive handling for partial API responses. If any currency is missing, the field will be undefined, creating a type mismatch. This could cause NaN results in downstream arithmetic operations.

Apply fallback values to ensure type safety:

🛡️ Proposed fix
     return {
       eur: json.EUR?.last,
       usd: json.USD?.last,
       chf: json.CHF?.last,
-      jpy: json.JPY?.last,
-      gbp: json.GBP?.last,
-      cny: json.CNY?.last,
+      jpy: json.JPY?.last ?? 0,
+      gbp: json.GBP?.last ?? 0,
+      cny: json.CNY?.last ?? 0,
     }

Also applies to: 16-23

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/fiat.ts` around lines 3 - 10, The FiatPrices interface requires all
fields to be numbers but the mapping uses optional chaining (e.g.,
json.JPY?.last) which can produce undefined; update the code that constructs the
FiatPrices object to coerce each currency value to a number with a safe fallback
(e.g., use "json.JPY?.last ?? 0" or "Number(json.JPY?.last ?? 0)") for eur, usd,
chf, jpy, gbp, and cny so every property on the FiatPrices object is a numeric
value and matches the interface (refer to the FiatPrices type and the place
where the API response is mapped into that object).
🧹 Nitpick comments (3)
src/screens/Wallet/Send/Form.tsx (1)

330-332: Input field decimal handling is hardcoded to 2 for fiat currencies.

While the display formatting now correctly uses fiatDecimals(), the input field text value formatting still uses hardcoded 2 decimal places for fiat (lines 331, 427, 515). For JPY and CNY users, this means the input field will show values like "1234.00" while the display shows "1,234".

Consider using fiatDecimals() for consistency:

♻️ Suggested refactor
   // Line 331-332
-  const maximumFractionDigits = useFiat ? 2 : 0
+  const maximumFractionDigits = useFiat ? fiatDecimals() : 0
   setTextValue(prettyNumber(value, maximumFractionDigits, false))

   // Line 427
-  setTextValue(useFiat ? prettyNumber(toFiat(sats), 2, false) : prettyNumber(sats, 0, false))
+  setTextValue(useFiat ? prettyNumber(toFiat(sats), fiatDecimals(), false) : prettyNumber(sats, 0, false))

   // Line 513-515
-  const maximumFractionDigits = useFiat ? 2 : 0
+  const maximumFractionDigits = useFiat ? fiatDecimals() : 0

Also applies to: 427-427, 513-515

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/screens/Wallet/Send/Form.tsx` around lines 330 - 332, The input-field
formatting uses a hardcoded 2 decimals for fiat; update the code that computes
maximumFractionDigits (where useFiat is checked before calling setTextValue) to
call fiatDecimals() instead of using 2 so input text and display formatting
match; specifically change the logic around
useFiat/toFiat/maximumFractionDigits/prettyNumber before invoking setTextValue
in the Send Form (the same pattern appears in the blocks that set textValue at
the uses around the prettyNumber calls) to use fiatDecimals() when useFiat is
true.
src/components/Keyboard.tsx (1)

61-71: Inconsistent decimal handling in getMaxDecimals() for fiat input.

The function returns a hardcoded 2 for fiat mode, but with JPY/CNY (zero-decimal currencies), users can type decimal values (e.g., "1234.56") that will then be displayed without decimals. This creates a confusing UX where input precision differs from display precision.

Consider using fiatDecimals() here as well:

♻️ Proposed fix
 const getMaxDecimals = () => {
   switch (inputMode) {
     case 'asset':
       return asset?.decimals ?? 0
     case 'fiat':
-      return 2
+      return fiatDecimals()
     case 'sats':
     default:
       return 0
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Keyboard.tsx` around lines 61 - 71, getMaxDecimals currently
hardcodes 2 for the 'fiat' inputMode which mismatches display precision for
zero-decimal currencies; update the 'fiat' case in getMaxDecimals to call
fiatDecimals(...) instead of returning 2, passing the current fiat
currency/locale variable used elsewhere (e.g., fiatCurrency or selectedFiat) so
the function returns the correct decimal count for currencies like JPY/CNY;
ensure getMaxDecimals still falls back to a sensible default (0 or 2) if
fiatDecimals cannot determine precision.
src/providers/fiat.tsx (1)

31-36: Pre-existing: Division by zero when price feed fails.

If getPriceFeed() fails or returns incomplete data, prices remain at 0 (from emptyFiatPrices), causing Decimal.div(fiat, 0) to return Infinity. This affects all currencies including the new ones. The fallback at line 70 switches to sats display, but there's a window where conversions could produce Infinity.

This is a pre-existing concern, but worth noting as scope expands to more currencies.

🛡️ Optional: Guard against zero prices
-const fromJPY = (fiat = 0) => toSatoshis(Decimal.div(fiat, fiatPrices.current.jpy).toNumber())
-const fromGBP = (fiat = 0) => toSatoshis(Decimal.div(fiat, fiatPrices.current.gbp).toNumber())
-const fromCNY = (fiat = 0) => toSatoshis(Decimal.div(fiat, fiatPrices.current.cny).toNumber())
+const fromJPY = (fiat = 0) => fiatPrices.current.jpy ? toSatoshis(Decimal.div(fiat, fiatPrices.current.jpy).toNumber()) : 0
+const fromGBP = (fiat = 0) => fiatPrices.current.gbp ? toSatoshis(Decimal.div(fiat, fiatPrices.current.gbp).toNumber()) : 0
+const fromCNY = (fiat = 0) => fiatPrices.current.cny ? toSatoshis(Decimal.div(fiat, fiatPrices.current.cny).toNumber()) : 0
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/providers/fiat.tsx` around lines 31 - 36, The conversion helpers
(fromEUR, fromUSD, fromCHF, fromJPY, fromGBP, fromCNY) can divide by zero when
fiatPrices.current.* is 0; update each helper to check the corresponding
fiatPrices.current.<currency> is a positive number before calling Decimal.div
and toSatoshis, and return a safe fallback (e.g., 0 sats or null) when the price
is missing/<=0; ensure the same guard is applied consistently across the
fromEUR/fromUSD/fromCHF/fromJPY/fromGBP/fromCNY functions and consider
centralizing the check into a small helper (e.g., safeFromFiat) that takes the
price key and fiat amount and only performs Decimal.div when price > 0.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/providers/fiat.tsx`:
- Around line 61-63: The fiatDecimals helper incorrectly treats Fiats.CNY as
zero-decimal; update the logic in fiatDecimals so that only Fiats.JPY returns 0
and Fiats.CNY returns 2 (i.e., change the condition that checks [Fiats.JPY,
Fiats.CNY] to exclude Fiats.CNY), referencing the fiatDecimals function and the
Fiats enum and config.fiat to locate the change; ensure the function returns 2
for CNY per ISO 4217.

---

Outside diff comments:
In `@src/lib/fiat.ts`:
- Around line 3-10: The FiatPrices interface requires all fields to be numbers
but the mapping uses optional chaining (e.g., json.JPY?.last) which can produce
undefined; update the code that constructs the FiatPrices object to coerce each
currency value to a number with a safe fallback (e.g., use "json.JPY?.last ?? 0"
or "Number(json.JPY?.last ?? 0)") for eur, usd, chf, jpy, gbp, and cny so every
property on the FiatPrices object is a numeric value and matches the interface
(refer to the FiatPrices type and the place where the API response is mapped
into that object).

---

Nitpick comments:
In `@src/components/Keyboard.tsx`:
- Around line 61-71: getMaxDecimals currently hardcodes 2 for the 'fiat'
inputMode which mismatches display precision for zero-decimal currencies; update
the 'fiat' case in getMaxDecimals to call fiatDecimals(...) instead of returning
2, passing the current fiat currency/locale variable used elsewhere (e.g.,
fiatCurrency or selectedFiat) so the function returns the correct decimal count
for currencies like JPY/CNY; ensure getMaxDecimals still falls back to a
sensible default (0 or 2) if fiatDecimals cannot determine precision.

In `@src/providers/fiat.tsx`:
- Around line 31-36: The conversion helpers (fromEUR, fromUSD, fromCHF, fromJPY,
fromGBP, fromCNY) can divide by zero when fiatPrices.current.* is 0; update each
helper to check the corresponding fiatPrices.current.<currency> is a positive
number before calling Decimal.div and toSatoshis, and return a safe fallback
(e.g., 0 sats or null) when the price is missing/<=0; ensure the same guard is
applied consistently across the fromEUR/fromUSD/fromCHF/fromJPY/fromGBP/fromCNY
functions and consider centralizing the check into a small helper (e.g.,
safeFromFiat) that takes the price key and fiat amount and only performs
Decimal.div when price > 0.

In `@src/screens/Wallet/Send/Form.tsx`:
- Around line 330-332: The input-field formatting uses a hardcoded 2 decimals
for fiat; update the code that computes maximumFractionDigits (where useFiat is
checked before calling setTextValue) to call fiatDecimals() instead of using 2
so input text and display formatting match; specifically change the logic around
useFiat/toFiat/maximumFractionDigits/prettyNumber before invoking setTextValue
in the Send Form (the same pattern appears in the blocks that set textValue at
the uses around the prettyNumber calls) to use fiatDecimals() when useFiat is
true.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f3a12ce9-3585-4a9b-9a6a-e3ac6dea66f9

📥 Commits

Reviewing files that changed from the base of the PR and between d8f8b1c and 9ba95fd.

📒 Files selected for processing (16)
  • src/components/Balance.tsx
  • src/components/InputAmount.tsx
  • src/components/Keyboard.tsx
  • src/components/TransactionsList.tsx
  • src/lib/fiat.ts
  • src/lib/format.ts
  • src/lib/types.ts
  • src/providers/fiat.tsx
  • src/screens/Apps/Assets/Detail.tsx
  • src/screens/Apps/Assets/MintSuccess.tsx
  • src/screens/Settings/Fiat.tsx
  • src/screens/Wallet/Notes/Success.tsx
  • src/screens/Wallet/Receive/Amount.tsx
  • src/screens/Wallet/Receive/Success.tsx
  • src/screens/Wallet/Send/Form.tsx
  • src/screens/Wallet/Send/Success.tsx

Comment thread src/providers/fiat.tsx Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 23, 2026 •

Copy link
Copy Markdown

Deploying wallet-bitcoin with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3049354
Status: ✅  Deploy successful!
Preview URL: https://ca32f6f7.wallet-bitcoin.pages.dev
Branch Preview URL: https://add-more-fiat-currencies.wallet-bitcoin.pages.dev

View logs

@ghost

ghost commented Mar 23, 2026

Copy link
Copy Markdown

Review (Arkana) — e99e6ea

Clean PR. Currency additions are consistent, and the fiatDecimals() approach is the right call for handling JPY's zero-decimal convention.

Observations:

  1. fiatDecimals() correctness — JPY → 0, everything else → 2. This is correct: GBP and CNY both use 2 decimal places (pence/fen). If more zero-decimal currencies are added later (e.g. KRW), this function is the single place to extend.

  2. Keyboard input validation — When inputMode === 'fiat' and currency is JPY, users can still type decimal points (the keyboard allows '.'). Since fiatDecimals() returns 0, the displayed value rounds correctly, but the input itself isn't constrained. Minor UX nit — not blocking.

  3. Division-by-zero on missing prices — If the price feed doesn't return JPY/GBP/CNY (API error, partial response), the corresponding price stays 0 from emptyFiatPrices. Decimal.div(fiat, 0) returns Infinity, which would propagate through the UI. This is a pre-existing pattern (same for EUR/USD/CHF), but worth noting as the surface area grows.

  4. prettyAmount signature — The new decimals parameter defaults to 2, which preserves backward compat for all existing call sites without the third arg. Good.

  5. Unrelated className='no-fade' additions — Keyboard.tsx, Detail.tsx, MintSuccess.tsx have style changes unrelated to the fiat feature. Not a problem, just noting for reviewers.

LGTM for the fiat logic. The input validation nit (point 2) and division-by-zero (point 3) are worth tracking but non-blocking.

@ghost

ghost commented Mar 23, 2026

Copy link
Copy Markdown

🔍 Arkana Review — New commits (prevent division by zero + fix Keyboard with JPY)

Scope: Two new commits since last review — division-by-zero guard on fromFiat conversions, and keyboard fix for JPY zero-decimal handling.

✅ Division by zero fix (fiat.tsx)

All fromXXX converters now guard against zero price before calling Decimal.div. Returns 0 sats when price is unavailable — safe fallback that prevents crashes when price feed hasn't loaded yet or fails. Clean fix.

✅ Keyboard JPY fix (Keyboard.tsx)

maxDecimals() now uses fiatDecimals() instead of hardcoded 2, so JPY input correctly prevents decimal entry. The toggle handler similarly uses fiatDecimals() when formatting the text value. Consistent with the rest of the codebase changes.

Overall assessment

  • +83 / -40 across 16 files — proportional to the scope (new currencies + plumbing decimal precision through all display paths)
  • fiatDecimals() correctly returns 0 for JPY, 2 for everything else (GBP and CNY are 2-decimal per ISO 4217 ✓)
  • prettyAmount now accepts optional decimals param with sensible default of 2 — backward compatible
  • All call sites consistently updated to use fiatDecimals() — no missed hardcoded 2 spotted
  • no-fade className additions on Detail/MintSuccess/Keyboard appear cosmetic/unrelated — minor but fine to bundle

No security concerns — this is purely display/formatting logic with no impact on key handling, signing, or VTXO operations.

LGTM on the new commits. 👍

@bordalix
bordalix merged commit 7234508 into master Mar 23, 2026
5 of 6 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 24, 2026
TaprootFreak pushed a commit to TaprootFreak/wallet that referenced this pull request Mar 27, 2026
* adds support to JPY and CNY

* fix: Per ISO 4217 standards, CNY (Chinese Yuan) has a minor unit exponent of 2

* prevent division by zero

* fix Keyboard with JPY
@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2026
@bordalix
bordalix deleted the add_more_fiat_currencies branch May 18, 2026 16:12
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.

Add more fiat currencies

1 participant