diff --git a/packages/core/src/main.ts b/packages/core/src/main.ts index b6c7069..41119b4 100644 --- a/packages/core/src/main.ts +++ b/packages/core/src/main.ts @@ -13,6 +13,7 @@ import { sortBy } from "./wallet/sort" import { initiateVirtualWallets, resolveVirtualWallet, + virtualWallets, } from "./wallet/virtualWallets" import { Permission, type StarknetWindowObject } from "@starknet-io/types-js" @@ -116,6 +117,14 @@ export function getStarknet( return firstAuthorizedWallet }, + discoverVirtualWallets: async () => { + virtualWallets.forEach(async (virtualWallet) => { + const hasSupport = await virtualWallet.hasSupport(windowObject) + if (hasSupport) { + windowObject[virtualWallet.windowKey] = virtualWallet + } + }) + }, enable: async (inputWallet, options) => { let wallet: StarknetWindowObject if (isVirtualWallet(inputWallet)) { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 3fb0c9e..49e81bf 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -69,6 +69,7 @@ export interface GetStarknetResult { ) => Promise // Returns only preauthorized wallets available in the window object getDiscoveryWallets: (options?: GetWalletOptions) => Promise // Returns all wallets in existence (from discovery file) getLastConnectedWallet: () => Promise // Returns the last wallet connected when it's still connected + discoverVirtualWallets: () => Promise // Discovers the virtual wallets by calling their hasSupport methods enable: ( wallet: StarknetWindowObject | VirtualWallet, options?: RequestAccountsParameters, diff --git a/packages/core/src/wallet/virtualWallets/index.ts b/packages/core/src/wallet/virtualWallets/index.ts index a7d5288..5924500 100644 --- a/packages/core/src/wallet/virtualWallets/index.ts +++ b/packages/core/src/wallet/virtualWallets/index.ts @@ -6,9 +6,11 @@ const virtualWallets: VirtualWallet[] = [metaMaskVirtualWallet] function initiateVirtualWallets(windowObject: Record) { virtualWallets.forEach(async (virtualWallet) => { - const hasSupport = await virtualWallet.hasSupport(windowObject) - if (hasSupport) { - windowObject[virtualWallet.windowKey] = virtualWallet + if (!(virtualWallet.windowKey in windowObject)) { + const hasSupport = await virtualWallet.hasSupport(windowObject) + if (hasSupport) { + windowObject[virtualWallet.windowKey] = virtualWallet + } } }) } @@ -28,4 +30,4 @@ async function resolveVirtualWallet( return wallet } -export { initiateVirtualWallets, resolveVirtualWallet } +export { initiateVirtualWallets, resolveVirtualWallet, virtualWallets }