fix: respect forceUnit across keypad and conversion display
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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')}`}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
@@ -145,9 +145,7 @@ export default class Conversion extends React.Component<
|
||||
colorOverride || themeColor('secondaryText')
|
||||
}}
|
||||
>
|
||||
{` | ${getRate(
|
||||
this.props.UnitsStore?.units === 'sats'
|
||||
)}`}
|
||||
{` | ${getRate(units === 'sats')}`}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -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<KeypadAmountDis
|
||||
lineHeight = 80,
|
||||
containerStyle,
|
||||
childrenBeforeConversion = false,
|
||||
forceUnit,
|
||||
FiatStore,
|
||||
UnitsStore,
|
||||
children
|
||||
} = this.props;
|
||||
const { units } = UnitsStore!;
|
||||
const units = forceUnit || UnitsStore!.units;
|
||||
const { symbol, space, rtl, separatorSwap } =
|
||||
units === 'fiat'
|
||||
? FiatStore!.getSymbol()
|
||||
@@ -97,7 +99,7 @@ export default class KeypadAmountDisplay extends React.Component<KeypadAmountDis
|
||||
...(conversionTop !== undefined && { top: conversionTop })
|
||||
}}
|
||||
>
|
||||
<Conversion amount={amount} />
|
||||
<Conversion amount={amount} forceUnit={forceUnit} />
|
||||
</View>
|
||||
);
|
||||
|
||||
|
||||
+12
-4
@@ -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 && (
|
||||
<View style={styles.unitToggleContainer}>
|
||||
<UnitToggle
|
||||
onToggle={this.handleUnitToggle}
|
||||
|
||||
Reference in New Issue
Block a user