From b4d5e0fdfa1aa08d80a04c3a368efeff7e7965ed Mon Sep 17 00:00:00 2001 From: Ivan Vershigora Date: Fri, 31 May 2024 12:53:34 +0100 Subject: [PATCH] fix: change unit on QuickConfirm screen --- .../lightning/LightningNavigator.tsx | 2 ++ src/screens/Lightning/QuickConfirm.tsx | 16 +++++++++----- src/screens/Lightning/QuickSetup.tsx | 21 ++++++++++++++++--- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/navigation/lightning/LightningNavigator.tsx b/src/navigation/lightning/LightningNavigator.tsx index 6cbc707e6..34753fc67 100644 --- a/src/navigation/lightning/LightningNavigator.tsx +++ b/src/navigation/lightning/LightningNavigator.tsx @@ -19,6 +19,7 @@ import Success from '../../screens/Lightning/Success'; import LNURLChannel from '../../screens/Lightning/LNURLChannel'; import LNURLChannelSuccess from '../../screens/Lightning/LNURLChannelSuccess'; import { __E2E__ } from '../../constants/env'; +import { EUnit } from '../../store/types/wallet'; export type LightningNavigationProp = NativeStackNavigationProp; @@ -30,6 +31,7 @@ export type LightningStackParamList = { QuickConfirm: { spendingAmount: number; orderId?: string; + onChangeUnitOutside: (nextUnit: EUnit) => void; }; CustomSetup: { spending: boolean; spendingAmount?: number }; CustomConfirm: { diff --git a/src/screens/Lightning/QuickConfirm.tsx b/src/screens/Lightning/QuickConfirm.tsx index b9f67894b..76c19ac1f 100644 --- a/src/screens/Lightning/QuickConfirm.tsx +++ b/src/screens/Lightning/QuickConfirm.tsx @@ -1,5 +1,5 @@ import React, { ReactElement, useMemo, useState } from 'react'; -import { StyleSheet, View } from 'react-native'; +import { StyleSheet, TouchableOpacity, View } from 'react-native'; import { Trans, useTranslation } from 'react-i18next'; import { Caption13Up, Display, BodyMB, BodyM } from '../../styles/text'; @@ -11,7 +11,7 @@ import Percentage from '../../components/Percentage'; import SwipeToConfirm from '../../components/SwipeToConfirm'; import Money from '../../components/Money'; import PieChart from './PieChart'; -import { useBalance } from '../../hooks/wallet'; +import { useBalance, useSwitchUnit } from '../../hooks/wallet'; import { useAppSelector } from '../../hooks/redux'; import { useCurrency, useDisplayValues } from '../../hooks/displayValues'; import type { LightningScreenProps } from '../../navigation/types'; @@ -21,6 +21,7 @@ import { selectedNetworkSelector, transactionFeeSelector, } from '../../store/reselect/wallet'; +import { unitSelector } from '../../store/reselect/settings'; const PIE_SIZE = 140; const PIE_SHIFT = 70; @@ -29,12 +30,14 @@ const QuickConfirm = ({ navigation, route, }: LightningScreenProps<'QuickConfirm'>): ReactElement => { - const { spendingAmount, orderId } = route.params; + const { spendingAmount, orderId, onChangeUnitOutside } = route.params; const { onchainBalance, lightningBalance } = useBalance(); const { t } = useTranslation('lightning'); const orders = useAppSelector(blocktankOrdersSelector); const transactionFee = useAppSelector(transactionFeeSelector); const selectedNetwork = useAppSelector(selectedNetworkSelector); + const switchUnit = useSwitchUnit(); + const unit = useAppSelector(unitSelector); const [loading, setLoading] = useState(false); const order = useMemo(() => { @@ -85,6 +88,9 @@ const QuickConfirm = ({ onClosePress={(): void => { navigation.navigate('Wallet'); }} + onBackPress={(): void => { + onChangeUnitOutside(unit); + }} /> @@ -132,12 +138,12 @@ const QuickConfirm = ({ - + {t('spending_label')} - + { + const onChangeUnit = useCallback((): void => { const result = getNumberPadText(spendingAmount, denomination, nextUnit); setTextFieldValue(result); switchUnit(); - }; + }, [denomination, spendingAmount, nextUnit, switchUnit]); + + /** Used to update the unit on other screens */ + const onChangeUnitOutside = useCallback( + (newUnit: EUnit): void => { + const result = getNumberPadText(spendingAmount, denomination, newUnit); + setTextFieldValue(result); + }, + [denomination, spendingAmount], + ); const onSliderChange = useCallback( (value: number) => { @@ -155,7 +165,10 @@ const QuickSetup = ({ } if (isTransferringToSavings) { - navigation.navigate('QuickConfirm', { spendingAmount }); + navigation.navigate('QuickConfirm', { + spendingAmount, + onChangeUnitOutside, + }); return; } @@ -179,6 +192,7 @@ const QuickSetup = ({ navigation.push('QuickConfirm', { spendingAmount, orderId: purchaseResponse.value.id, + onChangeUnitOutside, }); }, [ lnSetup, @@ -186,6 +200,7 @@ const QuickSetup = ({ navigation, sliderActive, spendingAmount, + onChangeUnitOutside, t, ]);