File tree Expand file tree Collapse file tree
wallets/core/src/namespaces/evm Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import type { ConnectOptions , EvmActions , ProviderAPI } from './types.js' ;
1+ import type {
2+ ConnectOptions ,
3+ EvmActions ,
4+ ProviderAccounts ,
5+ ProviderAPI ,
6+ } from './types.js' ;
27import type { Context } from '../../hub/namespaces/mod.js' ;
38import type { CanEagerConnect } from '../../hub/namespaces/types.js' ;
49import type { FunctionWithContext } from '../../types/actions.js' ;
@@ -43,7 +48,17 @@ export function connect(
4348 }
4449 }
4550
46- const providerAccounts = await getAccounts ( evmInstance ) ;
51+ let providerAccounts : ProviderAccounts ;
52+ /*
53+ * The `getAccounts` function can be optionally provided through `options`
54+ * to handle getting address and chainId of the specific wallet provider.
55+ * This approach is necessary because not all providers follow the same conventions.
56+ */
57+ if ( options ?. getAccounts ) {
58+ providerAccounts = await options . getAccounts ( evmInstance ) ;
59+ } else {
60+ providerAccounts = await getAccounts ( evmInstance ) ;
61+ }
4762
4863 /*
4964 * Ensure that the provider returns at least one valid account before proceeding.
Original file line number Diff line number Diff line change @@ -26,8 +26,12 @@ export type ProviderAPI = EIP1193Provider;
2626// A 0x-prefixed hexadecimal string
2727export type ChainId = string ;
2828export type Chain = AddEthereumChainParameter ;
29-
29+ export type ProviderAccounts = {
30+ accounts : string [ ] ;
31+ chainId : ChainId ;
32+ } ;
3033export type ConnectOptions = {
3134 switchOrAddNetwork ?: ( instance : ProviderAPI , chain : ChainId | Chain ) => void ;
35+ getAccounts ?: ( provider : ProviderAPI ) => Promise < ProviderAccounts > ;
3236 derivationPath ?: string ;
3337} ;
You can’t perform that action at this time.
0 commit comments