@injectivelabs/wallet-cosmos-strategy 1.17.2-alpha.2 → 1.17.2-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,61 @@
1
+ let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
1
2
  let __injectivelabs_wallet_core = require("@injectivelabs/wallet-core");
2
3
  let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
3
- let __injectivelabs_wallet_cosmos = require("@injectivelabs/wallet-cosmos");
4
4
 
5
- //#region src/strategy/strategies/cosmos.ts
6
- var CosmosWalletStrategy = class extends __injectivelabs_wallet_cosmos.CosmosWalletStrategy {
7
- constructor(args) {
8
- super(args);
9
- }
5
+ //#region src/strategy/lib.ts
6
+ let cachedCosmosWalletStrategy = null;
7
+ const loadCosmosWalletStrategy = async () => {
8
+ if (!cachedCosmosWalletStrategy) cachedCosmosWalletStrategy = (await import("@injectivelabs/wallet-cosmos")).CosmosWalletStrategy;
9
+ return cachedCosmosWalletStrategy;
10
10
  };
11
11
 
12
+ //#endregion
13
+ //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
14
+ function _typeof(o) {
15
+ "@babel/helpers - typeof";
16
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
17
+ return typeof o$1;
18
+ } : function(o$1) {
19
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
20
+ }, _typeof(o);
21
+ }
22
+
23
+ //#endregion
24
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
25
+ function toPrimitive(t, r) {
26
+ if ("object" != _typeof(t) || !t) return t;
27
+ var e = t[Symbol.toPrimitive];
28
+ if (void 0 !== e) {
29
+ var i = e.call(t, r || "default");
30
+ if ("object" != _typeof(i)) return i;
31
+ throw new TypeError("@@toPrimitive must return a primitive value.");
32
+ }
33
+ return ("string" === r ? String : Number)(t);
34
+ }
35
+
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
38
+ function toPropertyKey(t) {
39
+ var i = toPrimitive(t, "string");
40
+ return "symbol" == _typeof(i) ? i : i + "";
41
+ }
42
+
43
+ //#endregion
44
+ //#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
45
+ function _defineProperty(e, r, t) {
46
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
47
+ value: t,
48
+ enumerable: !0,
49
+ configurable: !0,
50
+ writable: !0
51
+ }) : e[r] = t, e;
52
+ }
53
+
12
54
  //#endregion
13
55
  //#region src/strategy/WalletStrategy.ts
14
- const createStrategy = ({ args, wallet }) => {
56
+ const createStrategy = async ({ args, wallet }) => {
57
+ if (!(0, __injectivelabs_wallet_base.isCosmosWallet)(wallet)) return;
58
+ const CosmosWalletStrategy = await loadCosmosWalletStrategy();
15
59
  switch (wallet) {
16
60
  case __injectivelabs_wallet_base.Wallet.Keplr: return new CosmosWalletStrategy({
17
61
  ...args,
@@ -36,26 +80,42 @@ const createStrategy = ({ args, wallet }) => {
36
80
  default: return;
37
81
  }
38
82
  };
39
- const createAllStrategies = (args) => {
40
- return Object.values(__injectivelabs_wallet_base.Wallet).reduce((strategies, wallet) => {
41
- if (strategies[wallet]) return strategies;
42
- strategies[wallet] = createStrategy({
43
- args,
44
- wallet
45
- });
46
- return strategies;
47
- }, {});
48
- };
49
83
  var BaseCosmosWalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrategy {
50
84
  constructor(args) {
51
- const strategies = createAllStrategies(args);
85
+ const strategies = {};
52
86
  super({
53
87
  ...args,
54
88
  strategies
55
89
  });
90
+ _defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
56
91
  }
57
92
  async setWallet(wallet) {
58
93
  this.wallet = (0, __injectivelabs_wallet_base.isCosmosWallet)(wallet) ? wallet : __injectivelabs_wallet_base.Wallet.Keplr;
94
+ await this.loadStrategy(this.wallet);
95
+ }
96
+ getStrategy() {
97
+ if (this.strategies[this.wallet]) return this.strategies[this.wallet];
98
+ throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} strategy not loaded. Call setWallet() or loadStrategy() first.`));
99
+ }
100
+ async loadStrategy(wallet = this.wallet) {
101
+ if (this.strategies[wallet]) return this.strategies[wallet];
102
+ const existingLoad = this.loadingStrategies.get(wallet);
103
+ if (existingLoad) return existingLoad;
104
+ const loadPromise = createStrategy({
105
+ args: this.args,
106
+ wallet
107
+ });
108
+ this.loadingStrategies.set(wallet, loadPromise);
109
+ try {
110
+ const strategy = await loadPromise;
111
+ if (strategy) this.strategies[wallet] = strategy;
112
+ return strategy;
113
+ } finally {
114
+ this.loadingStrategies.delete(wallet);
115
+ }
116
+ }
117
+ async loadStrategies(wallets) {
118
+ await Promise.all(wallets.map((wallet) => this.loadStrategy(wallet)));
59
119
  }
60
120
  };
61
121
  const createCosmosStrategyFactory = (args) => {
@@ -1,5 +1,5 @@
1
1
  import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
2
- import { Wallet } from "@injectivelabs/wallet-base";
2
+ import { ConcreteWalletStrategy, Wallet } from "@injectivelabs/wallet-base";
3
3
  import { CosmosChainId } from "@injectivelabs/ts-types";
4
4
 
5
5
  //#region src/strategy/types.d.ts
@@ -10,8 +10,12 @@ interface CosmosWalletStrategyArguments {
10
10
  //#endregion
11
11
  //#region src/strategy/WalletStrategy.d.ts
12
12
  declare class BaseCosmosWalletStrategy extends BaseWalletStrategy {
13
+ private loadingStrategies;
13
14
  constructor(args: CosmosWalletStrategyArguments);
14
15
  setWallet(wallet: Wallet): Promise<void>;
16
+ getStrategy(): ConcreteWalletStrategy;
17
+ loadStrategy(wallet?: Wallet): Promise<ConcreteWalletStrategy | undefined>;
18
+ loadStrategies(wallets: Wallet[]): Promise<void>;
15
19
  }
16
20
  declare const createCosmosStrategyFactory: (args: CosmosWalletStrategyArguments) => BaseCosmosWalletStrategy;
17
21
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
2
- import { Wallet } from "@injectivelabs/wallet-base";
2
+ import { ConcreteWalletStrategy, Wallet } from "@injectivelabs/wallet-base";
3
3
  import { CosmosChainId } from "@injectivelabs/ts-types";
4
4
 
5
5
  //#region src/strategy/types.d.ts
@@ -10,8 +10,12 @@ interface CosmosWalletStrategyArguments {
10
10
  //#endregion
11
11
  //#region src/strategy/WalletStrategy.d.ts
12
12
  declare class BaseCosmosWalletStrategy extends BaseWalletStrategy {
13
+ private loadingStrategies;
13
14
  constructor(args: CosmosWalletStrategyArguments);
14
15
  setWallet(wallet: Wallet): Promise<void>;
16
+ getStrategy(): ConcreteWalletStrategy;
17
+ loadStrategy(wallet?: Wallet): Promise<ConcreteWalletStrategy | undefined>;
18
+ loadStrategies(wallets: Wallet[]): Promise<void>;
15
19
  }
16
20
  declare const createCosmosStrategyFactory: (args: CosmosWalletStrategyArguments) => BaseCosmosWalletStrategy;
17
21
  //#endregion
package/dist/esm/index.js CHANGED
@@ -1,61 +1,121 @@
1
+ import { GeneralException } from "@injectivelabs/exceptions";
1
2
  import { BaseWalletStrategy } from "@injectivelabs/wallet-core";
2
3
  import { Wallet, isCosmosWallet } from "@injectivelabs/wallet-base";
3
- import { CosmosWalletStrategy } from "@injectivelabs/wallet-cosmos";
4
4
 
5
- //#region src/strategy/strategies/cosmos.ts
6
- var CosmosWalletStrategy$1 = class extends CosmosWalletStrategy {
7
- constructor(args) {
8
- super(args);
9
- }
5
+ //#region src/strategy/lib.ts
6
+ let cachedCosmosWalletStrategy = null;
7
+ const loadCosmosWalletStrategy = async () => {
8
+ if (!cachedCosmosWalletStrategy) cachedCosmosWalletStrategy = (await import("@injectivelabs/wallet-cosmos")).CosmosWalletStrategy;
9
+ return cachedCosmosWalletStrategy;
10
10
  };
11
11
 
12
+ //#endregion
13
+ //#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
14
+ function _typeof(o) {
15
+ "@babel/helpers - typeof";
16
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
17
+ return typeof o$1;
18
+ } : function(o$1) {
19
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
20
+ }, _typeof(o);
21
+ }
22
+
23
+ //#endregion
24
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
25
+ function toPrimitive(t, r) {
26
+ if ("object" != _typeof(t) || !t) return t;
27
+ var e = t[Symbol.toPrimitive];
28
+ if (void 0 !== e) {
29
+ var i = e.call(t, r || "default");
30
+ if ("object" != _typeof(i)) return i;
31
+ throw new TypeError("@@toPrimitive must return a primitive value.");
32
+ }
33
+ return ("string" === r ? String : Number)(t);
34
+ }
35
+
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
38
+ function toPropertyKey(t) {
39
+ var i = toPrimitive(t, "string");
40
+ return "symbol" == _typeof(i) ? i : i + "";
41
+ }
42
+
43
+ //#endregion
44
+ //#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
45
+ function _defineProperty(e, r, t) {
46
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
47
+ value: t,
48
+ enumerable: !0,
49
+ configurable: !0,
50
+ writable: !0
51
+ }) : e[r] = t, e;
52
+ }
53
+
12
54
  //#endregion
13
55
  //#region src/strategy/WalletStrategy.ts
14
- const createStrategy = ({ args, wallet }) => {
56
+ const createStrategy = async ({ args, wallet }) => {
57
+ if (!isCosmosWallet(wallet)) return;
58
+ const CosmosWalletStrategy = await loadCosmosWalletStrategy();
15
59
  switch (wallet) {
16
- case Wallet.Keplr: return new CosmosWalletStrategy$1({
60
+ case Wallet.Keplr: return new CosmosWalletStrategy({
17
61
  ...args,
18
62
  wallet: Wallet.Keplr
19
63
  });
20
- case Wallet.Cosmostation: return new CosmosWalletStrategy$1({
64
+ case Wallet.Cosmostation: return new CosmosWalletStrategy({
21
65
  ...args,
22
66
  wallet: Wallet.Cosmostation
23
67
  });
24
- case Wallet.Leap: return new CosmosWalletStrategy$1({
68
+ case Wallet.Leap: return new CosmosWalletStrategy({
25
69
  ...args,
26
70
  wallet: Wallet.Leap
27
71
  });
28
- case Wallet.Ninji: return new CosmosWalletStrategy$1({
72
+ case Wallet.Ninji: return new CosmosWalletStrategy({
29
73
  ...args,
30
74
  wallet: Wallet.Ninji
31
75
  });
32
- case Wallet.OWallet: return new CosmosWalletStrategy$1({
76
+ case Wallet.OWallet: return new CosmosWalletStrategy({
33
77
  ...args,
34
78
  wallet: Wallet.OWallet
35
79
  });
36
80
  default: return;
37
81
  }
38
82
  };
39
- const createAllStrategies = (args) => {
40
- return Object.values(Wallet).reduce((strategies, wallet) => {
41
- if (strategies[wallet]) return strategies;
42
- strategies[wallet] = createStrategy({
43
- args,
44
- wallet
45
- });
46
- return strategies;
47
- }, {});
48
- };
49
83
  var BaseCosmosWalletStrategy = class extends BaseWalletStrategy {
50
84
  constructor(args) {
51
- const strategies = createAllStrategies(args);
85
+ const strategies = {};
52
86
  super({
53
87
  ...args,
54
88
  strategies
55
89
  });
90
+ _defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
56
91
  }
57
92
  async setWallet(wallet) {
58
93
  this.wallet = isCosmosWallet(wallet) ? wallet : Wallet.Keplr;
94
+ await this.loadStrategy(this.wallet);
95
+ }
96
+ getStrategy() {
97
+ if (this.strategies[this.wallet]) return this.strategies[this.wallet];
98
+ throw new GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} strategy not loaded. Call setWallet() or loadStrategy() first.`));
99
+ }
100
+ async loadStrategy(wallet = this.wallet) {
101
+ if (this.strategies[wallet]) return this.strategies[wallet];
102
+ const existingLoad = this.loadingStrategies.get(wallet);
103
+ if (existingLoad) return existingLoad;
104
+ const loadPromise = createStrategy({
105
+ args: this.args,
106
+ wallet
107
+ });
108
+ this.loadingStrategies.set(wallet, loadPromise);
109
+ try {
110
+ const strategy = await loadPromise;
111
+ if (strategy) this.strategies[wallet] = strategy;
112
+ return strategy;
113
+ } finally {
114
+ this.loadingStrategies.delete(wallet);
115
+ }
116
+ }
117
+ async loadStrategies(wallets) {
118
+ await Promise.all(wallets.map((wallet) => this.loadStrategy(wallet)));
59
119
  }
60
120
  };
61
121
  const createCosmosStrategyFactory = (args) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-cosmos-strategy",
3
- "version": "1.17.2-alpha.2",
3
+ "version": "1.17.2-alpha.3",
4
4
  "description": "Wallet Cosmos Strategy with instantiated wallets",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -38,10 +38,10 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "@injectivelabs/ts-types": "1.17.2-alpha.2",
42
- "@injectivelabs/wallet-base": "1.17.2-alpha.2",
43
- "@injectivelabs/wallet-cosmos": "1.17.2-alpha.2",
44
- "@injectivelabs/wallet-core": "1.17.2-alpha.2"
41
+ "@injectivelabs/ts-types": "1.17.2-alpha.3",
42
+ "@injectivelabs/wallet-core": "1.17.2-alpha.3",
43
+ "@injectivelabs/wallet-base": "1.17.2-alpha.3",
44
+ "@injectivelabs/wallet-cosmos": "1.17.2-alpha.3"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"