From 8ba99e0079f564002b05a2dcf372ded5fcc1fe33 Mon Sep 17 00:00:00 2001 From: Chaitanya Potti Date: Tue, 24 Sep 2024 20:05:41 +0800 Subject: [PATCH] add wallet connect to solana defaults --- package-lock.json | 1 + .../default-solana-adapter/package.json | 1 + .../default-solana-adapter/src/index.ts | 26 +++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 125163b79..77d2ed43a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26751,6 +26751,7 @@ "@web3auth/base": "^9.0.2", "@web3auth/base-solana-adapter": "^9.0.2", "@web3auth/solana-provider": "^9.0.2", + "@web3auth/wallet-connect-v2-adapter": "^9.1.0", "bn.js": "^5.2.1" }, "engines": { diff --git a/packages/adapters/default-solana-adapter/package.json b/packages/adapters/default-solana-adapter/package.json index 259500171..54199c507 100644 --- a/packages/adapters/default-solana-adapter/package.json +++ b/packages/adapters/default-solana-adapter/package.json @@ -20,6 +20,7 @@ "pre-commit": "lint-staged --cwd ." }, "dependencies": { + "@web3auth/wallet-connect-v2-adapter": "^9.1.0", "@solana/wallet-standard-features": "^1.2.0", "@solana/web3.js": "^1.95.3", "@wallet-standard/app": "^1.0.1", diff --git a/packages/adapters/default-solana-adapter/src/index.ts b/packages/adapters/default-solana-adapter/src/index.ts index 84d141076..2369779a0 100644 --- a/packages/adapters/default-solana-adapter/src/index.ts +++ b/packages/adapters/default-solana-adapter/src/index.ts @@ -1,9 +1,31 @@ -import { IAdapter, IWeb3AuthCoreOptions } from "@web3auth/base"; +import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IWeb3AuthCoreOptions, WalletInitializationError } from "@web3auth/base"; +import { WalletConnectV2Adapter } from "@web3auth/wallet-connect-v2-adapter"; import { getInjectedAdapters } from "./injectedAdapters"; export const getDefaultExternalAdapters = (params: { options: IWeb3AuthCoreOptions }): IAdapter[] => { - return getInjectedAdapters(params); + const { options } = params; + const { clientId, chainConfig, sessionTime, web3AuthNetwork, useCoreKitKey } = options; + if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace)) + throw WalletInitializationError.invalidParams(`Invalid chainNamespace: ${chainConfig.chainNamespace}`); + const finalChainConfig = { + ...(getChainConfig(chainConfig.chainNamespace, chainConfig?.chainId) as CustomChainConfig), + ...(chainConfig || {}), + }; + + const wcv2Adapter = new WalletConnectV2Adapter({ + chainConfig: finalChainConfig, + clientId, + sessionTime, + web3AuthNetwork, + useCoreKitKey, + adapterSettings: { + walletConnectInitOptions: {}, + }, + }); + const injectedProviders = getInjectedAdapters({ options }); + + return [...injectedProviders, wcv2Adapter]; }; export { getInjectedAdapters };