From 9ffca296ec675db20ed16a2164e23466081fbb0c Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Tue, 16 Sep 2025 08:54:07 +1200 Subject: [PATCH] [SDK] Simplify wallet connection code and add Abstract wallet support --- .../typescript/v5/connecting-wallets/page.mdx | 12 +- .../external-wallets/[walletId]/page.tsx | 75 ++----- .../wallets/external-wallets/xyz.abs/page.tsx | 204 ++++++++++++++++++ 3 files changed, 218 insertions(+), 73 deletions(-) create mode 100644 apps/portal/src/app/wallets/external-wallets/xyz.abs/page.tsx diff --git a/apps/portal/src/app/typescript/v5/connecting-wallets/page.mdx b/apps/portal/src/app/typescript/v5/connecting-wallets/page.mdx index fe688b168a9..00838e0271a 100644 --- a/apps/portal/src/app/typescript/v5/connecting-wallets/page.mdx +++ b/apps/portal/src/app/typescript/v5/connecting-wallets/page.mdx @@ -41,14 +41,6 @@ import { createWallet, injectedProvider } from "thirdweb/wallets"; const client = createThirdwebClient({ clientId }); const metamask = createWallet("io.metamask"); // pass the wallet id - -// if user has metamask installed, connect to it -if (injectedProvider("io.metamask")) { - await metamask.connect({ client }); -} - -// open wallet connect modal so user can scan the QR code and connect -else { - await metamask.connect({ client, walletConnect: { showQrModal: true } }); -} +// if user has metamask installed, connect to it, otherwise opens a WalletConnect modal +await metamask.connect({ client }); ``` diff --git a/apps/portal/src/app/wallets/external-wallets/[walletId]/page.tsx b/apps/portal/src/app/wallets/external-wallets/[walletId]/page.tsx index 8a09c3497e9..4ecc80f5863 100644 --- a/apps/portal/src/app/wallets/external-wallets/[walletId]/page.tsx +++ b/apps/portal/src/app/wallets/external-wallets/[walletId]/page.tsx @@ -188,16 +188,7 @@ import { createWallet, injectedProvider } from "thirdweb/wallets"; const client = createThirdwebClient({ clientId }); const wallet = createWallet("${id}"); // pass the wallet id - -// if the wallet extension is installed, connect to it -if (injectedProvider("${id}")) { - await wallet.connect({ client }); -} - -// show error message to user that wallet is not installed -else { - alert('wallet is not installed'); -} +await wallet.connect({ client }); `; } @@ -209,12 +200,7 @@ import { createWallet } from "thirdweb/wallets"; const client = createThirdwebClient({ clientId }); const wallet = createWallet("${id}"); // pass the wallet id - -// open WalletConnect modal so user can scan the QR code and connect -await wallet.connect({ - client, - walletConnect: { showQrModal: true }, -}); +await wallet.connect({ client }); `; } @@ -226,19 +212,8 @@ import { createWallet, injectedProvider } from "thirdweb/wallets"; const client = createThirdwebClient({ clientId }); const wallet = createWallet("${id}"); // pass the wallet id - -// if user has wallet installed, connect to it -if (injectedProvider("${id}")) { - await wallet.connect({ client }); -} - -// open WalletConnect modal so user can scan the QR code and connect -else { - await wallet.connect({ - client, - walletConnect: { showQrModal: true }, - }); -} +// if user has wallet installed, connects to it, otherwise opens a WalletConnect modal +await wallet.connect({ client }); `; } @@ -257,20 +232,7 @@ function Example() { onClick={() => connect(async () => { const wallet = createWallet("${id}"); // pass the wallet id - - // if user has wallet installed, connect to it - if (injectedProvider("${id}")) { - await wallet.connect({ client }); - } - - // open WalletConnect modal so user can scan the QR code and connect - else { - await wallet.connect({ - client, - walletConnect: { showQrModal: true }, - }); - } - + await wallet.connect({ client }); // return the wallet to set it as active wallet return wallet; }) @@ -298,13 +260,7 @@ function Example() { onClick={() => connect(async () => { const wallet = createWallet("${id}"); // pass the wallet id - - // open WalletConnect modal so user can scan the QR code and connect - await wallet.connect({ - client, - walletConnect: { showQrModal: true }, - }); - + await wallet.connect({ client }); // return the wallet to set it as active wallet return wallet; }) @@ -330,19 +286,12 @@ function Example() { return ( + ); +} +`; +} + +function componentCode() { + return `\ +import { ConnectButton } from "thirdweb/react"; +import { createWallet } from "thirdweb/wallets"; +import { abstractWallet } from "@abstract-foundation/agw-react/thirdweb"; + +const wallets = [ + // Add your wallet in wallet list + ${createWallet()}, + // add other wallets... +]; + +function Example() { + return ( +
+ {/* Use ConnectButton */} + + + {/* Or Use ConnectEmbed */} + +
+ ); +}`; +} + +function createWallet() { + return `abstractWallet()`; +}