From 25c1aa6db90089e08b1d9711e86d8622190764b4 Mon Sep 17 00:00:00 2001 From: Gaerax Date: Tue, 19 Mar 2024 21:55:06 -0700 Subject: [PATCH] made requestPermission filter out commands that don't allow bypass --- .../WalletConnectRequestPermissionsConfirmDialog.tsx | 8 +++++++- packages/gui/src/constants/WalletConnectCommands.tsx | 3 ++- packages/gui/src/hooks/useWalletConnectPairs.ts | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/gui/src/components/walletConnect/WalletConnectRequestPermissionsConfirmDialog.tsx b/packages/gui/src/components/walletConnect/WalletConnectRequestPermissionsConfirmDialog.tsx index 98035b71a8..ede4ec659b 100644 --- a/packages/gui/src/components/walletConnect/WalletConnectRequestPermissionsConfirmDialog.tsx +++ b/packages/gui/src/components/walletConnect/WalletConnectRequestPermissionsConfirmDialog.tsx @@ -5,6 +5,7 @@ import { Typography, Divider } from '@mui/material'; import React, { useState, useMemo } from 'react'; import type WalletConnectCommandParam from '../../@types/WalletConnectCommandParam'; +import walletConnectCommands from '../../constants/WalletConnectCommands'; import useWalletConnectPairs from '../../hooks/useWalletConnectPairs'; import WalletConnectMetadata from './WalletConnectMetadata'; @@ -45,7 +46,12 @@ export default function WalletConnectRequestPermissionsConfirmDialog( if (confirmed) { params.forEach((element) => { if (element.name === 'commands') { - bypassCommands(topic, values[element.name], true); + // filter out commands that don't allow bypassing confirmation + const cmds = values[element.name].filter((cmd: string) => { + const cmdDescription = walletConnectCommands.find((item) => item.command === cmd); + return cmdDescription?.bypassConfirm; + }); + bypassCommands(topic, cmds, true); } }); } diff --git a/packages/gui/src/constants/WalletConnectCommands.tsx b/packages/gui/src/constants/WalletConnectCommands.tsx index 01a7876ec0..435acea8d7 100644 --- a/packages/gui/src/constants/WalletConnectCommands.tsx +++ b/packages/gui/src/constants/WalletConnectCommands.tsx @@ -15,7 +15,8 @@ const walletConnectCommands: WalletConnectCommand[] = [ command: 'requestPermissions', label: Request Permissions, description: App is requesting permission to execute these commands, - service: ServiceName.WALLET, + service: 'EXECUTE', + execute: {}, params: [ { name: WalletConnectCommandParamName.COMMANDS, diff --git a/packages/gui/src/hooks/useWalletConnectPairs.ts b/packages/gui/src/hooks/useWalletConnectPairs.ts index f2d63b598d..e95a98b048 100644 --- a/packages/gui/src/hooks/useWalletConnectPairs.ts +++ b/packages/gui/src/hooks/useWalletConnectPairs.ts @@ -20,6 +20,7 @@ export type Pairs = { removeSessionFromPair: (sessionTopic: string) => void; bypassCommand: (sessionTopic: string, command: string, confirm: boolean) => void; + bypassCommands: (sessionTopic: string, commands: string[], confirm: boolean) => void; removeBypassCommand: (sessionTopic: string, command: string) => void; resetBypassForAllPairs: () => void; resetBypassForPair: (pairTopic: string) => void;