Skip to content

Commit

Permalink
fix: change unit on QuickConfirm screen
Browse files Browse the repository at this point in the history
  • Loading branch information
limpbrains committed May 31, 2024
1 parent 39b58c8 commit b4d5e0f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/navigation/lightning/LightningNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<LightningStackParamList>;
Expand All @@ -30,6 +31,7 @@ export type LightningStackParamList = {
QuickConfirm: {
spendingAmount: number;
orderId?: string;
onChangeUnitOutside: (nextUnit: EUnit) => void;
};
CustomSetup: { spending: boolean; spendingAmount?: number };
CustomConfirm: {
Expand Down
16 changes: 11 additions & 5 deletions src/screens/Lightning/QuickConfirm.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -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;
Expand All @@ -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(() => {
Expand Down Expand Up @@ -85,6 +88,9 @@ const QuickConfirm = ({
onClosePress={(): void => {
navigation.navigate('Wallet');
}}
onBackPress={(): void => {
onChangeUnitOutside(unit);
}}
/>
<View style={styles.content} testID="Confirm">
<Display>
Expand Down Expand Up @@ -132,12 +138,12 @@ const QuickConfirm = ({
</View>
</View>

<View style={styles.amountContainer}>
<TouchableOpacity onPress={switchUnit} style={styles.amountContainer}>
<Caption13Up style={styles.amountCaption} color="purple">
{t('spending_label')}
</Caption13Up>
<Money sats={spendingAmount} size="displayT" symbol={true} />
</View>
</TouchableOpacity>

<SwipeToConfirm
text={t('transfer.swipe')}
Expand Down
21 changes: 18 additions & 3 deletions src/screens/Lightning/QuickSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
nextUnitSelector,
unitSelector,
} from '../../store/reselect/settings';
import { EUnit } from '../../store/types/wallet';

const QuickSetup = ({
navigation,
Expand Down Expand Up @@ -117,11 +118,20 @@ const QuickSetup = ({
setTextFieldValue(result);
}, [lnSetup.slider.maxValue, denomination, unit]);

const onChangeUnit = (): void => {
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) => {
Expand Down Expand Up @@ -155,7 +165,10 @@ const QuickSetup = ({
}

if (isTransferringToSavings) {
navigation.navigate('QuickConfirm', { spendingAmount });
navigation.navigate('QuickConfirm', {
spendingAmount,
onChangeUnitOutside,
});
return;
}

Expand All @@ -179,13 +192,15 @@ const QuickSetup = ({
navigation.push('QuickConfirm', {
spendingAmount,
orderId: purchaseResponse.value.id,
onChangeUnitOutside,
});
}, [
lnSetup,
max0ConfClientBalance,
navigation,
sliderActive,
spendingAmount,
onChangeUnitOutside,
t,
]);

Expand Down

0 comments on commit b4d5e0f

Please sign in to comment.