Skip to content

Commit

Permalink
made requestPermission filter out commands that don't allow bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaerax authored and ChiaMineJP committed Oct 25, 2024
1 parent 5e0ec29 commit 25c1aa6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion packages/gui/src/constants/WalletConnectCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const walletConnectCommands: WalletConnectCommand[] = [
command: 'requestPermissions',
label: <Trans>Request Permissions</Trans>,
description: <Trans>App is requesting permission to execute these commands</Trans>,
service: ServiceName.WALLET,
service: 'EXECUTE',
execute: {},
params: [
{
name: WalletConnectCommandParamName.COMMANDS,
Expand Down
1 change: 1 addition & 0 deletions packages/gui/src/hooks/useWalletConnectPairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 25c1aa6

Please sign in to comment.