11import { GeneralException } from '@injectivelabs/exceptions'
22import { BaseWalletStrategy } from '@injectivelabs/wallet-core'
3- import {
4- Wallet ,
5- isEvmWallet ,
6- type WalletMetadata ,
7- } from '@injectivelabs/wallet-base'
3+ import { Wallet , isEvmWallet } from '@injectivelabs/wallet-base'
84import {
95 loadEvmStrategy ,
106 loadMagicStrategy ,
@@ -16,6 +12,10 @@ import {
1612 loadWalletConnectStrategy ,
1713} from './loaders.js'
1814import type { Wallet as WalletType } from '@injectivelabs/wallet-base'
15+ import type {
16+ WalletMetadata ,
17+ StrategyEmitter ,
18+ } from '@injectivelabs/wallet-base'
1919import type {
2020 ConcreteStrategiesArg ,
2121 ConcreteWalletStrategy ,
@@ -43,9 +43,11 @@ const ethereumWalletsDisabled = (args: WalletStrategyArguments) => {
4343const createStrategy = async ( {
4444 args,
4545 wallet,
46+ emitter,
4647} : {
4748 wallet : Wallet
4849 args : WalletStrategyArguments
50+ emitter ?: StrategyEmitter
4951} ) : Promise < ConcreteWalletStrategy | undefined > => {
5052 /**
5153 * If we only want to use Cosmos Native Wallets
@@ -63,8 +65,14 @@ const createStrategy = async ({
6365 ...args ,
6466 chainId : args . chainId ,
6567 evmOptions : args . evmOptions as WalletStrategyEvmOptions ,
68+ emitter,
6669 } as ConcreteEvmWalletStrategyArgs
6770
71+ const cosmosWalletArgs = {
72+ ...args ,
73+ emitter,
74+ }
75+
6876 switch ( wallet ) {
6977 case Wallet . Metamask :
7078 case Wallet . TrustWallet :
@@ -88,7 +96,7 @@ const createStrategy = async ({
8896 case Wallet . Cosmostation : {
8997 const CosmosWalletStrategy = await loadCosmosStrategy ( )
9098
91- return new CosmosWalletStrategy ( { ...args , wallet } )
99+ return new CosmosWalletStrategy ( { ...cosmosWalletArgs , wallet } )
92100 }
93101
94102 case Wallet . Ledger : {
@@ -136,7 +144,7 @@ const createStrategy = async ({
136144 }
137145 const MagicStrategy = await loadMagicStrategy ( )
138146
139- return new MagicStrategy ( args )
147+ return new MagicStrategy ( cosmosWalletArgs )
140148 }
141149
142150 case Wallet . WalletConnect : {
@@ -179,7 +187,8 @@ export class WalletStrategy extends BaseWalletStrategy {
179187 this . wallet = wallet
180188
181189 // Preload the strategy for the new wallet
182- await this . loadStrategy ( wallet )
190+ const strategy = await this . loadStrategy ( wallet )
191+ await strategy ?. initStrategy ?.( )
183192 }
184193
185194 /**
@@ -221,6 +230,7 @@ export class WalletStrategy extends BaseWalletStrategy {
221230 metadata : { ...this . args . metadata , ...metadata } ,
222231 } ,
223232 wallet : walletEnum ,
233+ emitter : this . getEmitter ( ) ,
224234 } )
225235
226236 continue
@@ -240,7 +250,9 @@ export class WalletStrategy extends BaseWalletStrategy {
240250 */
241251 public getStrategy ( ) : ConcreteWalletStrategy {
242252 if ( this . strategies [ this . wallet ] ) {
243- return this . strategies [ this . wallet ] as ConcreteWalletStrategy
253+ const strategy = this . strategies [ this . wallet ] as ConcreteWalletStrategy
254+
255+ return strategy
244256 }
245257
246258 throw new GeneralException (
@@ -275,6 +287,7 @@ export class WalletStrategy extends BaseWalletStrategy {
275287 const loadPromise = createStrategy ( {
276288 args : this . args ,
277289 wallet,
290+ emitter : this . getEmitter ( ) ,
278291 } )
279292
280293 this . loadingStrategies . set ( wallet , loadPromise )
0 commit comments