Skip to content

Fiat currency display support - #4

Merged
joemarct merged 12 commits into
masterfrom
fiat-currency-display
Sep 7, 2026
Merged

joemarct merged 12 commits into
masterfrom
fiat-currency-display

Conversation

@joemarct

@joemarct joemarct commented Sep 7, 2026

Copy link
Copy Markdown
Member

Overview

Prepares the CLI for multicurrency fiat support by standardizing how fiat amounts are displayed and enriching wallet output with fiat conversions. The default display currency is USD (rendered as N USD); a user-configurable currency will come in a later version.

Changes

  • send: Show the USD conversion inline with the amount, e.g. Sending 0.00046359 BCH (≈ 1.20 USD) on mainnet, replacing the separate conversion line. Also replaces the --unit option with a positional [currency] argument (bch, sats/satoshis, or usd), e.g. paytaca send <address> 0.12 usd.
  • balance: Add fiat conversion for both BCH and CashToken balances (e.g. Balance: 23.57 LIFT / ≈ 3.17 USD). Drop the Spendable and satoshi lines from the default BCH view; remove the token Spendable concept.
  • swap: Rename the --direction option to --action (values sell / buy).
  • prices util: Format fiat values as N USD instead of $N across all commands (send, balance, wallet info, history, token).
  • Bump package version to v0.5.1.

Notes

All fiat output flows through formatUsd, so switching to another currency later is a single-point change.

joemarct and others added 9 commits September 7, 2026 21:23
- Fetch BCH-USD price via watchtower.cash asset-prices API
- Display USD value below the BCH balance line
- Remove Spendable balance line (causes more confusion than clarity)
…_price

Each history entry from Watchtower already includes the BCH-USD rate
at that moment (usd_price), so we display the USD conversion inline:
  IN  +0.00362899 BCH | ≈ /bin/zsh.93
  paytaca send <addr> 5 --unit usd    → converts $5 to BCH at current rate
  paytaca send <addr> 1000 --unit sats → converts 1000 sats to 0.00001 BCH
  paytaca send <addr> 0.01             → default BCH (unchanged)

  Displays the exchange rate when using USD.
Co-authored-by: joemarct <joemarct@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Build passes and all 88 tests pass. Reviewed the 8 changed files for security, correctness, and style.

Security Review

  • No new secret handling. No changes to mnemonic generation, key derivation, keychain storage, or signing logic.
  • No new trust boundaries. Price data still comes from the existing Watchtower API (getWatchtowerApiUrl), wrapped in try/catch with graceful degradation.
  • USD conversion in send is non-blind. When currency is usd, the computed BCH amount is printed before the user confirms (or before --yes skips the prompt), so the external price does not silently alter the transaction.
  • No secrets in output. formatUsd only formats numbers; no keys, phrases, or WIFs are logged.

Issues Found

1. Style / indentation — src/commands/swap.ts line 72

The const direction declaration is missing its leading indentation, making it flush with the block:

      const network = 'mainnet'
const direction: SwapDirection =
       opts.action === 'buy' ? 'buy' : 'sell'

Fix: restore consistent indentation:

      const direction: SwapDirection =
        opts.action === 'buy' ? 'buy' : 'sell'

2. Missing trailing newline — src/utils/prices.ts

The file now ends without a newline (\ No newline at end of file). Minor but worth fixing.

3. UI inconsistency — src/commands/wallet.ts vs balance.ts

wallet info shows the fiat value in chalk.green, while balance and history use chalk.dim. Consider aligning them (e.g., all chalk.dim for the fiat line) so the CLI has a consistent visual hierarchy.

4. Breaking CLI change — send argument structure

The send command changes from:

paytaca send <address> <amount> --unit sats

to:

paytaca send <address> <amount> [currency]

This is a breaking change for scripts using --unit. The PR description doesn't explicitly call this out; it only mentions "Show the USD conversion inline with the amount." Consider adding a note to the PR body so users know to update their scripts.

5. send formatting edge case

amountBch.toFixed(8).replace(/\.?0+$/, '') is slightly unconventional. For toFixed(8) output it works, but \.?0+$ is broader than necessary. A clearer pattern is replace(/\.0+$/, '').replace(/\.$/, '') or using a small helper. Not a bug, just a readability note.

Verdict

The changes are clean, well-scoped, and do what the PR description promises. The single-point formatUsd abstraction is a good foundation for future multicurrency support. Approve with minor fixes (indentation in swap.ts, trailing newline in prices.ts, and optional UI color alignment).

New%20session%20-%202026-09-07T15%3A45%3A07.797Z
opencode session  |  github run

@paytaca paytaca deleted a comment from github-actions Bot Sep 7, 2026
@paytaca paytaca deleted a comment from github-actions Bot Sep 7, 2026
Co-authored-by: joemarct <joemarct@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Build passes and all 88 tests pass. I made two minor fixes:

1. Missing trailing newline (src/utils/prices.ts) — Added the trailing newline that was missing after the formatUsd refactor.

2. Invalid price guard (src/utils/prices.ts) — Changed raw === 0 to raw <= 0 in priceInUsd. This prevents negative or zero prices from being returned and used downstream (e.g., in the new send <amount> usd path where a zero/negative price would cause a division-by-zero or inverted-sign transaction amount). Since market prices are never negative, this is a safe hardening change.

Review summary:

  • Security: No new secret handling or signing changes. Price data still comes from the existing Watchtower API, wrapped in try/catch with graceful degradation. The new send ... usd flow prints the computed BCH amount before broadcasting, so the external price cannot silently alter the transaction.
  • Correctness: The formatUsd refactor is clean and consistent across send, balance, wallet info, history, and token. The send positional [currency] argument is straightforward.
  • Breaking change: The send command replaces --unit <unit> with a positional [currency] argument. This is a breaking change for scripts using --unit — worth highlighting in release notes.
  • Minor note: balance.ts still computes spendableSats but no longer uses it in the default BCH view (only in --sats mode). This is harmless dead code leftover from the intentional removal of the Spendable line.

Approve with the two fixes applied.

New%20session%20-%202026-09-07T16%3A19%3A52.287Z
opencode session  |  github run

@paytaca paytaca deleted a comment from github-actions Bot Sep 7, 2026
@joemarct
joemarct merged commit 0f83410 into master Sep 7, 2026
1 check failed
@joemarct
joemarct deleted the fiat-currency-display branch September 7, 2026 16:33
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