@xchainjs/xchain-wallet 0.1.16 → 0.1.18
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/lib/index.d.ts +1 -0
- package/lib/index.esm.js +20 -16
- package/lib/index.js +20 -16
- package/lib/types.d.ts +21 -2
- package/lib/wallet.d.ts +2 -2
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -142,16 +142,15 @@ class Wallet {
|
|
|
142
142
|
* @param {Chain[]} chains Optional chains to get addresses for, if not provided, returns all wallet addresses
|
|
143
143
|
* @returns Addresses mapped by chain
|
|
144
144
|
*/
|
|
145
|
-
getAddresses(chains) {
|
|
145
|
+
getAddresses(chains = Object.keys(this.clients)) {
|
|
146
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const
|
|
148
|
-
const tasks = _chains.map((chain) => {
|
|
147
|
+
const tasks = chains.map((chain) => {
|
|
149
148
|
return this.getAddress(chain);
|
|
150
149
|
});
|
|
151
150
|
const walletAddresses = {};
|
|
152
151
|
const addresses = yield Promise.all(tasks);
|
|
153
152
|
addresses.map((walletAddress, index) => {
|
|
154
|
-
walletAddresses[
|
|
153
|
+
walletAddresses[chains[index]] = walletAddress;
|
|
155
154
|
});
|
|
156
155
|
return walletAddresses;
|
|
157
156
|
});
|
|
@@ -183,16 +182,22 @@ class Wallet {
|
|
|
183
182
|
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
184
183
|
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
185
184
|
*/
|
|
186
|
-
getBalances(assets) {
|
|
185
|
+
getBalances(assets = Object.keys(this.clients).reduce((prev, client) => {
|
|
186
|
+
prev[client] = undefined;
|
|
187
|
+
return prev;
|
|
188
|
+
}, {})) {
|
|
187
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const chains = assets ? Array.from(new Set(assets.map((asset) => asset.chain))) : Object.keys(this.clients);
|
|
189
|
-
const tasks = chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
return yield this.getBalance(chain, assets === null || assets === void 0 ? void 0 : assets.filter((asset) => asset.chain === chain));
|
|
191
|
-
}));
|
|
192
190
|
const walletBalances = {};
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
const chains = Object.keys(assets);
|
|
192
|
+
const results = yield Promise.allSettled(chains.map((chain) => {
|
|
193
|
+
return this.getBalance(chain, assets[chain]);
|
|
194
|
+
}));
|
|
195
|
+
results.forEach((chainBalance, index) => {
|
|
196
|
+
if (chainBalance.status === 'fulfilled') {
|
|
197
|
+
walletBalances[chains[index]] = { status: 'fulfilled', balances: chainBalance.value };
|
|
198
|
+
}
|
|
199
|
+
else if (chainBalance.status === 'rejected')
|
|
200
|
+
walletBalances[chains[index]] = { status: 'rejected', reason: chainBalance.reason };
|
|
196
201
|
});
|
|
197
202
|
return walletBalances;
|
|
198
203
|
});
|
|
@@ -227,16 +232,15 @@ class Wallet {
|
|
|
227
232
|
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
228
233
|
* @returns {TxsPage} the chain transaction history
|
|
229
234
|
*/
|
|
230
|
-
getTransactionsHistories(chains) {
|
|
235
|
+
getTransactionsHistories(chains = Object.keys(this.clients)) {
|
|
231
236
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
const
|
|
233
|
-
const tasks = _chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
const tasks = chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
234
238
|
return this.getTransactionsHistory(chain);
|
|
235
239
|
}));
|
|
236
240
|
const walletHistories = {};
|
|
237
241
|
const histories = yield Promise.all(tasks);
|
|
238
242
|
histories.map((history, index) => {
|
|
239
|
-
walletHistories[
|
|
243
|
+
walletHistories[chains[index]] = history;
|
|
240
244
|
});
|
|
241
245
|
return walletHistories;
|
|
242
246
|
});
|
package/lib/index.js
CHANGED
|
@@ -146,16 +146,15 @@ class Wallet {
|
|
|
146
146
|
* @param {Chain[]} chains Optional chains to get addresses for, if not provided, returns all wallet addresses
|
|
147
147
|
* @returns Addresses mapped by chain
|
|
148
148
|
*/
|
|
149
|
-
getAddresses(chains) {
|
|
149
|
+
getAddresses(chains = Object.keys(this.clients)) {
|
|
150
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const
|
|
152
|
-
const tasks = _chains.map((chain) => {
|
|
151
|
+
const tasks = chains.map((chain) => {
|
|
153
152
|
return this.getAddress(chain);
|
|
154
153
|
});
|
|
155
154
|
const walletAddresses = {};
|
|
156
155
|
const addresses = yield Promise.all(tasks);
|
|
157
156
|
addresses.map((walletAddress, index) => {
|
|
158
|
-
walletAddresses[
|
|
157
|
+
walletAddresses[chains[index]] = walletAddress;
|
|
159
158
|
});
|
|
160
159
|
return walletAddresses;
|
|
161
160
|
});
|
|
@@ -187,16 +186,22 @@ class Wallet {
|
|
|
187
186
|
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
188
187
|
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
189
188
|
*/
|
|
190
|
-
getBalances(assets) {
|
|
189
|
+
getBalances(assets = Object.keys(this.clients).reduce((prev, client) => {
|
|
190
|
+
prev[client] = undefined;
|
|
191
|
+
return prev;
|
|
192
|
+
}, {})) {
|
|
191
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
const chains = assets ? Array.from(new Set(assets.map((asset) => asset.chain))) : Object.keys(this.clients);
|
|
193
|
-
const tasks = chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
return yield this.getBalance(chain, assets === null || assets === void 0 ? void 0 : assets.filter((asset) => asset.chain === chain));
|
|
195
|
-
}));
|
|
196
194
|
const walletBalances = {};
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
195
|
+
const chains = Object.keys(assets);
|
|
196
|
+
const results = yield Promise.allSettled(chains.map((chain) => {
|
|
197
|
+
return this.getBalance(chain, assets[chain]);
|
|
198
|
+
}));
|
|
199
|
+
results.forEach((chainBalance, index) => {
|
|
200
|
+
if (chainBalance.status === 'fulfilled') {
|
|
201
|
+
walletBalances[chains[index]] = { status: 'fulfilled', balances: chainBalance.value };
|
|
202
|
+
}
|
|
203
|
+
else if (chainBalance.status === 'rejected')
|
|
204
|
+
walletBalances[chains[index]] = { status: 'rejected', reason: chainBalance.reason };
|
|
200
205
|
});
|
|
201
206
|
return walletBalances;
|
|
202
207
|
});
|
|
@@ -231,16 +236,15 @@ class Wallet {
|
|
|
231
236
|
* @param {Chain[]} chains - Optional. Chain of which return the transaction history
|
|
232
237
|
* @returns {TxsPage} the chain transaction history
|
|
233
238
|
*/
|
|
234
|
-
getTransactionsHistories(chains) {
|
|
239
|
+
getTransactionsHistories(chains = Object.keys(this.clients)) {
|
|
235
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
const
|
|
237
|
-
const tasks = _chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
const tasks = chains.map((chain) => __awaiter(this, void 0, void 0, function* () {
|
|
238
242
|
return this.getTransactionsHistory(chain);
|
|
239
243
|
}));
|
|
240
244
|
const walletHistories = {};
|
|
241
245
|
const histories = yield Promise.all(tasks);
|
|
242
246
|
histories.map((history, index) => {
|
|
243
|
-
walletHistories[
|
|
247
|
+
walletHistories[chains[index]] = history;
|
|
244
248
|
});
|
|
245
249
|
return walletHistories;
|
|
246
250
|
});
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TxParams as BaseTxParams } from '@xchainjs/xchain-client';
|
|
1
|
+
import { Balance, TxParams as BaseTxParams } from '@xchainjs/xchain-client';
|
|
2
2
|
import { TxParams as BaseEvmTxParams } from '@xchainjs/xchain-evm';
|
|
3
|
-
import { Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
3
|
+
import { Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
|
|
4
4
|
/**
|
|
5
5
|
* UTXO transfer params
|
|
6
6
|
*/
|
|
@@ -14,3 +14,22 @@ export type UtxoTxParams = BaseTxParams & {
|
|
|
14
14
|
export type EvmTxParams = BaseEvmTxParams & {
|
|
15
15
|
asset: Asset;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Fulfilled balance from a Chain
|
|
19
|
+
*/
|
|
20
|
+
type FulfilledBalance = {
|
|
21
|
+
status: 'fulfilled';
|
|
22
|
+
balances: Balance[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Rejected balance from a Chain
|
|
26
|
+
*/
|
|
27
|
+
type RejectedBalance = {
|
|
28
|
+
status: 'rejected';
|
|
29
|
+
reason: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Balances by chain, which can be fulfilled or rejected
|
|
33
|
+
*/
|
|
34
|
+
export type ChainBalances = Record<Chain, FulfilledBalance | RejectedBalance>;
|
|
35
|
+
export {};
|
package/lib/wallet.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { AssetInfo, Balance, FeeOption, Fees, Network, Protocol, Tx, TxHash, Txs
|
|
|
5
5
|
import { GasPrices } from '@xchainjs/xchain-evm';
|
|
6
6
|
import { DepositParam } from '@xchainjs/xchain-mayachain';
|
|
7
7
|
import { Address, Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
|
|
8
|
-
import { EvmTxParams, UtxoTxParams } from './types';
|
|
8
|
+
import { ChainBalances, EvmTxParams, UtxoTxParams } from './types';
|
|
9
9
|
export type NodeUrls = Record<Network, string>;
|
|
10
10
|
export declare class Wallet {
|
|
11
11
|
private clients;
|
|
@@ -82,7 +82,7 @@ export declare class Wallet {
|
|
|
82
82
|
* @param {Assets[]} assets - Optional. Assets of which return the balance
|
|
83
83
|
* @returns {Record<Chain, Balance[]>} Balances by chain
|
|
84
84
|
*/
|
|
85
|
-
getBalances(assets?: Asset[]): Promise<
|
|
85
|
+
getBalances(assets?: Record<Chain, Asset[] | undefined>): Promise<ChainBalances>;
|
|
86
86
|
/**
|
|
87
87
|
* Get transaction data from hash
|
|
88
88
|
* @param {Chain} chain - Chain in which the transaction was done
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-wallet",
|
|
3
3
|
"description": "XChainjs clients wrapper to work with several chains at the same time",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.18",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.esm.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@xchainjs/xchain-client": "0.16.7",
|
|
33
33
|
"@xchainjs/xchain-evm": "0.6.3",
|
|
34
|
-
"@xchainjs/xchain-mayachain": "1.0.
|
|
35
|
-
"@xchainjs/xchain-thorchain": "1.0
|
|
34
|
+
"@xchainjs/xchain-mayachain": "1.0.10",
|
|
35
|
+
"@xchainjs/xchain-thorchain": "1.1.0",
|
|
36
36
|
"@xchainjs/xchain-util": "0.13.6",
|
|
37
37
|
"@xchainjs/xchain-utxo": "0.1.9"
|
|
38
38
|
},
|