@injectivelabs/wallet-strategy 1.16.38-alpha.2 → 1.16.38-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,65 @@
1
- let __injectivelabs_wallet_magic = require("@injectivelabs/wallet-magic");
2
1
  let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
3
- let __injectivelabs_wallet_evm = require("@injectivelabs/wallet-evm");
4
2
  let __injectivelabs_wallet_core = require("@injectivelabs/wallet-core");
5
- let __injectivelabs_wallet_cosmos = require("@injectivelabs/wallet-cosmos");
6
- let __injectivelabs_wallet_turnkey = require("@injectivelabs/wallet-turnkey");
7
- let __injectivelabs_wallet_wallet_connect = require("@injectivelabs/wallet-wallet-connect");
8
- let __injectivelabs_wallet_private_key = require("@injectivelabs/wallet-private-key");
9
- let __injectivelabs_wallet_cosmostation = require("@injectivelabs/wallet-cosmostation");
10
3
  let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
11
- let __injectivelabs_wallet_ledger = require("@injectivelabs/wallet-ledger");
12
- let __injectivelabs_wallet_trezor = require("@injectivelabs/wallet-trezor");
13
4
 
5
+ //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
6
+ function _typeof(o) {
7
+ "@babel/helpers - typeof";
8
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
9
+ return typeof o$1;
10
+ } : function(o$1) {
11
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
12
+ }, _typeof(o);
13
+ }
14
+
15
+ //#endregion
16
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
17
+ function toPrimitive(t, r) {
18
+ if ("object" != _typeof(t) || !t) return t;
19
+ var e = t[Symbol.toPrimitive];
20
+ if (void 0 !== e) {
21
+ var i = e.call(t, r || "default");
22
+ if ("object" != _typeof(i)) return i;
23
+ throw new TypeError("@@toPrimitive must return a primitive value.");
24
+ }
25
+ return ("string" === r ? String : Number)(t);
26
+ }
27
+
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
30
+ function toPropertyKey(t) {
31
+ var i = toPrimitive(t, "string");
32
+ return "symbol" == _typeof(i) ? i : i + "";
33
+ }
34
+
35
+ //#endregion
36
+ //#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
37
+ function _defineProperty(e, r, t) {
38
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
39
+ value: t,
40
+ enumerable: !0,
41
+ configurable: !0,
42
+ writable: !0
43
+ }) : e[r] = t, e;
44
+ }
45
+
46
+ //#endregion
14
47
  //#region src/strategy/index.ts
48
+ const loadEvmStrategy = () => import("@injectivelabs/wallet-evm").then((m) => m.EvmWalletStrategy);
49
+ const loadCosmosStrategy = () => import("@injectivelabs/wallet-cosmos").then((m) => m.CosmosWalletStrategy);
50
+ const loadCosmostationStrategy = () => import("@injectivelabs/wallet-cosmostation").then((m) => m.CosmostationWalletStrategy);
51
+ const loadLedgerStrategies = () => import("@injectivelabs/wallet-ledger").then((m) => ({
52
+ LedgerLiveStrategy: m.LedgerLiveStrategy,
53
+ LedgerLegacyStrategy: m.LedgerLegacyStrategy
54
+ }));
55
+ const loadTrezorStrategies = () => import("@injectivelabs/wallet-trezor").then((m) => ({
56
+ TrezorBip32Strategy: m.TrezorBip32Strategy,
57
+ TrezorBip44Strategy: m.TrezorBip44Strategy
58
+ }));
59
+ const loadPrivateKeyStrategy = () => import("@injectivelabs/wallet-private-key").then((m) => m.PrivateKeyWalletStrategy);
60
+ const loadTurnkeyStrategy = () => import("@injectivelabs/wallet-turnkey").then((m) => m.TurnkeyWalletStrategy);
61
+ const loadMagicStrategy = () => import("@injectivelabs/wallet-magic").then((m) => m.MagicStrategy);
62
+ const loadWalletConnectStrategy = () => import("@injectivelabs/wallet-wallet-connect").then((m) => m.WalletConnectStrategy);
15
63
  const ethereumWalletsDisabled = (args) => {
16
64
  const { evmOptions } = args;
17
65
  if (!evmOptions) return true;
@@ -19,7 +67,7 @@ const ethereumWalletsDisabled = (args) => {
19
67
  if (!evmChainId) return true;
20
68
  return false;
21
69
  };
22
- const createStrategy = ({ args, wallet }) => {
70
+ const createStrategy = async ({ args, wallet }) => {
23
71
  /**
24
72
  * If we only want to use Cosmos Native Wallets
25
73
  * We are not creating strategies for Ethereum Native Wallets
@@ -34,68 +82,53 @@ const createStrategy = ({ args, wallet }) => {
34
82
  evmOptions: args.evmOptions
35
83
  };
36
84
  switch (wallet) {
37
- case __injectivelabs_wallet_base.Wallet.Metamask: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
38
- ...ethWalletArgs,
39
- wallet: __injectivelabs_wallet_base.Wallet.Metamask
40
- });
41
- case __injectivelabs_wallet_base.Wallet.TrustWallet: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
42
- ...ethWalletArgs,
43
- wallet: __injectivelabs_wallet_base.Wallet.TrustWallet
44
- });
45
- case __injectivelabs_wallet_base.Wallet.Phantom: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
46
- ...ethWalletArgs,
47
- wallet: __injectivelabs_wallet_base.Wallet.Phantom
48
- });
49
- case __injectivelabs_wallet_base.Wallet.OkxWallet: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
50
- ...ethWalletArgs,
51
- wallet: __injectivelabs_wallet_base.Wallet.OkxWallet
52
- });
53
- case __injectivelabs_wallet_base.Wallet.BitGet: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
54
- ...ethWalletArgs,
55
- wallet: __injectivelabs_wallet_base.Wallet.BitGet
56
- });
57
- case __injectivelabs_wallet_base.Wallet.Rainbow: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
58
- ...ethWalletArgs,
59
- wallet: __injectivelabs_wallet_base.Wallet.Rainbow
60
- });
61
- case __injectivelabs_wallet_base.Wallet.Rabby: return new __injectivelabs_wallet_evm.EvmWalletStrategy({
85
+ case __injectivelabs_wallet_base.Wallet.Metamask:
86
+ case __injectivelabs_wallet_base.Wallet.TrustWallet:
87
+ case __injectivelabs_wallet_base.Wallet.Phantom:
88
+ case __injectivelabs_wallet_base.Wallet.OkxWallet:
89
+ case __injectivelabs_wallet_base.Wallet.BitGet:
90
+ case __injectivelabs_wallet_base.Wallet.Rainbow:
91
+ case __injectivelabs_wallet_base.Wallet.Rabby: return new (await (loadEvmStrategy()))({
62
92
  ...ethWalletArgs,
63
- wallet: __injectivelabs_wallet_base.Wallet.Rabby
64
- });
65
- case __injectivelabs_wallet_base.Wallet.Keplr: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
66
- ...args,
67
- wallet: __injectivelabs_wallet_base.Wallet.Keplr
68
- });
69
- case __injectivelabs_wallet_base.Wallet.Leap: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
70
- ...args,
71
- wallet: __injectivelabs_wallet_base.Wallet.Leap
72
- });
73
- case __injectivelabs_wallet_base.Wallet.Ninji: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
74
- ...args,
75
- wallet: __injectivelabs_wallet_base.Wallet.Ninji
93
+ wallet
76
94
  });
77
- case __injectivelabs_wallet_base.Wallet.OWallet: return new __injectivelabs_wallet_cosmos.CosmosWalletStrategy({
95
+ case __injectivelabs_wallet_base.Wallet.Keplr:
96
+ case __injectivelabs_wallet_base.Wallet.Leap:
97
+ case __injectivelabs_wallet_base.Wallet.Ninji:
98
+ case __injectivelabs_wallet_base.Wallet.OWallet: return new (await (loadCosmosStrategy()))({
78
99
  ...args,
79
- wallet: __injectivelabs_wallet_base.Wallet.OWallet
100
+ wallet
80
101
  });
81
- case __injectivelabs_wallet_base.Wallet.Cosmostation: return new __injectivelabs_wallet_cosmostation.CosmostationWalletStrategy({ ...args });
82
- case __injectivelabs_wallet_base.Wallet.Ledger: return new __injectivelabs_wallet_ledger.LedgerLiveStrategy(ethWalletArgs);
83
- case __injectivelabs_wallet_base.Wallet.LedgerLegacy: return new __injectivelabs_wallet_ledger.LedgerLegacyStrategy(ethWalletArgs);
84
- case __injectivelabs_wallet_base.Wallet.TrezorBip32: return new __injectivelabs_wallet_trezor.TrezorBip32Strategy(ethWalletArgs);
85
- case __injectivelabs_wallet_base.Wallet.TrezorBip44: return new __injectivelabs_wallet_trezor.TrezorBip44Strategy(ethWalletArgs);
86
- case __injectivelabs_wallet_base.Wallet.PrivateKey: return new __injectivelabs_wallet_private_key.PrivateKeyWalletStrategy(ethWalletArgs);
102
+ case __injectivelabs_wallet_base.Wallet.Cosmostation: return new (await (loadCosmostationStrategy()))({ ...args });
103
+ case __injectivelabs_wallet_base.Wallet.Ledger: {
104
+ const { LedgerLiveStrategy } = await loadLedgerStrategies();
105
+ return new LedgerLiveStrategy(ethWalletArgs);
106
+ }
107
+ case __injectivelabs_wallet_base.Wallet.LedgerLegacy: {
108
+ const { LedgerLegacyStrategy } = await loadLedgerStrategies();
109
+ return new LedgerLegacyStrategy(ethWalletArgs);
110
+ }
111
+ case __injectivelabs_wallet_base.Wallet.TrezorBip32: {
112
+ const { TrezorBip32Strategy } = await loadTrezorStrategies();
113
+ return new TrezorBip32Strategy(ethWalletArgs);
114
+ }
115
+ case __injectivelabs_wallet_base.Wallet.TrezorBip44: {
116
+ const { TrezorBip44Strategy } = await loadTrezorStrategies();
117
+ return new TrezorBip44Strategy(ethWalletArgs);
118
+ }
119
+ case __injectivelabs_wallet_base.Wallet.PrivateKey: return new (await (loadPrivateKeyStrategy()))(ethWalletArgs);
87
120
  case __injectivelabs_wallet_base.Wallet.Turnkey:
88
121
  var _args$metadata;
89
122
  if (!((_args$metadata = args.metadata) === null || _args$metadata === void 0 || (_args$metadata = _args$metadata.turnkey) === null || _args$metadata === void 0 ? void 0 : _args$metadata.defaultOrganizationId)) return;
90
- return new __injectivelabs_wallet_turnkey.TurnkeyWalletStrategy(ethWalletArgs);
123
+ return new (await (loadTurnkeyStrategy()))(ethWalletArgs);
91
124
  case __injectivelabs_wallet_base.Wallet.Magic:
92
125
  var _args$metadata2, _args$metadata3;
93
126
  if (!((_args$metadata2 = args.metadata) === null || _args$metadata2 === void 0 || (_args$metadata2 = _args$metadata2.magic) === null || _args$metadata2 === void 0 ? void 0 : _args$metadata2.apiKey) || !((_args$metadata3 = args.metadata) === null || _args$metadata3 === void 0 || (_args$metadata3 = _args$metadata3.magic) === null || _args$metadata3 === void 0 ? void 0 : _args$metadata3.rpcEndpoint)) return;
94
- return new __injectivelabs_wallet_magic.MagicStrategy(args);
127
+ return new (await (loadMagicStrategy()))(args);
95
128
  case __injectivelabs_wallet_base.Wallet.WalletConnect:
96
129
  var _args$metadata4;
97
130
  if (!((_args$metadata4 = args.metadata) === null || _args$metadata4 === void 0 || (_args$metadata4 = _args$metadata4.walletConnect) === null || _args$metadata4 === void 0 ? void 0 : _args$metadata4.projectId)) return;
98
- return new __injectivelabs_wallet_wallet_connect.WalletConnectStrategy(ethWalletArgs);
131
+ return new (await (loadWalletConnectStrategy()))(ethWalletArgs);
99
132
  default: return;
100
133
  }
101
134
  };
@@ -106,6 +139,18 @@ var WalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrateg
106
139
  ...args,
107
140
  strategies
108
141
  });
142
+ _defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
143
+ }
144
+ /**
145
+ * Set the current wallet and load its strategy.
146
+ * This method is async because strategies are lazy-loaded.
147
+ *
148
+ * @param wallet - The wallet to set as active
149
+ * @throws GeneralException if the wallet strategy cannot be loaded
150
+ */
151
+ async setWallet(wallet) {
152
+ this.wallet = wallet;
153
+ await this.loadStrategy(wallet);
109
154
  }
110
155
  /**
111
156
  * This method is used to set the metadata for the wallet strategies.
@@ -121,7 +166,7 @@ var WalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrateg
121
166
  * Case 2: Similar to Case 1, but for Wallet Connect Metadata
122
167
  *
123
168
  */
124
- setMetadata(metadata) {
169
+ async setMetadata(metadata) {
125
170
  const shouldRecreateStrategyOnMetadataChange = [__injectivelabs_wallet_base.Wallet.PrivateKey, __injectivelabs_wallet_base.Wallet.WalletConnect];
126
171
  const strategiesWithPlaceholders = {
127
172
  ...this.strategies,
@@ -132,7 +177,8 @@ var WalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrateg
132
177
  var _this$strategies$wall, _this$strategies$wall2;
133
178
  const walletEnum = wallet;
134
179
  if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
135
- this.strategies[walletEnum] = createStrategy({
180
+ this.loadingStrategies.delete(walletEnum);
181
+ this.strategies[walletEnum] = await createStrategy({
136
182
  args: {
137
183
  ...this.args,
138
184
  metadata: {
@@ -147,15 +193,50 @@ var WalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrateg
147
193
  (_this$strategies$wall = this.strategies[walletEnum]) === null || _this$strategies$wall === void 0 || (_this$strategies$wall2 = _this$strategies$wall.setMetadata) === null || _this$strategies$wall2 === void 0 || _this$strategies$wall2.call(_this$strategies$wall, metadata);
148
194
  }
149
195
  }
196
+ /**
197
+ * Get the strategy for the current wallet.
198
+ *
199
+ * NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
200
+ * This method throws if the strategy hasn't been loaded yet.
201
+ *
202
+ * @throws GeneralException if the strategy hasn't been loaded
203
+ */
150
204
  getStrategy() {
151
205
  if (this.strategies[this.wallet]) return this.strategies[this.wallet];
152
- const strategy = createStrategy({
206
+ throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} strategy not loaded. Call setWallet() or loadStrategy() first.`));
207
+ }
208
+ /**
209
+ * Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
210
+ * Call this method before using getStrategy() for a wallet.
211
+ *
212
+ * @param wallet - The wallet strategy to load (defaults to current wallet)
213
+ * @returns The loaded strategy
214
+ */
215
+ async loadStrategy(wallet = this.wallet) {
216
+ if (this.strategies[wallet]) return this.strategies[wallet];
217
+ const existingLoad = this.loadingStrategies.get(wallet);
218
+ if (existingLoad) return existingLoad;
219
+ const loadPromise = createStrategy({
153
220
  args: this.args,
154
- wallet: this.wallet
221
+ wallet
155
222
  });
156
- if (!strategy) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} is not enabled/available!`));
157
- this.strategies[this.wallet] = strategy;
158
- return strategy;
223
+ this.loadingStrategies.set(wallet, loadPromise);
224
+ try {
225
+ const strategy = await loadPromise;
226
+ if (strategy) this.strategies[wallet] = strategy;
227
+ return strategy;
228
+ } finally {
229
+ this.loadingStrategies.delete(wallet);
230
+ }
231
+ }
232
+ /**
233
+ * Load multiple wallet strategies in parallel.
234
+ * Useful for preloading commonly used wallets during app initialization.
235
+ *
236
+ * @param wallets - Array of wallets to preload
237
+ */
238
+ async loadStrategies(wallets) {
239
+ await Promise.all(wallets.map((wallet) => this.loadStrategy(wallet)));
159
240
  }
160
241
  };
161
242
  const createStrategyFactory = (args) => {
@@ -1,9 +1,18 @@
1
1
  import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
2
- import { ConcreteWalletStrategy, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
2
+ import { ConcreteWalletStrategy, Wallet, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
3
3
 
4
4
  //#region src/strategy/index.d.ts
5
5
  declare class WalletStrategy extends BaseWalletStrategy {
6
+ private loadingStrategies;
6
7
  constructor(args: WalletStrategyArguments);
8
+ /**
9
+ * Set the current wallet and load its strategy.
10
+ * This method is async because strategies are lazy-loaded.
11
+ *
12
+ * @param wallet - The wallet to set as active
13
+ * @throws GeneralException if the wallet strategy cannot be loaded
14
+ */
15
+ setWallet(wallet: Wallet): Promise<void>;
7
16
  /**
8
17
  * This method is used to set the metadata for the wallet strategies.
9
18
  * In some cases we are going to set the metadata dynamically on the fly, and in
@@ -18,8 +27,31 @@ declare class WalletStrategy extends BaseWalletStrategy {
18
27
  * Case 2: Similar to Case 1, but for Wallet Connect Metadata
19
28
  *
20
29
  */
21
- setMetadata(metadata?: WalletMetadata): void;
30
+ setMetadata(metadata?: WalletMetadata): Promise<void>;
31
+ /**
32
+ * Get the strategy for the current wallet.
33
+ *
34
+ * NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
35
+ * This method throws if the strategy hasn't been loaded yet.
36
+ *
37
+ * @throws GeneralException if the strategy hasn't been loaded
38
+ */
22
39
  getStrategy(): ConcreteWalletStrategy;
40
+ /**
41
+ * Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
42
+ * Call this method before using getStrategy() for a wallet.
43
+ *
44
+ * @param wallet - The wallet strategy to load (defaults to current wallet)
45
+ * @returns The loaded strategy
46
+ */
47
+ loadStrategy(wallet?: Wallet): Promise<ConcreteWalletStrategy | undefined>;
48
+ /**
49
+ * Load multiple wallet strategies in parallel.
50
+ * Useful for preloading commonly used wallets during app initialization.
51
+ *
52
+ * @param wallets - Array of wallets to preload
53
+ */
54
+ loadStrategies(wallets: Wallet[]): Promise<void>;
23
55
  }
24
56
  declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
25
57
  //#endregion
@@ -1,9 +1,18 @@
1
1
  import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
2
- import { ConcreteWalletStrategy, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
2
+ import { ConcreteWalletStrategy, Wallet, WalletMetadata, WalletStrategyArguments } from "@injectivelabs/wallet-base";
3
3
 
4
4
  //#region src/strategy/index.d.ts
5
5
  declare class WalletStrategy extends BaseWalletStrategy {
6
+ private loadingStrategies;
6
7
  constructor(args: WalletStrategyArguments);
8
+ /**
9
+ * Set the current wallet and load its strategy.
10
+ * This method is async because strategies are lazy-loaded.
11
+ *
12
+ * @param wallet - The wallet to set as active
13
+ * @throws GeneralException if the wallet strategy cannot be loaded
14
+ */
15
+ setWallet(wallet: Wallet): Promise<void>;
7
16
  /**
8
17
  * This method is used to set the metadata for the wallet strategies.
9
18
  * In some cases we are going to set the metadata dynamically on the fly, and in
@@ -18,8 +27,31 @@ declare class WalletStrategy extends BaseWalletStrategy {
18
27
  * Case 2: Similar to Case 1, but for Wallet Connect Metadata
19
28
  *
20
29
  */
21
- setMetadata(metadata?: WalletMetadata): void;
30
+ setMetadata(metadata?: WalletMetadata): Promise<void>;
31
+ /**
32
+ * Get the strategy for the current wallet.
33
+ *
34
+ * NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
35
+ * This method throws if the strategy hasn't been loaded yet.
36
+ *
37
+ * @throws GeneralException if the strategy hasn't been loaded
38
+ */
22
39
  getStrategy(): ConcreteWalletStrategy;
40
+ /**
41
+ * Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
42
+ * Call this method before using getStrategy() for a wallet.
43
+ *
44
+ * @param wallet - The wallet strategy to load (defaults to current wallet)
45
+ * @returns The loaded strategy
46
+ */
47
+ loadStrategy(wallet?: Wallet): Promise<ConcreteWalletStrategy | undefined>;
48
+ /**
49
+ * Load multiple wallet strategies in parallel.
50
+ * Useful for preloading commonly used wallets during app initialization.
51
+ *
52
+ * @param wallets - Array of wallets to preload
53
+ */
54
+ loadStrategies(wallets: Wallet[]): Promise<void>;
23
55
  }
24
56
  declare const createStrategyFactory: (args: WalletStrategyArguments) => WalletStrategy;
25
57
  //#endregion
package/dist/esm/index.js CHANGED
@@ -1,17 +1,65 @@
1
- import { MagicStrategy } from "@injectivelabs/wallet-magic";
2
1
  import { GeneralException } from "@injectivelabs/exceptions";
3
- import { EvmWalletStrategy } from "@injectivelabs/wallet-evm";
4
2
  import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
5
- import { CosmosWalletStrategy } from "@injectivelabs/wallet-cosmos";
6
- import { TurnkeyWalletStrategy } from "@injectivelabs/wallet-turnkey";
7
- import { WalletConnectStrategy } from "@injectivelabs/wallet-wallet-connect";
8
- import { PrivateKeyWalletStrategy } from "@injectivelabs/wallet-private-key";
9
- import { CosmostationWalletStrategy } from "@injectivelabs/wallet-cosmostation";
10
3
  import { Wallet, isEvmWallet } from "@injectivelabs/wallet-base";
11
- import { LedgerLegacyStrategy, LedgerLiveStrategy } from "@injectivelabs/wallet-ledger";
12
- import { TrezorBip32Strategy, TrezorBip44Strategy } from "@injectivelabs/wallet-trezor";
13
4
 
5
+ //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
6
+ function _typeof(o) {
7
+ "@babel/helpers - typeof";
8
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
9
+ return typeof o$1;
10
+ } : function(o$1) {
11
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
12
+ }, _typeof(o);
13
+ }
14
+
15
+ //#endregion
16
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
17
+ function toPrimitive(t, r) {
18
+ if ("object" != _typeof(t) || !t) return t;
19
+ var e = t[Symbol.toPrimitive];
20
+ if (void 0 !== e) {
21
+ var i = e.call(t, r || "default");
22
+ if ("object" != _typeof(i)) return i;
23
+ throw new TypeError("@@toPrimitive must return a primitive value.");
24
+ }
25
+ return ("string" === r ? String : Number)(t);
26
+ }
27
+
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
30
+ function toPropertyKey(t) {
31
+ var i = toPrimitive(t, "string");
32
+ return "symbol" == _typeof(i) ? i : i + "";
33
+ }
34
+
35
+ //#endregion
36
+ //#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
37
+ function _defineProperty(e, r, t) {
38
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
39
+ value: t,
40
+ enumerable: !0,
41
+ configurable: !0,
42
+ writable: !0
43
+ }) : e[r] = t, e;
44
+ }
45
+
46
+ //#endregion
14
47
  //#region src/strategy/index.ts
48
+ const loadEvmStrategy = () => import("@injectivelabs/wallet-evm").then((m) => m.EvmWalletStrategy);
49
+ const loadCosmosStrategy = () => import("@injectivelabs/wallet-cosmos").then((m) => m.CosmosWalletStrategy);
50
+ const loadCosmostationStrategy = () => import("@injectivelabs/wallet-cosmostation").then((m) => m.CosmostationWalletStrategy);
51
+ const loadLedgerStrategies = () => import("@injectivelabs/wallet-ledger").then((m) => ({
52
+ LedgerLiveStrategy: m.LedgerLiveStrategy,
53
+ LedgerLegacyStrategy: m.LedgerLegacyStrategy
54
+ }));
55
+ const loadTrezorStrategies = () => import("@injectivelabs/wallet-trezor").then((m) => ({
56
+ TrezorBip32Strategy: m.TrezorBip32Strategy,
57
+ TrezorBip44Strategy: m.TrezorBip44Strategy
58
+ }));
59
+ const loadPrivateKeyStrategy = () => import("@injectivelabs/wallet-private-key").then((m) => m.PrivateKeyWalletStrategy);
60
+ const loadTurnkeyStrategy = () => import("@injectivelabs/wallet-turnkey").then((m) => m.TurnkeyWalletStrategy);
61
+ const loadMagicStrategy = () => import("@injectivelabs/wallet-magic").then((m) => m.MagicStrategy);
62
+ const loadWalletConnectStrategy = () => import("@injectivelabs/wallet-wallet-connect").then((m) => m.WalletConnectStrategy);
15
63
  const ethereumWalletsDisabled = (args) => {
16
64
  const { evmOptions } = args;
17
65
  if (!evmOptions) return true;
@@ -19,7 +67,7 @@ const ethereumWalletsDisabled = (args) => {
19
67
  if (!evmChainId) return true;
20
68
  return false;
21
69
  };
22
- const createStrategy = ({ args, wallet }) => {
70
+ const createStrategy = async ({ args, wallet }) => {
23
71
  /**
24
72
  * If we only want to use Cosmos Native Wallets
25
73
  * We are not creating strategies for Ethereum Native Wallets
@@ -34,68 +82,53 @@ const createStrategy = ({ args, wallet }) => {
34
82
  evmOptions: args.evmOptions
35
83
  };
36
84
  switch (wallet) {
37
- case Wallet.Metamask: return new EvmWalletStrategy({
38
- ...ethWalletArgs,
39
- wallet: Wallet.Metamask
40
- });
41
- case Wallet.TrustWallet: return new EvmWalletStrategy({
42
- ...ethWalletArgs,
43
- wallet: Wallet.TrustWallet
44
- });
45
- case Wallet.Phantom: return new EvmWalletStrategy({
46
- ...ethWalletArgs,
47
- wallet: Wallet.Phantom
48
- });
49
- case Wallet.OkxWallet: return new EvmWalletStrategy({
50
- ...ethWalletArgs,
51
- wallet: Wallet.OkxWallet
52
- });
53
- case Wallet.BitGet: return new EvmWalletStrategy({
54
- ...ethWalletArgs,
55
- wallet: Wallet.BitGet
56
- });
57
- case Wallet.Rainbow: return new EvmWalletStrategy({
58
- ...ethWalletArgs,
59
- wallet: Wallet.Rainbow
60
- });
61
- case Wallet.Rabby: return new EvmWalletStrategy({
85
+ case Wallet.Metamask:
86
+ case Wallet.TrustWallet:
87
+ case Wallet.Phantom:
88
+ case Wallet.OkxWallet:
89
+ case Wallet.BitGet:
90
+ case Wallet.Rainbow:
91
+ case Wallet.Rabby: return new (await (loadEvmStrategy()))({
62
92
  ...ethWalletArgs,
63
- wallet: Wallet.Rabby
64
- });
65
- case Wallet.Keplr: return new CosmosWalletStrategy({
66
- ...args,
67
- wallet: Wallet.Keplr
68
- });
69
- case Wallet.Leap: return new CosmosWalletStrategy({
70
- ...args,
71
- wallet: Wallet.Leap
72
- });
73
- case Wallet.Ninji: return new CosmosWalletStrategy({
74
- ...args,
75
- wallet: Wallet.Ninji
93
+ wallet
76
94
  });
77
- case Wallet.OWallet: return new CosmosWalletStrategy({
95
+ case Wallet.Keplr:
96
+ case Wallet.Leap:
97
+ case Wallet.Ninji:
98
+ case Wallet.OWallet: return new (await (loadCosmosStrategy()))({
78
99
  ...args,
79
- wallet: Wallet.OWallet
100
+ wallet
80
101
  });
81
- case Wallet.Cosmostation: return new CosmostationWalletStrategy({ ...args });
82
- case Wallet.Ledger: return new LedgerLiveStrategy(ethWalletArgs);
83
- case Wallet.LedgerLegacy: return new LedgerLegacyStrategy(ethWalletArgs);
84
- case Wallet.TrezorBip32: return new TrezorBip32Strategy(ethWalletArgs);
85
- case Wallet.TrezorBip44: return new TrezorBip44Strategy(ethWalletArgs);
86
- case Wallet.PrivateKey: return new PrivateKeyWalletStrategy(ethWalletArgs);
102
+ case Wallet.Cosmostation: return new (await (loadCosmostationStrategy()))({ ...args });
103
+ case Wallet.Ledger: {
104
+ const { LedgerLiveStrategy } = await loadLedgerStrategies();
105
+ return new LedgerLiveStrategy(ethWalletArgs);
106
+ }
107
+ case Wallet.LedgerLegacy: {
108
+ const { LedgerLegacyStrategy } = await loadLedgerStrategies();
109
+ return new LedgerLegacyStrategy(ethWalletArgs);
110
+ }
111
+ case Wallet.TrezorBip32: {
112
+ const { TrezorBip32Strategy } = await loadTrezorStrategies();
113
+ return new TrezorBip32Strategy(ethWalletArgs);
114
+ }
115
+ case Wallet.TrezorBip44: {
116
+ const { TrezorBip44Strategy } = await loadTrezorStrategies();
117
+ return new TrezorBip44Strategy(ethWalletArgs);
118
+ }
119
+ case Wallet.PrivateKey: return new (await (loadPrivateKeyStrategy()))(ethWalletArgs);
87
120
  case Wallet.Turnkey:
88
121
  var _args$metadata;
89
122
  if (!((_args$metadata = args.metadata) === null || _args$metadata === void 0 || (_args$metadata = _args$metadata.turnkey) === null || _args$metadata === void 0 ? void 0 : _args$metadata.defaultOrganizationId)) return;
90
- return new TurnkeyWalletStrategy(ethWalletArgs);
123
+ return new (await (loadTurnkeyStrategy()))(ethWalletArgs);
91
124
  case Wallet.Magic:
92
125
  var _args$metadata2, _args$metadata3;
93
126
  if (!((_args$metadata2 = args.metadata) === null || _args$metadata2 === void 0 || (_args$metadata2 = _args$metadata2.magic) === null || _args$metadata2 === void 0 ? void 0 : _args$metadata2.apiKey) || !((_args$metadata3 = args.metadata) === null || _args$metadata3 === void 0 || (_args$metadata3 = _args$metadata3.magic) === null || _args$metadata3 === void 0 ? void 0 : _args$metadata3.rpcEndpoint)) return;
94
- return new MagicStrategy(args);
127
+ return new (await (loadMagicStrategy()))(args);
95
128
  case Wallet.WalletConnect:
96
129
  var _args$metadata4;
97
130
  if (!((_args$metadata4 = args.metadata) === null || _args$metadata4 === void 0 || (_args$metadata4 = _args$metadata4.walletConnect) === null || _args$metadata4 === void 0 ? void 0 : _args$metadata4.projectId)) return;
98
- return new WalletConnectStrategy(ethWalletArgs);
131
+ return new (await (loadWalletConnectStrategy()))(ethWalletArgs);
99
132
  default: return;
100
133
  }
101
134
  };
@@ -106,6 +139,18 @@ var WalletStrategy = class extends BaseWalletStrategy {
106
139
  ...args,
107
140
  strategies
108
141
  });
142
+ _defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
143
+ }
144
+ /**
145
+ * Set the current wallet and load its strategy.
146
+ * This method is async because strategies are lazy-loaded.
147
+ *
148
+ * @param wallet - The wallet to set as active
149
+ * @throws GeneralException if the wallet strategy cannot be loaded
150
+ */
151
+ async setWallet(wallet) {
152
+ this.wallet = wallet;
153
+ await this.loadStrategy(wallet);
109
154
  }
110
155
  /**
111
156
  * This method is used to set the metadata for the wallet strategies.
@@ -121,7 +166,7 @@ var WalletStrategy = class extends BaseWalletStrategy {
121
166
  * Case 2: Similar to Case 1, but for Wallet Connect Metadata
122
167
  *
123
168
  */
124
- setMetadata(metadata) {
169
+ async setMetadata(metadata) {
125
170
  const shouldRecreateStrategyOnMetadataChange = [Wallet.PrivateKey, Wallet.WalletConnect];
126
171
  const strategiesWithPlaceholders = {
127
172
  ...this.strategies,
@@ -132,7 +177,8 @@ var WalletStrategy = class extends BaseWalletStrategy {
132
177
  var _this$strategies$wall, _this$strategies$wall2;
133
178
  const walletEnum = wallet;
134
179
  if (shouldRecreateStrategyOnMetadataChange.includes(walletEnum)) {
135
- this.strategies[walletEnum] = createStrategy({
180
+ this.loadingStrategies.delete(walletEnum);
181
+ this.strategies[walletEnum] = await createStrategy({
136
182
  args: {
137
183
  ...this.args,
138
184
  metadata: {
@@ -147,15 +193,50 @@ var WalletStrategy = class extends BaseWalletStrategy {
147
193
  (_this$strategies$wall = this.strategies[walletEnum]) === null || _this$strategies$wall === void 0 || (_this$strategies$wall2 = _this$strategies$wall.setMetadata) === null || _this$strategies$wall2 === void 0 || _this$strategies$wall2.call(_this$strategies$wall, metadata);
148
194
  }
149
195
  }
196
+ /**
197
+ * Get the strategy for the current wallet.
198
+ *
199
+ * NOTE: Ensure the strategy is loaded first by calling setWallet() or loadStrategy().
200
+ * This method throws if the strategy hasn't been loaded yet.
201
+ *
202
+ * @throws GeneralException if the strategy hasn't been loaded
203
+ */
150
204
  getStrategy() {
151
205
  if (this.strategies[this.wallet]) return this.strategies[this.wallet];
152
- const strategy = createStrategy({
206
+ throw new GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} strategy not loaded. Call setWallet() or loadStrategy() first.`));
207
+ }
208
+ /**
209
+ * Load a wallet strategy. Strategies are lazy-loaded to reduce initial bundle size.
210
+ * Call this method before using getStrategy() for a wallet.
211
+ *
212
+ * @param wallet - The wallet strategy to load (defaults to current wallet)
213
+ * @returns The loaded strategy
214
+ */
215
+ async loadStrategy(wallet = this.wallet) {
216
+ if (this.strategies[wallet]) return this.strategies[wallet];
217
+ const existingLoad = this.loadingStrategies.get(wallet);
218
+ if (existingLoad) return existingLoad;
219
+ const loadPromise = createStrategy({
153
220
  args: this.args,
154
- wallet: this.wallet
221
+ wallet
155
222
  });
156
- if (!strategy) throw new GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} is not enabled/available!`));
157
- this.strategies[this.wallet] = strategy;
158
- return strategy;
223
+ this.loadingStrategies.set(wallet, loadPromise);
224
+ try {
225
+ const strategy = await loadPromise;
226
+ if (strategy) this.strategies[wallet] = strategy;
227
+ return strategy;
228
+ } finally {
229
+ this.loadingStrategies.delete(wallet);
230
+ }
231
+ }
232
+ /**
233
+ * Load multiple wallet strategies in parallel.
234
+ * Useful for preloading commonly used wallets during app initialization.
235
+ *
236
+ * @param wallets - Array of wallets to preload
237
+ */
238
+ async loadStrategies(wallets) {
239
+ await Promise.all(wallets.map((wallet) => this.loadStrategy(wallet)));
159
240
  }
160
241
  };
161
242
  const createStrategyFactory = (args) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-strategy",
3
- "version": "1.16.38-alpha.2",
3
+ "version": "1.16.38-alpha.3",
4
4
  "description": "Wallet strategy with instantiated wallets",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -42,22 +42,22 @@
42
42
  "ethers": "^6.13.5",
43
43
  "hdkey": "^2.1.0",
44
44
  "viem": "^2.40.3",
45
- "@injectivelabs/exceptions": "1.16.38-alpha.1",
45
+ "@injectivelabs/exceptions": "1.16.38-alpha.2",
46
46
  "@injectivelabs/networks": "1.16.38-alpha.1",
47
+ "@injectivelabs/sdk-ts": "1.16.38-alpha.3",
47
48
  "@injectivelabs/ts-types": "1.16.38-alpha.1",
48
- "@injectivelabs/sdk-ts": "1.16.38-alpha.2",
49
- "@injectivelabs/utils": "1.16.38-alpha.1",
50
- "@injectivelabs/wallet-base": "1.16.38-alpha.2",
51
- "@injectivelabs/wallet-core": "1.16.38-alpha.2",
52
- "@injectivelabs/wallet-cosmos": "1.16.38-alpha.2",
53
- "@injectivelabs/wallet-evm": "1.16.38-alpha.2",
54
- "@injectivelabs/wallet-ledger": "1.16.38-alpha.2",
55
- "@injectivelabs/wallet-cosmostation": "1.16.38-alpha.2",
56
- "@injectivelabs/wallet-private-key": "1.16.38-alpha.2",
57
- "@injectivelabs/wallet-trezor": "1.16.38-alpha.2",
58
- "@injectivelabs/wallet-magic": "1.16.38-alpha.2",
59
- "@injectivelabs/wallet-wallet-connect": "1.16.38-alpha.2",
60
- "@injectivelabs/wallet-turnkey": "1.16.38-alpha.2"
49
+ "@injectivelabs/utils": "1.16.38-alpha.2",
50
+ "@injectivelabs/wallet-base": "1.16.38-alpha.3",
51
+ "@injectivelabs/wallet-core": "1.16.38-alpha.3",
52
+ "@injectivelabs/wallet-cosmostation": "1.16.38-alpha.3",
53
+ "@injectivelabs/wallet-cosmos": "1.16.38-alpha.3",
54
+ "@injectivelabs/wallet-evm": "1.16.38-alpha.3",
55
+ "@injectivelabs/wallet-ledger": "1.16.38-alpha.3",
56
+ "@injectivelabs/wallet-private-key": "1.16.38-alpha.3",
57
+ "@injectivelabs/wallet-magic": "1.16.38-alpha.3",
58
+ "@injectivelabs/wallet-trezor": "1.16.38-alpha.3",
59
+ "@injectivelabs/wallet-turnkey": "1.16.38-alpha.3",
60
+ "@injectivelabs/wallet-wallet-connect": "1.16.38-alpha.3"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/hdkey": "^2.0.1"