Skip to content

Commit 7db61d5

Browse files
committed
fix: change unit on QuickConfirm screen
1 parent 3da0c20 commit 7db61d5

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/navigation/lightning/LightningNavigator.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Success from '../../screens/Lightning/Success';
1919
import LNURLChannel from '../../screens/Lightning/LNURLChannel';
2020
import LNURLChannelSuccess from '../../screens/Lightning/LNURLChannelSuccess';
2121
import { __E2E__ } from '../../constants/env';
22+
import { EUnit } from '../../store/types/wallet';
2223

2324
export type LightningNavigationProp =
2425
NativeStackNavigationProp<LightningStackParamList>;
@@ -30,6 +31,7 @@ export type LightningStackParamList = {
3031
QuickConfirm: {
3132
spendingAmount: number;
3233
orderId?: string;
34+
onChangeUnitOutside: (nextUnit: EUnit) => void;
3335
};
3436
CustomSetup: { spending: boolean; spendingAmount?: number };
3537
CustomConfirm: {

src/screens/Lightning/QuickConfirm.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ReactElement, useMemo, useState } from 'react';
2-
import { StyleSheet, View } from 'react-native';
2+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
33
import { Trans, useTranslation } from 'react-i18next';
44

55
import { Caption13Up, Display, BodyMB, BodyM } from '../../styles/text';
@@ -11,7 +11,7 @@ import Percentage from '../../components/Percentage';
1111
import SwipeToConfirm from '../../components/SwipeToConfirm';
1212
import Money from '../../components/Money';
1313
import PieChart from './PieChart';
14-
import { useBalance } from '../../hooks/wallet';
14+
import { useBalance, useSwitchUnit } from '../../hooks/wallet';
1515
import { useAppSelector } from '../../hooks/redux';
1616
import { useCurrency, useDisplayValues } from '../../hooks/displayValues';
1717
import type { LightningScreenProps } from '../../navigation/types';
@@ -21,6 +21,7 @@ import {
2121
selectedNetworkSelector,
2222
transactionFeeSelector,
2323
} from '../../store/reselect/wallet';
24+
import { unitSelector } from '../../store/reselect/settings';
2425

2526
const PIE_SIZE = 140;
2627
const PIE_SHIFT = 70;
@@ -29,12 +30,14 @@ const QuickConfirm = ({
2930
navigation,
3031
route,
3132
}: LightningScreenProps<'QuickConfirm'>): ReactElement => {
32-
const { spendingAmount, orderId } = route.params;
33+
const { spendingAmount, orderId, onChangeUnitOutside } = route.params;
3334
const { onchainBalance, lightningBalance } = useBalance();
3435
const { t } = useTranslation('lightning');
3536
const orders = useAppSelector(blocktankOrdersSelector);
3637
const transactionFee = useAppSelector(transactionFeeSelector);
3738
const selectedNetwork = useAppSelector(selectedNetworkSelector);
39+
const switchUnit = useSwitchUnit();
40+
const unit = useAppSelector(unitSelector);
3841
const [loading, setLoading] = useState(false);
3942

4043
const order = useMemo(() => {
@@ -84,6 +87,9 @@ const QuickConfirm = ({
8487
onClosePress={(): void => {
8588
navigation.navigate('Wallet');
8689
}}
90+
onBackPress={(): void => {
91+
onChangeUnitOutside(unit);
92+
}}
8793
/>
8894
<View style={styles.content} testID="Confirm">
8995
<Display>
@@ -131,12 +137,12 @@ const QuickConfirm = ({
131137
</View>
132138
</View>
133139

134-
<View style={styles.amountContainer}>
140+
<TouchableOpacity onPress={switchUnit} style={styles.amountContainer}>
135141
<Caption13Up style={styles.amountCaption} color="purple">
136142
{t('spending_label')}
137143
</Caption13Up>
138144
<Money sats={spendingAmount} size="displayT" symbol={true} />
139-
</View>
145+
</TouchableOpacity>
140146

141147
<SwipeToConfirm
142148
text={t('transfer.swipe')}

src/screens/Lightning/QuickSetup.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
nextUnitSelector,
4343
unitSelector,
4444
} from '../../store/reselect/settings';
45+
import { EUnit } from '../../store/types/wallet';
4546

4647
const QuickSetup = ({
4748
navigation,
@@ -117,11 +118,20 @@ const QuickSetup = ({
117118
setTextFieldValue(result);
118119
}, [lnSetup.slider.maxValue, denomination, unit]);
119120

120-
const onChangeUnit = (): void => {
121+
const onChangeUnit = useCallback((): void => {
121122
const result = getNumberPadText(spendingAmount, denomination, nextUnit);
122123
setTextFieldValue(result);
123124
switchUnit();
124-
};
125+
}, [denomination, spendingAmount, nextUnit, switchUnit]);
126+
127+
/** Used to update the unit on other screens */
128+
const onChangeUnitOutside = useCallback(
129+
(newUnit: EUnit): void => {
130+
const result = getNumberPadText(spendingAmount, denomination, newUnit);
131+
setTextFieldValue(result);
132+
},
133+
[denomination, spendingAmount],
134+
);
125135

126136
const onSliderChange = useCallback(
127137
(value: number) => {
@@ -155,7 +165,10 @@ const QuickSetup = ({
155165
}
156166

157167
if (isTransferringToSavings) {
158-
navigation.navigate('QuickConfirm', { spendingAmount });
168+
navigation.navigate('QuickConfirm', {
169+
spendingAmount,
170+
onChangeUnitOutside,
171+
});
159172
return;
160173
}
161174

@@ -181,13 +194,15 @@ const QuickSetup = ({
181194
navigation.push('QuickConfirm', {
182195
spendingAmount,
183196
orderId: purchaseResponse.value.id,
197+
onChangeUnitOutside,
184198
});
185199
}, [
186200
lnSetup,
187201
max0ConfClientBalance,
188202
navigation,
189203
sliderActive,
190204
spendingAmount,
205+
onChangeUnitOutside,
191206
t,
192207
]);
193208

0 commit comments

Comments
 (0)