Skip to content

Commit 7fe7391

Browse files
committed
Added "quiet mode" option when creating a WalletConnect pairing
1 parent 5b56604 commit 7fe7391

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

packages/gui/src/components/walletConnect/WalletConnectAddConnectionDialog.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useGetKeysQuery, useGetLoggedInFingerprintQuery, usePrefs } from '@chia-network/api-react';
1+
import { useGetKeysQuery, useGetLoggedInFingerprintQuery, usePrefs, useLocalStorage } from '@chia-network/api-react';
22
import {
33
ButtonLoading,
44
DialogActions,
@@ -51,6 +51,7 @@ export default function WalletConnectAddConnectionDialog(props: WalletConnectAdd
5151
const { onClose = () => {}, open = false } = props;
5252

5353
const [step, setStep] = useState<Step>(Step.CONNECT);
54+
const [bypassReadonlyCommands, toggleBypassReadonlyCommands] = useLocalStorage('bypass-readonly-commands', false);
5455
const { pair, isLoading: isLoadingWallet } = useWalletConnectContext();
5556
const { data: keys, isLoading: isLoadingPublicKeys } = useGetKeysQuery({});
5657
const [sortedWallets] = usePrefs('sortedWallets', []);
@@ -212,6 +213,23 @@ export default function WalletConnectAddConnectionDialog(props: WalletConnectAdd
212213
return null;
213214
}
214215

216+
function renderQuietModeOption() {
217+
return (
218+
<Flex
219+
sx={{ cursor: 'pointer' }}
220+
alignItems="center"
221+
onClick={() => {
222+
toggleBypassReadonlyCommands(!bypassReadonlyCommands);
223+
}}
224+
>
225+
<Checkbox checked={bypassReadonlyCommands} disableRipple sx={{ paddingLeft: 0 }} />
226+
<Typography variant="body2">
227+
<Trans>Bypass confirmation for all read-only commands</Trans>
228+
</Typography>
229+
</Flex>
230+
);
231+
}
232+
215233
return (
216234
<Dialog onClose={handleClose} maxWidth="xs" open={open} fullWidth>
217235
<DialogTitle>
@@ -259,6 +277,7 @@ export default function WalletConnectAddConnectionDialog(props: WalletConnectAdd
259277
{renderSelectedAsPills()}
260278
</Flex>
261279
{renderKeysMultiSelect()}
280+
{renderQuietModeOption()}
262281
</Flex>
263282
)}
264283
</Flex>

packages/gui/src/hooks/useWalletConnectCommand.tsx

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import api, { store, useGetLoggedInFingerprintQuery } from '@chia-network/api-react';
1+
import api, { store, useGetLoggedInFingerprintQuery, useLocalStorage } from '@chia-network/api-react';
22
import { useOpenDialog, useAuth } from '@chia-network/core';
33
import { Trans } from '@lingui/macro';
44
import debug from 'debug';
@@ -80,6 +80,8 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand
8080

8181
const isLoading = isLoadingLoggedInFingerprint;
8282

83+
const [bypassReadonlyCommands] = useLocalStorage('bypass-readonly-commands', false);
84+
8385
async function confirm(props: {
8486
topic: string;
8587
message: ReactNode;
@@ -172,24 +174,31 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand
172174
values = newValues;
173175
}
174176

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+
}));
193202

194203
if (!confirmed) {
195204
throw new Error(`User cancelled command ${requestedCommand}`);

0 commit comments

Comments
 (0)