|
1 |
| -import api, { store, useGetLoggedInFingerprintQuery } from '@chia-network/api-react'; |
| 1 | +import api, { store, useGetLoggedInFingerprintQuery, useLocalStorage } from '@chia-network/api-react'; |
2 | 2 | import { useOpenDialog, useAuth } from '@chia-network/core';
|
3 | 3 | import { Trans } from '@lingui/macro';
|
4 | 4 | import debug from 'debug';
|
@@ -80,6 +80,8 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand
|
80 | 80 |
|
81 | 81 | const isLoading = isLoadingLoggedInFingerprint;
|
82 | 82 |
|
| 83 | + const [bypassReadonlyCommands] = useLocalStorage('bypass-readonly-commands', false); |
| 84 | + |
83 | 85 | async function confirm(props: {
|
84 | 86 | topic: string;
|
85 | 87 | message: ReactNode;
|
@@ -172,24 +174,31 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand
|
172 | 174 | values = newValues;
|
173 | 175 | }
|
174 | 176 |
|
175 |
| - const confirmed = await confirm({ |
176 |
| - topic, |
177 |
| - message: |
178 |
| - !allFingerprints && isDifferentFingerprint ? ( |
179 |
| - <Trans> |
180 |
| - Do you want to log in to {fingerprint} and execute command {command}? |
181 |
| - </Trans> |
182 |
| - ) : ( |
183 |
| - <Trans>Do you want to execute command {command}?</Trans> |
184 |
| - ), |
185 |
| - params: definitionParams, |
186 |
| - values, |
187 |
| - fingerprint, |
188 |
| - isDifferentFingerprint, |
189 |
| - command, |
190 |
| - bypassConfirm, |
191 |
| - onChange: handleChangeParam, |
192 |
| - }); |
| 177 | + const isReadOnly = |
| 178 | + ['spend', 'cancel', 'create', 'transfer', 'send', 'take', 'add', 'set'].filter( |
| 179 | + (startsWith: string) => command.indexOf(startsWith) === 0 |
| 180 | + ).length === 0; |
| 181 | + |
| 182 | + const confirmed = |
| 183 | + (bypassReadonlyCommands && isReadOnly) || |
| 184 | + (await confirm({ |
| 185 | + topic, |
| 186 | + message: |
| 187 | + !allFingerprints && isDifferentFingerprint ? ( |
| 188 | + <Trans> |
| 189 | + Do you want to log in to {fingerprint} and execute command {command}? |
| 190 | + </Trans> |
| 191 | + ) : ( |
| 192 | + <Trans>Do you want to execute command {command}?</Trans> |
| 193 | + ), |
| 194 | + params: definitionParams, |
| 195 | + values, |
| 196 | + fingerprint, |
| 197 | + isDifferentFingerprint, |
| 198 | + command, |
| 199 | + bypassConfirm, |
| 200 | + onChange: handleChangeParam, |
| 201 | + })); |
193 | 202 |
|
194 | 203 | if (!confirmed) {
|
195 | 204 | throw new Error(`User cancelled command ${requestedCommand}`);
|
|
0 commit comments