@subwallet/extension-base 1.0.2-2 → 1.0.2-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +46 -38
- package/background/KoniTypes.js +8 -8
- package/background/errors/TransactionError.js +25 -1
- package/background/types.d.ts +10 -5
- package/cjs/background/KoniTypes.js +8 -8
- 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 +382 -207
- package/cjs/koni/background/handlers/State.js +41 -33
- package/cjs/koni/background/handlers/Tabs.js +50 -17
- package/cjs/koni/background/subscription.js +32 -29
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/index.js +59 -45
- 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 +19 -13
- package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
- package/cjs/services/keyring-service/index.js +11 -13
- package/cjs/services/price-service/coingecko.js +0 -1
- package/cjs/services/price-service/index.js +2 -3
- 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 +56 -34
- package/cjs/services/storage-service/db-stores/Nft.js +7 -15
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +26 -15
- package/cjs/utils/address.js +10 -1
- package/cjs/utils/index.js +9 -15
- 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 +8 -3
- package/koni/background/handlers/Extension.js +297 -126
- package/koni/background/handlers/State.d.ts +5 -6
- package/koni/background/handlers/State.js +43 -33
- package/koni/background/handlers/Tabs.js +50 -17
- package/koni/background/subscription.js +31 -30
- package/package.json +18 -13
- package/packageInfo.js +1 -1
- 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 +3 -2
- package/services/chain-service/index.js +53 -40
- 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 +4 -2
- package/services/history-service/index.js +19 -13
- 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/price-service/coingecko.js +0 -1
- package/services/price-service/index.js +2 -3
- 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 +1 -0
- package/services/storage-service/DatabaseService.js +56 -34
- package/services/storage-service/db-stores/Nft.d.ts +2 -2
- package/services/storage-service/db-stores/Nft.js +7 -14
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.js +26 -15
- 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
|
@@ -31,7 +31,6 @@ var _AccountRef = _interopRequireDefault(require("@subwallet/extension-base/stor
|
|
|
31
31
|
var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
32
32
|
var _decode = require("@subwallet/keyring/pair/decode");
|
|
33
33
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
34
|
-
var _accounts = require("@subwallet/ui-keyring/observable/accounts");
|
|
35
34
|
var _ethSimpleKeyring = _interopRequireDefault(require("eth-simple-keyring"));
|
|
36
35
|
var _rxjs = require("rxjs");
|
|
37
36
|
var _util = require("@polkadot/util");
|
|
@@ -67,7 +66,6 @@ class KoniState {
|
|
|
67
66
|
unsubscriptionMap = {};
|
|
68
67
|
accountRefStore = new _AccountRef.default();
|
|
69
68
|
externalRequest = {};
|
|
70
|
-
serviceInfoSubject = new _rxjs.Subject();
|
|
71
69
|
balanceMap = {};
|
|
72
70
|
balanceSubject = new _rxjs.Subject();
|
|
73
71
|
crowdloanMap = generateDefaultCrowdloanMap();
|
|
@@ -94,10 +92,10 @@ class KoniState {
|
|
|
94
92
|
this.notificationService = new _NotificationService.default();
|
|
95
93
|
this.chainService = new _chainService.ChainService(this.dbService, this.eventService);
|
|
96
94
|
this.settingService = new _SettingService.default();
|
|
97
|
-
this.requestService = new _requestService.default(this.chainService, this.settingService);
|
|
95
|
+
this.requestService = new _requestService.default(this.chainService, this.settingService, this.keyringService);
|
|
98
96
|
this.priceService = new _priceService.PriceService(this.dbService, this.eventService, this.chainService);
|
|
99
97
|
this.balanceService = new _balanceService.BalanceService(this.chainService);
|
|
100
|
-
this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService);
|
|
98
|
+
this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
|
|
101
99
|
this.transactionService = new _transactionService.default(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
|
|
102
100
|
this.migrationService = new _migrationService.default(this);
|
|
103
101
|
this.subscription = new _subscription.KoniSubscription(this, this.dbService);
|
|
@@ -266,7 +264,7 @@ class KoniState {
|
|
|
266
264
|
}
|
|
267
265
|
getAddressList() {
|
|
268
266
|
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
269
|
-
const addressList = Object.keys(
|
|
267
|
+
const addressList = Object.keys(this.keyringService.accounts);
|
|
270
268
|
return addressList.reduce((addressList, v) => ({
|
|
271
269
|
...addressList,
|
|
272
270
|
[v]: value
|
|
@@ -309,7 +307,7 @@ class KoniState {
|
|
|
309
307
|
return addresses;
|
|
310
308
|
}
|
|
311
309
|
async getPooledStakingRecordsByAddress(addresses) {
|
|
312
|
-
return
|
|
310
|
+
return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
|
|
313
311
|
}
|
|
314
312
|
|
|
315
313
|
// TODO: delete later
|
|
@@ -367,12 +365,12 @@ class KoniState {
|
|
|
367
365
|
this.dbService.addNft(address, nftData).catch(e => this.logger.warn(e));
|
|
368
366
|
callback && callback(nftData);
|
|
369
367
|
}
|
|
370
|
-
removeNfts(chain, address, collectionId, nftIds) {
|
|
371
|
-
return this.dbService.removeNfts(chain, address, collectionId, nftIds);
|
|
372
|
-
}
|
|
373
368
|
deleteNftCollection(chain, collectionId) {
|
|
374
369
|
return this.dbService.deleteNftCollection(chain, collectionId);
|
|
375
370
|
}
|
|
371
|
+
cleanUpNfts(chain, owner, collectionId, nftIds, ownNothing) {
|
|
372
|
+
this.dbService.cleanUpNft(chain, owner, collectionId, nftIds, ownNothing).catch(e => this.logger.warn(e));
|
|
373
|
+
}
|
|
376
374
|
async getNft() {
|
|
377
375
|
const addresses = this.getDecodedAddresses();
|
|
378
376
|
if (!addresses.length) {
|
|
@@ -459,7 +457,7 @@ class KoniState {
|
|
|
459
457
|
if (address === _constants.ALL_ACCOUNT_KEY) {
|
|
460
458
|
const pairs = _uiKeyring.keyring.getAccounts();
|
|
461
459
|
const pair = pairs[0];
|
|
462
|
-
const pairGenesisHash = pair.meta.genesisHash;
|
|
460
|
+
const pairGenesisHash = (pair === null || pair === void 0 ? void 0 : pair.meta.genesisHash) || '';
|
|
463
461
|
if (pairs.length > 1 || !pair) {
|
|
464
462
|
result.allGenesisHash = currentGenesisHash || undefined;
|
|
465
463
|
} else {
|
|
@@ -546,7 +544,11 @@ class KoniState {
|
|
|
546
544
|
isApproved
|
|
547
545
|
} = _ref4;
|
|
548
546
|
if (isApproved) {
|
|
549
|
-
|
|
547
|
+
if (networkData.mode === 'insert') {
|
|
548
|
+
await this.upsertChainInfo(networkData);
|
|
549
|
+
} else {
|
|
550
|
+
// TODO: update existed network (need more discussion)
|
|
551
|
+
}
|
|
550
552
|
return null;
|
|
551
553
|
} else {
|
|
552
554
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.USER_REJECTED_REQUEST);
|
|
@@ -673,7 +675,7 @@ class KoniState {
|
|
|
673
675
|
const items = await this.dbService.stores.balance.getBalanceMapByAddress(address);
|
|
674
676
|
return items || {};
|
|
675
677
|
}
|
|
676
|
-
async
|
|
678
|
+
async handleSwitchAccount(newAddress) {
|
|
677
679
|
await Promise.all([this.resetBalanceMap(newAddress), this.resetCrowdloanMap(newAddress)]);
|
|
678
680
|
}
|
|
679
681
|
async resetBalanceMap(newAddress) {
|
|
@@ -754,9 +756,6 @@ class KoniState {
|
|
|
754
756
|
subscribeCrowdloan() {
|
|
755
757
|
return this.crowdloanSubject;
|
|
756
758
|
}
|
|
757
|
-
getAllPriceIds() {
|
|
758
|
-
return this.chainService.getAllPriceIds();
|
|
759
|
-
}
|
|
760
759
|
getSmartContractNfts() {
|
|
761
760
|
return this.chainService.getSmartContractNfts();
|
|
762
761
|
}
|
|
@@ -814,7 +813,9 @@ class KoniState {
|
|
|
814
813
|
await this.chainService.updateAssetSetting(tokenSlug, {
|
|
815
814
|
visible: true
|
|
816
815
|
});
|
|
817
|
-
this.eventService.emit('asset.
|
|
816
|
+
this.eventService.emit('asset.updateState', tokenSlug);
|
|
817
|
+
} else {
|
|
818
|
+
this.eventService.emit('asset.updateState', tokenSlug);
|
|
818
819
|
}
|
|
819
820
|
}
|
|
820
821
|
deleteCustomAssets(targetTokens) {
|
|
@@ -841,6 +842,7 @@ class KoniState {
|
|
|
841
842
|
await this.chainService.updateAssetSetting(newNativeTokenSlug, {
|
|
842
843
|
visible: true
|
|
843
844
|
});
|
|
845
|
+
this.eventService.emit('asset.updateState', newNativeTokenSlug);
|
|
844
846
|
}
|
|
845
847
|
return true;
|
|
846
848
|
}
|
|
@@ -884,13 +886,6 @@ class KoniState {
|
|
|
884
886
|
const defaultChains = this.getDefaultNetworkKeys();
|
|
885
887
|
return this.chainService.resetChainInfoMap(defaultChains);
|
|
886
888
|
}
|
|
887
|
-
updateNetworkStatus(networkKey, status) {
|
|
888
|
-
const chainState = this.chainService.getChainStateByKey(networkKey);
|
|
889
|
-
if (chainState.connectionStatus === status) {
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
this.chainService.setChainConnectionStatus(networkKey, status);
|
|
893
|
-
}
|
|
894
889
|
getSubstrateApiMap() {
|
|
895
890
|
return this.chainService.getSubstrateApiMap();
|
|
896
891
|
}
|
|
@@ -916,9 +911,6 @@ class KoniState {
|
|
|
916
911
|
refreshWeb3Api(key) {
|
|
917
912
|
this.chainService.refreshEvmApi(key);
|
|
918
913
|
}
|
|
919
|
-
subscribeServiceInfo() {
|
|
920
|
-
return this.serviceInfoSubject;
|
|
921
|
-
}
|
|
922
914
|
getServiceInfo() {
|
|
923
915
|
return {
|
|
924
916
|
chainInfoMap: this.chainService.getChainInfoMap(),
|
|
@@ -1020,8 +1012,9 @@ class KoniState {
|
|
|
1020
1012
|
return [undefined, undefined];
|
|
1021
1013
|
}
|
|
1022
1014
|
const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref8 => {
|
|
1015
|
+
var _chainInfo$evmInfo;
|
|
1023
1016
|
let [networkKey, chainInfo] = _ref8;
|
|
1024
|
-
return (0
|
|
1017
|
+
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) === chainId;
|
|
1025
1018
|
});
|
|
1026
1019
|
if (rs) {
|
|
1027
1020
|
return rs;
|
|
@@ -1259,17 +1252,23 @@ class KoniState {
|
|
|
1259
1252
|
account: account,
|
|
1260
1253
|
canSign: true
|
|
1261
1254
|
};
|
|
1255
|
+
const eType = transaction.value ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.EVM_EXECUTE;
|
|
1256
|
+
const transactionData = {
|
|
1257
|
+
...transaction
|
|
1258
|
+
};
|
|
1259
|
+
if (eType === _KoniTypes.ExtrinsicType.TRANSFER_BALANCE) {
|
|
1260
|
+
// @ts-ignore
|
|
1261
|
+
transactionData.tokenSlug = this.chainService.getNativeTokenInfo(networkKey).slug;
|
|
1262
|
+
}
|
|
1262
1263
|
|
|
1263
|
-
//
|
|
1264
|
+
// Custom handle this instead of general handler transaction
|
|
1264
1265
|
const transactionEmitter = await this.transactionService.addTransaction({
|
|
1265
1266
|
transaction: requestPayload,
|
|
1266
1267
|
address: requestPayload.from,
|
|
1267
1268
|
chain: networkKey,
|
|
1268
1269
|
url,
|
|
1269
|
-
data:
|
|
1270
|
-
|
|
1271
|
-
},
|
|
1272
|
-
extrinsicType: transaction.value ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.EVM_EXECUTE,
|
|
1270
|
+
data: transactionData,
|
|
1271
|
+
extrinsicType: eType,
|
|
1273
1272
|
chainType: _KoniTypes.ChainType.EVM
|
|
1274
1273
|
});
|
|
1275
1274
|
|
|
@@ -1368,6 +1367,9 @@ class KoniState {
|
|
|
1368
1367
|
createUnsubscriptionHandle(id, unsubscribe) {
|
|
1369
1368
|
this.unsubscriptionMap[id] = unsubscribe;
|
|
1370
1369
|
}
|
|
1370
|
+
updateChainConnectionStatus(chain, status) {
|
|
1371
|
+
this.chainService.setChainConnectionStatus(chain, status);
|
|
1372
|
+
}
|
|
1371
1373
|
async autoEnableChains(addresses) {
|
|
1372
1374
|
const assetMap = this.chainService.getAssetRegistry();
|
|
1373
1375
|
const promiseList = addresses.map(address => {
|
|
@@ -1394,7 +1396,7 @@ class KoniState {
|
|
|
1394
1396
|
} = _ref14;
|
|
1395
1397
|
const chain = _subscanChainMap.SUBSCAN_CHAIN_MAP_REVERSE[network];
|
|
1396
1398
|
const chainInfo = chain ? chainMap[chain] : null;
|
|
1397
|
-
const balanceIsEmpty = (!balance || balance === '0') && !locked
|
|
1399
|
+
const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
|
|
1398
1400
|
|
|
1399
1401
|
// Cancel if chain is not supported or is testnet or balance is 0
|
|
1400
1402
|
if (!chainInfo || chainInfo.isTestnet || balanceIsEmpty) {
|
|
@@ -1439,5 +1441,11 @@ class KoniState {
|
|
|
1439
1441
|
stores.staking.removeAllByAddress(address).catch(console.error);
|
|
1440
1442
|
});
|
|
1441
1443
|
}
|
|
1444
|
+
async reloadNft() {
|
|
1445
|
+
return await this.cron.reloadNft();
|
|
1446
|
+
}
|
|
1447
|
+
async reloadStaking() {
|
|
1448
|
+
return await this.cron.reloadStaking();
|
|
1449
|
+
}
|
|
1442
1450
|
}
|
|
1443
1451
|
exports.default = KoniState;
|
|
@@ -17,7 +17,6 @@ var _defaults = require("@subwallet/extension-base/defaults");
|
|
|
17
17
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
18
18
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
19
19
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
20
|
-
var _accounts = require("@subwallet/ui-keyring/observable/accounts");
|
|
21
20
|
var _web = _interopRequireDefault(require("web3"));
|
|
22
21
|
var _phishing = require("@polkadot/phishing");
|
|
23
22
|
var _util = require("@polkadot/util");
|
|
@@ -220,14 +219,14 @@ class KoniTabs {
|
|
|
220
219
|
anyType
|
|
221
220
|
} = _ref10;
|
|
222
221
|
const authInfo = await this.getAuthInfo(url);
|
|
223
|
-
return transformAccountsV2(
|
|
222
|
+
return transformAccountsV2(this.#koniState.keyringService.accounts, anyType, authInfo, accountAuthType);
|
|
224
223
|
}
|
|
225
224
|
accountsSubscribeV2(url, _ref11, id, port) {
|
|
226
225
|
let {
|
|
227
226
|
accountAuthType
|
|
228
227
|
} = _ref11;
|
|
229
228
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
230
|
-
const subscription =
|
|
229
|
+
const subscription = this.#koniState.keyringService.accountSubject.subscribe(accounts => {
|
|
231
230
|
this.getAuthInfo(url).then(authInfo => {
|
|
232
231
|
cb(transformAccountsV2(accounts, false, authInfo, accountAuthType));
|
|
233
232
|
}).catch(console.error);
|
|
@@ -253,7 +252,7 @@ class KoniTabs {
|
|
|
253
252
|
let getAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
254
253
|
return await new Promise(resolve => {
|
|
255
254
|
this.getAuthInfo(url).then(authInfo => {
|
|
256
|
-
const allAccounts =
|
|
255
|
+
const allAccounts = this.#koniState.keyringService.accounts;
|
|
257
256
|
const accountList = transformAccountsV2(allAccounts, false, authInfo, 'evm').map(a => a.address);
|
|
258
257
|
let accounts = [];
|
|
259
258
|
const address = this.#koniState.keyringService.currentAccount.address;
|
|
@@ -290,18 +289,25 @@ class KoniTabs {
|
|
|
290
289
|
slug
|
|
291
290
|
} = currentEvmNetwork;
|
|
292
291
|
const evmApi = this.#koniState.getEvmApi(slug);
|
|
293
|
-
const web3 = evmApi.api;
|
|
294
|
-
if (web3.currentProvider instanceof _web.default.providers.WebsocketProvider) {
|
|
292
|
+
const web3 = evmApi === null || evmApi === void 0 ? void 0 : evmApi.api;
|
|
293
|
+
if ((web3 === null || web3 === void 0 ? void 0 : web3.currentProvider) instanceof _web.default.providers.WebsocketProvider) {
|
|
295
294
|
if (!web3.currentProvider.connected) {
|
|
296
295
|
console.log(`[Web3] ${slug} is disconnected, trying to connect...`);
|
|
297
296
|
this.#koniState.refreshWeb3Api(slug);
|
|
297
|
+
let checkingNum = 0;
|
|
298
298
|
const poll = resolve => {
|
|
299
|
+
checkingNum += 1;
|
|
299
300
|
if (web3.currentProvider.connected) {
|
|
300
301
|
console.log(`Network [${slug}] is connected.`);
|
|
301
302
|
resolve(true);
|
|
302
303
|
} else {
|
|
303
304
|
console.log(`Connecting to network [${slug}]`);
|
|
304
|
-
|
|
305
|
+
if (checkingNum < 10) {
|
|
306
|
+
setTimeout(() => poll(resolve), 900);
|
|
307
|
+
} else {
|
|
308
|
+
console.log(`Max retry, stop checking [${slug}]`);
|
|
309
|
+
resolve(false);
|
|
310
|
+
}
|
|
305
311
|
}
|
|
306
312
|
};
|
|
307
313
|
await new Promise(poll);
|
|
@@ -371,12 +377,16 @@ class KoniTabs {
|
|
|
371
377
|
contractAddress: input.options.address,
|
|
372
378
|
originChain: chain
|
|
373
379
|
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
380
|
+
|
|
381
|
+
// Below code is comment because we will handle exited token in the ui-view
|
|
382
|
+
// if (validate.isExist) {
|
|
383
|
+
// throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, 'Current token is existed');
|
|
384
|
+
// } else
|
|
385
|
+
if (validate.contractError) {
|
|
377
386
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Contract address is invalid');
|
|
378
387
|
}
|
|
379
388
|
const tokenInfo = {
|
|
389
|
+
slug: validate === null || validate === void 0 ? void 0 : validate.existedSlug,
|
|
380
390
|
type: tokenType,
|
|
381
391
|
name: validate.name,
|
|
382
392
|
contractAddress: input.options.address,
|
|
@@ -400,16 +410,38 @@ class KoniTabs {
|
|
|
400
410
|
} = input[0];
|
|
401
411
|
if (chainId) {
|
|
402
412
|
const chainIdNum = parseInt(chainId, 16);
|
|
403
|
-
const [
|
|
404
|
-
if (
|
|
413
|
+
const [existedNetworkSlug, existedChainInfo] = this.#koniState.findNetworkKeyByChainId(chainIdNum);
|
|
414
|
+
if (existedNetworkSlug && existedChainInfo && existedChainInfo !== null && existedChainInfo !== void 0 && existedChainInfo.evmInfo) {
|
|
415
|
+
const evmInfo = existedChainInfo.evmInfo;
|
|
416
|
+
const substrateInfo = existedChainInfo.substrateInfo;
|
|
417
|
+
const chainState = this.#koniState.getChainStateByKey(existedNetworkSlug);
|
|
418
|
+
await this.#koniState.addNetworkConfirm(id, url, {
|
|
419
|
+
mode: 'update',
|
|
420
|
+
chainSpec: {
|
|
421
|
+
evmChainId: evmInfo.evmChainId,
|
|
422
|
+
decimals: evmInfo.decimals,
|
|
423
|
+
existentialDeposit: evmInfo.existentialDeposit,
|
|
424
|
+
genesisHash: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.genesisHash) || '',
|
|
425
|
+
paraId: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.paraId) || null,
|
|
426
|
+
addressPrefix: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.addressPrefix) || 0
|
|
427
|
+
},
|
|
428
|
+
chainEditInfo: {
|
|
429
|
+
blockExplorer: blockExplorerUrls === null || blockExplorerUrls === void 0 ? void 0 : blockExplorerUrls[0],
|
|
430
|
+
slug: existedNetworkSlug,
|
|
431
|
+
currentProvider: chainState.currentProvider,
|
|
432
|
+
providers: existedChainInfo.providers,
|
|
433
|
+
symbol: evmInfo.symbol,
|
|
434
|
+
chainType: 'EVM',
|
|
435
|
+
name: existedChainInfo.name
|
|
436
|
+
}
|
|
437
|
+
});
|
|
405
438
|
return await this.switchEvmChain(id, url, {
|
|
406
439
|
method: 'wallet_switchEthereumChain',
|
|
407
440
|
params: [{
|
|
408
441
|
chainId
|
|
409
442
|
}]
|
|
410
443
|
});
|
|
411
|
-
}
|
|
412
|
-
if (rpcUrls && chainName) {
|
|
444
|
+
} else if (rpcUrls && chainName) {
|
|
413
445
|
const filteredUrls = rpcUrls.filter(targetString => {
|
|
414
446
|
let url;
|
|
415
447
|
try {
|
|
@@ -450,6 +482,8 @@ class KoniTabs {
|
|
|
450
482
|
name: chainInfo.name
|
|
451
483
|
}
|
|
452
484
|
});
|
|
485
|
+
} else {
|
|
486
|
+
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Invalid provider');
|
|
453
487
|
}
|
|
454
488
|
}
|
|
455
489
|
}
|
|
@@ -710,9 +744,8 @@ class KoniTabs {
|
|
|
710
744
|
if (e.code) {
|
|
711
745
|
throw e;
|
|
712
746
|
} else {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, e.message);
|
|
747
|
+
console.error(e);
|
|
748
|
+
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, e === null || e === void 0 ? void 0 : e.toString());
|
|
716
749
|
}
|
|
717
750
|
}
|
|
718
751
|
}
|
|
@@ -14,6 +14,7 @@ var _paraChain = require("@subwallet/extension-base/koni/api/staking/paraChain")
|
|
|
14
14
|
var _handlers = require("@subwallet/extension-base/koni/background/handlers");
|
|
15
15
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
16
16
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
17
|
+
var _types = require("@subwallet/extension-base/services/event-service/types");
|
|
17
18
|
var _util = require("@polkadot/util");
|
|
18
19
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
19
20
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -64,30 +65,28 @@ class KoniSubscription {
|
|
|
64
65
|
this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
|
|
65
66
|
this.subscribeStakingOnChain(currentAddress, this.state.getSubstrateApiMap());
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
this.state.eventService.onLazy(this.eventHandler);
|
|
85
|
-
}
|
|
68
|
+
this.eventHandler = (events, eventTypes) => {
|
|
69
|
+
var _serviceInfo$currentA;
|
|
70
|
+
const serviceInfo = this.state.getServiceInfo();
|
|
71
|
+
const needReload = eventTypes.some(eventType => _types.COMMON_RELOAD_EVENTS.includes(eventType));
|
|
72
|
+
if (!needReload) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.logger.log('ServiceInfo updated, restarting...');
|
|
76
|
+
const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
|
|
77
|
+
if (!address) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.subscribeBalancesAndCrowdloans(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
|
|
81
|
+
this.subscribeStakingOnChain(address, serviceInfo.chainApiMap.substrate);
|
|
82
|
+
};
|
|
83
|
+
this.state.eventService.onLazy(this.eventHandler);
|
|
86
84
|
}
|
|
87
85
|
stop() {
|
|
88
86
|
this.logger.log('Stopping subscription');
|
|
89
87
|
if (this.eventHandler) {
|
|
90
88
|
this.state.eventService.offLazy(this.eventHandler);
|
|
89
|
+
this.eventHandler = undefined;
|
|
91
90
|
}
|
|
92
91
|
this.stopAllSubscription();
|
|
93
92
|
}
|
|
@@ -113,7 +112,7 @@ class KoniSubscription {
|
|
|
113
112
|
});
|
|
114
113
|
}
|
|
115
114
|
subscribeBalancesAndCrowdloans(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
|
|
116
|
-
this.state.
|
|
115
|
+
this.state.handleSwitchAccount(address).then(() => {
|
|
117
116
|
const addresses = this.state.getDecodedAddresses(address);
|
|
118
117
|
if (!addresses.length) {
|
|
119
118
|
return;
|
|
@@ -189,8 +188,8 @@ class KoniSubscription {
|
|
|
189
188
|
return _this.state.updateNftData(...arguments);
|
|
190
189
|
}, function () {
|
|
191
190
|
return _this.state.setNftCollection(...arguments);
|
|
192
|
-
}
|
|
193
|
-
|
|
191
|
+
}, function () {
|
|
192
|
+
return _this.state.cleanUpNfts(...arguments);
|
|
194
193
|
}).catch(this.logger.log);
|
|
195
194
|
}
|
|
196
195
|
async subscribeStakingReward(address) {
|
|
@@ -209,7 +208,6 @@ class KoniSubscription {
|
|
|
209
208
|
});
|
|
210
209
|
const result = await (0, _staking.getNominationStakingRewardData)(addresses, targetNetworkMap);
|
|
211
210
|
this.state.updateStakingReward(result, 'slowInterval');
|
|
212
|
-
this.logger.log('Set staking reward state done', result);
|
|
213
211
|
}
|
|
214
212
|
async subscribeStakingRewardFastInterval(address) {
|
|
215
213
|
const addresses = this.state.getDecodedAddresses(address);
|
|
@@ -239,15 +237,21 @@ class KoniSubscription {
|
|
|
239
237
|
const [poolingStakingRewards, amplitudeUnclaimedStakingRewards] = await Promise.all([(0, _staking.getPoolingStakingRewardData)(pooledAddresses, targetChainMap, this.state.getSubstrateApiMap()), (0, _paraChain.getAmplitudeUnclaimedStakingReward)(this.state.getSubstrateApiMap(), addresses, chainInfoMap, activeNetworks)]);
|
|
240
238
|
const result = [...poolingStakingRewards, ...amplitudeUnclaimedStakingRewards];
|
|
241
239
|
this.state.updateStakingReward(result, 'fastInterval');
|
|
242
|
-
this.logger.log('Set staking reward state with fast interval done', result);
|
|
243
240
|
}
|
|
244
241
|
async fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap) {
|
|
245
|
-
|
|
242
|
+
const filteredChainInfoMap = {};
|
|
243
|
+
Object.values(chainInfoMap).forEach(chainInfo => {
|
|
246
244
|
const chainState = chainStateMap[chainInfo.slug];
|
|
247
245
|
if (chainState !== null && chainState !== void 0 && chainState.active && (0, _utils._isChainSupportSubstrateStaking)(chainInfo)) {
|
|
248
|
-
|
|
249
|
-
this.state.updateChainStakingMetadata(chainStakingMetadata);
|
|
246
|
+
filteredChainInfoMap[chainInfo.slug] = chainInfo;
|
|
250
247
|
}
|
|
248
|
+
});
|
|
249
|
+
if (Object.values(filteredChainInfoMap).length === 0) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
await Promise.all(Object.values(filteredChainInfoMap).map(async chainInfo => {
|
|
253
|
+
const chainStakingMetadata = await (0, _bonding.getChainStakingMetadata)(chainInfo, substrateApiMap[chainInfo.slug]);
|
|
254
|
+
this.state.updateChainStakingMetadata(chainStakingMetadata);
|
|
251
255
|
}));
|
|
252
256
|
}
|
|
253
257
|
async fetchNominatorMetadata(currentAddress, chainInfoMap, chainStateMap, substrateApiMap) {
|
|
@@ -262,8 +266,7 @@ class KoniSubscription {
|
|
|
262
266
|
if (currentAddress === _constants.ALL_ACCOUNT_KEY) {
|
|
263
267
|
addresses = await this.state.getStakingOwnersByChains(Object.keys(filteredChainInfoMap));
|
|
264
268
|
}
|
|
265
|
-
|
|
266
|
-
await Promise.all(validAddresses.map(async address => {
|
|
269
|
+
await Promise.all(addresses.map(async address => {
|
|
267
270
|
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(address);
|
|
268
271
|
await Promise.all(Object.values(filteredChainInfoMap).map(async chainInfo => {
|
|
269
272
|
if (isEvmAddress && !(0, _utils._isChainEvmCompatible)(chainInfo)) {
|
package/cjs/packageInfo.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.SubstrateChainHandler = exports.DEFAULT_AUX = void 0;
|
|
|
7
7
|
var _api = require("@acala-network/api");
|
|
8
8
|
var _types = require("@oak-foundation/types");
|
|
9
9
|
var _types2 = require("@subwallet/chain-list/types");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/koni/api/tokens/wasm/utils");
|
|
10
11
|
var _lightClient = require("@subwallet/extension-base/services/chain-service/handler/light-client");
|
|
11
12
|
var _api2 = require("@polkadot/api");
|
|
12
13
|
var _apiContract = require("@polkadot/api-contract");
|
|
@@ -94,13 +95,13 @@ class SubstrateChainHandler {
|
|
|
94
95
|
if (tokenType === _types2._AssetType.PSP22) {
|
|
95
96
|
tokenContract = new _apiContract.ContractPromise(substrateApi.api, _helper._PSP22_ABI, contractAddress);
|
|
96
97
|
const [nameResp, symbolResp, decimalsResp] = await Promise.all([tokenContract.query['psp22Metadata::tokenName'](contractCaller || contractAddress, {
|
|
97
|
-
gasLimit:
|
|
98
|
+
gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
|
|
98
99
|
}),
|
|
99
100
|
// read-only operation so no gas limit
|
|
100
101
|
tokenContract.query['psp22Metadata::tokenSymbol'](contractCaller || contractAddress, {
|
|
101
|
-
gasLimit:
|
|
102
|
+
gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
|
|
102
103
|
}), tokenContract.query['psp22Metadata::tokenDecimals'](contractCaller || contractAddress, {
|
|
103
|
-
gasLimit:
|
|
104
|
+
gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
|
|
104
105
|
})]);
|
|
105
106
|
if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
|
|
106
107
|
this.logger.error('Error response while validating WASM contract');
|
|
@@ -111,18 +112,22 @@ class SubstrateChainHandler {
|
|
|
111
112
|
contractError: true
|
|
112
113
|
};
|
|
113
114
|
} else {
|
|
114
|
-
var _symbolResp$output, _decimalsResp$output,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
var _symbolResp$output, _decimalsResp$output, _nameResp$output;
|
|
116
|
+
const symbolObj = (_symbolResp$output = symbolResp.output) === null || _symbolResp$output === void 0 ? void 0 : _symbolResp$output.toHuman();
|
|
117
|
+
const decimalsObj = (_decimalsResp$output = decimalsResp.output) === null || _decimalsResp$output === void 0 ? void 0 : _decimalsResp$output.toHuman();
|
|
118
|
+
const nameObj = (_nameResp$output = nameResp.output) === null || _nameResp$output === void 0 ? void 0 : _nameResp$output.toHuman();
|
|
119
|
+
name = nameResp.output ? nameObj.Ok || nameObj.ok : '';
|
|
120
|
+
decimals = decimalsResp.output ? new _util.BN(decimalsObj.Ok || decimalsObj.ok).toNumber() : 0;
|
|
121
|
+
symbol = decimalsResp.output ? symbolObj.Ok || symbolObj.ok : '';
|
|
118
122
|
if (name === '' || symbol === '') {
|
|
119
123
|
contractError = true;
|
|
120
124
|
}
|
|
125
|
+
console.log('validate PSP22', name, symbol, decimals);
|
|
121
126
|
}
|
|
122
127
|
} else {
|
|
123
128
|
tokenContract = new _apiContract.ContractPromise(substrateApi.api, _helper._PSP34_ABI, contractAddress);
|
|
124
129
|
const collectionIdResp = await tokenContract.query['psp34::collectionId'](contractCaller || contractAddress, {
|
|
125
|
-
gasLimit:
|
|
130
|
+
gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
|
|
126
131
|
}); // read-only operation so no gas limit
|
|
127
132
|
|
|
128
133
|
if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
|