@injectivelabs/wallet-cosmos-strategy 1.17.2-alpha.0 → 1.17.2-alpha.10
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.
- package/dist/cjs/index.cjs +76 -25
- package/dist/cjs/index.d.cts +5 -1
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.js +80 -29
- package/package.json +9 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,32 +1,67 @@
|
|
|
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
|
-
let __injectivelabs_wallet_cosmostation = require("@injectivelabs/wallet-cosmostation");
|
|
5
4
|
|
|
6
|
-
//#region src/strategy/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
//#endregion
|
|
14
|
-
//#region
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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.");
|
|
18
32
|
}
|
|
19
|
-
|
|
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
|
+
}
|
|
20
53
|
|
|
21
54
|
//#endregion
|
|
22
55
|
//#region src/strategy/WalletStrategy.ts
|
|
23
|
-
const createStrategy = ({ args, wallet }) => {
|
|
56
|
+
const createStrategy = async ({ args, wallet }) => {
|
|
57
|
+
if (!(0, __injectivelabs_wallet_base.isCosmosWallet)(wallet)) return;
|
|
58
|
+
const CosmosWalletStrategy = await loadCosmosWalletStrategy();
|
|
24
59
|
switch (wallet) {
|
|
25
60
|
case __injectivelabs_wallet_base.Wallet.Keplr: return new CosmosWalletStrategy({
|
|
26
61
|
...args,
|
|
27
62
|
wallet: __injectivelabs_wallet_base.Wallet.Keplr
|
|
28
63
|
});
|
|
29
|
-
case __injectivelabs_wallet_base.Wallet.Cosmostation: return new
|
|
64
|
+
case __injectivelabs_wallet_base.Wallet.Cosmostation: return new CosmosWalletStrategy({
|
|
30
65
|
...args,
|
|
31
66
|
wallet: __injectivelabs_wallet_base.Wallet.Cosmostation
|
|
32
67
|
});
|
|
@@ -45,26 +80,42 @@ const createStrategy = ({ args, wallet }) => {
|
|
|
45
80
|
default: return;
|
|
46
81
|
}
|
|
47
82
|
};
|
|
48
|
-
const createAllStrategies = (args) => {
|
|
49
|
-
return Object.values(__injectivelabs_wallet_base.Wallet).reduce((strategies, wallet) => {
|
|
50
|
-
if (strategies[wallet]) return strategies;
|
|
51
|
-
strategies[wallet] = createStrategy({
|
|
52
|
-
args,
|
|
53
|
-
wallet
|
|
54
|
-
});
|
|
55
|
-
return strategies;
|
|
56
|
-
}, {});
|
|
57
|
-
};
|
|
58
83
|
var BaseCosmosWalletStrategy = class extends __injectivelabs_wallet_core.BaseWalletStrategy {
|
|
59
84
|
constructor(args) {
|
|
60
|
-
const strategies =
|
|
85
|
+
const strategies = {};
|
|
61
86
|
super({
|
|
62
87
|
...args,
|
|
63
88
|
strategies
|
|
64
89
|
});
|
|
90
|
+
_defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
|
|
65
91
|
}
|
|
66
92
|
async setWallet(wallet) {
|
|
67
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)));
|
|
68
119
|
}
|
|
69
120
|
};
|
|
70
121
|
const createCosmosStrategyFactory = (args) => {
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -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.d.ts
CHANGED
|
@@ -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,70 +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
|
-
import { CosmostationWalletStrategy } from "@injectivelabs/wallet-cosmostation";
|
|
5
4
|
|
|
6
|
-
//#region src/strategy/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
//#endregion
|
|
14
|
-
//#region
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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.");
|
|
18
32
|
}
|
|
19
|
-
|
|
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
|
+
}
|
|
20
53
|
|
|
21
54
|
//#endregion
|
|
22
55
|
//#region src/strategy/WalletStrategy.ts
|
|
23
|
-
const createStrategy = ({ args, wallet }) => {
|
|
56
|
+
const createStrategy = async ({ args, wallet }) => {
|
|
57
|
+
if (!isCosmosWallet(wallet)) return;
|
|
58
|
+
const CosmosWalletStrategy = await loadCosmosWalletStrategy();
|
|
24
59
|
switch (wallet) {
|
|
25
|
-
case Wallet.Keplr: return new CosmosWalletStrategy
|
|
60
|
+
case Wallet.Keplr: return new CosmosWalletStrategy({
|
|
26
61
|
...args,
|
|
27
62
|
wallet: Wallet.Keplr
|
|
28
63
|
});
|
|
29
|
-
case Wallet.Cosmostation: return new
|
|
64
|
+
case Wallet.Cosmostation: return new CosmosWalletStrategy({
|
|
30
65
|
...args,
|
|
31
66
|
wallet: Wallet.Cosmostation
|
|
32
67
|
});
|
|
33
|
-
case Wallet.Leap: return new CosmosWalletStrategy
|
|
68
|
+
case Wallet.Leap: return new CosmosWalletStrategy({
|
|
34
69
|
...args,
|
|
35
70
|
wallet: Wallet.Leap
|
|
36
71
|
});
|
|
37
|
-
case Wallet.Ninji: return new CosmosWalletStrategy
|
|
72
|
+
case Wallet.Ninji: return new CosmosWalletStrategy({
|
|
38
73
|
...args,
|
|
39
74
|
wallet: Wallet.Ninji
|
|
40
75
|
});
|
|
41
|
-
case Wallet.OWallet: return new CosmosWalletStrategy
|
|
76
|
+
case Wallet.OWallet: return new CosmosWalletStrategy({
|
|
42
77
|
...args,
|
|
43
78
|
wallet: Wallet.OWallet
|
|
44
79
|
});
|
|
45
80
|
default: return;
|
|
46
81
|
}
|
|
47
82
|
};
|
|
48
|
-
const createAllStrategies = (args) => {
|
|
49
|
-
return Object.values(Wallet).reduce((strategies, wallet) => {
|
|
50
|
-
if (strategies[wallet]) return strategies;
|
|
51
|
-
strategies[wallet] = createStrategy({
|
|
52
|
-
args,
|
|
53
|
-
wallet
|
|
54
|
-
});
|
|
55
|
-
return strategies;
|
|
56
|
-
}, {});
|
|
57
|
-
};
|
|
58
83
|
var BaseCosmosWalletStrategy = class extends BaseWalletStrategy {
|
|
59
84
|
constructor(args) {
|
|
60
|
-
const strategies =
|
|
85
|
+
const strategies = {};
|
|
61
86
|
super({
|
|
62
87
|
...args,
|
|
63
88
|
strategies
|
|
64
89
|
});
|
|
90
|
+
_defineProperty(this, "loadingStrategies", /* @__PURE__ */ new Map());
|
|
65
91
|
}
|
|
66
92
|
async setWallet(wallet) {
|
|
67
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)));
|
|
68
119
|
}
|
|
69
120
|
};
|
|
70
121
|
const createCosmosStrategyFactory = (args) => {
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-cosmos-strategy",
|
|
3
|
-
"version": "1.17.2-alpha.
|
|
3
|
+
"version": "1.17.2-alpha.10",
|
|
4
4
|
"description": "Wallet Cosmos Strategy with instantiated wallets",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "InjectiveLabs",
|
|
8
8
|
"email": "admin@injectivelabs.org"
|
|
9
9
|
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/InjectiveLabs/injective-ts"
|
|
13
|
+
},
|
|
10
14
|
"type": "module",
|
|
11
15
|
"sideEffects": false,
|
|
12
16
|
"exports": {
|
|
@@ -38,11 +42,10 @@
|
|
|
38
42
|
"dist"
|
|
39
43
|
],
|
|
40
44
|
"dependencies": {
|
|
41
|
-
"@injectivelabs/ts-types": "1.17.2-alpha.
|
|
42
|
-
"@injectivelabs/wallet-core": "1.17.2-alpha.
|
|
43
|
-
"@injectivelabs/wallet-
|
|
44
|
-
"@injectivelabs/wallet-
|
|
45
|
-
"@injectivelabs/wallet-base": "1.17.2-alpha.0"
|
|
45
|
+
"@injectivelabs/ts-types": "1.17.2-alpha.10",
|
|
46
|
+
"@injectivelabs/wallet-core": "1.17.2-alpha.10",
|
|
47
|
+
"@injectivelabs/wallet-base": "1.17.2-alpha.10",
|
|
48
|
+
"@injectivelabs/wallet-cosmos": "1.17.2-alpha.10"
|
|
46
49
|
},
|
|
47
50
|
"publishConfig": {
|
|
48
51
|
"access": "public"
|