mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-13 11:09:20 +01:00
ADD: Remove all recipients
This commit is contained in:
parent
22cc361976
commit
eea5b04fcc
4 changed files with 98 additions and 25 deletions
|
@ -130,6 +130,9 @@
|
|||
"details_insert_contact": "Insert Contact",
|
||||
"details_add_rec_add": "Add Recipient",
|
||||
"details_add_rec_rem": "Remove Recipient",
|
||||
"details_add_recc_rem_all_alert_description": "Are you sure you want to remove all recipients?",
|
||||
"details_add_rec_rem_all": "Remove All Recipients",
|
||||
"details_recipients_title": "Recipients",
|
||||
"details_address": "Address",
|
||||
"details_address_field_is_not_valid": "The address is not valid.",
|
||||
"details_adv_fee_bump": "Allow Fee Bump",
|
||||
|
|
|
@ -57,6 +57,7 @@ import { useKeyboard } from '../../hooks/useKeyboard';
|
|||
import { DismissKeyboardInputAccessory, DismissKeyboardInputAccessoryViewID } from '../../components/DismissKeyboardInputAccessory';
|
||||
import ActionSheet from '../ActionSheet';
|
||||
import HeaderMenuButton from '../../components/HeaderMenuButton';
|
||||
import { CommonToolTipActions } from '../../typings/CommonToolTipActions';
|
||||
|
||||
interface IPaymentDestinations {
|
||||
address: string; // btc address or payment code
|
||||
|
@ -852,6 +853,24 @@ const SendDetails = () => {
|
|||
}, 0);
|
||||
};
|
||||
|
||||
const onRemoveAllRecipientsConfirmed = useCallback(() => {
|
||||
setAddresses([{ address: '', key: String(Math.random()) } as IPaymentDestinations]);
|
||||
}, []);
|
||||
|
||||
const handleRemoveAllRecipients = useCallback(() => {
|
||||
Alert.alert(loc.send.details_recipients_title, loc.send.details_add_recc_rem_all_alert_description, [
|
||||
{
|
||||
text: loc._.cancel,
|
||||
onPress: () => {},
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: loc._.ok,
|
||||
onPress: onRemoveAllRecipientsConfirmed,
|
||||
},
|
||||
]);
|
||||
}, [onRemoveAllRecipientsConfirmed]);
|
||||
|
||||
const handleRemoveRecipient = () => {
|
||||
if (addresses.length > 1) {
|
||||
const newAddresses = [...addresses];
|
||||
|
@ -933,9 +952,9 @@ const SendDetails = () => {
|
|||
// Header Right Button
|
||||
|
||||
const headerRightOnPress = (id: string) => {
|
||||
if (id === SendDetails.actionKeys.AddRecipient) {
|
||||
if (id === CommonToolTipActions.AddRecipient.id) {
|
||||
handleAddRecipient();
|
||||
} else if (id === SendDetails.actionKeys.RemoveRecipient) {
|
||||
} else if (id === CommonToolTipActions.RemoveRecipient.id) {
|
||||
handleRemoveRecipient();
|
||||
} else if (id === SendDetails.actionKeys.SignPSBT) {
|
||||
handlePsbtSign();
|
||||
|
@ -955,6 +974,8 @@ const SendDetails = () => {
|
|||
handleCoinControl();
|
||||
} else if (id === SendDetails.actionKeys.InsertContact) {
|
||||
handleInsertContact();
|
||||
} else if (id === CommonToolTipActions.RemoveAllRecipients.id) {
|
||||
handleRemoveAllRecipients();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1007,19 +1028,13 @@ const SendDetails = () => {
|
|||
if ((wallet as MultisigHDWallet)?.allowCosignPsbt()) {
|
||||
transactionActions.push({ id: SendDetails.actionKeys.SignPSBT, text: loc.send.psbt_sign, icon: SendDetails.actionIcons.SignPSBT });
|
||||
}
|
||||
actions.push(transactionActions, [
|
||||
{
|
||||
id: SendDetails.actionKeys.AddRecipient,
|
||||
text: loc.send.details_add_rec_add,
|
||||
icon: SendDetails.actionIcons.AddRecipient,
|
||||
},
|
||||
{
|
||||
id: SendDetails.actionKeys.RemoveRecipient,
|
||||
text: loc.send.details_add_rec_rem,
|
||||
disabled: addresses.length < 2,
|
||||
icon: SendDetails.actionIcons.RemoveRecipient,
|
||||
},
|
||||
]);
|
||||
actions.push(transactionActions);
|
||||
|
||||
const recipientActions: Action[] = [CommonToolTipActions.AddRecipient, CommonToolTipActions.RemoveRecipient];
|
||||
if (addresses.length > 1) {
|
||||
recipientActions.push(CommonToolTipActions.RemoveAllRecipients);
|
||||
}
|
||||
actions.push(recipientActions);
|
||||
}
|
||||
|
||||
actions.push({ id: SendDetails.actionKeys.CoinControl, text: loc.cc.header, icon: SendDetails.actionIcons.CoinControl });
|
||||
|
@ -1355,8 +1370,6 @@ SendDetails.actionKeys = {
|
|||
InsertContact: 'InsertContact',
|
||||
SignPSBT: 'SignPSBT',
|
||||
SendMax: 'SendMax',
|
||||
AddRecipient: 'AddRecipient',
|
||||
RemoveRecipient: 'RemoveRecipient',
|
||||
AllowRBF: 'AllowRBF',
|
||||
ImportTransaction: 'ImportTransaction',
|
||||
ImportTransactionMultsig: 'ImportTransactionMultisig',
|
||||
|
@ -1369,8 +1382,6 @@ SendDetails.actionIcons = {
|
|||
InsertContact: { iconValue: 'at.badge.plus' },
|
||||
SignPSBT: { iconValue: 'signature' },
|
||||
SendMax: 'SendMax',
|
||||
AddRecipient: { iconValue: 'person.badge.plus' },
|
||||
RemoveRecipient: { iconValue: 'person.badge.minus' },
|
||||
AllowRBF: 'AllowRBF',
|
||||
ImportTransaction: { iconValue: 'square.and.arrow.down' },
|
||||
ImportTransactionMultsig: { iconValue: 'square.and.arrow.down.on.square' },
|
||||
|
|
|
@ -203,7 +203,7 @@ describe('BlueWallet UI Tests - import BIP84 wallet', () => {
|
|||
await element(by.type('android.widget.EditText')).typeText(feeRate + '\n');
|
||||
await element(by.text('OK')).tap();
|
||||
|
||||
// lest add another two outputs
|
||||
// lets add another two outputs
|
||||
await element(by.id('HeaderMenuButton')).tap();
|
||||
await element(by.text('Add Recipient')).tap();
|
||||
await yo('Transaction1'); // adding a recipient autoscrolls it to the last one
|
||||
|
@ -213,13 +213,38 @@ describe('BlueWallet UI Tests - import BIP84 wallet', () => {
|
|||
await element(by.id('HeaderMenuButton')).tap();
|
||||
await element(by.text('Add Recipient')).tap();
|
||||
await yo('Transaction2'); // adding a recipient autoscrolls it to the last one
|
||||
await element(by.id('AddressInput').withAncestor(by.id('Transaction2'))).replaceText('bc1qh6tf004ty7z7un2v5ntu4mkf630545gvhs45u7');
|
||||
await element(by.id('BitcoinAmountInput').withAncestor(by.id('Transaction2'))).replaceText('0.0003\n');
|
||||
|
||||
// remove last output, check if second output is shown
|
||||
// Now testing 'Remove All Recipients' functionality
|
||||
await element(by.id('HeaderMenuButton')).tap();
|
||||
await element(by.text('Remove Recipient')).tap();
|
||||
await yo('Transaction1');
|
||||
await element(by.text('Remove All Recipients')).tap();
|
||||
|
||||
// Confirm the alert dialog
|
||||
await sup('Are you sure you want to remove all recipients?');
|
||||
await element(by.text('OK')).tap();
|
||||
|
||||
// Verify that only one recipient remains (the default empty one)
|
||||
await expect(element(by.id('Transaction0'))).toBeVisible();
|
||||
await expect(element(by.id('Transaction1'))).not.toBeVisible();
|
||||
await expect(element(by.id('Transaction2'))).not.toBeVisible();
|
||||
|
||||
// Verify that the address and amount fields are empty
|
||||
await expect(element(by.id('AddressInput').withAncestor(by.id('Transaction0')))).toHaveText('');
|
||||
await expect(element(by.id('BitcoinAmountInput').withAncestor(by.id('Transaction0')))).toHaveText('');
|
||||
|
||||
// Now, we can add the recipients again to proceed with the test
|
||||
// let's create real transaction:
|
||||
await element(by.id('AddressInput').withAncestor(by.id('Transaction0'))).replaceText('bc1qnapskphjnwzw2w3dk4anpxntunc77v6qrua0f7');
|
||||
await element(by.id('BitcoinAmountInput').withAncestor(by.id('Transaction0'))).replaceText('0.0001\n');
|
||||
|
||||
// let's add another two outputs
|
||||
await element(by.id('HeaderMenuButton')).tap();
|
||||
await element(by.text('Add Recipient')).tap();
|
||||
await yo('Transaction1'); // adding a recipient autoscrolls it to the last one
|
||||
await element(by.id('AddressInput').withAncestor(by.id('Transaction1'))).replaceText('bc1q063ctu6jhe5k4v8ka99qac8rcm2tzjjnuktyrl');
|
||||
await element(by.id('BitcoinAmountInput').withAncestor(by.id('Transaction1'))).replaceText('0.0002\n');
|
||||
|
||||
// adding it again
|
||||
await element(by.id('HeaderMenuButton')).tap();
|
||||
await element(by.text('Add Recipient')).tap();
|
||||
await yo('Transaction2'); // adding a recipient autoscrolls it to the last one
|
||||
|
@ -227,11 +252,24 @@ describe('BlueWallet UI Tests - import BIP84 wallet', () => {
|
|||
await element(by.id('BitcoinAmountInput').withAncestor(by.id('Transaction2'))).replaceText('0.0003\n');
|
||||
|
||||
// remove second output
|
||||
// Swipe horizontally to Transaction2
|
||||
await element(by.id('Transaction0')).swipe('left'); // Swipe to Transaction1
|
||||
await element(by.id('Transaction1')).swipe('left'); // Swipe to Transaction2
|
||||
await element(by.id('Transaction2')).swipe('right', 'fast', NaN, 0.2);
|
||||
await sleep(5000);
|
||||
await sleep(500); // Wait for the swipe animation
|
||||
await element(by.id('HeaderMenuButton')).tap();
|
||||
await element(by.text('Remove Recipient')).tap();
|
||||
|
||||
// Swipe back to Transaction1
|
||||
await element(by.id('Transaction1')).swipe('right');
|
||||
|
||||
// adding it again
|
||||
await element(by.id('HeaderMenuButton')).tap();
|
||||
await element(by.text('Add Recipient')).tap();
|
||||
await yo('Transaction2'); // adding a recipient autoscrolls it to the last one
|
||||
await element(by.id('AddressInput').withAncestor(by.id('Transaction2'))).replaceText('bc1qh6tf004ty7z7un2v5ntu4mkf630545gvhs45u7');
|
||||
await element(by.id('BitcoinAmountInput').withAncestor(by.id('Transaction2'))).replaceText('0.0003\n');
|
||||
|
||||
// creating and verifying. tx should have 3 outputs
|
||||
if (process.env.TRAVIS) await sleep(5000);
|
||||
try {
|
||||
|
|
|
@ -19,6 +19,9 @@ const keys = {
|
|||
MoreInfo: 'moreInfo',
|
||||
SaveChanges: 'saveChanges',
|
||||
PaymentsCode: 'paymentsCode',
|
||||
RemoveAllRecipients: 'RemoveAllRecipients',
|
||||
AddRecipient: 'AddRecipient',
|
||||
RemoveRecipient: 'RemoveRecipient',
|
||||
};
|
||||
|
||||
const icons = {
|
||||
|
@ -67,6 +70,9 @@ const icons = {
|
|||
PaymentsCode: {
|
||||
iconValue: 'qrcode',
|
||||
},
|
||||
RemoveAllRecipients: { iconValue: 'person.2.slash' },
|
||||
AddRecipient: { iconValue: 'person.badge.plus' },
|
||||
RemoveRecipient: { iconValue: 'person.badge.minus' },
|
||||
};
|
||||
|
||||
export const CommonToolTipActions = {
|
||||
|
@ -95,6 +101,16 @@ export const CommonToolTipActions = {
|
|||
text: loc.transactions.details_copy_amount,
|
||||
icon: icons.Clipboard,
|
||||
},
|
||||
AddRecipient: {
|
||||
id: keys.AddRecipient,
|
||||
text: loc.send.details_add_rec_add,
|
||||
icon: icons.AddRecipient,
|
||||
},
|
||||
RemoveRecipient: {
|
||||
id: keys.RemoveRecipient,
|
||||
text: loc.send.details_add_rec_rem,
|
||||
icon: icons.RemoveRecipient,
|
||||
},
|
||||
CopyNote: {
|
||||
id: keys.CopyNote,
|
||||
text: loc.transactions.details_copy_note,
|
||||
|
@ -135,6 +151,11 @@ export const CommonToolTipActions = {
|
|||
text: loc.wallets.add_entropy_provide,
|
||||
icon: icons.Entropy,
|
||||
},
|
||||
RemoveAllRecipients: {
|
||||
id: keys.RemoveAllRecipients,
|
||||
text: loc.send.details_add_rec_rem_all,
|
||||
icon: icons.RemoveAllRecipients,
|
||||
},
|
||||
SearchAccount: {
|
||||
id: keys.SearchAccount,
|
||||
text: loc.wallets.import_search_accounts,
|
||||
|
|
Loading…
Add table
Reference in a new issue