ADD: Clear clipboard on import

This commit is contained in:
Marcos Rodriguez Velez 2024-10-06 17:49:52 -04:00
parent 6285cff4ea
commit dd9c75ce7d
3 changed files with 43 additions and 13 deletions

View File

@ -401,6 +401,7 @@
"add_wallet_seed_length_24": "24 words",
"clipboard_bitcoin": "You have a Bitcoin address on your clipboard. Would you like to use it for a transaction?",
"clipboard_lightning": "You have a Lightning invoice on your clipboard. Would you like to use it for a transaction?",
"clear_clipboard_on_import": "Clear clipboard on import",
"details_address": "Address",
"details_advanced": "Advanced",
"details_are_you_sure": "Are you sure?",

View File

@ -14,6 +14,7 @@ import {
import { CommonToolTipActions } from '../../typings/CommonToolTipActions';
import { useKeyboard } from '../../hooks/useKeyboard';
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
import Clipboard from '@react-native-clipboard/clipboard';
import HeaderMenuButton from '../../components/HeaderMenuButton';
const WalletsImport = () => {
@ -26,8 +27,9 @@ const WalletsImport = () => {
const [importText, setImportText] = useState(label);
const [isToolbarVisibleForAndroid, setIsToolbarVisibleForAndroid] = useState(false);
const [, setSpeedBackdoor] = useState(0);
const [searchAccounts, setSearchAccounts] = useState(false);
const [askPassphrase, setAskPassphrase] = useState(false);
const [searchAccountsMenuState, setSearchAccountsMenuState] = useState(false);
const [askPassphraseMenuState, setAskPassphraseMenuState] = useState(false);
const [clearClipboardMenuState, setClearClipboardMenuState] = useState(true);
const { enableBlur, disableBlur } = usePrivacy();
// Styles
@ -86,8 +88,21 @@ const WalletsImport = () => {
importMnemonic(textToImport);
};
const importMnemonic = text => {
navigation.navigate('ImportWalletDiscovery', { importText: text, askPassphrase, searchAccounts });
const importMnemonic = async text => {
if (clearClipboardMenuState) {
try {
if (await Clipboard.hasString()) {
Clipboard.setString('');
}
} catch (error) {
console.error('Failed to clear clipboard:', error);
}
}
navigation.navigate('ImportWalletDiscovery', {
importText: text,
askPassphrase: askPassphraseMenuState,
searchAccounts: searchAccountsMenuState,
});
};
const onBarScanned = value => {
@ -114,24 +129,28 @@ const WalletsImport = () => {
const toolTipOnPressMenuItem = useCallback(
menuItem => {
Keyboard.dismiss();
if (menuItem === CommonToolTipActions.Passphrase.id) {
setAskPassphrase(!askPassphrase);
setAskPassphraseMenuState(!askPassphraseMenuState);
} else if (menuItem === CommonToolTipActions.SearchAccount.id) {
setSearchAccounts(!searchAccounts);
setSearchAccountsMenuState(!searchAccountsMenuState);
} else if (menuItem === CommonToolTipActions.ClearClipboard.id) {
setClearClipboardMenuState(!clearClipboardMenuState);
}
},
[askPassphrase, searchAccounts],
[askPassphraseMenuState, clearClipboardMenuState, searchAccountsMenuState],
);
// ToolTipMenu actions for advanced options
const toolTipActions = useMemo(() => {
const askPassphraseAction = CommonToolTipActions.Passphrase;
askPassphraseAction.menuState = askPassphrase;
askPassphraseAction.menuState = askPassphraseMenuState;
const searchAccountsAction = CommonToolTipActions.SearchAccount;
searchAccountsAction.menuState = searchAccounts;
return [askPassphraseAction, searchAccountsAction];
}, [askPassphrase, searchAccounts]);
searchAccountsAction.menuState = searchAccountsMenuState;
const clearClipboardAction = CommonToolTipActions.ClearClipboard;
clearClipboardAction.menuState = clearClipboardMenuState;
return [askPassphraseAction, searchAccountsAction, clearClipboardAction];
}, [askPassphraseMenuState, clearClipboardMenuState, searchAccountsMenuState]);
const HeaderRight = useMemo(
() => <HeaderMenuButton onPressMenuItem={toolTipOnPressMenuItem} actions={toolTipActions} />,
@ -143,7 +162,7 @@ const WalletsImport = () => {
navigation.setOptions({
headerRight: () => HeaderRight,
});
}, [askPassphrase, searchAccounts, colors.foregroundColor, navigation, toolTipActions, HeaderRight]);
}, [colors.foregroundColor, navigation, toolTipActions, HeaderRight]);
const renderOptionsAndImportButton = (
<>

View File

@ -18,6 +18,7 @@ const keys = {
Passphrase: 'passphrase',
MoreInfo: 'moreInfo',
SaveChanges: 'saveChanges',
ClearClipboard: 'clearClipboard',
PaymentsCode: 'paymentsCode',
};
@ -31,6 +32,9 @@ const icons = {
Clipboard: {
iconValue: 'doc.on.doc',
},
ClearClipboard: {
iconValue: 'clipboard',
},
Link: {
iconValue: 'link',
},
@ -164,4 +168,10 @@ export const CommonToolTipActions = {
icon: icons.PaymentsCode,
menuState: false,
},
ClearClipboard: {
id: keys.ClearClipboard,
text: loc.wallets.clear_clipboard_on_import,
icon: icons.ClearClipboard,
menuState: true,
},
};