diff --git a/packages/gui/src/components/walletConnect/WalletConnectAddConnectionDialog.tsx b/packages/gui/src/components/walletConnect/WalletConnectAddConnectionDialog.tsx index 8cd7cba9df..d60073cd5e 100644 --- a/packages/gui/src/components/walletConnect/WalletConnectAddConnectionDialog.tsx +++ b/packages/gui/src/components/walletConnect/WalletConnectAddConnectionDialog.tsx @@ -1,4 +1,4 @@ -import { useGetKeysQuery, useGetLoggedInFingerprintQuery, usePrefs } from '@chia-network/api-react'; +import { useGetKeysQuery, useGetLoggedInFingerprintQuery, usePrefs, useLocalStorage } from '@chia-network/api-react'; import { ButtonLoading, DialogActions, @@ -51,6 +51,7 @@ export default function WalletConnectAddConnectionDialog(props: WalletConnectAdd const { onClose = () => {}, open = false } = props; const [step, setStep] = useState(Step.CONNECT); + const [bypassReadonlyCommands, toggleBypassReadonlyCommands] = useLocalStorage('bypass-readonly-commands', false); const { pair, isLoading: isLoadingWallet } = useWalletConnectContext(); const { data: keys, isLoading: isLoadingPublicKeys } = useGetKeysQuery({}); const [sortedWallets] = usePrefs('sortedWallets', []); @@ -212,6 +213,23 @@ export default function WalletConnectAddConnectionDialog(props: WalletConnectAdd return null; } + function renderQuietModeOption() { + return ( + { + toggleBypassReadonlyCommands(!bypassReadonlyCommands); + }} + > + + + Bypass confirmation for all read-only commands + + + ); + } + return ( @@ -259,6 +277,7 @@ export default function WalletConnectAddConnectionDialog(props: WalletConnectAdd {renderSelectedAsPills()} {renderKeysMultiSelect()} + {renderQuietModeOption()} )} diff --git a/packages/gui/src/hooks/useWalletConnectCommand.tsx b/packages/gui/src/hooks/useWalletConnectCommand.tsx index 5694d9585c..a7abb0bddf 100644 --- a/packages/gui/src/hooks/useWalletConnectCommand.tsx +++ b/packages/gui/src/hooks/useWalletConnectCommand.tsx @@ -1,4 +1,4 @@ -import api, { store, useGetLoggedInFingerprintQuery } from '@chia-network/api-react'; +import api, { store, useGetLoggedInFingerprintQuery, useLocalStorage } from '@chia-network/api-react'; import { useOpenDialog, useAuth } from '@chia-network/core'; import { Trans } from '@lingui/macro'; import debug from 'debug'; @@ -80,6 +80,8 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand const isLoading = isLoadingLoggedInFingerprint; + const [bypassReadonlyCommands] = useLocalStorage('bypass-readonly-commands', false); + async function confirm(props: { topic: string; message: ReactNode; @@ -172,24 +174,31 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand values = newValues; } - const confirmed = await confirm({ - topic, - message: - !allFingerprints && isDifferentFingerprint ? ( - - Do you want to log in to {fingerprint} and execute command {command}? - - ) : ( - Do you want to execute command {command}? - ), - params: definitionParams, - values, - fingerprint, - isDifferentFingerprint, - command, - bypassConfirm, - onChange: handleChangeParam, - }); + const isReadOnly = + ['spend', 'cancel', 'create', 'transfer', 'send', 'take', 'add', 'set'].filter( + (startsWith: string) => command.indexOf(startsWith) === 0 + ).length === 0; + + const confirmed = + (bypassReadonlyCommands && isReadOnly) || + (await confirm({ + topic, + message: + !allFingerprints && isDifferentFingerprint ? ( + + Do you want to log in to {fingerprint} and execute command {command}? + + ) : ( + Do you want to execute command {command}? + ), + params: definitionParams, + values, + fingerprint, + isDifferentFingerprint, + command, + bypassConfirm, + onChange: handleChangeParam, + })); if (!confirmed) { throw new Error(`User cancelled command ${requestedCommand}`);