From 5ec493e513f5fab18026b32dba9008dc9d45aa8d Mon Sep 17 00:00:00 2001 From: Andreas Gassmann Date: Fri, 6 Oct 2023 15:40:01 +0200 Subject: [PATCH] feat(): update dapp example --- src/docs/getting-started/first-dapp.mdx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/docs/getting-started/first-dapp.mdx b/src/docs/getting-started/first-dapp.mdx index 1478b002..706a103f 100644 --- a/src/docs/getting-started/first-dapp.mdx +++ b/src/docs/getting-started/first-dapp.mdx @@ -54,6 +54,12 @@ import { DAppClient } from "@airgap/beacon-sdk"; const dAppClient = new DAppClient({ name: "Beacon Docs" }); +// Listen for all the active account changes +dAppClient.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, async (account) => { + // An active account has been set, update the dApp UI + console.log(`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `, account); +}); + try { console.log("Requesting permissions..."); const permissions = await dAppClient.requestPermissions(); @@ -77,6 +83,15 @@ const wallet = new BeaconWallet({ name: "Beacon Docs Taquito" }); Tezos.setWalletProvider(wallet); +// Listen for all the active account changes +wallet.client.subscribeToEvent( + BeaconEvent.ACTIVE_ACCOUNT_SET, + async (account) => { + // An active account has been set, update the dApp UI + console.log(`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `, account); + } +); + try { console.log("Requesting permissions..."); const permissions = await wallet.client.requestPermissions(); @@ -395,7 +410,7 @@ wallet.client.subscribeToEvent( ]); console.log(response); - }, + } ); // Check if we are connected. If not, do a permission request first.