added user prompt to sign in session request of wallet connect

This commit is contained in:
Samuel Andert 2023-07-20 19:54:19 +02:00
parent 940b4c3c45
commit 68f85d9f29

View File

@ -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 @@
}
</script>
<main>
<h1>Connect to dapp:</h1>
<input type="text" bind:value={uri} placeholder="Enter the URI" />
<button on:click={handleConnect}>Connect</button>
<main class="flex flex-col items-center justify-center">
<h1 class="text-2xl font-bold mb-4">Connect to dapp:</h1>
<input type="text" bind:value={uri} placeholder="Enter the URI" class="p-2 mb-4 text-lg w-72" />
<button
on:click={handleConnect}
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Connect</button
>
</main>
<style>
main {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
input {
padding: 8px;
margin-bottom: 16px;
font-size: 16px;
width: 300px;
}
</style>