From 68f85d9f29d41dc1fdd0d899d93601bb537e7b56 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Thu, 20 Jul 2023 19:54:19 +0200 Subject: [PATCH] added user prompt to sign in session request of wallet connect --- src/lib/WalletConnect.svelte | 55 ++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/lib/WalletConnect.svelte b/src/lib/WalletConnect.svelte index 8dcbc7d..e50f8e6 100644 --- a/src/lib/WalletConnect.svelte +++ b/src/lib/WalletConnect.svelte @@ -63,16 +63,24 @@ } function onSessionRequest(requestEvent) { - console.log('Received session request: ', requestEvent); - const { topic, params } = requestEvent; - const { request } = params; - const requestSession = getSignClient().session.get(topic); - const { name, url } = requestSession.peer.metadata; - console.log(`\nApproving ${request.method} request for session ${name} (${url})...\n`); - pkpWalletConnect.approveSessionRequest(requestEvent).then(() => { - console.log(`Check the ${name} dapp to confirm whether the request was approved`); - console.log('\n' + '*'.repeat(50) + '\n'); - }); + const isConfirmed = confirm( + `The dApp ${requestEvent.params.request.method} is requesting an action. Do you want to proceed?` + ); + + if (isConfirmed) { + console.log('Received session request: ', requestEvent); + const { topic, params } = requestEvent; + const { request } = params; + const requestSession = getSignClient().session.get(topic); + const { name, url } = requestSession.peer.metadata; + console.log(`\nApproving ${request.method} request for session ${name} (${url})...\n`); + pkpWalletConnect.approveSessionRequest(requestEvent).then(() => { + console.log(`Check the ${name} dapp to confirm whether the request was approved`); + console.log('\n' + '*'.repeat(50) + '\n'); + }); + } else { + console.log(`User declined the ${requestEvent.params.request.method} request.`); + } } function onSessionDelete(event) { @@ -108,24 +116,11 @@ } -
-

Connect to dapp:

- - +
+

Connect to dapp:

+ +
- -