Skip to content

Commit 57d5334

Browse files
committed
feat: pick first account
1 parent ee055f2 commit 57d5334

File tree

1 file changed

+19
-3
lines changed
  • wallets/provider-metamask/src/namespaces

1 file changed

+19
-3
lines changed

wallets/provider-metamask/src/namespaces/evm.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import type { EvmActions } from '@rango-dev/wallets-core/namespaces/evm';
22

3-
import { NamespaceBuilder } from '@rango-dev/wallets-core';
3+
import { ActionBuilder, NamespaceBuilder } from '@rango-dev/wallets-core';
44
import {
55
builders as commonBuilders,
6+
connectAndUpdateStateForMultiNetworks,
7+
intoConnecting,
8+
intoConnectionFinished,
69
standardizeAndThrowError,
710
} from '@rango-dev/wallets-core/namespaces/common';
811
import {
@@ -26,12 +29,25 @@ const [changeAccountSubscriber, changeAccountCleanup] = builders
2629
})
2730
.build();
2831

29-
const connect = builders
30-
.connect()
32+
const connect = new ActionBuilder<EvmActions, 'connect'>('connect')
3133
.action(actions.connect(evmMetamask))
34+
/*
35+
* Metamask Wallet's `connect` returns a list where the currently selected account
36+
* is always the first item. We're directly taking this first item as the active account.
37+
*
38+
* ***NOTE***: Please keep it synced with `wallets/core/src/namespaces/solana/builders.ts`.
39+
*
40+
*/
41+
.and((_, connectResult) => ({
42+
...connectResult,
43+
accounts: [connectResult.accounts[0]],
44+
}))
45+
.and(connectAndUpdateStateForMultiNetworks)
46+
.before(intoConnecting)
3247
.before(changeAccountSubscriber)
3348
.or(changeAccountCleanup)
3449
.or(standardizeAndThrowError)
50+
.after(intoConnectionFinished)
3551
.build();
3652

3753
const canEagerConnect = builders

0 commit comments

Comments
 (0)