From 3147a2df4bf22d4284a38d4369b6faff468db56c Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Thu, 19 Feb 2026 10:57:12 -0500 Subject: [PATCH] fix: respect forceUnit across keypad and conversion display --- components/AmountInput.tsx | 13 +++++++++---- components/Conversion.tsx | 14 ++++++-------- components/KeypadAmountDisplay.tsx | 6 ++++-- views/AmountKeypad.tsx | 16 ++++++++++++---- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/components/AmountInput.tsx b/components/AmountInput.tsx index 2623d5321..fb4b54fa5 100644 --- a/components/AmountInput.tsx +++ b/components/AmountInput.tsx @@ -44,11 +44,11 @@ interface AmountInputState { satAmount: string | number; } -const getAmount = (sats: string | number) => { +const getAmount = (sats: string | number, forceUnit?: string) => { const { fiatRates } = fiatStore; const { settings } = settingsStore; const { fiat } = settings; - const { units } = unitsStore; + const units = forceUnit || unitsStore.units; // replace , with . for unit separator const value = sats ? sats.toString().replace(/,/g, '.') : ''; @@ -133,8 +133,12 @@ export default class AmountInput extends React.Component< }; getDisplayValue = (): string => { - const { amount, sats } = this.props; - return amount !== undefined ? amount : sats ? getAmount(sats) : '0'; + const { amount, sats, forceUnit } = this.props; + return amount !== undefined + ? amount + : sats + ? getAmount(sats, forceUnit) + : '0'; }; openKeypad = () => { @@ -155,6 +159,7 @@ export default class AmountInput extends React.Component< NavigationService.navigate('AmountKeypad', { initialAmount: displayValue || '0', hideUnitChangeButton, + forceUnit: this.props.forceUnit, onConfirm: (newAmount: string) => { const { onAmountChange, forceUnit } = this.props; const satAmount = getSatAmount(newAmount, forceUnit); diff --git a/components/Conversion.tsx b/components/Conversion.tsx index e0319b6cf..03c572fb5 100644 --- a/components/Conversion.tsx +++ b/components/Conversion.tsx @@ -20,6 +20,7 @@ interface ConversionProps { sats?: string | number; satsPending?: string | number; colorOverride?: string; + forceUnit?: string; FiatStore?: FiatStore; UnitsStore?: UnitsStore; SettingsStore?: SettingsStore; @@ -55,10 +56,11 @@ export default class Conversion extends React.Component< UnitsStore, SettingsStore, colorOverride, + forceUnit, sensitive } = this.props; const { showRate } = this.state; - const { units } = UnitsStore!; + const units = forceUnit || UnitsStore!.units; const { settings } = SettingsStore!; const { fiatEnabled } = settings; @@ -70,7 +72,7 @@ export default class Conversion extends React.Component< } else { satAmount = Number.isNaN(Number(amount)) ? 0 - : getSatAmount(amount ?? 0); + : getSatAmount(amount ?? 0, forceUnit); } if (!fiatEnabled || (!amount && !sats)) return; @@ -98,9 +100,7 @@ export default class Conversion extends React.Component< colorOverride || themeColor('secondaryText') }} > - {` | ${getRate( - this.props.UnitsStore?.units === 'sats' - )}`} + {` | ${getRate(units === 'sats')}`} )} @@ -145,9 +145,7 @@ export default class Conversion extends React.Component< colorOverride || themeColor('secondaryText') }} > - {` | ${getRate( - this.props.UnitsStore?.units === 'sats' - )}`} + {` | ${getRate(units === 'sats')}`} )} diff --git a/components/KeypadAmountDisplay.tsx b/components/KeypadAmountDisplay.tsx index 3c3680f95..f49e5dd8f 100644 --- a/components/KeypadAmountDisplay.tsx +++ b/components/KeypadAmountDisplay.tsx @@ -25,6 +25,7 @@ interface KeypadAmountDisplayProps { lineHeight?: number; containerStyle?: ViewStyle; childrenBeforeConversion?: boolean; + forceUnit?: string; FiatStore?: FiatStore; UnitsStore?: UnitsStore; children?: React.ReactNode; @@ -44,11 +45,12 @@ export default class KeypadAmountDisplay extends React.Component - + ); diff --git a/views/AmountKeypad.tsx b/views/AmountKeypad.tsx index 6fca2d275..c6d573aa1 100644 --- a/views/AmountKeypad.tsx +++ b/views/AmountKeypad.tsx @@ -33,6 +33,7 @@ interface AmountKeypadProps { { initialAmount?: string; hideUnitChangeButton?: boolean; + forceUnit?: 'sats' | 'BTC' | 'fiat'; onConfirm?: (amount: string) => void; } >; @@ -63,10 +64,15 @@ export default class AmountKeypad extends React.Component< }; } + getEffectiveUnits = (): string => { + const forceUnit = this.props.route.params?.forceUnit; + return forceUnit || this.props.UnitsStore!.units; + }; + appendValue = (value: string): boolean => { const { amount } = this.state; - const { FiatStore, SettingsStore, UnitsStore } = this.props; - const { units } = UnitsStore!; + const { FiatStore, SettingsStore } = this.props; + const units = this.getEffectiveUnits(); const { valid, newAmount } = validateKeypadInput( amount, @@ -128,7 +134,7 @@ export default class AmountKeypad extends React.Component< getAmountFontSize = () => { const { amount } = this.state; - const { units } = this.props.UnitsStore!; + const units = this.getEffectiveUnits(); const { count } = getDecimalPlaceholder(amount, units); return getAmountFontSize(amount.length, count); }; @@ -137,6 +143,7 @@ export default class AmountKeypad extends React.Component< const { navigation, route } = this.props; const { amount } = this.state; const hideUnitChangeButton = route.params?.hideUnitChangeButton; + const forceUnit = route.params?.forceUnit; const fontSize = this.getAmountFontSize(); @@ -161,9 +168,10 @@ export default class AmountKeypad extends React.Component< shakeAnimation={this.shakeAnimation} textAnimation={this.textAnimation} fontSize={fontSize} + forceUnit={forceUnit} showConversion > - {!hideUnitChangeButton && ( + {!hideUnitChangeButton && !forceUnit && (