Skip to content

Commit

Permalink
fix(send): update review screen
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed Dec 11, 2024
1 parent 37dd5ad commit eef957b
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 173 deletions.
51 changes: 37 additions & 14 deletions e2e/send.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,33 @@ d('Send', () => {
.toHaveText('129 502')
.withTimeout(10000);

// send to unified invoice w/ amount
// can edit invoice on the review screen
const { paymentRequest: invoice2 } = await lnd.addInvoice({ value: 10000 });
await enterAddress(invoice2);
let attributes = await element(
by.id('ReviewAmount-primary'),
).getAttributes();
let amount = attributes.label;
jestExpect(amount).toBe('10 000');
await element(by.id('ReviewUri')).tap();
await element(by.id('RecipientInput')).replaceText(onchainAddress);
await element(by.id('RecipientInput')).tapReturnKey();
await element(by.id('AddressContinue')).tap();
await expect(element(by.id('AssetButton-savings'))).toBeVisible();
await element(by.id('N2').withAncestor(by.id('SendAmountNumberPad'))).tap();
await element(
by.id('N0').withAncestor(by.id('SendAmountNumberPad')),
).multiTap(4);
await element(by.id('ContinueAmount')).tap();
attributes = await element(by.id('ReviewAmount-primary')).getAttributes();
amount = attributes.label;
jestExpect(amount).toBe('20 000');
await element(by.id('SendSheet')).swipe('down');

// send to unified invoice w/ amount
const { paymentRequest: invoice3 } = await lnd.addInvoice({ value: 10000 });
const unified1 = encode(onchainAddress, {
lightning: invoice2,
lightning: invoice3,
amount: 10000,
});

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

// send to unified invoice w/ amount exceeding balance(s)
const { paymentRequest: invoice3 } = await lnd.addInvoice({
const { paymentRequest: invoice4 } = await lnd.addInvoice({
value: 200000,
});
const unified2 = encode(onchainAddress, {
lightning: invoice3,
lightning: invoice4,
amount: 200000,
});

Expand Down Expand Up @@ -369,8 +392,8 @@ d('Send', () => {
.withTimeout(10000);

// send to unified invoice w/o amount (lightning)
const { paymentRequest: invoice4 } = await lnd.addInvoice();
const unified4 = encode(onchainAddress, { lightning: invoice4 });
const { paymentRequest: invoice5 } = await lnd.addInvoice();
const unified4 = encode(onchainAddress, { lightning: invoice5 });

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

// send to unified invoice w/o amount (switch to onchain)
const { paymentRequest: invoice5 } = await lnd.addInvoice();
const unified5 = encode(onchainAddress, { lightning: invoice5 });
const { paymentRequest: invoice6 } = await lnd.addInvoice();
const unified5 = encode(onchainAddress, { lightning: invoice6 });

await enterAddress(unified5);

Expand Down Expand Up @@ -434,7 +457,7 @@ d('Send', () => {
.withTimeout(10000);

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

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

await enterAddress(invoice6);
await enterAddress(invoice7);
await waitFor(element(by.id('SendSuccess')))
.toBeVisible()
.withTimeout(10000);
Expand All @@ -456,9 +479,9 @@ d('Send', () => {
.withTimeout(10000);

// send to unified invoice w/ amount (quickpay)
const { paymentRequest: invoice7 } = await lnd.addInvoice({ value: 1000 });
const { paymentRequest: invoice8 } = await lnd.addInvoice({ value: 1000 });
const unified7 = encode(onchainAddress, {
lightning: invoice7,
lightning: invoice8,
amount: 1000,
});

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

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

Expand Down
5 changes: 4 additions & 1 deletion src/components/Money.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ const Money = (props: MoneyProps): ReactElement => {
}

return (
<View style={[styles.root, props.style]} testID={testID}>
<View
style={[styles.root, props.style]}
accessibilityLabel={text}
testID={testID}>
{sign && (
<Text
style={styles.sign}
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/bottom-sheet/SendNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type SendStackParamList = {
PinCheck: { onSuccess: () => void };
Recipient: undefined;
Contacts: undefined;
Address: undefined;
Address: { uri?: string } | undefined;
Scanner: undefined;
Amount: undefined;
CoinSelection: undefined;
Expand Down
14 changes: 10 additions & 4 deletions src/screens/Settings/AddressViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ import { updateWallet } from '../../../store/slices/wallet';
import {
resetSendTransaction,
setupOnChainTransaction,
updateSendTransaction,
updateBeignetSendTransaction,
} from '../../../store/actions/wallet';
import { updateUi } from '../../../store/slices/ui';
import { updateSendTransaction } from '../../../store/slices/ui';
import { showBottomSheet } from '../../../store/utils/ui';
import SearchInput from '../../../components/SearchInput';
import AddressViewerListItem from './AddressViewerListItem';
Expand Down Expand Up @@ -640,11 +640,17 @@ const AddressViewer = ({
if (receiveAddress.isErr()) {
return;
}
updateSendTransaction({
updateBeignetSendTransaction({
...transactionRes.value,
outputs: [{ address: receiveAddress.value, value: 0, index: 0 }],
});
dispatch(updateUi({ fromAddressViewer: true }));
dispatch(
updateSendTransaction({
fromAddressViewer: true,
paymentMethod: 'onchain',
uri: receiveAddress.value,
}),
);
sendMax();
showBottomSheet('sendNavigation', { screen: 'ReviewAndSend' });
},
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Transfer/ExternalNode/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { createFundedChannel } from '../../../utils/wallet/transfer';
import { useAppSelector } from '../../../hooks/redux';
import { TransferScreenProps } from '../../../navigation/types';
import { transactionFeeSelector } from '../../../store/reselect/wallet';
import { updateSendTransaction } from '../../../store/actions/wallet';
import { updateBeignetSendTransaction } from '../../../store/actions/wallet';

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

Expand All @@ -38,7 +38,7 @@ const ExternalConfirm = ({
useCallback(() => {
// Using a placeholder address here to enable the FeeCustom screen to function properly.
// The actual funding address will be updated later in createFundedChannel.
updateSendTransaction({
updateBeignetSendTransaction({
outputs: [{ address: 'xxx', value: localBalance, index: 0 }],
});
}, [localBalance]),
Expand Down
11 changes: 6 additions & 5 deletions src/screens/Wallets/AssetButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Caption13Up } from '../../styles/text';
import { SwitchIcon } from '../../styles/icons';
import { useAppDispatch, useAppSelector } from '../../hooks/redux';
import useColors from '../../hooks/colors';
import { updateUi } from '../../store/slices/ui';
import { updateSendTransaction } from '../../store/slices/ui';
import { sendTransactionSelector } from '../../store/reselect/ui';

const AssetButton = ({
style,
Expand All @@ -21,9 +22,9 @@ const AssetButton = ({
const { t } = useTranslation('wallet');
const colors = useColors();
const dispatch = useAppDispatch();
const method = useAppSelector((state) => state.ui.paymentMethod);
const { paymentMethod } = useAppSelector(sendTransactionSelector);

const usesLightning = method === 'lightning';
const usesLightning = paymentMethod === 'lightning';

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

const onSwitch = (): void => {
const paymentMethod = usesLightning ? 'onchain' : 'lightning';
dispatch(updateUi({ paymentMethod }));
const method = paymentMethod === 'lightning' ? 'onchain' : 'lightning';
dispatch(updateSendTransaction({ paymentMethod: method }));
};

if (!canSwitch) {
Expand Down
8 changes: 5 additions & 3 deletions src/screens/Wallets/Send/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ type TValidation = {
[x: string]: boolean;
};

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

const onChangeText = async (text: string): Promise<void> => {
const diff = Math.abs(text.length - textFieldValue.length);
Expand Down
15 changes: 8 additions & 7 deletions src/screens/Wallets/Send/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ import { useBalance, useSwitchUnit } from '../../../hooks/wallet';
import {
setupFeeForOnChainTransaction,
setupOnChainTransaction,
updateSendTransaction,
updateBeignetSendTransaction,
} from '../../../store/actions/wallet';
import { getNumberPadText } from '../../../utils/numberpad';
import { showToast } from '../../../utils/notifications';
import { convertToSats } from '../../../utils/conversion';
import { TRANSACTION_DEFAULTS } from '../../../utils/wallet/constants';
import type { SendScreenProps } from '../../../navigation/types';
import { sendTransactionSelector } from '../../../store/reselect/ui';

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

const method = useAppSelector((state) => state.ui.paymentMethod);
const usesLightning = method === 'lightning';
const { paymentMethod } = useAppSelector(sendTransactionSelector);
const usesLightning = paymentMethod === 'lightning';

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

const availableAmount = useMemo(() => {
const maxAmountResponse = getMaxSendAmount({ method });
const maxAmountResponse = getMaxSendAmount({ method: paymentMethod });
if (maxAmountResponse.isOk()) {
return maxAmountResponse.value.amount;
}
return 0;
// recalculate max when utxos, fee or payment method change
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [transaction.outputs, transaction.satsPerByte, method]);
}, [transaction.outputs, transaction.satsPerByte, paymentMethod]);

useFocusEffect(
useCallback(() => {
Expand Down Expand Up @@ -145,11 +146,11 @@ const Amount = ({ navigation }: SendScreenProps<'Amount'>): ReactElement => {
return;
}
if (isMaxSendAmount && amount !== availableAmount) {
updateSendTransaction({ max: false });
updateBeignetSendTransaction({ max: false });
}

if (!isMaxSendAmount && amount === availableAmount) {
updateSendTransaction({ max: true });
updateBeignetSendTransaction({ max: true });
}
}, [isMaxSendAmount, amount, availableAmount, transaction?.lightningInvoice]);

Expand Down
4 changes: 2 additions & 2 deletions src/screens/Wallets/Send/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
resetSendTransaction,
setupOnChainTransaction,
} from '../../../store/actions/wallet';
import { closeSheet, updateUi } from '../../../store/slices/ui';
import { closeSheet, updateSendTransaction } from '../../../store/slices/ui';
import { transactionSelector } from '../../../store/reselect/wallet';

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

const handleRetry = async (): Promise<void> => {
if (isSlashpayLightning) {
dispatch(updateUi({ paymentMethod: 'onchain' }));
dispatch(updateSendTransaction({ paymentMethod: 'onchain' }));
const res = await processUri({
uri: slashTagsUrl,
source: 'send',
Expand Down
Loading

0 comments on commit eef957b

Please sign in to comment.