11import 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' ;
44import {
55 builders as commonBuilders ,
6+ connectAndUpdateStateForMultiNetworks ,
7+ intoConnecting ,
8+ intoConnectionFinished ,
69 standardizeAndThrowError ,
710} from '@rango-dev/wallets-core/namespaces/common' ;
811import {
@@ -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
3753const canEagerConnect = builders
0 commit comments