@subwallet/extension-base 1.0.4-0 → 1.0.5-1
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/background/KoniTypes.d.ts +37 -16
- package/background/KoniTypes.js +2 -0
- package/background/errors/TransactionError.js +4 -0
- package/background/handlers/State.d.ts +1 -1
- package/background/handlers/State.js +2 -8
- package/background/handlers/subscriptions.js +0 -1
- package/background/types.d.ts +2 -2
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/background/errors/TransactionError.js +4 -0
- package/cjs/background/handlers/State.js +1 -7
- package/cjs/background/handlers/subscriptions.js +0 -1
- package/cjs/constants/index.js +6 -6
- package/cjs/koni/api/coingecko.js +1 -4
- package/cjs/koni/api/dotsama/balance.js +7 -5
- package/cjs/koni/api/dotsama/crowdloan.js +0 -4
- package/cjs/koni/api/dotsama/transfer.js +0 -4
- package/cjs/koni/api/nft/acala_nft/index.js +1 -1
- package/cjs/koni/api/nft/bit.country/index.js +1 -1
- package/cjs/koni/api/nft/evm_nft/index.js +2 -3
- package/cjs/koni/api/nft/index.js +1 -2
- package/cjs/koni/api/nft/karura_nft/index.js +1 -1
- package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
- package/cjs/koni/api/nft/transfer.js +5 -5
- package/cjs/koni/api/nft/unique_nft/index.js +1 -1
- package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -2
- package/cjs/koni/api/staking/bonding/astar.js +37 -13
- package/cjs/koni/api/staking/bonding/paraChain.js +10 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +21 -4
- package/cjs/koni/api/staking/bonding/utils.js +4 -0
- package/cjs/koni/api/staking/relayChain.js +0 -1
- package/cjs/koni/api/staking/subsquidStaking.js +0 -2
- package/cjs/koni/api/tokens/wasm/index.js +0 -1
- package/cjs/koni/api/tokens/wasm/utils.js +0 -1
- package/cjs/koni/api/xcm/index.js +0 -1
- package/cjs/koni/background/cron.js +0 -45
- package/cjs/koni/background/handlers/Extension.js +204 -132
- package/cjs/koni/background/handlers/State.js +30 -3
- package/cjs/koni/background/handlers/Tabs.js +34 -2
- package/cjs/koni/background/handlers/index.js +3 -2
- package/cjs/koni/background/subscription.js +0 -26
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -10
- package/cjs/services/chain-service/handler/light-client/index.js +9 -6
- package/cjs/services/chain-service/index.js +75 -28
- package/cjs/services/chain-service/utils.js +3 -0
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +108 -0
- package/cjs/services/history-service/index.js +60 -5
- package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
- package/cjs/services/history-service/testChainMap.js +724 -0
- package/cjs/services/keyring-service/index.js +9 -2
- package/cjs/services/migration-service/index.js +7 -7
- package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +39 -0
- package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
- package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
- package/cjs/services/migration-service/scripts/index.js +7 -1
- package/cjs/services/price-service/coingecko.js +1 -1
- package/cjs/services/price-service/index.js +0 -4
- package/cjs/services/request-service/handler/AuthRequestHandler.js +8 -1
- package/cjs/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/cjs/services/request-service/index.js +6 -0
- package/cjs/services/setting-service/SettingService.js +4 -9
- package/cjs/services/setting-service/constants.js +18 -2
- package/cjs/services/storage-service/DatabaseService.js +16 -44
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStore.js +3 -0
- package/cjs/services/transaction-service/constants.js +11 -0
- package/cjs/services/transaction-service/index.js +31 -9
- package/cjs/services/transaction-service/utils.js +25 -14
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/coingecko.js +1 -4
- package/koni/api/dotsama/balance.js +7 -5
- package/koni/api/dotsama/crowdloan.js +0 -4
- package/koni/api/dotsama/transfer.js +0 -4
- package/koni/api/nft/acala_nft/index.js +1 -1
- package/koni/api/nft/bit.country/index.js +1 -1
- package/koni/api/nft/evm_nft/index.js +2 -3
- package/koni/api/nft/index.js +1 -2
- package/koni/api/nft/karura_nft/index.js +1 -1
- package/koni/api/nft/quartz_nft/index.js +1 -1
- package/koni/api/nft/rmrk_nft/index.js +2 -3
- package/koni/api/nft/statemine_nft/index.js +1 -1
- package/koni/api/nft/transfer.js +5 -5
- package/koni/api/nft/unique_nft/index.js +1 -1
- package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/koni/api/nft/wasm_nft/index.js +1 -2
- package/koni/api/staking/bonding/amplitude.js +9 -2
- package/koni/api/staking/bonding/astar.d.ts +2 -1
- package/koni/api/staking/bonding/astar.js +36 -13
- package/koni/api/staking/bonding/paraChain.js +10 -2
- package/koni/api/staking/bonding/relayChain.js +21 -4
- package/koni/api/staking/bonding/utils.js +4 -0
- package/koni/api/staking/relayChain.js +0 -1
- package/koni/api/staking/subsquidStaking.js +0 -2
- package/koni/api/tokens/wasm/index.js +0 -1
- package/koni/api/tokens/wasm/utils.js +0 -1
- package/koni/api/xcm/index.js +0 -1
- package/koni/background/cron.js +0 -45
- package/koni/background/handlers/Extension.d.ts +3 -0
- package/koni/background/handlers/Extension.js +120 -51
- package/koni/background/handlers/State.d.ts +4 -1
- package/koni/background/handlers/State.js +30 -3
- package/koni/background/handlers/Tabs.d.ts +1 -0
- package/koni/background/handlers/Tabs.js +32 -1
- package/koni/background/handlers/index.js +3 -2
- package/koni/background/subscription.d.ts +0 -1
- package/koni/background/subscription.js +0 -26
- package/package.json +65 -39
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +3 -10
- package/services/chain-service/handler/light-client/index.js +8 -6
- package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
- package/services/chain-service/index.d.ts +2 -1
- package/services/chain-service/index.js +75 -28
- package/services/chain-service/utils.js +3 -0
- package/services/history-service/helpers/recoverHistoryStatus.d.ts +11 -0
- package/services/history-service/helpers/recoverHistoryStatus.js +98 -0
- package/services/history-service/index.d.ts +6 -0
- package/services/history-service/index.js +61 -6
- package/services/history-service/subsquid-multi-chain-history.js +3 -2
- package/services/history-service/testChainMap.d.ts +3 -0
- package/services/history-service/testChainMap.js +716 -0
- package/services/keyring-service/index.d.ts +1 -0
- package/services/keyring-service/index.js +9 -2
- package/services/migration-service/index.js +7 -7
- package/services/migration-service/scripts/MigrateAuthUrls.d.ts +4 -0
- package/services/migration-service/scripts/MigrateAuthUrls.js +31 -0
- package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
- package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
- package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
- package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
- package/services/migration-service/scripts/index.js +7 -1
- package/services/price-service/coingecko.js +1 -1
- package/services/price-service/index.js +0 -4
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +8 -1
- package/services/request-service/handler/EvmRequestHandler.d.ts +1 -0
- package/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -0
- package/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
- package/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/services/request-service/index.d.ts +1 -0
- package/services/request-service/index.js +6 -0
- package/services/setting-service/SettingService.d.ts +1 -0
- package/services/setting-service/SettingService.js +5 -10
- package/services/setting-service/constants.d.ts +4 -1
- package/services/setting-service/constants.js +14 -1
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +16 -44
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStore.d.ts +1 -0
- package/services/storage-service/db-stores/BaseStore.js +3 -0
- package/services/transaction-service/constants.d.ts +1 -0
- package/services/transaction-service/constants.js +4 -0
- package/services/transaction-service/index.d.ts +2 -0
- package/services/transaction-service/index.js +32 -10
- package/services/transaction-service/utils.d.ts +1 -1
- package/services/transaction-service/utils.js +24 -13
|
@@ -12,6 +12,7 @@ var _TransactionWarning = require("@subwallet/extension-base/background/warnings
|
|
|
12
12
|
var _constants = require("@subwallet/extension-base/constants");
|
|
13
13
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
14
14
|
var _constants2 = require("@subwallet/extension-base/services/request-service/constants");
|
|
15
|
+
var _constants3 = require("@subwallet/extension-base/services/transaction-service/constants");
|
|
15
16
|
var _eventParser = require("@subwallet/extension-base/services/transaction-service/event-parser");
|
|
16
17
|
var _helpers = require("@subwallet/extension-base/services/transaction-service/helpers");
|
|
17
18
|
var _utils2 = require("@subwallet/extension-base/services/transaction-service/utils");
|
|
@@ -276,7 +277,7 @@ class TransactionService {
|
|
|
276
277
|
getTransactionLink(id) {
|
|
277
278
|
const transaction = this.getTransaction(id);
|
|
278
279
|
const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
|
|
279
|
-
return (0, _utils2.
|
|
280
|
+
return (0, _utils2.getExplorerLink)(chainInfo, transaction.extrinsicHash, 'tx');
|
|
280
281
|
}
|
|
281
282
|
transactionToHistories(id, eventLogs) {
|
|
282
283
|
const transaction = this.getTransaction(id);
|
|
@@ -463,7 +464,7 @@ class TransactionService {
|
|
|
463
464
|
let {
|
|
464
465
|
id
|
|
465
466
|
} = _ref;
|
|
466
|
-
console.
|
|
467
|
+
console.debug(`Transaction "${id}" is signed`);
|
|
467
468
|
}
|
|
468
469
|
onSend(_ref2) {
|
|
469
470
|
let {
|
|
@@ -476,23 +477,25 @@ class TransactionService {
|
|
|
476
477
|
|
|
477
478
|
// Create Input History Transaction History
|
|
478
479
|
this.historyService.insertHistories(this.transactionToHistories(id)).catch(console.error);
|
|
479
|
-
console.
|
|
480
|
+
console.debug(`Transaction "${id}" is sent`);
|
|
480
481
|
}
|
|
481
482
|
onHasTransactionHash(_ref3) {
|
|
482
483
|
let {
|
|
484
|
+
blockHash,
|
|
483
485
|
extrinsicHash,
|
|
484
486
|
id
|
|
485
487
|
} = _ref3;
|
|
486
488
|
// Write processing transaction history
|
|
487
489
|
const updateData = {
|
|
488
490
|
extrinsicHash,
|
|
489
|
-
status: _KoniTypes.ExtrinsicStatus.PROCESSING
|
|
491
|
+
status: _KoniTypes.ExtrinsicStatus.PROCESSING,
|
|
492
|
+
blockHash: blockHash || ''
|
|
490
493
|
};
|
|
491
494
|
this.updateTransaction(id, updateData);
|
|
492
495
|
|
|
493
496
|
// In this case transaction id is the same as extrinsic hash and will change after below update
|
|
494
497
|
this.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
|
|
495
|
-
console.
|
|
498
|
+
console.debug(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
|
|
496
499
|
}
|
|
497
500
|
handlePostProcessing(id) {
|
|
498
501
|
// must be done after success/failure to make sure the transaction is finalized
|
|
@@ -530,7 +533,6 @@ class TransactionService {
|
|
|
530
533
|
this.updateTransaction(id, {
|
|
531
534
|
status: _KoniTypes.ExtrinsicStatus.SUCCESS
|
|
532
535
|
});
|
|
533
|
-
console.log('Transaction completed', id, transaction.extrinsicHash);
|
|
534
536
|
|
|
535
537
|
// Write success transaction history
|
|
536
538
|
this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
|
|
@@ -563,7 +565,6 @@ class TransactionService {
|
|
|
563
565
|
status: nextStatus,
|
|
564
566
|
errors
|
|
565
567
|
});
|
|
566
|
-
console.log('Transaction failed', id, transaction.extrinsicHash);
|
|
567
568
|
|
|
568
569
|
// Write failed transaction history
|
|
569
570
|
this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
|
|
@@ -582,8 +583,6 @@ class TransactionService {
|
|
|
582
583
|
});
|
|
583
584
|
}
|
|
584
585
|
this.eventService.emit('transaction.failed', transaction);
|
|
585
|
-
// Log transaction errors
|
|
586
|
-
console.error(errors);
|
|
587
586
|
}
|
|
588
587
|
generateHashPayload(chain, transaction) {
|
|
589
588
|
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
@@ -694,6 +693,7 @@ class TransactionService {
|
|
|
694
693
|
emitter.emit('signed', eventData);
|
|
695
694
|
|
|
696
695
|
// Send transaction
|
|
696
|
+
this.handleTransactionTimeout(emitter, eventData);
|
|
697
697
|
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
698
698
|
signedTransaction && web3Api.eth.sendSignedTransaction(signedTransaction).once('transactionHash', hash => {
|
|
699
699
|
eventData.extrinsicHash = hash;
|
|
@@ -749,7 +749,9 @@ class TransactionService {
|
|
|
749
749
|
emitter.emit('signed', eventData);
|
|
750
750
|
|
|
751
751
|
// Send transaction
|
|
752
|
+
this.handleTransactionTimeout(emitter, eventData);
|
|
752
753
|
emitter.emit('send', eventData); // This event is needed after sending transaction with queue
|
|
754
|
+
|
|
753
755
|
rs.send(txState => {
|
|
754
756
|
// handle events, logs, history
|
|
755
757
|
if (!txState || !txState.status) {
|
|
@@ -759,6 +761,7 @@ class TransactionService {
|
|
|
759
761
|
eventData.eventLogs = txState.events;
|
|
760
762
|
if (!eventData.extrinsicHash || eventData.extrinsicHash === '') {
|
|
761
763
|
eventData.extrinsicHash = txState.txHash.toHex();
|
|
764
|
+
eventData.blockHash = txState.status.asInBlock.toHex();
|
|
762
765
|
emitter.emit('extrinsicHash', eventData);
|
|
763
766
|
}
|
|
764
767
|
}
|
|
@@ -798,5 +801,24 @@ class TransactionService {
|
|
|
798
801
|
});
|
|
799
802
|
return emitter;
|
|
800
803
|
}
|
|
804
|
+
handleTransactionTimeout(emitter, eventData) {
|
|
805
|
+
const timeout = setTimeout(() => {
|
|
806
|
+
const transaction = this.getTransaction(eventData.id);
|
|
807
|
+
if (transaction.status !== _KoniTypes.ExtrinsicStatus.SUCCESS && transaction.status !== _KoniTypes.ExtrinsicStatus.FAIL) {
|
|
808
|
+
eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.TIMEOUT, 'Transaction timeout'));
|
|
809
|
+
emitter.emit('error', eventData);
|
|
810
|
+
clearTimeout(timeout);
|
|
811
|
+
}
|
|
812
|
+
}, _constants3.TRANSACTION_TIMEOUT);
|
|
813
|
+
emitter.once('success', () => {
|
|
814
|
+
clearTimeout(timeout);
|
|
815
|
+
});
|
|
816
|
+
emitter.once('error', () => {
|
|
817
|
+
clearTimeout(timeout);
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
resetWallet() {
|
|
821
|
+
this.transactionSubject.next({});
|
|
822
|
+
}
|
|
801
823
|
}
|
|
802
824
|
exports.default = TransactionService;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getExplorerLink = getExplorerLink;
|
|
7
7
|
exports.parseTransactionData = parseTransactionData;
|
|
8
8
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
9
9
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -14,19 +14,30 @@ function parseTransactionData(data) {
|
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
function getBlockExplorerAccountRoute(explorerLink) {
|
|
18
|
+
if (explorerLink.includes('explorer.subspace.network')) {
|
|
19
|
+
return 'accounts';
|
|
20
|
+
}
|
|
21
|
+
if (explorerLink.includes('subscan.io')) {
|
|
22
|
+
return 'account';
|
|
23
|
+
}
|
|
24
|
+
return 'address';
|
|
25
|
+
}
|
|
26
|
+
function getBlockExplorerTxRoute(chainInfo) {
|
|
27
|
+
if ((0, _utils._isPureEvmChain)(chainInfo)) {
|
|
28
|
+
return 'tx';
|
|
29
|
+
}
|
|
30
|
+
return 'extrinsic';
|
|
31
|
+
}
|
|
32
|
+
function getExplorerLink(chainInfo, value, type) {
|
|
33
|
+
const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
|
|
34
|
+
if (explorerLink && type === 'account') {
|
|
35
|
+
const route = getBlockExplorerAccountRoute(explorerLink);
|
|
36
|
+
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
|
|
37
|
+
}
|
|
38
|
+
if (explorerLink && value.startsWith('0x')) {
|
|
39
|
+
const route = getBlockExplorerTxRoute(chainInfo);
|
|
40
|
+
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
|
|
30
41
|
}
|
|
31
42
|
return undefined;
|
|
32
43
|
}
|
package/constants/index.d.ts
CHANGED
|
@@ -11,10 +11,10 @@ export declare const CRON_REFRESH_HISTORY_INTERVAL = 900000;
|
|
|
11
11
|
export declare const CRON_GET_API_MAP_STATUS = 10000;
|
|
12
12
|
export declare const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
|
|
13
13
|
export declare const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
|
|
14
|
+
export declare const CRON_RECOVER_HISTORY_INTERVAL = 30000;
|
|
14
15
|
export declare const ALL_ACCOUNT_KEY = "ALL";
|
|
15
16
|
export declare const ALL_NETWORK_KEY = "all";
|
|
16
17
|
export declare const ALL_GENESIS_HASH: null;
|
|
17
18
|
export declare const IGNORE_GET_SUBSTRATE_FEATURES_LIST: string[];
|
|
18
19
|
export declare const IGNORE_QR_SIGNER: string[];
|
|
19
|
-
export declare const DEFAULT_TIME_AUTO_LOCK: number;
|
|
20
20
|
export * from './staking';
|
package/constants/index.js
CHANGED
|
@@ -14,10 +14,10 @@ export const CRON_REFRESH_HISTORY_INTERVAL = 900000;
|
|
|
14
14
|
export const CRON_GET_API_MAP_STATUS = 10000;
|
|
15
15
|
export const CRON_REFRESH_CHAIN_STAKING_METADATA = 900000;
|
|
16
16
|
export const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
|
|
17
|
+
export const CRON_RECOVER_HISTORY_INTERVAL = 30000;
|
|
17
18
|
export const ALL_ACCOUNT_KEY = 'ALL';
|
|
18
19
|
export const ALL_NETWORK_KEY = 'all';
|
|
19
20
|
export const ALL_GENESIS_HASH = null;
|
|
20
21
|
export const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
|
|
21
22
|
export const IGNORE_QR_SIGNER = [];
|
|
22
|
-
export const DEFAULT_TIME_AUTO_LOCK = 15 * 60 * 1000;
|
|
23
23
|
export * from "./staking.js";
|
package/koni/api/coingecko.js
CHANGED
|
@@ -7,9 +7,6 @@ export const getTokenPrice = async (priceIds, currency = 'usd') => {
|
|
|
7
7
|
// const inverseMap: Record<string, string> = {};
|
|
8
8
|
const idStr = priceIds.join(',');
|
|
9
9
|
const res = await axios.get(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency}&per_page=1000&ids=${idStr}`);
|
|
10
|
-
if (res.status !== 200) {
|
|
11
|
-
console.warn('Failed to get token price');
|
|
12
|
-
}
|
|
13
10
|
const responseData = res.data;
|
|
14
11
|
const priceMap = {};
|
|
15
12
|
const price24hMap = {};
|
|
@@ -31,7 +28,7 @@ export const getTokenPrice = async (priceIds, currency = 'usd') => {
|
|
|
31
28
|
price24hMap
|
|
32
29
|
};
|
|
33
30
|
} catch (err) {
|
|
34
|
-
console.error(
|
|
31
|
+
console.error(err);
|
|
35
32
|
throw err;
|
|
36
33
|
}
|
|
37
34
|
};
|
|
@@ -109,11 +109,13 @@ async function subscribeWithSystemAccountPallet(addresses, chainInfo, networkAPI
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
balances.forEach(balance => {
|
|
112
|
-
var _balance$data, _balance$data$free, _balance$data2, _balance$data2$reserv, _balance$data3, _balance$data3$miscFr, _balance$data4, _balance$data4$feeFro;
|
|
112
|
+
var _balance$data, _balance$data$free, _balance$data2, _balance$data2$reserv, _balance$data3, _balance$data3$miscFr, _balance$data4, _balance$data4$frozen, _balance$data5, _balance$data5$feeFro;
|
|
113
113
|
total = total.add(((_balance$data = balance.data) === null || _balance$data === void 0 ? void 0 : (_balance$data$free = _balance$data.free) === null || _balance$data$free === void 0 ? void 0 : _balance$data$free.toBn()) || new BN(0)); // reserved is seperated
|
|
114
114
|
reserved = reserved.add(((_balance$data2 = balance.data) === null || _balance$data2 === void 0 ? void 0 : (_balance$data2$reserv = _balance$data2.reserved) === null || _balance$data2$reserv === void 0 ? void 0 : _balance$data2$reserv.toBn()) || new BN(0));
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
117
|
+
miscFrozen = miscFrozen.add(((_balance$data3 = balance.data) === null || _balance$data3 === void 0 ? void 0 : (_balance$data3$miscFr = _balance$data3.miscFrozen) === null || _balance$data3$miscFr === void 0 ? void 0 : _balance$data3$miscFr.toBn()) || (balance === null || balance === void 0 ? void 0 : (_balance$data4 = balance.data) === null || _balance$data4 === void 0 ? void 0 : (_balance$data4$frozen = _balance$data4.frozen) === null || _balance$data4$frozen === void 0 ? void 0 : _balance$data4$frozen.toBn()) || new BN(0)); // TODO: update frozen
|
|
118
|
+
feeFrozen = feeFrozen.add(((_balance$data5 = balance.data) === null || _balance$data5 === void 0 ? void 0 : (_balance$data5$feeFro = _balance$data5.feeFrozen) === null || _balance$data5$feeFro === void 0 ? void 0 : _balance$data5$feeFro.toBn()) || new BN(0));
|
|
117
119
|
});
|
|
118
120
|
let locked = reserved.add(miscFrozen);
|
|
119
121
|
total = total.add(reserved); // total = free + reserved
|
|
@@ -159,7 +161,7 @@ function subscribeERC20Interval(addresses, chain, evmApiMap, callBack) {
|
|
|
159
161
|
state: APIItemState.READY
|
|
160
162
|
});
|
|
161
163
|
} catch (err) {
|
|
162
|
-
console.log(
|
|
164
|
+
console.log(tokenInfo.slug, err);
|
|
163
165
|
}
|
|
164
166
|
});
|
|
165
167
|
};
|
|
@@ -197,7 +199,7 @@ function subscribePSP22Balance(addresses, chain, api, callBack) {
|
|
|
197
199
|
state: APIItemState.READY
|
|
198
200
|
});
|
|
199
201
|
} catch (err) {
|
|
200
|
-
console.warn(
|
|
202
|
+
console.warn(tokenInfo.slug, err); // TODO: error createType
|
|
201
203
|
}
|
|
202
204
|
});
|
|
203
205
|
};
|
|
@@ -37,10 +37,6 @@ export const subscribeAcalaContributeInterval = (polkadotAddresses, paraState, c
|
|
|
37
37
|
let contribute = new BN(0);
|
|
38
38
|
resList.forEach(res => {
|
|
39
39
|
var _res$data$data, _res$data$data$acala, _res$data$data$acala$;
|
|
40
|
-
if (res.status !== 200) {
|
|
41
|
-
console.warn('Failed to get Acala, Karura crowdloan contribute');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
40
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
|
|
45
41
|
contribute = contribute.add(new BN(((_res$data$data = res.data.data) === null || _res$data$data === void 0 ? void 0 : (_res$data$data$acala = _res$data$data.acala) === null || _res$data$data$acala === void 0 ? void 0 : (_res$data$data$acala$ = _res$data$data$acala[0]) === null || _res$data$data$acala$ === void 0 ? void 0 : _res$data$data$acala$.totalDOTLocked) || '0'));
|
|
46
42
|
});
|
|
@@ -94,7 +94,6 @@ export const createTransferExtrinsic = async ({
|
|
|
94
94
|
transferAll,
|
|
95
95
|
value
|
|
96
96
|
}) => {
|
|
97
|
-
var _transfer;
|
|
98
97
|
const api = substrateApi.api;
|
|
99
98
|
|
|
100
99
|
// @ts-ignore
|
|
@@ -142,8 +141,5 @@ export const createTransferExtrinsic = async ({
|
|
|
142
141
|
transfer = api.tx.balances.transfer(to, new BN(value));
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
|
-
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
147
|
-
console.log('transfer extrinsic: ', (_transfer = transfer) === null || _transfer === void 0 ? void 0 : _transfer.toHex());
|
|
148
144
|
return [transfer, transferAmount || value];
|
|
149
145
|
};
|
|
@@ -113,7 +113,7 @@ export class AcalaNftApi extends BaseNftApi {
|
|
|
113
113
|
}));
|
|
114
114
|
params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
|
|
115
115
|
} catch (e) {
|
|
116
|
-
console.error(
|
|
116
|
+
console.error(`${this.chain}`, e);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
async handleNfts(params) {
|
|
@@ -111,7 +111,7 @@ export class BitCountryNftApi extends BaseNftApi {
|
|
|
111
111
|
}));
|
|
112
112
|
params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
|
|
113
113
|
} catch (e) {
|
|
114
|
-
console.error(
|
|
114
|
+
console.error(`${this.chain}`, e);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
async handleNfts(params) {
|
|
@@ -106,7 +106,6 @@ export class EvmNftApi extends BaseNftApi {
|
|
|
106
106
|
const resp = await fetch(detailUrl);
|
|
107
107
|
const itemDetail = resp && resp.ok && (await resp.json());
|
|
108
108
|
if (!itemDetail) {
|
|
109
|
-
console.warn((resp === null || resp === void 0 ? void 0 : resp.statusText) || `Cannot fetch NFT id [${nftId}] from Web3.`);
|
|
110
109
|
return;
|
|
111
110
|
}
|
|
112
111
|
const parsedItem = this.parseMetadata(itemDetail);
|
|
@@ -123,13 +122,13 @@ export class EvmNftApi extends BaseNftApi {
|
|
|
123
122
|
ownItem = true;
|
|
124
123
|
}
|
|
125
124
|
} catch (e) {
|
|
126
|
-
console.error(
|
|
125
|
+
console.error(`${this.chain}`, e);
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
}));
|
|
130
129
|
nftOwnerMap[address] = nftIds;
|
|
131
130
|
} catch (e) {
|
|
132
|
-
console.error(
|
|
131
|
+
console.error(`${this.chain}`, e);
|
|
133
132
|
}
|
|
134
133
|
}));
|
|
135
134
|
if (ownItem) {
|
package/koni/api/nft/index.js
CHANGED
|
@@ -118,10 +118,9 @@ export class NftHandler {
|
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
this.needSetupApi = false;
|
|
121
|
-
// console.log(`${this.handlers.length} nft handlers connected`, this.handlers);
|
|
122
121
|
}
|
|
123
122
|
} catch (e) {
|
|
124
|
-
console.error(
|
|
123
|
+
console.error(e);
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
async handleNfts(nftContracts, updateItem, updateCollection, cleanUpNfts) {
|
|
@@ -118,7 +118,7 @@ export class KaruraNftApi extends BaseNftApi {
|
|
|
118
118
|
}));
|
|
119
119
|
params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
|
|
120
120
|
} catch (e) {
|
|
121
|
-
console.error(
|
|
121
|
+
console.error(`${this.chain}`, e);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
async handleNfts(params) {
|
|
@@ -193,7 +193,6 @@ export class RmrkNftApi extends BaseNftApi {
|
|
|
193
193
|
return {};
|
|
194
194
|
}
|
|
195
195
|
} catch (e) {
|
|
196
|
-
console.error('error fetching collection info', url);
|
|
197
196
|
return {};
|
|
198
197
|
}
|
|
199
198
|
}));
|
|
@@ -220,7 +219,7 @@ export class RmrkNftApi extends BaseNftApi {
|
|
|
220
219
|
};
|
|
221
220
|
}
|
|
222
221
|
} catch (e) {
|
|
223
|
-
console.error(
|
|
222
|
+
console.error(item.url, e);
|
|
224
223
|
}
|
|
225
224
|
}));
|
|
226
225
|
allCollections.forEach(item => {
|
|
@@ -245,7 +244,7 @@ export class RmrkNftApi extends BaseNftApi {
|
|
|
245
244
|
const allNftIds = allNfts.map(nft => nft === null || nft === void 0 ? void 0 : nft.id);
|
|
246
245
|
params.cleanUpNfts(this.chain, address, allCollectionIds, allNftIds);
|
|
247
246
|
} catch (e) {
|
|
248
|
-
console.error(
|
|
247
|
+
console.error(`${this.chain}`, e);
|
|
249
248
|
}
|
|
250
249
|
}
|
|
251
250
|
async handleNfts(params) {
|
|
@@ -119,7 +119,7 @@ export default class StatemineNftApi extends BaseNftApi {
|
|
|
119
119
|
}));
|
|
120
120
|
params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
|
|
121
121
|
} catch (e) {
|
|
122
|
-
console.error(
|
|
122
|
+
console.error(`${this.chain}`, e);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
async handleNfts(params) {
|
package/koni/api/nft/transfer.js
CHANGED
|
@@ -12,7 +12,7 @@ export function acalaGetExtrinsic(substrateApi, senderAddress, recipientAddress,
|
|
|
12
12
|
const collectionId = params.collectionId;
|
|
13
13
|
return substrateApi.api.tx.nft.transfer(recipientAddress, [collectionId, itemId]);
|
|
14
14
|
} catch (e) {
|
|
15
|
-
console.error(
|
|
15
|
+
console.error(e);
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -25,7 +25,7 @@ export function rmrkGetExtrinsic(substrateApi, senderAddress, recipientAddress,
|
|
|
25
25
|
const parsedRemark = remark.concat(recipientAddress.replace(/\\s/g, ''));
|
|
26
26
|
return substrateApi.api.tx.system.remark(parsedRemark);
|
|
27
27
|
} catch (e) {
|
|
28
|
-
console.error(
|
|
28
|
+
console.error(e);
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -37,7 +37,7 @@ export function uniqueGetExtrinsic(substrateApi, senderAddress, recipientAddress
|
|
|
37
37
|
Substrate: recipientAddress
|
|
38
38
|
}, collectionId, itemId, 1);
|
|
39
39
|
} catch (e) {
|
|
40
|
-
console.error(
|
|
40
|
+
console.error(e);
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -49,7 +49,7 @@ export function quartzGetExtrinsic(substrateApi, senderAddress, recipientAddress
|
|
|
49
49
|
Substrate: recipientAddress
|
|
50
50
|
}, collectionId, itemId, 1);
|
|
51
51
|
} catch (e) {
|
|
52
|
-
console.error(
|
|
52
|
+
console.error(e);
|
|
53
53
|
return null;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -59,7 +59,7 @@ export function statemineGetExtrinsic(substrateApi, senderAddress, recipientAddr
|
|
|
59
59
|
const collectionId = params.collectionId;
|
|
60
60
|
return substrateApi.api.tx.uniques.transfer(collectionId, itemId, recipientAddress);
|
|
61
61
|
} catch (e) {
|
|
62
|
-
console.error(
|
|
62
|
+
console.error(e);
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -175,7 +175,7 @@ export default class UniqueNftApi extends BaseNftApi {
|
|
|
175
175
|
}));
|
|
176
176
|
params.cleanUpNfts(this.chain, address, collectionIds, allNftIds);
|
|
177
177
|
} catch (e) {
|
|
178
|
-
console.error(
|
|
178
|
+
console.error(`${this.chain}`, e);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
async handleNfts(params) {
|
|
@@ -216,7 +216,6 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
if (!itemDetail) {
|
|
219
|
-
console.warn(`Cannot fetch NFT metadata [${tokenId}] from PSP-34 contract.`);
|
|
220
219
|
return nftItem;
|
|
221
220
|
}
|
|
222
221
|
nftItem.name = itemDetail.name;
|
|
@@ -298,7 +297,7 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
298
297
|
|
|
299
298
|
nftOwnerMap[address] = nftIds;
|
|
300
299
|
} catch (e) {
|
|
301
|
-
console.error(
|
|
300
|
+
console.error(`${this.chain}`, e);
|
|
302
301
|
}
|
|
303
302
|
}));
|
|
304
303
|
if (isFeatured) {
|
|
@@ -42,9 +42,16 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
|
|
|
42
42
|
const minDelegatorStake = chainApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
43
43
|
const delegatorState = _delegatorState.toPrimitive();
|
|
44
44
|
const unstakingInfo = _unstakingInfo.toPrimitive();
|
|
45
|
-
console.log('unstakingInfo ampe', unstakingInfo, !!unstakingInfo);
|
|
46
45
|
if (!delegatorState && !unstakingInfo) {
|
|
47
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
chain: chainInfo.slug,
|
|
48
|
+
type: StakingType.NOMINATED,
|
|
49
|
+
address,
|
|
50
|
+
status: StakingStatus.NOT_STAKING,
|
|
51
|
+
activeStake: '0',
|
|
52
|
+
nominations: [],
|
|
53
|
+
unstakings: []
|
|
54
|
+
};
|
|
48
55
|
}
|
|
49
56
|
let activeStake = '0';
|
|
50
57
|
if (delegatorState) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { ChainStakingMetadata, NominatorMetadata, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { ChainStakingMetadata, NominatorMetadata, UnstakingInfo, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
export declare function getAstarStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
5
5
|
export declare function getAstarNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
@@ -8,3 +8,4 @@ export declare function getAstarBondingExtrinsic(substrateApi: _SubstrateApi, am
|
|
|
8
8
|
export declare function getAstarUnbondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappAddress: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
9
9
|
export declare function getAstarWithdrawalExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
10
10
|
export declare function getAstarClaimRewardExtrinsic(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
11
|
+
export declare function getAstarWithdrawable(nominatorMetadata: NominatorMetadata): UnstakingInfo;
|
|
@@ -96,20 +96,28 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
96
96
|
|
|
97
97
|
const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
|
|
98
98
|
if (unlockingChunks.length > 0) {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
99
|
+
for (const unlockingChunk of unlockingChunks) {
|
|
100
|
+
const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) <= 0;
|
|
101
|
+
const remainingEra = unlockingChunk.unlockEra - (parseInt(currentEra) + 1);
|
|
102
|
+
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
|
|
103
|
+
unstakingList.push({
|
|
104
|
+
chain,
|
|
105
|
+
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
106
|
+
claimable: unlockingChunk.amount.toString(),
|
|
107
|
+
waitingTime: waitingTime > 0 ? waitingTime : 0
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
110
|
}
|
|
111
111
|
if (nominationList.length === 0 && unstakingList.length === 0) {
|
|
112
|
-
return
|
|
112
|
+
return {
|
|
113
|
+
chain: chainInfo.slug,
|
|
114
|
+
type: StakingType.NOMINATED,
|
|
115
|
+
address,
|
|
116
|
+
status: StakingStatus.NOT_STAKING,
|
|
117
|
+
activeStake: '0',
|
|
118
|
+
nominations: [],
|
|
119
|
+
unstakings: []
|
|
120
|
+
};
|
|
113
121
|
}
|
|
114
122
|
const stakingStatus = getStakingStatusByNominations(bnTotalActiveStake, nominationList);
|
|
115
123
|
return {
|
|
@@ -239,6 +247,21 @@ export async function getAstarClaimRewardExtrinsic(substrateApi, address) {
|
|
|
239
247
|
transactions.push(tx);
|
|
240
248
|
}
|
|
241
249
|
}
|
|
242
|
-
console.log('no of astar claim reward tx: ', transactions.length);
|
|
243
250
|
return apiPromise.api.tx.utility.batch(transactions);
|
|
251
|
+
}
|
|
252
|
+
export function getAstarWithdrawable(nominatorMetadata) {
|
|
253
|
+
const unstakingInfo = {
|
|
254
|
+
chain: nominatorMetadata.chain,
|
|
255
|
+
status: UnstakingStatus.CLAIMABLE,
|
|
256
|
+
claimable: '0',
|
|
257
|
+
waitingTime: 0
|
|
258
|
+
};
|
|
259
|
+
let bnWithdrawable = BN_ZERO;
|
|
260
|
+
for (const unstaking of nominatorMetadata.unstakings) {
|
|
261
|
+
if (unstaking.status === UnstakingStatus.CLAIMABLE) {
|
|
262
|
+
bnWithdrawable = bnWithdrawable.add(new BN(unstaking.claimable));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
unstakingInfo.claimable = bnWithdrawable.toString();
|
|
266
|
+
return unstakingInfo;
|
|
244
267
|
}
|
|
@@ -42,7 +42,7 @@ export function validateParaChainBondingCondition(chainInfo, amount, selectedCol
|
|
|
42
42
|
const bnChainMinStake = new BN(chainStakingMetadata.minStake || '0');
|
|
43
43
|
const bnCollatorMinStake = new BN(selectedCollator.minBond || '0');
|
|
44
44
|
const bnMinStake = bnCollatorMinStake > bnChainMinStake ? bnCollatorMinStake : bnChainMinStake;
|
|
45
|
-
if (!nominatorMetadata) {
|
|
45
|
+
if (!nominatorMetadata || nominatorMetadata.status === StakingStatus.NOT_STAKING) {
|
|
46
46
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
47
47
|
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
48
48
|
}
|
|
@@ -130,7 +130,15 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
130
130
|
const _delegatorState = await chainApi.api.query.parachainStaking.delegatorState(address);
|
|
131
131
|
const delegatorState = _delegatorState.toPrimitive();
|
|
132
132
|
if (!delegatorState) {
|
|
133
|
-
return
|
|
133
|
+
return {
|
|
134
|
+
chain: chainInfo.slug,
|
|
135
|
+
type: StakingType.NOMINATED,
|
|
136
|
+
address,
|
|
137
|
+
status: StakingStatus.NOT_STAKING,
|
|
138
|
+
activeStake: '0',
|
|
139
|
+
nominations: [],
|
|
140
|
+
unstakings: []
|
|
141
|
+
};
|
|
134
142
|
}
|
|
135
143
|
let bnTotalActiveStake = BN_ZERO;
|
|
136
144
|
await Promise.all(delegatorState.delegations.map(async delegation => {
|