@subwallet/extension-base 1.0.2-2 → 1.0.3-0
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 +56 -40
- package/background/KoniTypes.js +11 -9
- package/background/errors/TransactionError.js +25 -1
- package/background/types.d.ts +10 -5
- package/cjs/background/KoniTypes.js +11 -9
- package/cjs/background/errors/TransactionError.js +24 -0
- package/cjs/constants/index.js +8 -26
- package/cjs/koni/api/dotsama/balance.js +49 -224
- package/cjs/koni/api/dotsama/transfer.js +34 -39
- package/cjs/koni/api/nft/acala_nft/index.js +7 -7
- package/cjs/koni/api/nft/bit.country/index.js +7 -6
- package/cjs/koni/api/nft/evm_nft/index.js +8 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +7 -6
- package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
- package/cjs/koni/api/nft/unique_nft/index.js +5 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +170 -111
- package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
- package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
- package/cjs/koni/api/staking/bonding/astar.js +15 -13
- package/cjs/koni/api/staking/bonding/index.js +22 -10
- package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +122 -16
- package/cjs/koni/api/staking/bonding/utils.js +27 -8
- package/cjs/koni/api/tokens/wasm/index.js +5 -4
- package/cjs/koni/api/tokens/wasm/utils.js +63 -0
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +171 -61
- package/cjs/koni/background/handlers/Extension.js +391 -207
- package/cjs/koni/background/handlers/State.js +49 -34
- package/cjs/koni/background/handlers/Tabs.js +50 -17
- package/cjs/koni/background/subscription.js +53 -28
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/base/types.js +20 -0
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/index.js +73 -49
- package/cjs/services/event-service/index.js +5 -1
- package/cjs/services/event-service/types.js +11 -1
- package/cjs/services/history-service/index.js +101 -50
- package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
- package/cjs/services/keyring-service/index.js +11 -13
- package/cjs/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/cjs/services/price-service/coingecko.js +0 -1
- package/cjs/services/price-service/index.js +71 -24
- package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
- package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/cjs/services/request-service/index.js +14 -5
- package/cjs/services/storage-service/DatabaseService.js +66 -34
- package/cjs/services/storage-service/db-stores/Nft.js +7 -15
- package/cjs/services/storage-service/db-stores/Transaction.js +6 -10
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +104 -48
- package/cjs/services/transaction-service/utils.js +10 -8
- package/cjs/utils/address.js +10 -1
- package/cjs/utils/index.js +9 -15
- package/cjs/utils/promise.js +26 -0
- package/constants/index.d.ts +7 -13
- package/constants/index.js +7 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +22 -197
- package/koni/api/dotsama/transfer.js +11 -16
- package/koni/api/nft/acala_nft/index.js +7 -7
- package/koni/api/nft/bit.country/index.js +7 -6
- package/koni/api/nft/evm_nft/index.js +7 -3
- package/koni/api/nft/index.d.ts +1 -2
- package/koni/api/nft/index.js +3 -6
- package/koni/api/nft/karura_nft/index.js +7 -6
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +11 -1
- package/koni/api/nft/statemine_nft/index.js +7 -6
- package/koni/api/nft/unique_nft/index.js +5 -1
- package/koni/api/nft/wasm_nft/index.d.ts +0 -2
- package/koni/api/nft/wasm_nft/index.js +168 -109
- package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
- package/koni/api/nft/wasm_nft/utils.js +7 -5
- package/koni/api/staking/bonding/amplitude.d.ts +0 -1
- package/koni/api/staking/bonding/amplitude.js +15 -10
- package/koni/api/staking/bonding/astar.js +8 -6
- package/koni/api/staking/bonding/index.d.ts +4 -1
- package/koni/api/staking/bonding/index.js +23 -13
- package/koni/api/staking/bonding/paraChain.d.ts +3 -0
- package/koni/api/staking/bonding/paraChain.js +86 -5
- package/koni/api/staking/bonding/relayChain.d.ts +5 -1
- package/koni/api/staking/bonding/relayChain.js +121 -18
- package/koni/api/staking/bonding/utils.d.ts +3 -2
- package/koni/api/staking/bonding/utils.js +27 -9
- package/koni/api/tokens/wasm/index.js +5 -4
- package/koni/api/tokens/wasm/utils.d.ts +6 -0
- package/koni/api/tokens/wasm/utils.js +54 -0
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +172 -62
- package/koni/background/handlers/Extension.d.ts +9 -3
- package/koni/background/handlers/Extension.js +306 -126
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +51 -34
- package/koni/background/handlers/Tabs.js +50 -17
- package/koni/background/subscription.d.ts +2 -0
- package/koni/background/subscription.js +51 -29
- package/package.json +29 -14
- package/packageInfo.js +1 -1
- package/services/base/types.d.ts +34 -0
- package/services/base/types.js +15 -0
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- package/services/chain-service/helper/psp22_abi.json +1041 -881
- package/services/chain-service/helper/psp34_abi.json +2963 -1807
- package/services/chain-service/index.d.ts +5 -2
- package/services/chain-service/index.js +68 -45
- package/services/chain-service/types.d.ts +1 -0
- package/services/event-service/index.js +5 -1
- package/services/event-service/types.d.ts +5 -9
- package/services/event-service/types.js +4 -1
- package/services/history-service/index.d.ts +28 -7
- package/services/history-service/index.js +101 -50
- package/services/history-service/subsquid-multi-chain-history.js +16 -12
- package/services/keyring-service/index.d.ts +4 -2
- package/services/keyring-service/index.js +11 -13
- package/services/migration-service/scripts/MigrateImportedToken.js +2 -1
- package/services/price-service/coingecko.js +0 -1
- package/services/price-service/index.d.ts +22 -1
- package/services/price-service/index.js +71 -24
- package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
- package/services/request-service/handler/AuthRequestHandler.js +13 -7
- package/services/request-service/handler/EvmRequestHandler.js +8 -12
- package/services/request-service/index.d.ts +3 -1
- package/services/request-service/index.js +14 -5
- package/services/storage-service/DatabaseService.d.ts +2 -0
- package/services/storage-service/DatabaseService.js +66 -34
- package/services/storage-service/db-stores/Nft.d.ts +2 -2
- package/services/storage-service/db-stores/Nft.js +7 -14
- package/services/storage-service/db-stores/Transaction.d.ts +2 -0
- package/services/storage-service/db-stores/Transaction.js +6 -10
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.d.ts +2 -0
- package/services/transaction-service/index.js +86 -32
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +10 -8
- package/utils/address.d.ts +3 -0
- package/utils/address.js +8 -1
- package/utils/index.d.ts +2 -2
- package/utils/index.js +7 -13
- package/utils/promise.d.ts +6 -0
- package/utils/promise.js +20 -0
|
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.ChainService = void 0;
|
|
8
8
|
var _chainList = require("@subwallet/chain-list");
|
|
9
9
|
var _types = require("@subwallet/chain-list/types");
|
|
10
|
-
var _constants = require("@subwallet/extension-base/constants");
|
|
11
|
-
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
10
|
+
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
12
11
|
var _EvmChainHandler = require("@subwallet/extension-base/services/chain-service/handler/EvmChainHandler");
|
|
13
12
|
var _SubstrateChainHandler = require("@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler");
|
|
14
13
|
var _types2 = require("@subwallet/extension-base/services/chain-service/handler/types");
|
|
@@ -51,7 +50,7 @@ class ChainService {
|
|
|
51
50
|
this.multiChainAssetMapSubject.next(_chainList.MultiChainAssetMap);
|
|
52
51
|
this.xcmRefMapSubject.next(this.getXcmRefMap());
|
|
53
52
|
this.logger = (0, _logger.logger)('chain-service');
|
|
54
|
-
this.refreshChainStateInterval(3000);
|
|
53
|
+
this.refreshChainStateInterval(3000, 6);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
// Getter
|
|
@@ -158,7 +157,8 @@ class ChainService {
|
|
|
158
157
|
priceId: '',
|
|
159
158
|
slug: '',
|
|
160
159
|
symbol: '',
|
|
161
|
-
hasValue: true
|
|
160
|
+
hasValue: true,
|
|
161
|
+
icon: ''
|
|
162
162
|
};
|
|
163
163
|
for (const assetInfo of Object.values(this.getAssetRegistry())) {
|
|
164
164
|
if (assetInfo.assetType === _types._AssetType.NATIVE && assetInfo.originChain === chainSlug) {
|
|
@@ -286,7 +286,7 @@ class ChainService {
|
|
|
286
286
|
this.dbService.removeFromChainStore([slug]).catch(console.error);
|
|
287
287
|
this.updateChainSubscription();
|
|
288
288
|
this.lockChainInfoMap = false;
|
|
289
|
-
this.eventService.emit('chain.
|
|
289
|
+
this.eventService.emit('chain.updateState', slug);
|
|
290
290
|
return true;
|
|
291
291
|
}
|
|
292
292
|
resetChainInfoMap(excludedChains) {
|
|
@@ -296,7 +296,7 @@ class ChainService {
|
|
|
296
296
|
this.lockChainInfoMap = true;
|
|
297
297
|
const chainStateMap = this.getChainStateMap();
|
|
298
298
|
for (const [slug, chainState] of Object.entries(chainStateMap)) {
|
|
299
|
-
if (!
|
|
299
|
+
if (!_constants._DEFAULT_ACTIVE_CHAINS.includes(slug) && !(excludedChains !== null && excludedChains !== void 0 && excludedChains.includes(slug))) {
|
|
300
300
|
chainState.active = false;
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -352,7 +352,7 @@ class ChainService {
|
|
|
352
352
|
this.dbService.removeFromAssetStore(targetAssets).catch(e => this.logger.error(e));
|
|
353
353
|
this.assetRegistrySubject.next(assetRegistry);
|
|
354
354
|
targetAssets.forEach(assetSlug => {
|
|
355
|
-
this.eventService.emit('asset.
|
|
355
|
+
this.eventService.emit('asset.updateState', assetSlug);
|
|
356
356
|
});
|
|
357
357
|
}
|
|
358
358
|
|
|
@@ -419,14 +419,14 @@ class ChainService {
|
|
|
419
419
|
this.lockChainInfoMap = true;
|
|
420
420
|
chainStateMap[chainSlug].active = true;
|
|
421
421
|
this.initApiForChain(chainInfo);
|
|
422
|
-
this.refreshChainStateInterval(
|
|
422
|
+
this.refreshChainStateInterval(3000, 6);
|
|
423
423
|
this.dbService.updateChainStore({
|
|
424
424
|
...chainInfo,
|
|
425
425
|
active: true,
|
|
426
426
|
currentProvider: chainStateMap[chainSlug].currentProvider
|
|
427
427
|
}).catch(console.error);
|
|
428
428
|
this.lockChainInfoMap = false;
|
|
429
|
-
this.eventService.emit('chain.
|
|
429
|
+
this.eventService.emit('chain.updateState', chainSlug);
|
|
430
430
|
return true;
|
|
431
431
|
}
|
|
432
432
|
enableChain(chainSlug) {
|
|
@@ -461,7 +461,7 @@ class ChainService {
|
|
|
461
461
|
}).catch(console.error);
|
|
462
462
|
this.updateChainStateMapSubscription();
|
|
463
463
|
this.lockChainInfoMap = false;
|
|
464
|
-
this.eventService.emit('chain.
|
|
464
|
+
this.eventService.emit('chain.updateState', chainSlug);
|
|
465
465
|
return true;
|
|
466
466
|
}
|
|
467
467
|
checkExistedPredefinedChain(genesisHash, evmChainId) {
|
|
@@ -497,13 +497,13 @@ class ChainService {
|
|
|
497
497
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
498
498
|
slug: chainInfo.slug,
|
|
499
499
|
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
500
|
-
active:
|
|
500
|
+
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
|
|
501
501
|
};
|
|
502
502
|
|
|
503
503
|
// create data for storage
|
|
504
504
|
newStorageData.push({
|
|
505
505
|
...chainInfo,
|
|
506
|
-
active:
|
|
506
|
+
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
|
|
507
507
|
currentProvider: Object.keys(chainInfo.providers)[0]
|
|
508
508
|
});
|
|
509
509
|
});
|
|
@@ -559,7 +559,8 @@ class ChainService {
|
|
|
559
559
|
evmInfo: storedChainInfo.evmInfo,
|
|
560
560
|
substrateInfo: storedChainInfo.substrateInfo,
|
|
561
561
|
isTestnet: storedChainInfo.isTestnet,
|
|
562
|
-
chainStatus: storedChainInfo.chainStatus
|
|
562
|
+
chainStatus: storedChainInfo.chainStatus,
|
|
563
|
+
icon: storedChainInfo.icon
|
|
563
564
|
};
|
|
564
565
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
565
566
|
currentProvider: storedChainInfo.currentProvider,
|
|
@@ -584,11 +585,11 @@ class ChainService {
|
|
|
584
585
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
585
586
|
slug,
|
|
586
587
|
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
587
|
-
active:
|
|
588
|
+
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug)
|
|
588
589
|
};
|
|
589
590
|
newStorageData.push({
|
|
590
591
|
...mergedChainInfoMap[slug],
|
|
591
|
-
active:
|
|
592
|
+
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
592
593
|
currentProvider: Object.keys(chainInfo.providers)[0]
|
|
593
594
|
});
|
|
594
595
|
}
|
|
@@ -685,7 +686,7 @@ class ChainService {
|
|
|
685
686
|
active: targetChainState.active,
|
|
686
687
|
currentProvider: targetChainState.currentProvider
|
|
687
688
|
}).then(() => {
|
|
688
|
-
this.eventService.emit('chain.
|
|
689
|
+
this.eventService.emit('chain.updateState', chainSlug);
|
|
689
690
|
}).catch(e => this.logger.error(e));
|
|
690
691
|
}
|
|
691
692
|
insertChain(params) {
|
|
@@ -731,7 +732,8 @@ class ChainService {
|
|
|
731
732
|
substrateInfo,
|
|
732
733
|
evmInfo,
|
|
733
734
|
isTestnet: false,
|
|
734
|
-
chainStatus: _types._ChainStatus.ACTIVE
|
|
735
|
+
chainStatus: _types._ChainStatus.ACTIVE,
|
|
736
|
+
icon: '' // Todo: Allow update with custom chain
|
|
735
737
|
};
|
|
736
738
|
|
|
737
739
|
// insert new chainInfo
|
|
@@ -759,7 +761,8 @@ class ChainService {
|
|
|
759
761
|
priceId: params.chainEditInfo.priceId || null,
|
|
760
762
|
slug: '',
|
|
761
763
|
symbol: params.chainEditInfo.symbol,
|
|
762
|
-
hasValue: true
|
|
764
|
+
hasValue: true,
|
|
765
|
+
icon: ''
|
|
763
766
|
});
|
|
764
767
|
|
|
765
768
|
// update subscription
|
|
@@ -974,21 +977,23 @@ class ChainService {
|
|
|
974
977
|
}
|
|
975
978
|
async validateCustomToken(data) {
|
|
976
979
|
const assetRegistry = this.getSmartContractTokens();
|
|
977
|
-
let
|
|
980
|
+
let existedToken;
|
|
978
981
|
for (const token of Object.values(assetRegistry)) {
|
|
979
982
|
var _token$metadata2;
|
|
980
983
|
const contractAddress = token === null || token === void 0 ? void 0 : (_token$metadata2 = token.metadata) === null || _token$metadata2 === void 0 ? void 0 : _token$metadata2.contractAddress;
|
|
981
984
|
if ((0, _utils._isEqualContractAddress)(contractAddress, data.contractAddress) && token.assetType === data.type && token.originChain === data.originChain) {
|
|
982
|
-
|
|
985
|
+
existedToken = token;
|
|
983
986
|
break;
|
|
984
987
|
}
|
|
985
988
|
}
|
|
986
|
-
if (
|
|
989
|
+
if (existedToken) {
|
|
990
|
+
var _existedToken;
|
|
987
991
|
return {
|
|
988
|
-
decimals:
|
|
989
|
-
name:
|
|
990
|
-
symbol:
|
|
991
|
-
isExist,
|
|
992
|
+
decimals: existedToken.decimals || 0,
|
|
993
|
+
name: existedToken.name,
|
|
994
|
+
symbol: existedToken.symbol,
|
|
995
|
+
isExist: !!existedToken,
|
|
996
|
+
existedSlug: (_existedToken = existedToken) === null || _existedToken === void 0 ? void 0 : _existedToken.slug,
|
|
992
997
|
contractError: false
|
|
993
998
|
};
|
|
994
999
|
}
|
|
@@ -1002,7 +1007,7 @@ class ChainService {
|
|
|
1002
1007
|
name,
|
|
1003
1008
|
decimals,
|
|
1004
1009
|
symbol,
|
|
1005
|
-
isExist,
|
|
1010
|
+
isExist: !!existedToken,
|
|
1006
1011
|
contractError
|
|
1007
1012
|
};
|
|
1008
1013
|
}
|
|
@@ -1052,20 +1057,28 @@ class ChainService {
|
|
|
1052
1057
|
|
|
1053
1058
|
return this.substrateChainHandler.resumeAllApis();
|
|
1054
1059
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1060
|
+
refreshChainStateTimeout = undefined;
|
|
1061
|
+
refreshChainStateTimes = 0;
|
|
1057
1062
|
refreshChainStateInterval() {
|
|
1058
1063
|
let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
1064
|
+
let times = arguments.length > 1 ? arguments[1] : undefined;
|
|
1059
1065
|
clearTimeout(this.refreshChainStateTimeout);
|
|
1060
1066
|
setTimeout(() => {
|
|
1061
|
-
|
|
1067
|
+
if (times) {
|
|
1068
|
+
this.refreshChainStateTimes = times;
|
|
1069
|
+
}
|
|
1070
|
+
this.refreshChainStateTimes -= 1;
|
|
1071
|
+
if (this.refreshChainStateTimes < 0) {
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
this.updateApiMapStatus().catch(console.error);
|
|
1062
1075
|
this.refreshChainStateTimeout = setTimeout(() => {
|
|
1063
|
-
this.updateApiMapStatus();
|
|
1064
|
-
this.refreshChainStateInterval();
|
|
1065
|
-
},
|
|
1076
|
+
this.updateApiMapStatus().catch(console.error);
|
|
1077
|
+
this.refreshChainStateInterval(0);
|
|
1078
|
+
}, 3000);
|
|
1066
1079
|
}, delay);
|
|
1067
1080
|
}
|
|
1068
|
-
updateApiMapStatus() {
|
|
1081
|
+
async updateApiMapStatus() {
|
|
1069
1082
|
const substrateApiMap = this.getSubstrateApiMap();
|
|
1070
1083
|
const evmApiMap = this.getEvmApiMap();
|
|
1071
1084
|
const chainStateMap = this.getChainStateMap();
|
|
@@ -1076,25 +1089,31 @@ class ChainService {
|
|
|
1076
1089
|
update = true;
|
|
1077
1090
|
}
|
|
1078
1091
|
}
|
|
1079
|
-
Object.entries(chainStateMap).
|
|
1092
|
+
const promiseList = Object.entries(chainStateMap).map(async _ref4 => {
|
|
1080
1093
|
let [chain, chainState] = _ref4;
|
|
1081
|
-
|
|
1082
|
-
if (
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1094
|
+
try {
|
|
1095
|
+
if (chainState.active) {
|
|
1096
|
+
if (substrateApiMap[chain]) {
|
|
1097
|
+
const api = substrateApiMap[chain];
|
|
1098
|
+
if (api.isApiConnected) {
|
|
1099
|
+
updateState(chainState, _types3._ChainConnectionStatus.CONNECTED);
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
} else if (evmApiMap[chain]) {
|
|
1103
|
+
var _api$api;
|
|
1104
|
+
const api = evmApiMap[chain];
|
|
1105
|
+
if (await (api === null || api === void 0 ? void 0 : (_api$api = api.api) === null || _api$api === void 0 ? void 0 : _api$api.eth.net.isListening())) {
|
|
1106
|
+
updateState(chainState, _types3._ChainConnectionStatus.CONNECTED);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1093
1109
|
}
|
|
1094
1110
|
}
|
|
1111
|
+
updateState(chainState, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1112
|
+
} catch (e) {
|
|
1113
|
+
updateState(chainState, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1095
1114
|
}
|
|
1096
|
-
updateState(chainState, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1097
1115
|
});
|
|
1116
|
+
await Promise.all(promiseList);
|
|
1098
1117
|
if (update) {
|
|
1099
1118
|
console.log('Update chain connection state');
|
|
1100
1119
|
this.chainStateMapSubject.next(chainStateMap);
|
|
@@ -1120,7 +1139,6 @@ class ChainService {
|
|
|
1120
1139
|
this.setAssetSettings(assetSettings, false);
|
|
1121
1140
|
}
|
|
1122
1141
|
this.eventService.emit('asset.ready', true);
|
|
1123
|
-
console.log('Done init asset settings');
|
|
1124
1142
|
}
|
|
1125
1143
|
setAssetSettings(assetSettings) {
|
|
1126
1144
|
let emitEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
@@ -1135,7 +1153,7 @@ class ChainService {
|
|
|
1135
1153
|
}
|
|
1136
1154
|
this.assetSettingSubject.next(assetSettings);
|
|
1137
1155
|
updateAssets.forEach(slug => {
|
|
1138
|
-
this.eventService.emit(
|
|
1156
|
+
this.eventService.emit('asset.updateState', slug);
|
|
1139
1157
|
});
|
|
1140
1158
|
this.store.set('AssetSetting', assetSettings);
|
|
1141
1159
|
}
|
|
@@ -1184,5 +1202,11 @@ class ChainService {
|
|
|
1184
1202
|
subscribeAssetSettings() {
|
|
1185
1203
|
return this.assetSettingSubject;
|
|
1186
1204
|
}
|
|
1205
|
+
async getChainLogoMap() {
|
|
1206
|
+
return Promise.resolve(_chainList.ChainLogoMap);
|
|
1207
|
+
}
|
|
1208
|
+
async getAssetLogoMap() {
|
|
1209
|
+
return Promise.resolve(_chainList.AssetLogoMap);
|
|
1210
|
+
}
|
|
1187
1211
|
}
|
|
1188
1212
|
exports.ChainService = ChainService;
|
|
@@ -42,7 +42,11 @@ class EventService extends _eventemitter.default {
|
|
|
42
42
|
}, this.lazyTime);
|
|
43
43
|
}
|
|
44
44
|
emitLazy() {
|
|
45
|
-
|
|
45
|
+
try {
|
|
46
|
+
this.lazyEmitter.emit('lazy', this.pendingEvents, this.pendingEvents.map(e => e.type));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error('Get error in some listener of lazy event', e);
|
|
49
|
+
}
|
|
46
50
|
this.pendingEvents = [];
|
|
47
51
|
this.timeoutId = null;
|
|
48
52
|
}
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.COMMON_RELOAD_EVENTS = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const COMMON_RELOAD_EVENTS = ['account.updateCurrent', 'asset.updateState', 'account.add', 'chain.updateState', 'account.remove', 'chain.add'];
|
|
11
|
+
exports.COMMON_RELOAD_EVENTS = COMMON_RELOAD_EVENTS;
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.HistoryService = void 0;
|
|
7
7
|
var _constants = require("@subwallet/extension-base/constants");
|
|
8
|
-
var
|
|
8
|
+
var _types = require("@subwallet/extension-base/services/base/types");
|
|
9
|
+
var _promise = require("@subwallet/extension-base/utils/promise");
|
|
9
10
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
10
|
-
var _accounts = require("@subwallet/ui-keyring/observable/accounts");
|
|
11
11
|
var _rxjs = require("rxjs");
|
|
12
12
|
var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
|
|
13
13
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -15,28 +15,15 @@ var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
|
|
|
15
15
|
|
|
16
16
|
class HistoryService {
|
|
17
17
|
historySubject = new _rxjs.BehaviorSubject([]);
|
|
18
|
-
constructor(dbService, chainService, eventService) {
|
|
18
|
+
constructor(dbService, chainService, eventService, keyringService) {
|
|
19
19
|
this.dbService = dbService;
|
|
20
20
|
this.chainService = chainService;
|
|
21
21
|
this.eventService = eventService;
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
this.historySubject.next(histories);
|
|
25
|
-
}).catch(console.error);
|
|
26
|
-
|
|
27
|
-
// Wait for keyring and chain ready and start
|
|
28
|
-
Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
|
|
29
|
-
this.getHistories().catch(console.log);
|
|
30
|
-
this.eventService.on('account.add', () => {
|
|
31
|
-
this.refreshHistoryInterval();
|
|
32
|
-
});
|
|
33
|
-
this.eventService.on('account.remove', address => {
|
|
34
|
-
this.removeHistoryByAddress(address).catch(console.error);
|
|
35
|
-
});
|
|
36
|
-
}).catch(console.error);
|
|
22
|
+
this.keyringService = keyringService;
|
|
23
|
+
this.init().catch(console.error);
|
|
37
24
|
}
|
|
38
25
|
fetchPromise = null;
|
|
39
|
-
|
|
26
|
+
interval = undefined;
|
|
40
27
|
async fetchAndLoadHistories(addresses) {
|
|
41
28
|
if (!addresses || addresses.length === 0) {
|
|
42
29
|
return [];
|
|
@@ -47,7 +34,7 @@ class HistoryService {
|
|
|
47
34
|
const historyRecords = await (0, _subsquidMultiChainHistory.fetchMultiChainHistories)(addresses, chainMap);
|
|
48
35
|
|
|
49
36
|
// Fill additional info
|
|
50
|
-
const accountMap = Object.entries(
|
|
37
|
+
const accountMap = Object.entries(this.keyringService.accounts).reduce((map, _ref) => {
|
|
51
38
|
let [address, account] = _ref;
|
|
52
39
|
map[address.toLowerCase()] = account.json.meta.name || address;
|
|
53
40
|
return map;
|
|
@@ -57,44 +44,24 @@ class HistoryService {
|
|
|
57
44
|
record.fromName = accountMap[(_record$from = record.from) === null || _record$from === void 0 ? void 0 : _record$from.toLowerCase()];
|
|
58
45
|
record.toName = accountMap[(_record$to = record.to) === null || _record$to === void 0 ? void 0 : _record$to.toLowerCase()];
|
|
59
46
|
});
|
|
60
|
-
this.
|
|
47
|
+
await this.addHistoryItems(historyRecords);
|
|
61
48
|
return historyRecords;
|
|
62
49
|
}
|
|
63
|
-
async fetchHistories(addresses) {
|
|
64
|
-
if (!this.fetchPromise) {
|
|
65
|
-
// Fetch another histories data data indexer and merge it with stored in database
|
|
66
|
-
this.fetchPromise = this.fetchAndLoadHistories(addresses);
|
|
67
|
-
}
|
|
68
|
-
return this.fetchPromise;
|
|
69
|
-
}
|
|
70
|
-
invalidCache() {
|
|
71
|
-
this.fetchPromise = null;
|
|
72
|
-
}
|
|
73
|
-
refreshHistoryInterval() {
|
|
74
|
-
clearTimeout(this.nextFetch);
|
|
75
|
-
this.invalidCache();
|
|
76
|
-
this.getHistories().catch(console.error);
|
|
77
|
-
this.nextFetch = setTimeout(() => {
|
|
78
|
-
this.refreshHistoryInterval();
|
|
79
|
-
}, _constants.CRON_REFRESH_HISTORY_INTERVAL);
|
|
80
|
-
}
|
|
81
50
|
async getHistories() {
|
|
82
51
|
const addressList = _uiKeyring.keyring.getAccounts().map(a => a.address);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
if (!this.fetchPromise) {
|
|
53
|
+
this.fetchPromise = (async () => {
|
|
54
|
+
await this.fetchAndLoadHistories(addressList);
|
|
55
|
+
const histories = await this.dbService.getHistories();
|
|
56
|
+
this.historySubject.next(histories);
|
|
57
|
+
})();
|
|
87
58
|
}
|
|
88
|
-
return this.historySubject.getValue();
|
|
59
|
+
return Promise.resolve(this.historySubject.getValue());
|
|
89
60
|
}
|
|
90
61
|
async getHistorySubject() {
|
|
91
62
|
await this.getHistories();
|
|
92
63
|
return this.historySubject;
|
|
93
64
|
}
|
|
94
|
-
async insertHistories(historyItems) {
|
|
95
|
-
await this.dbService.upsertHistory(historyItems);
|
|
96
|
-
this.historySubject.next(await this.dbService.getHistories());
|
|
97
|
-
}
|
|
98
65
|
async updateHistories(chain, extrinsicHash, updateData) {
|
|
99
66
|
const existedRecords = await this.dbService.getHistories({
|
|
100
67
|
chain,
|
|
@@ -108,14 +75,29 @@ class HistoryService {
|
|
|
108
75
|
});
|
|
109
76
|
await this.addHistoryItems(updatedRecords);
|
|
110
77
|
}
|
|
78
|
+
async updateHistoryByExtrinsicHash(extrinsicHash, updateData) {
|
|
79
|
+
await this.dbService.updateHistoryByNewExtrinsicHash(extrinsicHash, updateData);
|
|
80
|
+
this.historySubject.next(await this.dbService.getHistories());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Insert history without check override origin 'app'
|
|
84
|
+
async insertHistories(historyItems) {
|
|
85
|
+
await this.dbService.upsertHistory(historyItems);
|
|
86
|
+
this.historySubject.next(await this.dbService.getHistories());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Insert history with check override origin 'app'
|
|
111
90
|
async addHistoryItems(historyItems) {
|
|
112
91
|
// Prevent override record with original is 'app'
|
|
113
92
|
const appRecords = this.historySubject.value.filter(item => item.origin === 'app');
|
|
114
93
|
const excludeKeys = appRecords.map(item => {
|
|
115
|
-
return `${item.chain}-${
|
|
94
|
+
return `${item.chain}-${item.extrinsicHash}`;
|
|
116
95
|
});
|
|
117
96
|
const updateRecords = historyItems.filter(item => {
|
|
118
|
-
const key = `${item.chain}-${
|
|
97
|
+
const key = `${item.chain}-${item.extrinsicHash}`;
|
|
98
|
+
|
|
99
|
+
// !excludeKeys.includes(key) && console.log('Cancel update', key);
|
|
100
|
+
|
|
119
101
|
return item.origin === 'app' || !excludeKeys.includes(key);
|
|
120
102
|
});
|
|
121
103
|
await this.dbService.upsertHistory(updateRecords);
|
|
@@ -125,5 +107,74 @@ class HistoryService {
|
|
|
125
107
|
await this.dbService.stores.transaction.removeAllByAddress(address);
|
|
126
108
|
this.historySubject.next(await this.dbService.getHistories());
|
|
127
109
|
}
|
|
110
|
+
status = _types.ServiceStatus.NOT_INITIALIZED;
|
|
111
|
+
async loadData() {
|
|
112
|
+
const histories = await this.dbService.getHistories();
|
|
113
|
+
this.historySubject.next(histories);
|
|
114
|
+
}
|
|
115
|
+
async persistData() {
|
|
116
|
+
await this.dbService.upsertHistory(this.historySubject.value);
|
|
117
|
+
}
|
|
118
|
+
async startCron() {
|
|
119
|
+
await this.getHistories();
|
|
120
|
+
this.interval = setInterval(() => {
|
|
121
|
+
this.getHistories().catch(console.error);
|
|
122
|
+
}, _constants.CRON_REFRESH_HISTORY_INTERVAL);
|
|
123
|
+
}
|
|
124
|
+
stopCron() {
|
|
125
|
+
clearTimeout(this.interval);
|
|
126
|
+
this.fetchPromise = null;
|
|
127
|
+
return Promise.resolve();
|
|
128
|
+
}
|
|
129
|
+
startPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
130
|
+
async init() {
|
|
131
|
+
this.status = _types.ServiceStatus.INITIALIZING;
|
|
132
|
+
await this.loadData();
|
|
133
|
+
Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
|
|
134
|
+
this.getHistories().catch(console.log);
|
|
135
|
+
this.eventService.on('account.add', () => {
|
|
136
|
+
(async () => {
|
|
137
|
+
await this.stopCron();
|
|
138
|
+
await this.startCron();
|
|
139
|
+
})().catch(console.error);
|
|
140
|
+
});
|
|
141
|
+
this.eventService.on('account.remove', address => {
|
|
142
|
+
this.removeHistoryByAddress(address).catch(console.error);
|
|
143
|
+
});
|
|
144
|
+
}).catch(console.error);
|
|
145
|
+
this.status = _types.ServiceStatus.INITIALIZED;
|
|
146
|
+
}
|
|
147
|
+
async start() {
|
|
148
|
+
try {
|
|
149
|
+
console.debug('Start history service');
|
|
150
|
+
this.startPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
151
|
+
this.status = _types.ServiceStatus.STARTING;
|
|
152
|
+
await this.startCron();
|
|
153
|
+
this.status = _types.ServiceStatus.STARTED;
|
|
154
|
+
this.startPromiseHandler.resolve();
|
|
155
|
+
} catch (e) {
|
|
156
|
+
this.startPromiseHandler.reject(e);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
waitForStarted() {
|
|
160
|
+
return this.startPromiseHandler.promise;
|
|
161
|
+
}
|
|
162
|
+
stopPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
163
|
+
async stop() {
|
|
164
|
+
console.debug('Stop history service');
|
|
165
|
+
try {
|
|
166
|
+
this.stopPromiseHandler = (0, _promise.createPromiseHandler)();
|
|
167
|
+
this.status = _types.ServiceStatus.STOPPING;
|
|
168
|
+
await this.persistData();
|
|
169
|
+
await this.stopCron();
|
|
170
|
+
this.stopPromiseHandler.resolve();
|
|
171
|
+
this.status = _types.ServiceStatus.STOPPED;
|
|
172
|
+
} catch (e) {
|
|
173
|
+
this.stopPromiseHandler.reject(e);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
waitForStopped() {
|
|
177
|
+
return this.stopPromiseHandler.promise;
|
|
178
|
+
}
|
|
128
179
|
}
|
|
129
180
|
exports.HistoryService = HistoryService;
|
|
@@ -67,12 +67,15 @@ function autoFormatAddress(address) {
|
|
|
67
67
|
return '';
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
function generateSignature(
|
|
71
|
-
|
|
70
|
+
function generateSignature(input) {
|
|
71
|
+
if (!input) {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
const {
|
|
72
75
|
r,
|
|
73
76
|
s,
|
|
74
77
|
v
|
|
75
|
-
} =
|
|
78
|
+
} = input;
|
|
76
79
|
const rHex = r.startsWith('0x') ? r.slice(2) : r;
|
|
77
80
|
const sHex = s.startsWith('0x') ? s.slice(2) : s;
|
|
78
81
|
const vHex = parseInt(v).toString(16);
|
|
@@ -118,7 +121,7 @@ function parseSubsquidTransactionData(address, type, historyItem, chainInfo, arg
|
|
|
118
121
|
const transaction = data.call.data.args.transaction.value;
|
|
119
122
|
to = autoFormatAddress(parsedArgs.to);
|
|
120
123
|
from = autoFormatAddress(parsedArgs.from);
|
|
121
|
-
extrinsicHash = parsedArgs.transactionHash;
|
|
124
|
+
extrinsicHash = parsedArgs.transactionHash || extrinsic.hash;
|
|
122
125
|
amount = transaction.value || '0';
|
|
123
126
|
fee = (parseInt(transaction.gasPrice) * parseInt(transaction.gasLimit)).toString();
|
|
124
127
|
signature = generateSignature(transaction.signature);
|
|
@@ -255,14 +258,14 @@ async function fetchMultiChainHistories(addresses, chainMap) {
|
|
|
255
258
|
console.warn(`Not found chain info for chain id: ${chainId}`);
|
|
256
259
|
return;
|
|
257
260
|
}
|
|
258
|
-
|
|
259
|
-
|
|
261
|
+
usedAddresses.forEach(address => {
|
|
262
|
+
try {
|
|
260
263
|
const transactionData = parseSubsquidTransactionData(address, name, historyItem, chainInfo, parseData(args), parseData(_data));
|
|
261
264
|
histories.push(transactionData);
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
265
|
+
} catch (e) {
|
|
266
|
+
console.warn('Parse transaction data failed', address, e);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
266
269
|
});
|
|
267
270
|
return histories;
|
|
268
271
|
}
|
|
@@ -16,8 +16,9 @@ class KeyringService {
|
|
|
16
16
|
address: '',
|
|
17
17
|
currentGenesisHash: null
|
|
18
18
|
});
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
addressesSubject = _uiKeyring.keyring.addresses.subject;
|
|
20
|
+
accountSubject = _uiKeyring.keyring.accounts.subject;
|
|
21
|
+
beforeAccount = this.accountSubject.value;
|
|
21
22
|
keyringStateSubject = new _rxjs.BehaviorSubject({
|
|
22
23
|
isReady: false,
|
|
23
24
|
hasMasterPassword: false,
|
|
@@ -26,23 +27,17 @@ class KeyringService {
|
|
|
26
27
|
constructor(eventService) {
|
|
27
28
|
this.eventService = eventService;
|
|
28
29
|
this.currentAccountStore.get('CurrentAccountInfo', rs => {
|
|
29
|
-
this.currentAccountSubject.next(rs);
|
|
30
|
+
rs && this.currentAccountSubject.next(rs);
|
|
30
31
|
});
|
|
31
32
|
this.subscribeAccounts().catch(console.error);
|
|
32
33
|
}
|
|
33
34
|
async subscribeAccounts() {
|
|
34
35
|
// Wait until account ready
|
|
35
|
-
await
|
|
36
|
-
const onReady = () => {
|
|
37
|
-
this.eventService.off('account.ready', onReady);
|
|
38
|
-
resolve(true);
|
|
39
|
-
};
|
|
40
|
-
this.eventService.on('account.ready', onReady);
|
|
41
|
-
});
|
|
36
|
+
await this.eventService.waitAccountReady;
|
|
42
37
|
this.beforeAccount = {
|
|
43
|
-
...this.
|
|
38
|
+
...this.accountSubject.value
|
|
44
39
|
};
|
|
45
|
-
this.
|
|
40
|
+
this.accountSubject.subscribe(subjectInfo => {
|
|
46
41
|
// Check if accounts changed
|
|
47
42
|
const beforeAddresses = Object.keys(this.beforeAccount);
|
|
48
43
|
const afterAddresses = Object.keys(subjectInfo);
|
|
@@ -87,7 +82,10 @@ class KeyringService {
|
|
|
87
82
|
});
|
|
88
83
|
}
|
|
89
84
|
get accounts() {
|
|
90
|
-
return this.
|
|
85
|
+
return this.accountSubject.value;
|
|
86
|
+
}
|
|
87
|
+
get addresses() {
|
|
88
|
+
return this.addressesSubject.value;
|
|
91
89
|
}
|
|
92
90
|
get currentAccount() {
|
|
93
91
|
return this.currentAccountSubject.value;
|
|
@@ -24,7 +24,6 @@ const getTokenPrice = async function (priceIds) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
if (useBackupApi || ((_res = res) === null || _res === void 0 ? void 0 : _res.status) !== 200) {
|
|
27
|
-
console.log('Use backup api for price');
|
|
28
27
|
useBackupApi = true;
|
|
29
28
|
res = await _axios.default.get(`https://chain-data.subwallet.app/api/price/get?ids=${idStr}`);
|
|
30
29
|
}
|