Skip to content

Commit 3913667

Browse files
authored
fix(send): update review screen (#2398)
1 parent 8529ce2 commit 3913667

File tree

19 files changed

+231
-173
lines changed

19 files changed

+231
-173
lines changed

e2e/send.e2e.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,33 @@ d('Send', () => {
299299
.toHaveText('129 502')
300300
.withTimeout(10000);
301301

302-
// send to unified invoice w/ amount
302+
// can edit invoice on the review screen
303303
const { paymentRequest: invoice2 } = await lnd.addInvoice({ value: 10000 });
304+
await enterAddress(invoice2);
305+
let attributes = await element(
306+
by.id('ReviewAmount-primary'),
307+
).getAttributes();
308+
let amount = attributes.label;
309+
jestExpect(amount).toBe('10 000');
310+
await element(by.id('ReviewUri')).tap();
311+
await element(by.id('RecipientInput')).replaceText(onchainAddress);
312+
await element(by.id('RecipientInput')).tapReturnKey();
313+
await element(by.id('AddressContinue')).tap();
314+
await expect(element(by.id('AssetButton-savings'))).toBeVisible();
315+
await element(by.id('N2').withAncestor(by.id('SendAmountNumberPad'))).tap();
316+
await element(
317+
by.id('N0').withAncestor(by.id('SendAmountNumberPad')),
318+
).multiTap(4);
319+
await element(by.id('ContinueAmount')).tap();
320+
attributes = await element(by.id('ReviewAmount-primary')).getAttributes();
321+
amount = attributes.label;
322+
jestExpect(amount).toBe('20 000');
323+
await element(by.id('SendSheet')).swipe('down');
324+
325+
// send to unified invoice w/ amount
326+
const { paymentRequest: invoice3 } = await lnd.addInvoice({ value: 10000 });
304327
const unified1 = encode(onchainAddress, {
305-
lightning: invoice2,
328+
lightning: invoice3,
306329
amount: 10000,
307330
});
308331

@@ -319,11 +342,11 @@ d('Send', () => {
319342
.withTimeout(10000);
320343

321344
// send to unified invoice w/ amount exceeding balance(s)
322-
const { paymentRequest: invoice3 } = await lnd.addInvoice({
345+
const { paymentRequest: invoice4 } = await lnd.addInvoice({
323346
value: 200000,
324347
});
325348
const unified2 = encode(onchainAddress, {
326-
lightning: invoice3,
349+
lightning: invoice4,
327350
amount: 200000,
328351
});
329352

@@ -369,8 +392,8 @@ d('Send', () => {
369392
.withTimeout(10000);
370393

371394
// send to unified invoice w/o amount (lightning)
372-
const { paymentRequest: invoice4 } = await lnd.addInvoice();
373-
const unified4 = encode(onchainAddress, { lightning: invoice4 });
395+
const { paymentRequest: invoice5 } = await lnd.addInvoice();
396+
const unified4 = encode(onchainAddress, { lightning: invoice5 });
374397

375398
await enterAddress(unified4);
376399
// max amount (lightning)
@@ -396,8 +419,8 @@ d('Send', () => {
396419
.withTimeout(10000);
397420

398421
// send to unified invoice w/o amount (switch to onchain)
399-
const { paymentRequest: invoice5 } = await lnd.addInvoice();
400-
const unified5 = encode(onchainAddress, { lightning: invoice5 });
422+
const { paymentRequest: invoice6 } = await lnd.addInvoice();
423+
const unified5 = encode(onchainAddress, { lightning: invoice6 });
401424

402425
await enterAddress(unified5);
403426

@@ -434,7 +457,7 @@ d('Send', () => {
434457
.withTimeout(10000);
435458

436459
// send to lightning invoice w/ amount (quickpay)
437-
const { paymentRequest: invoice6 } = await lnd.addInvoice({ value: 1000 });
460+
const { paymentRequest: invoice7 } = await lnd.addInvoice({ value: 1000 });
438461

439462
// enable quickpay
440463
await element(by.id('Settings')).tap();
@@ -444,7 +467,7 @@ d('Send', () => {
444467
await element(by.id('QuickpayToggle')).tap();
445468
await element(by.id('NavigationClose')).tap();
446469

447-
await enterAddress(invoice6);
470+
await enterAddress(invoice7);
448471
await waitFor(element(by.id('SendSuccess')))
449472
.toBeVisible()
450473
.withTimeout(10000);
@@ -456,9 +479,9 @@ d('Send', () => {
456479
.withTimeout(10000);
457480

458481
// send to unified invoice w/ amount (quickpay)
459-
const { paymentRequest: invoice7 } = await lnd.addInvoice({ value: 1000 });
482+
const { paymentRequest: invoice8 } = await lnd.addInvoice({ value: 1000 });
460483
const unified7 = encode(onchainAddress, {
461-
lightning: invoice7,
484+
lightning: invoice8,
462485
amount: 1000,
463486
});
464487

@@ -474,8 +497,8 @@ d('Send', () => {
474497
.withTimeout(10000);
475498

476499
// send to lightning invoice w/ amount (skip quickpay for large amounts)
477-
const { paymentRequest: invoice8 } = await lnd.addInvoice({ value: 10000 });
478-
await enterAddress(invoice8);
500+
const { paymentRequest: invoice9 } = await lnd.addInvoice({ value: 10000 });
501+
await enterAddress(invoice9);
479502
await expect(element(by.id('ReviewAmount'))).toBeVisible();
480503
await element(by.id('SendSheet')).swipe('down');
481504

src/components/Money.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ const Money = (props: MoneyProps): ReactElement => {
133133
}
134134

135135
return (
136-
<View style={[styles.root, props.style]} testID={testID}>
136+
<View
137+
style={[styles.root, props.style]}
138+
accessibilityLabel={text}
139+
testID={testID}>
137140
{sign && (
138141
<Text
139142
style={styles.sign}

src/navigation/bottom-sheet/SendNavigation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export type SendStackParamList = {
5151
PinCheck: { onSuccess: () => void };
5252
Recipient: undefined;
5353
Contacts: undefined;
54-
Address: undefined;
54+
Address: { uri?: string } | undefined;
5555
Scanner: undefined;
5656
Amount: undefined;
5757
CoinSelection: undefined;

src/screens/Settings/AddressViewer/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ import { updateWallet } from '../../../store/slices/wallet';
5656
import {
5757
resetSendTransaction,
5858
setupOnChainTransaction,
59-
updateSendTransaction,
59+
updateBeignetSendTransaction,
6060
} from '../../../store/actions/wallet';
61-
import { updateUi } from '../../../store/slices/ui';
61+
import { updateSendTransaction } from '../../../store/slices/ui';
6262
import { showBottomSheet } from '../../../store/utils/ui';
6363
import SearchInput from '../../../components/SearchInput';
6464
import AddressViewerListItem from './AddressViewerListItem';
@@ -640,11 +640,17 @@ const AddressViewer = ({
640640
if (receiveAddress.isErr()) {
641641
return;
642642
}
643-
updateSendTransaction({
643+
updateBeignetSendTransaction({
644644
...transactionRes.value,
645645
outputs: [{ address: receiveAddress.value, value: 0, index: 0 }],
646646
});
647-
dispatch(updateUi({ fromAddressViewer: true }));
647+
dispatch(
648+
updateSendTransaction({
649+
fromAddressViewer: true,
650+
paymentMethod: 'onchain',
651+
uri: receiveAddress.value,
652+
}),
653+
);
648654
sendMax();
649655
showBottomSheet('sendNavigation', { screen: 'ReviewAndSend' });
650656
},

src/screens/Transfer/ExternalNode/Confirm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { createFundedChannel } from '../../../utils/wallet/transfer';
1818
import { useAppSelector } from '../../../hooks/redux';
1919
import { TransferScreenProps } from '../../../navigation/types';
2020
import { transactionFeeSelector } from '../../../store/reselect/wallet';
21-
import { updateSendTransaction } from '../../../store/actions/wallet';
21+
import { updateBeignetSendTransaction } from '../../../store/actions/wallet';
2222

2323
const image = require('../../../assets/illustrations/coin-stack-x.png');
2424

@@ -38,7 +38,7 @@ const ExternalConfirm = ({
3838
useCallback(() => {
3939
// Using a placeholder address here to enable the FeeCustom screen to function properly.
4040
// The actual funding address will be updated later in createFundedChannel.
41-
updateSendTransaction({
41+
updateBeignetSendTransaction({
4242
outputs: [{ address: 'xxx', value: localBalance, index: 0 }],
4343
});
4444
}, [localBalance]),

src/screens/Wallets/AssetButton.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { Caption13Up } from '../../styles/text';
77
import { SwitchIcon } from '../../styles/icons';
88
import { useAppDispatch, useAppSelector } from '../../hooks/redux';
99
import useColors from '../../hooks/colors';
10-
import { updateUi } from '../../store/slices/ui';
10+
import { updateSendTransaction } from '../../store/slices/ui';
11+
import { sendTransactionSelector } from '../../store/reselect/ui';
1112

1213
const AssetButton = ({
1314
style,
@@ -21,9 +22,9 @@ const AssetButton = ({
2122
const { t } = useTranslation('wallet');
2223
const colors = useColors();
2324
const dispatch = useAppDispatch();
24-
const method = useAppSelector((state) => state.ui.paymentMethod);
25+
const { paymentMethod } = useAppSelector(sendTransactionSelector);
2526

26-
const usesLightning = method === 'lightning';
27+
const usesLightning = paymentMethod === 'lightning';
2728

2829
const canSwitch = savings && spending;
2930
const text = usesLightning ? t('spending.title') : t('savings.title');
@@ -38,8 +39,8 @@ const AssetButton = ({
3839
};
3940

4041
const onSwitch = (): void => {
41-
const paymentMethod = usesLightning ? 'onchain' : 'lightning';
42-
dispatch(updateUi({ paymentMethod }));
42+
const method = paymentMethod === 'lightning' ? 'onchain' : 'lightning';
43+
dispatch(updateSendTransaction({ paymentMethod: method }));
4344
};
4445

4546
if (!canSwitch) {

src/screens/Wallets/Send/Address.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ type TValidation = {
2020
[x: string]: boolean;
2121
};
2222

23-
const Address = ({}: SendScreenProps<'Address'>): ReactElement => {
23+
const Address = ({ route }: SendScreenProps<'Address'>): ReactElement => {
24+
const uri = route.params?.uri ?? '';
2425
const colors = useColors();
2526
const { t } = useTranslation('wallet');
2627
const { keyboardShown } = useKeyboard();
27-
const [textFieldValue, setTextFieldValue] = useState('');
28-
const [isValid, setIsValid] = useState<TValidation>({});
28+
const [textFieldValue, setTextFieldValue] = useState(uri);
29+
// if a URI is passed in, we assume it's valid
30+
const [isValid, setIsValid] = useState<TValidation>({ [uri]: !!uri });
2931

3032
const onChangeText = async (text: string): Promise<void> => {
3133
const diff = Math.abs(text.length - textFieldValue.length);

src/screens/Wallets/Send/Amount.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ import { useBalance, useSwitchUnit } from '../../../hooks/wallet';
4848
import {
4949
setupFeeForOnChainTransaction,
5050
setupOnChainTransaction,
51-
updateSendTransaction,
51+
updateBeignetSendTransaction,
5252
} from '../../../store/actions/wallet';
5353
import { getNumberPadText } from '../../../utils/numberpad';
5454
import { showToast } from '../../../utils/notifications';
5555
import { convertToSats } from '../../../utils/conversion';
5656
import { TRANSACTION_DEFAULTS } from '../../../utils/wallet/constants';
5757
import type { SendScreenProps } from '../../../navigation/types';
58+
import { sendTransactionSelector } from '../../../store/reselect/ui';
5859

5960
const Amount = ({ navigation }: SendScreenProps<'Amount'>): ReactElement => {
6061
const route = useRoute();
@@ -74,23 +75,23 @@ const Amount = ({ navigation }: SendScreenProps<'Amount'>): ReactElement => {
7475
const utxos = useAppSelector(utxosSelector);
7576
const { onchainBalance } = useBalance();
7677

77-
const method = useAppSelector((state) => state.ui.paymentMethod);
78-
const usesLightning = method === 'lightning';
78+
const { paymentMethod } = useAppSelector(sendTransactionSelector);
79+
const usesLightning = paymentMethod === 'lightning';
7980

8081
const outputAmount = useMemo(() => {
8182
const amount = getTransactionOutputValue({ outputs: transaction.outputs });
8283
return amount;
8384
}, [transaction.outputs]);
8485

8586
const availableAmount = useMemo(() => {
86-
const maxAmountResponse = getMaxSendAmount({ method });
87+
const maxAmountResponse = getMaxSendAmount({ method: paymentMethod });
8788
if (maxAmountResponse.isOk()) {
8889
return maxAmountResponse.value.amount;
8990
}
9091
return 0;
9192
// recalculate max when utxos, fee or payment method change
9293
// eslint-disable-next-line react-hooks/exhaustive-deps
93-
}, [transaction.outputs, transaction.satsPerByte, method]);
94+
}, [transaction.outputs, transaction.satsPerByte, paymentMethod]);
9495

9596
useFocusEffect(
9697
useCallback(() => {
@@ -145,11 +146,11 @@ const Amount = ({ navigation }: SendScreenProps<'Amount'>): ReactElement => {
145146
return;
146147
}
147148
if (isMaxSendAmount && amount !== availableAmount) {
148-
updateSendTransaction({ max: false });
149+
updateBeignetSendTransaction({ max: false });
149150
}
150151

151152
if (!isMaxSendAmount && amount === availableAmount) {
152-
updateSendTransaction({ max: true });
153+
updateBeignetSendTransaction({ max: true });
153154
}
154155
}, [isMaxSendAmount, amount, availableAmount, transaction?.lightningInvoice]);
155156

src/screens/Wallets/Send/Error.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
resetSendTransaction,
1616
setupOnChainTransaction,
1717
} from '../../../store/actions/wallet';
18-
import { closeSheet, updateUi } from '../../../store/slices/ui';
18+
import { closeSheet, updateSendTransaction } from '../../../store/slices/ui';
1919
import { transactionSelector } from '../../../store/reselect/wallet';
2020

2121
const imageCross = require('../../../assets/illustrations/cross.png');
@@ -50,7 +50,7 @@ const Error = ({
5050

5151
const handleRetry = async (): Promise<void> => {
5252
if (isSlashpayLightning) {
53-
dispatch(updateUi({ paymentMethod: 'onchain' }));
53+
dispatch(updateSendTransaction({ paymentMethod: 'onchain' }));
5454
const res = await processUri({
5555
uri: slashTagsUrl,
5656
source: 'send',

0 commit comments

Comments
 (0)