From 11cf6ad6b8cc3652312b93e1e5e47a7b6b66b30b Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Tue, 22 Oct 2024 17:05:09 -0400 Subject: [PATCH] REF: SendDetails actions --- components/HeaderMenuButton.tsx | 2 +- components/TotalWalletsBalance.tsx | 2 +- components/types.ts | 2 +- screen/send/SendDetails.tsx | 102 +++++++++----------- typings/CommonToolTipActions.ts | 150 ++++++++++++++++++----------- 5 files changed, 143 insertions(+), 115 deletions(-) diff --git a/components/HeaderMenuButton.tsx b/components/HeaderMenuButton.tsx index ac4dc38b9..393364717 100644 --- a/components/HeaderMenuButton.tsx +++ b/components/HeaderMenuButton.tsx @@ -7,7 +7,7 @@ import { Action } from './types'; interface HeaderMenuButtonProps { onPressMenuItem: (id: string) => void; - actions: Action[]; + actions: Action[] | Action[][]; disabled?: boolean; } diff --git a/components/TotalWalletsBalance.tsx b/components/TotalWalletsBalance.tsx index 50e08f63a..177314ae0 100644 --- a/components/TotalWalletsBalance.tsx +++ b/components/TotalWalletsBalance.tsx @@ -99,7 +99,7 @@ const TotalWalletsBalance: React.FC = () => { {loc.wallets.total_balance} - onPressMenuItem(CommonToolTipActions.ViewInBitcoin.id)}> + onPressMenuItem(CommonToolTipActions.ViewInBitcoin.id.toString())}> {formattedBalance}{' '} {totalBalancePreferredUnit !== BitcoinUnit.LOCAL_CURRENCY && ( diff --git a/components/types.ts b/components/types.ts index dc39a2ee8..cca1824ec 100644 --- a/components/types.ts +++ b/components/types.ts @@ -19,7 +19,7 @@ export interface Action { } export interface ToolTipMenuProps { - actions: Action[]; + actions: Action[] | Action[][]; children: React.ReactNode; enableAndroidRipple?: boolean; dismissMenu?: () => void; diff --git a/screen/send/SendDetails.tsx b/screen/send/SendDetails.tsx index 74cd43c79..b2d419420 100644 --- a/screen/send/SendDetails.tsx +++ b/screen/send/SendDetails.tsx @@ -51,7 +51,6 @@ import { SendDetailsStackParamList } from '../../navigation/SendDetailsStackPara import { useExtendedNavigation } from '../../hooks/useExtendedNavigation'; import { ContactList } from '../../class/contact-list'; import { useStorage } from '../../hooks/context/useStorage'; -import { Action } from '../../components/types'; import SelectFeeModal from '../../components/SelectFeeModal'; import { useKeyboard } from '../../hooks/useKeyboard'; import { DismissKeyboardInputAccessory, DismissKeyboardInputAccessoryViewID } from '../../components/DismissKeyboardInputAccessory'; @@ -980,66 +979,57 @@ const SendDetails = () => { }; const headerRightActions = () => { - const actions: Action[] & Action[][] = []; - if (isEditable) { - if (wallet?.allowBIP47() && wallet?.isBIP47Enabled()) { - actions.push([ - { id: SendDetails.actionKeys.InsertContact, text: loc.send.details_insert_contact, icon: SendDetails.actionIcons.InsertContact }, - ]); - } + const transactionActions = [ + { + ...CommonToolTipActions.SendMax, + hidden: !(isEditable && Number(wallet?.getBalance()) > 0), + }, + { + ...CommonToolTipActions.AllowRBF, + hidden: !(wallet?.type === HDSegwitBech32Wallet.type && isTransactionReplaceable !== undefined), + menuState: isTransactionReplaceable, + }, + ]; - if (Number(wallet?.getBalance()) > 0) { - const isSendMaxUsed = addresses.some(element => element.amount === BitcoinUnit.MAX); + const importActions = [ + { + ...CommonToolTipActions.ImportTransaction, + hidden: !(wallet?.type === WatchOnlyWallet.type && wallet.isHd()), + }, + { + ...CommonToolTipActions.ImportTransactionQR, + hidden: !(wallet?.type === WatchOnlyWallet.type && wallet.isHd()), + }, + { + ...CommonToolTipActions.ImportTransactionMultsig, + hidden: !(wallet?.type === MultisigHDWallet.type && wallet.howManySignaturesCanWeMake() > 0), + }, + { + ...CommonToolTipActions.CoSignTransaction, + hidden: !(wallet?.type === MultisigHDWallet.type && wallet.howManySignaturesCanWeMake() > 0), + }, + ]; - actions.push([{ id: SendDetails.actionKeys.SendMax, text: loc.send.details_adv_full, disabled: balance === 0 || isSendMaxUsed }]); - } - if (wallet?.type === HDSegwitBech32Wallet.type && isTransactionReplaceable !== undefined) { - actions.push([{ id: SendDetails.actionKeys.AllowRBF, text: loc.send.details_adv_fee_bump, menuState: !!isTransactionReplaceable }]); - } - const transactionActions = []; - if (wallet?.type === WatchOnlyWallet.type && wallet.isHd()) { - transactionActions.push( - { - id: SendDetails.actionKeys.ImportTransaction, - text: loc.send.details_adv_import, - icon: SendDetails.actionIcons.ImportTransaction, - }, - { - id: SendDetails.actionKeys.ImportTransactionQR, - text: loc.send.details_adv_import_qr, - icon: SendDetails.actionIcons.ImportTransactionQR, - }, - ); - } - if (wallet?.type === MultisigHDWallet.type) { - transactionActions.push({ - id: SendDetails.actionKeys.ImportTransactionMultsig, - text: loc.send.details_adv_import, - icon: SendDetails.actionIcons.ImportTransactionMultsig, - }); - } - if (wallet?.type === MultisigHDWallet.type && wallet.howManySignaturesCanWeMake() > 0) { - transactionActions.push({ - id: SendDetails.actionKeys.CoSignTransaction, - text: loc.multisig.co_sign_transaction, - icon: SendDetails.actionIcons.SignPSBT, - }); - } - if ((wallet as MultisigHDWallet)?.allowCosignPsbt()) { - transactionActions.push({ id: SendDetails.actionKeys.SignPSBT, text: loc.send.psbt_sign, icon: SendDetails.actionIcons.SignPSBT }); - } - actions.push(transactionActions); + const recipientActions = [ + CommonToolTipActions.AddRecipient, + CommonToolTipActions.RemoveRecipient, + { + ...CommonToolTipActions.RemoveAllRecipients, + hidden: addresses.length <= 1, + }, + ]; - const recipientActions: Action[] = [CommonToolTipActions.AddRecipient, CommonToolTipActions.RemoveRecipient]; - if (addresses.length > 1) { - recipientActions.push(CommonToolTipActions.RemoveAllRecipients); - } - actions.push(recipientActions); - } + const walletActions = [ + { + ...CommonToolTipActions.InsertContact, + hidden: !(isEditable && wallet?.allowBIP47() && wallet?.isBIP47Enabled()), + }, + CommonToolTipActions.CoinControl, + ]; - actions.push({ id: SendDetails.actionKeys.CoinControl, text: loc.cc.header, icon: SendDetails.actionIcons.CoinControl }); + const availableActions = [walletActions, transactionActions, importActions, recipientActions]; - return actions; + return availableActions; }; const setHeaderRightOptions = () => { diff --git a/typings/CommonToolTipActions.ts b/typings/CommonToolTipActions.ts index a66214ead..7eb670c3e 100644 --- a/typings/CommonToolTipActions.ts +++ b/typings/CommonToolTipActions.ts @@ -1,5 +1,6 @@ import { Platform } from 'react-native'; import loc from '../loc'; +import { Action } from '../components/types'; const keys = { CopyTXID: 'copyTX_ID', @@ -27,69 +28,51 @@ const keys = { CopyFromClipboard: 'copy_from_clipboard', ChoosePhoto: 'choose_photo', ImportFile: 'import_file', + InsertContact: 'InsertContact', + SignPSBT: 'SignPSBT', + SendMax: 'SendMax', + AllowRBF: 'AllowRBF', + ImportTransaction: 'ImportTransaction', + ImportTransactionMultsig: 'ImportTransactionMultsig', + ImportTransactionQR: 'ImportTransactionQR', + CoinControl: 'CoinControl', + CoSignTransaction: 'CoSignTransaction', }; -const icons = { - Eye: { - iconValue: 'eye', - }, - EyeSlash: { - iconValue: 'eye.slash', - }, - Link: { - iconValue: 'link', - }, - Note: { - iconValue: 'note.text', - }, - ManageWallets: { - iconValue: 'slider.horizontal.3', - }, - ImportWallet: { - iconValue: 'square.and.arrow.down.on.square', - }, - ViewInBitcoin: { - iconValue: 'bitcoinsign.circle', - }, - ViewInFiat: { - iconValue: 'coloncurrencysign.circle', - }, - Entropy: { - iconValue: 'dice', - }, - SearchAccount: { - iconValue: 'magnifyingglass', - }, - Passphrase: { - iconValue: 'rectangle.and.pencil.and.ellipsis', - }, - MoreInfo: { - iconValue: 'info.circle', - }, - SaveChanges: { - iconValue: 'checkmark', - }, - PaymentsCode: { - iconValue: 'qrcode', - }, +const icons: { [key: string]: { iconValue: string } } = { + Eye: { iconValue: 'eye' }, + EyeSlash: { iconValue: 'eye.slash' }, + Link: { iconValue: 'link' }, + Note: { iconValue: 'note.text' }, + ManageWallets: { iconValue: 'slider.horizontal.3' }, + ImportWallet: { iconValue: 'square.and.arrow.down.on.square' }, + ViewInBitcoin: { iconValue: 'bitcoinsign.circle' }, + ViewInFiat: { iconValue: 'coloncurrencysign.circle' }, + Entropy: { iconValue: 'dice' }, + SearchAccount: { iconValue: 'magnifyingglass' }, + Passphrase: { iconValue: 'rectangle.and.pencil.and.ellipsis' }, + MoreInfo: { iconValue: 'info.circle' }, + SaveChanges: { iconValue: 'checkmark' }, + InsertContact: { iconValue: 'at.badge.plus' }, + SignPSBT: { iconValue: 'signature' }, + SendMax: { iconValue: 'dial.high' }, + AllowRBF: { iconValue: 'arrowshape.up.circle' }, + ImportTransaction: { iconValue: 'square.and.arrow.down' }, + ImportTransactionMultsig: { iconValue: 'square.and.arrow.down.on.square' }, + ImportTransactionQR: { iconValue: 'qrcode.viewfinder' }, + CoinControl: { iconValue: 'switch.2' }, + CoSignTransaction: { iconValue: 'signature' }, + PaymentsCode: { iconValue: 'qrcode' }, RemoveAllRecipients: { iconValue: 'person.2.slash' }, AddRecipient: { iconValue: 'person.badge.plus' }, RemoveRecipient: { iconValue: 'person.badge.minus' }, - ScanQR: { - iconValue: Platform.OS === 'ios' ? 'qrcode' : 'ic_menu_camera', - }, - ImportFile: { - iconValue: 'doc', - }, - ChoosePhoto: { - iconValue: Platform.OS === 'ios' ? 'photo' : 'ic_menu_gallery', - }, - Clipboard: { - iconValue: Platform.OS === 'ios' ? 'doc.on.doc' : 'ic_menu_file', - }, + ScanQR: { iconValue: Platform.OS === 'ios' ? 'qrcode' : 'ic_menu_camera' }, + ImportFile: { iconValue: 'doc' }, + ChoosePhoto: { iconValue: Platform.OS === 'ios' ? 'photo' : 'ic_menu_gallery' }, + Clipboard: { iconValue: Platform.OS === 'ios' ? 'doc.on.doc' : 'ic_menu_file' }, }; -export const CommonToolTipActions = { +export const CommonToolTipActions: { [key: string]: Action } = { CopyTXID: { id: keys.CopyTXID, text: loc.transactions.details_copy_txid, @@ -221,4 +204,59 @@ export const CommonToolTipActions = { text: loc.wallets.import_file, icon: icons.ImportFile, }, + InsertContact: { + id: keys.InsertContact, + text: loc.send.details_insert_contact, + icon: icons.InsertContact, + hidden: true, + }, + SignPSBT: { + id: keys.SignPSBT, + text: loc.send.psbt_sign, + icon: icons.SignPSBT, + hidden: true, + }, + SendMax: { + id: keys.SendMax, + text: loc.send.details_adv_full, + icon: icons.SendMax, + hidden: true, + }, + AllowRBF: { + id: keys.AllowRBF, + text: loc.send.details_adv_fee_bump, + icon: icons.AllowRBF, + hidden: true, + menuState: false, + }, + ImportTransaction: { + id: keys.ImportTransaction, + text: loc.send.details_adv_import, + icon: icons.ImportTransaction, + hidden: true, + }, + ImportTransactionQR: { + id: keys.ImportTransactionQR, + text: loc.send.details_adv_import_qr, + icon: icons.ImportTransactionQR, + hidden: true, + }, + ImportTransactionMultsig: { + id: keys.ImportTransactionMultsig, + text: loc.send.details_adv_import, + icon: icons.ImportTransactionMultsig, + hidden: true, + }, + CoSignTransaction: { + id: keys.CoSignTransaction, + text: loc.multisig.co_sign_transaction, + icon: icons.CoSignTransaction, + hidden: true, + }, + CoinControl: { + id: keys.CoinControl, + text: loc.cc.header, + icon: icons.CoinControl, + hidden: false, + }, };