diff --git a/.changeset/famous-places-hug.md b/.changeset/famous-places-hug.md new file mode 100644 index 00000000000..e7fa4ff0f4c --- /dev/null +++ b/.changeset/famous-places-hug.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/wagmi-adapter": patch +--- + +Add onConnect callback diff --git a/packages/wagmi-adapter/src/connector.ts b/packages/wagmi-adapter/src/connector.ts index 1307d3f857a..1556bf33d92 100644 --- a/packages/wagmi-adapter/src/connector.ts +++ b/packages/wagmi-adapter/src/connector.ts @@ -9,12 +9,14 @@ import { type MultiStepAuthArgsType, type SingleStepAuthArgsType, inAppWallet as thirdwebInAppWallet, + type Wallet, } from "thirdweb/wallets"; export type InAppWalletParameters = Prettify< InAppWalletCreationOptions & { client: ThirdwebClient; ecosystemId?: `ecosystem.${string}`; + onConnect?: (wallet: Wallet) => void; } >; export type InAppWalletConnector = ReturnType; @@ -106,6 +108,7 @@ export function inAppWalletConnector( chain: defineChain(chainId), client, wallets: [wallet], + onConnect: args.onConnect, }); const account = wallet.getAccount(); @@ -140,6 +143,7 @@ export function inAppWalletConnector( rawStorage?.setItem(connectedWalletIdsKey, JSON.stringify([wallet.id])); rawStorage?.setItem(activeWalletIdKey, wallet.id); await config.storage?.setItem("thirdweb:lastChainId", chain.id); + args.onConnect?.(wallet); return { accounts: [getAddress(account.address)], chainId: chain.id }; }, disconnect: async () => { @@ -166,6 +170,7 @@ export function inAppWalletConnector( chain, client, wallets: [wallet], + onConnect: args.onConnect, }); } return EIP1193.toProvider({