Skip to content

Commit cc41e86

Browse files
committed
chore: change evm connect to accept getAccounts
1 parent e83d757 commit cc41e86

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

wallets/core/src/namespaces/evm/actions.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { ConnectOptions, EvmActions, ProviderAPI } from './types.js';
1+
import type {
2+
ConnectOptions,
3+
EvmActions,
4+
ProviderAccounts,
5+
ProviderAPI,
6+
} from './types.js';
27
import type { Context } from '../../hub/namespaces/mod.js';
38
import type { CanEagerConnect } from '../../hub/namespaces/types.js';
49
import 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.

wallets/core/src/namespaces/evm/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ export type ProviderAPI = EIP1193Provider;
2626
// A 0x-prefixed hexadecimal string
2727
export type ChainId = string;
2828
export type Chain = AddEthereumChainParameter;
29-
29+
export type ProviderAccounts = {
30+
accounts: string[];
31+
chainId: ChainId;
32+
};
3033
export type ConnectOptions = {
3134
switchOrAddNetwork?: (instance: ProviderAPI, chain: ChainId | Chain) => void;
35+
getAccounts?: (provider: ProviderAPI) => Promise<ProviderAccounts>;
3236
derivationPath?: string;
3337
};

0 commit comments

Comments
 (0)