@subwallet/extension-base 1.0.1 → 1.0.2-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.
Files changed (169) hide show
  1. package/background/KoniTypes.d.ts +10 -3
  2. package/background/KoniTypes.js +6 -0
  3. package/cjs/background/KoniTypes.js +8 -1
  4. package/cjs/constants/index.js +6 -3
  5. package/cjs/koni/api/dotsama/balance.js +11 -0
  6. package/cjs/koni/api/staking/bonding/amplitude.js +6 -2
  7. package/cjs/koni/api/staking/bonding/astar.js +40 -243
  8. package/cjs/koni/api/staking/bonding/index.js +4 -4
  9. package/cjs/koni/api/staking/bonding/paraChain.js +16 -10
  10. package/cjs/koni/api/staking/bonding/relayChain.js +62 -7
  11. package/cjs/koni/api/staking/bonding/utils.js +29 -3
  12. package/cjs/koni/api/xcm/index.js +0 -111
  13. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  14. package/cjs/koni/api/xcm/xTokens.js +2 -4
  15. package/cjs/koni/background/cron.js +61 -62
  16. package/cjs/koni/background/handlers/Extension.js +143 -149
  17. package/cjs/koni/background/handlers/State.js +129 -91
  18. package/cjs/koni/background/handlers/Tabs.js +40 -38
  19. package/cjs/koni/background/subscription.js +48 -43
  20. package/cjs/packageInfo.js +1 -1
  21. package/cjs/page/index.js +5 -0
  22. package/cjs/services/chain-service/constants.js +1 -11
  23. package/cjs/services/chain-service/index.js +39 -5
  24. package/cjs/services/chain-service/utils.js +4 -0
  25. package/cjs/services/event-service/index.js +71 -0
  26. package/cjs/services/event-service/types.js +1 -0
  27. package/cjs/services/history-service/index.js +36 -17
  28. package/cjs/services/history-service/subsquid-multi-chain-history.js +7 -2
  29. package/cjs/services/keyring-service/index.js +101 -0
  30. package/cjs/services/migration-service/index.js +13 -10
  31. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  32. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  33. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  34. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  35. package/cjs/services/migration-service/scripts/index.js +13 -4
  36. package/cjs/services/price-service/coingecko.js +16 -3
  37. package/cjs/services/price-service/index.js +15 -17
  38. package/cjs/services/request-service/constants.js +8 -2
  39. package/cjs/services/request-service/handler/AuthRequestHandler.js +39 -12
  40. package/cjs/services/request-service/index.js +3 -0
  41. package/cjs/services/storage-service/DatabaseService.js +1 -1
  42. package/cjs/services/storage-service/databases/index.js +1 -1
  43. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  44. package/cjs/services/storage-service/db-stores/Nft.js +4 -1
  45. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  46. package/cjs/services/subscan-service/index.js +107 -0
  47. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  48. package/cjs/services/subscan-service/types.js +1 -0
  49. package/cjs/services/transaction-service/index.js +45 -10
  50. package/cjs/services/transaction-service/utils.js +4 -6
  51. package/cjs/utils/address.js +9 -1
  52. package/cjs/utils/index.js +24 -13
  53. package/constants/index.d.ts +1 -0
  54. package/constants/index.js +1 -0
  55. package/koni/api/dotsama/balance.js +11 -0
  56. package/koni/api/staking/bonding/amplitude.d.ts +1 -1
  57. package/koni/api/staking/bonding/amplitude.js +8 -4
  58. package/koni/api/staking/bonding/astar.d.ts +2 -11
  59. package/koni/api/staking/bonding/astar.js +35 -229
  60. package/koni/api/staking/bonding/index.d.ts +1 -1
  61. package/koni/api/staking/bonding/index.js +4 -4
  62. package/koni/api/staking/bonding/paraChain.d.ts +1 -1
  63. package/koni/api/staking/bonding/paraChain.js +17 -11
  64. package/koni/api/staking/bonding/relayChain.d.ts +1 -1
  65. package/koni/api/staking/bonding/relayChain.js +63 -8
  66. package/koni/api/staking/bonding/utils.d.ts +13 -1
  67. package/koni/api/staking/bonding/utils.js +27 -3
  68. package/koni/api/xcm/index.js +1 -112
  69. package/koni/api/xcm/polkadotXcm.js +1 -1
  70. package/koni/api/xcm/xTokens.js +3 -5
  71. package/koni/background/cron.js +60 -60
  72. package/koni/background/handlers/Extension.js +71 -76
  73. package/koni/background/handlers/State.d.ts +16 -14
  74. package/koni/background/handlers/State.js +126 -91
  75. package/koni/background/handlers/Tabs.js +22 -19
  76. package/koni/background/subscription.d.ts +1 -1
  77. package/koni/background/subscription.js +49 -44
  78. package/package.json +56 -16
  79. package/packageInfo.js +1 -1
  80. package/page/index.d.ts +2 -0
  81. package/page/index.js +4 -0
  82. package/services/chain-service/constants.d.ts +0 -1
  83. package/services/chain-service/constants.js +0 -9
  84. package/services/chain-service/index.d.ts +6 -4
  85. package/services/chain-service/index.js +39 -7
  86. package/services/chain-service/utils.d.ts +1 -0
  87. package/services/chain-service/utils.js +3 -0
  88. package/services/event-service/index.d.ts +22 -0
  89. package/services/event-service/index.js +59 -0
  90. package/services/event-service/types.d.ts +32 -0
  91. package/services/event-service/types.js +1 -0
  92. package/services/history-service/index.d.ts +5 -3
  93. package/services/history-service/index.js +36 -17
  94. package/services/history-service/subsquid-multi-chain-history.js +7 -2
  95. package/services/keyring-service/index.d.ts +19 -0
  96. package/services/keyring-service/index.js +93 -0
  97. package/services/migration-service/index.js +11 -9
  98. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  99. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  100. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  101. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  102. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  103. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  104. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  105. package/services/migration-service/scripts/index.d.ts +1 -0
  106. package/services/migration-service/scripts/index.js +10 -3
  107. package/services/price-service/coingecko.js +16 -3
  108. package/services/price-service/index.d.ts +5 -3
  109. package/services/price-service/index.js +15 -17
  110. package/services/request-service/constants.d.ts +1 -0
  111. package/services/request-service/constants.js +6 -1
  112. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  113. package/services/request-service/handler/AuthRequestHandler.js +40 -13
  114. package/services/request-service/index.d.ts +7 -1
  115. package/services/request-service/index.js +3 -0
  116. package/services/storage-service/DatabaseService.js +1 -1
  117. package/services/storage-service/databases/index.js +1 -1
  118. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  119. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  120. package/services/storage-service/db-stores/Nft.d.ts +2 -1
  121. package/services/storage-service/db-stores/Nft.js +4 -1
  122. package/services/storage-service/db-stores/Transaction.js +10 -7
  123. package/services/subscan-service/index.d.ts +20 -0
  124. package/services/subscan-service/index.js +99 -0
  125. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  126. package/services/subscan-service/subscan-chain-map.js +63 -0
  127. package/services/subscan-service/types.d.ts +27 -0
  128. package/services/subscan-service/types.js +1 -0
  129. package/services/transaction-service/event-parser/index.d.ts +2 -2
  130. package/services/transaction-service/index.d.ts +4 -2
  131. package/services/transaction-service/index.js +45 -10
  132. package/services/transaction-service/utils.js +5 -6
  133. package/utils/address.d.ts +1 -0
  134. package/utils/address.js +9 -2
  135. package/utils/index.d.ts +1 -0
  136. package/utils/index.js +21 -12
  137. package/cjs/background/errors/EvmRpcError.js +0 -21
  138. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  139. package/cjs/constants/ethereum.js +0 -19
  140. package/cjs/errors/SubWalletProviderError.js +0 -17
  141. package/cjs/koni/api/xcm/astar.js +0 -160
  142. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  143. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  144. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  145. package/cjs/koni/migration/Base.js +0 -20
  146. package/cjs/koni/migration/index.js +0 -45
  147. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  148. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  149. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  150. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  151. package/cjs/koni/migration/scripts/index.js +0 -22
  152. package/cjs/koni/page/index.js +0 -16
  153. package/cjs/services/asset-service/index.js +0 -91
  154. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  155. package/cjs/stores/Balance.js +0 -18
  156. package/cjs/stores/Crowdloan.js +0 -18
  157. package/cjs/stores/CustomEvmToken.js +0 -18
  158. package/cjs/stores/NetworkMap.js +0 -18
  159. package/cjs/stores/Nft.js +0 -18
  160. package/cjs/stores/NftCollection.js +0 -18
  161. package/cjs/stores/Price.js +0 -18
  162. package/cjs/stores/Staking.js +0 -18
  163. package/cjs/stores/StakingReward.js +0 -18
  164. package/cjs/utils/eth/parseTransactionData.js +0 -284
  165. package/koni/page/index.d.ts +0 -2
  166. package/koni/page/index.js +0 -9
  167. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  168. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  169. /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
@@ -36,13 +36,16 @@ class TransactionStore extends _BaseStoreWithAddressAndChain.default {
36
36
  }
37
37
  async bulkUpsert(records) {
38
38
  await this.table.bulkPut(records);
39
- await Promise.all(records.map(record => {
40
- return this.table.where({
41
- chain: record.chain,
42
- address: record.address,
43
- extrinsicHash: record.extrinsicHash
44
- }).filter(item => item.origin === 'app' && record.origin !== 'app').delete();
45
- }));
39
+
40
+ // await Promise.all(records.map((record) => {
41
+ // return this.table.where({
42
+ // chain: record.chain,
43
+ // address: record.address,
44
+ // extrinsicHash: record.extrinsicHash
45
+ // }).filter((item) => (item.origin === 'app' && record.origin !== 'app'))
46
+ // .delete();
47
+ // }));
48
+
46
49
  return true;
47
50
  }
48
51
  }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SubscanService = void 0;
8
+ var _SWError = require("@subwallet/extension-base/background/errors/SWError");
9
+ var _subscanChainMap = _interopRequireDefault(require("@subwallet/extension-base/services/subscan-service/subscan-chain-map"));
10
+ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
11
+ // Copyright 2019-2022 @subwallet/extension-base
12
+ // SPDX-License-Identifier: Apache-2.0
13
+
14
+ class SubscanService {
15
+ limitRate = 2; // limit per interval check
16
+ intervalCheck = 1000; // interval check in ms
17
+ maxRetry = 9; // interval check in ms
18
+ requestMap = {};
19
+ nextId = 0;
20
+ isRunning = false;
21
+ getId() {
22
+ return this.nextId++;
23
+ }
24
+ constructor(options) {
25
+ this.limitRate = (options === null || options === void 0 ? void 0 : options.limitRate) || this.limitRate;
26
+ this.intervalCheck = (options === null || options === void 0 ? void 0 : options.intervalCheck) || this.intervalCheck;
27
+ this.maxRetry = (options === null || options === void 0 ? void 0 : options.maxRetry) || this.maxRetry;
28
+ }
29
+ getApiUrl(chain, path) {
30
+ const subscanChain = _subscanChainMap.default[chain];
31
+ if (!subscanChain) {
32
+ throw new _SWError.SWError('NOT_SUPPORTED', 'Chain is not supported');
33
+ }
34
+ return `https://${chain}.api.subscan.io/${path}`;
35
+ }
36
+ postRequest(url, body) {
37
+ return (0, _crossFetch.default)(url, {
38
+ method: 'POST',
39
+ headers: {
40
+ 'Content-Type': 'application/json'
41
+ },
42
+ body: JSON.stringify(body)
43
+ });
44
+ }
45
+ addRequest(run) {
46
+ const newId = this.getId();
47
+ return new Promise((resolve, reject) => {
48
+ this.requestMap[newId] = {
49
+ id: newId,
50
+ status: 'pending',
51
+ retry: -1,
52
+ run,
53
+ resolve,
54
+ reject
55
+ };
56
+ if (!this.isRunning) {
57
+ this.process();
58
+ }
59
+ });
60
+ }
61
+ process() {
62
+ this.isRunning = true;
63
+ const maxRetry = this.maxRetry;
64
+ const interval = setInterval(() => {
65
+ const remainingRequests = Object.values(this.requestMap);
66
+ if (remainingRequests.length === 0) {
67
+ this.isRunning = false;
68
+ clearInterval(interval);
69
+ return;
70
+ }
71
+
72
+ // Get first this.limit requests base on id
73
+ const requests = remainingRequests.filter(request => request.status !== 'running').sort((a, b) => a.id - b.id).slice(0, this.limitRate);
74
+
75
+ // Start requests
76
+ requests.forEach(request => {
77
+ request.status = 'running';
78
+ request.run().then(rs => {
79
+ request.resolve(rs);
80
+ }).catch(e => {
81
+ if (request.retry < maxRetry) {
82
+ request.status = 'pending';
83
+ request.retry++;
84
+ } else {
85
+ // Reject request
86
+ request.reject(new _SWError.SWError('MAX_RETRY', String(e)));
87
+ }
88
+ });
89
+ });
90
+ }, this.intervalCheck);
91
+ }
92
+
93
+ // Implement Subscan API
94
+ getMultiChainBalance(address) {
95
+ return this.addRequest(async () => {
96
+ const rs = await this.postRequest(this.getApiUrl('polkadot', 'api/scan/multiChain/account'), {
97
+ address
98
+ });
99
+ if (rs.status !== 200) {
100
+ throw new _SWError.SWError('SubscanService.getMultiChainBalance', await rs.text());
101
+ }
102
+ const jsonData = await rs.json();
103
+ return jsonData.data;
104
+ });
105
+ }
106
+ }
107
+ exports.SubscanService = SubscanService;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.SUBSCAN_CHAIN_MAP_REVERSE = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ const SUBSCAN_CHAIN_MAP = {
11
+ polkadot: 'polkadot',
12
+ kusama: 'kusama',
13
+ moonbeam: 'moonbeam',
14
+ acala: 'acala',
15
+ astar: 'astar',
16
+ shiden: 'shiden',
17
+ shibuya: 'shibuya',
18
+ westend: 'westend',
19
+ moonbase: 'moonbase',
20
+ moonriver: 'moonriver',
21
+ turing: 'turing',
22
+ bifrost_testnet: 'bifrost-testnet',
23
+ calamari: 'calamari',
24
+ statemint: 'statemint',
25
+ pioneer: 'pioneer',
26
+ parallel: 'parallel',
27
+ clover: 'clover',
28
+ hydradx_main: 'hydradx',
29
+ edgeware: 'edgeware',
30
+ centrifuge: 'centrifuge',
31
+ interlay: 'interlay',
32
+ nodle: 'nodle',
33
+ darwinia: 'darwinia',
34
+ polkadex: 'polkadex',
35
+ aleph: 'alephzero',
36
+ dolphin: 'dolphin',
37
+ efinity: 'efinity',
38
+ composableFinance: 'composable',
39
+ phala: 'phala',
40
+ crust: 'crust',
41
+ statemine: 'statemine',
42
+ karura: 'karura',
43
+ khala: 'khala',
44
+ kilt: 'spiritnet',
45
+ basilisk: 'basilisk',
46
+ altair: 'altair',
47
+ heiko: 'parallel-heiko',
48
+ kintsugi: 'kintsugi',
49
+ picasso: 'picasso',
50
+ quartz: 'quartz',
51
+ unique_network: 'unique',
52
+ genshiro: 'genshiro',
53
+ zeitgeist: 'zeitgeist',
54
+ sakura: 'sakura',
55
+ shadow: 'shadow',
56
+ robonomics: 'robonomics',
57
+ integritee: 'integritee',
58
+ acala_testnet: 'acala-testnet',
59
+ mangatax: 'mangatax',
60
+ encointer: 'encointer',
61
+ subspace_gemini_2a: 'subspace',
62
+ origintrail: 'origintrail',
63
+ bajun: 'bajun',
64
+ snow: 'snow',
65
+ kilt_peregrine: 'kilt-testnet',
66
+ polymesh: 'polymesh'
67
+ };
68
+ const SUBSCAN_CHAIN_MAP_REVERSE = Object.fromEntries(Object.entries(SUBSCAN_CHAIN_MAP).map(_ref => {
69
+ let [k, v] = _ref;
70
+ return [v, k];
71
+ }));
72
+ exports.SUBSCAN_CHAIN_MAP_REVERSE = SUBSCAN_CHAIN_MAP_REVERSE;
73
+ var _default = SUBSCAN_CHAIN_MAP;
74
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -31,8 +31,9 @@ class TransactionService {
31
31
  get transactions() {
32
32
  return this.transactionSubject.getValue();
33
33
  }
34
- constructor(chainService, requestService, balanceService, historyService, notificationService, databaseService) {
34
+ constructor(chainService, eventService, requestService, balanceService, historyService, notificationService, databaseService) {
35
35
  this.chainService = chainService;
36
+ this.eventService = eventService;
36
37
  this.requestService = requestService;
37
38
  this.balanceService = balanceService;
38
39
  this.historyService = historyService;
@@ -272,9 +273,10 @@ class TransactionService {
272
273
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
273
274
  return (0, _utils2.getTransactionLink)(chainInfo, transaction.extrinsicHash);
274
275
  }
275
- transactionToHistory(id, eventLogs) {
276
+ transactionToHistories(id, eventLogs) {
276
277
  const transaction = this.getTransaction(id);
277
278
  const historyItem = {
279
+ origin: 'app',
278
280
  chain: transaction.chain,
279
281
  direction: _KoniTypes.TransactionDirection.SEND,
280
282
  type: transaction.extrinsicType,
@@ -287,8 +289,8 @@ class TransactionService {
287
289
  time: transaction.createdAt.getTime(),
288
290
  fee: transaction.estimateFee,
289
291
  blockNumber: 0,
290
- // TODO: to be added later
291
- blockHash: '' // TODO: to be added later
292
+ // Will be added in next step
293
+ blockHash: '' // Will be added in next step
292
294
  };
293
295
 
294
296
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
@@ -337,6 +339,12 @@ class TransactionService {
337
339
  decimals: sendingTokenInfo.decimals || 0,
338
340
  symbol: sendingTokenInfo.symbol
339
341
  };
342
+
343
+ // @ts-ignore
344
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
345
+ historyItem.additionalInfo = {
346
+ destinationChain: (inputData === null || inputData === void 0 ? void 0 : inputData.destinationNetworkKey) || ''
347
+ };
340
348
  eventLogs && (0, _eventParser.parseXcmEventLogs)(historyItem, eventLogs, transaction.chain, sendingTokenInfo, chainInfo);
341
349
  }
342
350
  break;
@@ -403,15 +411,41 @@ class TransactionService {
403
411
  {
404
412
  const data = (0, _utils2.parseTransactionData)(transaction.data);
405
413
  historyItem.to = data.validatorAddress || '';
414
+ historyItem.amount = {
415
+ ...baseNativeAmount,
416
+ value: data.unstakingInfo.claimable || '0'
417
+ };
418
+ break;
419
+ }
420
+ case _KoniTypes.ExtrinsicType.STAKING_CANCEL_UNSTAKE:
421
+ {
422
+ const data = (0, _utils2.parseTransactionData)(transaction.data);
423
+ historyItem.amount = {
424
+ ...baseNativeAmount,
425
+ value: data.selectedUnstaking.claimable || '0'
426
+ };
427
+ break;
406
428
  }
407
- break;
408
429
  case _KoniTypes.ExtrinsicType.EVM_EXECUTE:
409
430
  // Todo: Update historyItem.to
410
431
  break;
411
432
  case _KoniTypes.ExtrinsicType.UNKNOWN:
412
433
  break;
413
434
  }
414
- return historyItem;
435
+ try {
436
+ // Return one more history record if transaction send to account in the wallets
437
+ const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && _uiKeyring.default.getAccount(historyItem.to);
438
+ if (toAccount) {
439
+ return [historyItem, {
440
+ ...historyItem,
441
+ address: historyItem.to,
442
+ direction: _KoniTypes.TransactionDirection.RECEIVED
443
+ }];
444
+ }
445
+ } catch (e) {
446
+ console.warn(e);
447
+ }
448
+ return [historyItem];
415
449
  }
416
450
  onHasTransactionHash(_ref) {
417
451
  let {
@@ -424,7 +458,7 @@ class TransactionService {
424
458
  extrinsicHash,
425
459
  status: _KoniTypes.ExtrinsicStatus.PROCESSING
426
460
  });
427
- this.historyService.insertHistory(this.transactionToHistory(id, eventLogs)).catch(console.error);
461
+ this.historyService.insertHistories(this.transactionToHistories(id, eventLogs)).catch(console.error);
428
462
  console.log(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
429
463
  }
430
464
  handlePostProcessing(id) {
@@ -457,7 +491,7 @@ class TransactionService {
457
491
  console.log('Transaction completed', id, transaction.extrinsicHash);
458
492
 
459
493
  // Write success transaction history
460
- this.historyService.updateHistory(transaction.chain, transaction.extrinsicHash, {
494
+ this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
461
495
  status: _KoniTypes.ExtrinsicStatus.SUCCESS,
462
496
  blockNumber: blockNumber || 0,
463
497
  blockHash: blockHash || ''
@@ -471,6 +505,7 @@ class TransactionService {
471
505
  },
472
506
  notifyViaBrowser: true
473
507
  });
508
+ this.eventService.emit('transaction.done', transaction);
474
509
  }
475
510
  onFailed(_ref3) {
476
511
  let {
@@ -488,7 +523,7 @@ class TransactionService {
488
523
  console.log('Transaction failed', id, transaction.extrinsicHash);
489
524
 
490
525
  // Write failed transaction history
491
- this.historyService.updateHistory(transaction.chain, transaction.extrinsicHash, {
526
+ this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
492
527
  status: _KoniTypes.ExtrinsicStatus.FAIL,
493
528
  blockNumber: blockNumber || 0,
494
529
  blockHash: blockHash || ''
@@ -503,7 +538,7 @@ class TransactionService {
503
538
  notifyViaBrowser: true
504
539
  });
505
540
  }
506
-
541
+ this.eventService.emit('transaction.failed', transaction);
507
542
  // Log transaction errors
508
543
  console.error(errors);
509
544
  }
@@ -5,25 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getTransactionLink = getTransactionLink;
7
7
  exports.parseTransactionData = parseTransactionData;
8
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
8
9
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
9
10
  // SPDX-License-Identifier: Apache-2.0
10
11
 
11
12
  // @ts-ignore
12
13
  function parseTransactionData(data) {
13
- // @ts-ignore
14
14
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
15
15
  return data;
16
16
  }
17
17
  function getTransactionLink(chainInfo, extrinsicHash) {
18
- if (chainInfo.evmInfo) {
19
- var _chainInfo$evmInfo;
20
- const explorerLink = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.blockExplorer;
18
+ const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
19
+ if ((0, _utils._isPureEvmChain)(chainInfo)) {
21
20
  if (explorerLink) {
22
21
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
23
22
  }
24
23
  } else {
25
- var _chainInfo$substrateI;
26
- const explorerLink = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI = chainInfo.substrateInfo) === null || _chainInfo$substrateI === void 0 ? void 0 : _chainInfo$substrateI.blockExplorer;
24
+ const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
27
25
  if (explorerLink) {
28
26
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
29
27
  }
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
6
7
  exports.simpleAddress = void 0;
8
+ var _index = require("@subwallet/extension-base/utils/index");
7
9
  var _utilCrypto = require("@polkadot/util-crypto");
8
10
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
9
11
  // SPDX-License-Identifier: Apache-2.0
@@ -14,4 +16,10 @@ const simpleAddress = address => {
14
16
  }
15
17
  return (0, _utilCrypto.encodeAddress)((0, _utilCrypto.decodeAddress)(address));
16
18
  };
17
- exports.simpleAddress = simpleAddress;
19
+ exports.simpleAddress = simpleAddress;
20
+ function quickFormatAddressToCompare(address) {
21
+ if (!(0, _utilCrypto.isAddress)(address)) {
22
+ return address;
23
+ }
24
+ return (0, _index.reformatAddress)(address, 42).toLowerCase();
25
+ }
@@ -15,7 +15,9 @@ exports.categoryNetworks = categoryNetworks;
15
15
  exports.convertFundStatus = void 0;
16
16
  exports.convertToEvmAddress = convertToEvmAddress;
17
17
  exports.filterAddressByNetworkKey = filterAddressByNetworkKey;
18
- exports.getNftProvider = exports.getCurrentProvider = exports.filterAndSortingAccountByAuthType = void 0;
18
+ exports.getCurrentProvider = exports.filterAndSortingAccountByAuthType = void 0;
19
+ exports.getDomainFromUrl = getDomainFromUrl;
20
+ exports.getNftProvider = void 0;
19
21
  exports.hexToStr = hexToStr;
20
22
  exports.hexToUTF16 = hexToUTF16;
21
23
  exports.inJestTest = inJestTest;
@@ -54,20 +56,25 @@ function isAccountAll(address) {
54
56
  }
55
57
  function reformatAddress(address, networkPrefix) {
56
58
  let isEthereum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
57
- if ((0, _utilCrypto.isEthereumAddress)(address)) {
58
- return address;
59
- }
60
- if (isAccountAll(address)) {
61
- return address;
62
- }
63
- const publicKey = (0, _utilCrypto.decodeAddress)(address);
64
- if (isEthereum) {
65
- return (0, _utilCrypto.ethereumEncode)(publicKey);
66
- }
67
- if (networkPrefix < 0) {
59
+ try {
60
+ if ((0, _utilCrypto.isEthereumAddress)(address)) {
61
+ return address;
62
+ }
63
+ if (isAccountAll(address)) {
64
+ return address;
65
+ }
66
+ const publicKey = (0, _utilCrypto.decodeAddress)(address);
67
+ if (isEthereum) {
68
+ return (0, _utilCrypto.ethereumEncode)(publicKey);
69
+ }
70
+ if (networkPrefix < 0) {
71
+ return address;
72
+ }
73
+ return (0, _utilCrypto.encodeAddress)(publicKey, networkPrefix);
74
+ } catch (e) {
75
+ console.warn('Get error while reformat address', address, e);
68
76
  return address;
69
77
  }
70
- return (0, _utilCrypto.encodeAddress)(publicKey, networkPrefix);
71
78
  }
72
79
  function filterAddressByNetworkKey(addresses, networkKey, isEthereum) {
73
80
  if (isEthereum) {
@@ -321,4 +328,8 @@ function parseNumberToDisplay(amount, decimals) {
321
328
  }
322
329
  function isSameAddress(address1, address2) {
323
330
  return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
331
+ }
332
+
333
+ function getDomainFromUrl(url) {
334
+ return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
324
335
  }
@@ -22,4 +22,5 @@ export declare const ALL_NETWORK_KEY = "all";
22
22
  export declare const ALL_GENESIS_HASH: null;
23
23
  export declare const IGNORE_GET_SUBSTRATE_FEATURES_LIST: string[];
24
24
  export declare const IGNORE_QR_SIGNER: string[];
25
+ export declare const DEFAULT_TIME_AUTO_LOCK: number;
25
26
  export * from './staking';
@@ -25,4 +25,5 @@ export const ALL_NETWORK_KEY = 'all';
25
25
  export const ALL_GENESIS_HASH = null;
26
26
  export const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
27
27
  export const IGNORE_QR_SIGNER = [];
28
+ export const DEFAULT_TIME_AUTO_LOCK = 15 * 60 * 1000;
28
29
  export * from "./staking.js";
@@ -25,6 +25,17 @@ export function subscribeBalance(addresses, chainInfoMap, substrateApiMap, evmAp
25
25
  return subscribeEVMBalance(chainSlug, useAddresses, evmApiMap, callback, nativeTokenInfo);
26
26
  }
27
27
  if (!useAddresses || useAddresses.length === 0 || _PURE_EVM_CHAINS.indexOf(chainSlug) > -1) {
28
+ const fungibleTokensByChain = state.chainService.getFungibleTokensByChain(chainSlug, true);
29
+ const now = new Date().getTime();
30
+ Object.values(fungibleTokensByChain).map(token => {
31
+ return {
32
+ tokenSlug: token.slug,
33
+ free: '0',
34
+ locked: '0',
35
+ state: APIItemState.READY,
36
+ timestamp: now
37
+ };
38
+ }).forEach(callback);
28
39
  return undefined;
29
40
  }
30
41
  const networkAPI = await substrateApiMap[chainSlug].isReady;
@@ -4,7 +4,7 @@ import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/
4
4
  export declare function getAmplitudeStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
5
5
  export declare function getAmplitudeNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
6
6
  export declare function getAmplitudeCollatorsInfo(chain: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
7
- export declare function getAmplitudeBondingExtrinsic(nominatorMetadata: NominatorMetadata, substrateApi: _SubstrateApi, amount: string, selectedValidatorInfo: ValidatorInfo): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
7
+ export declare function getAmplitudeBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, selectedValidatorInfo: ValidatorInfo, nominatorMetadata?: NominatorMetadata): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
8
8
  export declare function getAmplitudeUnbondingExtrinsic(substrateApi: _SubstrateApi, amount: string, nominatorMetadata: NominatorMetadata, collatorAddress: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
9
9
  export declare function getAmplitudeWithdrawalExtrinsic(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
10
10
  export declare function getAmplitudeClaimRewardExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
@@ -1,10 +1,10 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
4
+ import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { getBondedValidators, isUnstakeAll, parseIdentity } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
6
6
  import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
7
- import { parseRawNumber } from '@subwallet/extension-base/utils';
7
+ import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
8
8
  import { BN } from '@polkadot/util';
9
9
  import { isEthereumAddress } from '@polkadot/util-crypto';
10
10
  export async function getAmplitudeStakingMetadata(chain, substrateApi) {
@@ -51,6 +51,7 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
51
51
  const identity = parseIdentity(identityInfo);
52
52
  activeStake = delegatorState.amount.toString();
53
53
  nominationList.push({
54
+ status: StakingStatus.NOT_EARNING,
54
55
  chain,
55
56
  validatorAddress: delegatorState.owner,
56
57
  activeStake: delegatorState.amount.toString(),
@@ -121,13 +122,16 @@ export async function getAmplitudeCollatorsInfo(chain, substrateApi) {
121
122
  }
122
123
  return allCollators;
123
124
  }
124
- export async function getAmplitudeBondingExtrinsic(nominatorMetadata, substrateApi, amount, selectedValidatorInfo) {
125
+ export async function getAmplitudeBondingExtrinsic(substrateApi, amount, selectedValidatorInfo, nominatorMetadata) {
125
126
  const chainApi = await substrateApi.isReady;
126
127
  const binaryAmount = new BN(amount);
128
+ if (!nominatorMetadata) {
129
+ return chainApi.api.tx.parachainStaking.joinDelegators(selectedValidatorInfo.address, binaryAmount);
130
+ }
127
131
  const {
128
132
  bondedValidators
129
133
  } = getBondedValidators(nominatorMetadata.nominations);
130
- if (!bondedValidators.includes(selectedValidatorInfo.address)) {
134
+ if (!bondedValidators.includes(reformatAddress(selectedValidatorInfo.address, 0))) {
131
135
  return chainApi.api.tx.parachainStaking.joinDelegators(selectedValidatorInfo.address, binaryAmount);
132
136
  } else {
133
137
  const _params = chainApi.api.tx.parachainStaking.delegatorStakeMore.toJSON();
@@ -1,19 +1,10 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
- import { BasicTxInfo, ChainStakingMetadata, NominatorMetadata, StakingType, UnlockingStakeInfo, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
3
- import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
2
+ import { ChainStakingMetadata, NominatorMetadata, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
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>;
6
6
  export declare function getAstarDappsInfo(networkKey: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
7
- export declare function getAstarBondingTxInfo(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, stakerAddress: string, amount: number, dappInfo: ValidatorInfo): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
8
- export declare function handleAstarBondingTxInfo(chainInfo: _ChainInfo, amount: number, networkKey: string, stakerAddress: string, dappInfo: ValidatorInfo, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>): Promise<BasicTxInfo>;
9
7
  export declare function getAstarBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappInfo: ValidatorInfo): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
10
- export declare function getAstarUnbondingTxInfo(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, stakerAddress: string, amount: number, dappAddress: string): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
11
- export declare function handleAstarUnbondingTxInfo(chainInfo: _ChainInfo, amount: number, networkKey: string, stakerAddress: string, dappAddress: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>): Promise<BasicTxInfo>;
12
8
  export declare function getAstarUnbondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappAddress: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
13
- export declare function handleAstarUnlockingInfo(substrateApi: _SubstrateApi, chainInfo: _ChainInfo, networkKey: string, address: string, type: StakingType): Promise<UnlockingStakeInfo>;
14
- export declare function getAstarWithdrawalTxInfo(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
15
- export declare function handleAstarWithdrawalTxInfo(networkKey: string, chainInfo: _ChainInfo, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, address: string): Promise<BasicTxInfo>;
16
9
  export declare function getAstarWithdrawalExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
17
- export declare function getAstarClaimRewardTxInfo(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
18
- export declare function handleAstarClaimRewardTxInfo(address: string, networkKey: string, chainInfo: _ChainInfo, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>): Promise<BasicTxInfo>;
19
10
  export declare function getAstarClaimRewardExtrinsic(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;