From c699860663e1d68d72e5c0e83fed734910050403 Mon Sep 17 00:00:00 2001 From: Ben Kremer Date: Wed, 5 Apr 2023 15:12:26 +0200 Subject: [PATCH] fix(wallet): ensures legacy v1 modals handle JsonRpcError vs JsonRpcResult --- .../LegacySessionSendTransactionModal.tsx | 18 +++++++++++++----- .../src/views/LegacySessionSignModal.tsx | 18 +++++++++++++----- .../views/LegacySessionSignTypedDataModal.tsx | 18 +++++++++++++----- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/wallets/react-wallet-v2/src/views/LegacySessionSendTransactionModal.tsx b/wallets/react-wallet-v2/src/views/LegacySessionSendTransactionModal.tsx index 02b0802..c2095b4 100644 --- a/wallets/react-wallet-v2/src/views/LegacySessionSendTransactionModal.tsx +++ b/wallets/react-wallet-v2/src/views/LegacySessionSendTransactionModal.tsx @@ -32,16 +32,24 @@ export default function LegacySessionSendTransactionModal() { // Handle approve action async function onApprove() { if (requestEvent) { - const { result } = await approveEIP155Request({ + const response = await approveEIP155Request({ id, topic: '', params: { request: { method, params }, chainId: '1' } }) - legacySignClient.approveRequest({ - id, - result - }) + if ('error' in response) { + legacySignClient.rejectRequest({ + id, + error: response.error + }) + } else { + legacySignClient.approveRequest({ + id, + result: response.result + }) + } + ModalStore.close() } } diff --git a/wallets/react-wallet-v2/src/views/LegacySessionSignModal.tsx b/wallets/react-wallet-v2/src/views/LegacySessionSignModal.tsx index a0b0b41..5d67c2f 100644 --- a/wallets/react-wallet-v2/src/views/LegacySessionSignModal.tsx +++ b/wallets/react-wallet-v2/src/views/LegacySessionSignModal.tsx @@ -28,16 +28,24 @@ export default function LegacySessionSignModal() { // Handle approve action (logic varies based on request method) async function onApprove() { if (requestEvent) { - const { result } = await approveEIP155Request({ + const response = await approveEIP155Request({ id, topic: '', params: { request: { method, params }, chainId: '1' } }) - legacySignClient.approveRequest({ - id, - result - }) + if ('error' in response) { + legacySignClient.rejectRequest({ + id, + error: response.error + }) + } else { + legacySignClient.approveRequest({ + id, + result: response.result + }) + } + ModalStore.close() } } diff --git a/wallets/react-wallet-v2/src/views/LegacySessionSignTypedDataModal.tsx b/wallets/react-wallet-v2/src/views/LegacySessionSignTypedDataModal.tsx index 8ed4cd3..070b059 100644 --- a/wallets/react-wallet-v2/src/views/LegacySessionSignTypedDataModal.tsx +++ b/wallets/react-wallet-v2/src/views/LegacySessionSignTypedDataModal.tsx @@ -29,16 +29,24 @@ export default function LegacySessionSignTypedDataModal() { // Handle approve action (logic varies based on request method) async function onApprove() { if (requestEvent) { - const { result } = await approveEIP155Request({ + const response = await approveEIP155Request({ id, topic: '', params: { request: { method, params }, chainId: '1' } }) - legacySignClient.approveRequest({ - id, - result - }) + if ('error' in response) { + legacySignClient.rejectRequest({ + id, + error: response.error + }) + } else { + legacySignClient.approveRequest({ + id, + result: response.result + }) + } + ModalStore.close() } }