@subwallet/extension-base 1.0.4-1 → 1.0.5-2

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 (140) hide show
  1. package/background/KoniTypes.d.ts +14 -1
  2. package/background/KoniTypes.js +1 -0
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/handlers/State.d.ts +1 -1
  5. package/background/handlers/State.js +2 -8
  6. package/background/handlers/subscriptions.js +0 -1
  7. package/background/types.d.ts +2 -2
  8. package/cjs/background/KoniTypes.js +1 -0
  9. package/cjs/background/errors/TransactionError.js +4 -0
  10. package/cjs/background/handlers/State.js +1 -7
  11. package/cjs/background/handlers/subscriptions.js +0 -1
  12. package/cjs/constants/index.js +6 -6
  13. package/cjs/koni/api/coingecko.js +1 -4
  14. package/cjs/koni/api/dotsama/balance.js +7 -5
  15. package/cjs/koni/api/dotsama/crowdloan.js +0 -4
  16. package/cjs/koni/api/dotsama/transfer.js +0 -4
  17. package/cjs/koni/api/nft/acala_nft/index.js +1 -1
  18. package/cjs/koni/api/nft/bit.country/index.js +1 -1
  19. package/cjs/koni/api/nft/evm_nft/index.js +2 -3
  20. package/cjs/koni/api/nft/index.js +1 -2
  21. package/cjs/koni/api/nft/karura_nft/index.js +1 -1
  22. package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
  23. package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
  24. package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
  25. package/cjs/koni/api/nft/transfer.js +5 -5
  26. package/cjs/koni/api/nft/unique_nft/index.js +1 -1
  27. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  28. package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
  29. package/cjs/koni/api/staking/bonding/astar.js +28 -12
  30. package/cjs/koni/api/staking/bonding/utils.js +4 -0
  31. package/cjs/koni/api/staking/relayChain.js +0 -1
  32. package/cjs/koni/api/staking/subsquidStaking.js +0 -2
  33. package/cjs/koni/api/tokens/wasm/index.js +0 -1
  34. package/cjs/koni/api/tokens/wasm/utils.js +0 -1
  35. package/cjs/koni/api/xcm/index.js +0 -1
  36. package/cjs/koni/background/cron.js +0 -45
  37. package/cjs/koni/background/handlers/Extension.js +164 -134
  38. package/cjs/koni/background/handlers/State.js +18 -3
  39. package/cjs/koni/background/handlers/Tabs.js +34 -2
  40. package/cjs/koni/background/handlers/index.js +3 -2
  41. package/cjs/koni/background/subscription.js +0 -26
  42. package/cjs/packageInfo.js +1 -1
  43. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  44. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  45. package/cjs/services/chain-service/handler/light-client/index.js +9 -6
  46. package/cjs/services/chain-service/index.js +0 -2
  47. package/cjs/services/chain-service/utils.js +3 -0
  48. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +227 -0
  49. package/cjs/services/history-service/index.js +68 -6
  50. package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
  51. package/cjs/services/history-service/testChainMap.js +724 -0
  52. package/cjs/services/keyring-service/index.js +0 -2
  53. package/cjs/services/migration-service/index.js +0 -3
  54. package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
  55. package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
  56. package/cjs/services/migration-service/scripts/index.js +5 -1
  57. package/cjs/services/notification-service/NotificationService.js +1 -1
  58. package/cjs/services/price-service/coingecko.js +1 -1
  59. package/cjs/services/price-service/index.js +0 -3
  60. package/cjs/services/request-service/handler/AuthRequestHandler.js +1 -1
  61. package/cjs/services/setting-service/constants.js +8 -2
  62. package/cjs/services/storage-service/DatabaseService.js +3 -45
  63. package/cjs/services/transaction-service/constants.js +11 -0
  64. package/cjs/services/transaction-service/index.js +60 -20
  65. package/cjs/services/transaction-service/utils.js +25 -14
  66. package/cjs/utils/index.js +3 -0
  67. package/constants/index.d.ts +1 -1
  68. package/constants/index.js +1 -1
  69. package/koni/api/coingecko.js +1 -4
  70. package/koni/api/dotsama/balance.js +7 -5
  71. package/koni/api/dotsama/crowdloan.js +0 -4
  72. package/koni/api/dotsama/transfer.js +0 -4
  73. package/koni/api/nft/acala_nft/index.js +1 -1
  74. package/koni/api/nft/bit.country/index.js +1 -1
  75. package/koni/api/nft/evm_nft/index.js +2 -3
  76. package/koni/api/nft/index.js +1 -2
  77. package/koni/api/nft/karura_nft/index.js +1 -1
  78. package/koni/api/nft/quartz_nft/index.js +1 -1
  79. package/koni/api/nft/rmrk_nft/index.js +2 -3
  80. package/koni/api/nft/statemine_nft/index.js +1 -1
  81. package/koni/api/nft/transfer.js +5 -5
  82. package/koni/api/nft/unique_nft/index.js +1 -1
  83. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  84. package/koni/api/nft/wasm_nft/index.js +1 -2
  85. package/koni/api/staking/bonding/astar.d.ts +2 -1
  86. package/koni/api/staking/bonding/astar.js +27 -12
  87. package/koni/api/staking/bonding/utils.js +4 -0
  88. package/koni/api/staking/relayChain.js +0 -1
  89. package/koni/api/staking/subsquidStaking.js +0 -2
  90. package/koni/api/tokens/wasm/index.js +0 -1
  91. package/koni/api/tokens/wasm/utils.js +0 -1
  92. package/koni/api/xcm/index.js +0 -1
  93. package/koni/background/cron.js +0 -45
  94. package/koni/background/handlers/Extension.d.ts +2 -0
  95. package/koni/background/handlers/Extension.js +79 -51
  96. package/koni/background/handlers/State.d.ts +3 -1
  97. package/koni/background/handlers/State.js +18 -3
  98. package/koni/background/handlers/Tabs.d.ts +1 -0
  99. package/koni/background/handlers/Tabs.js +32 -1
  100. package/koni/background/handlers/index.js +3 -2
  101. package/koni/background/subscription.d.ts +0 -1
  102. package/koni/background/subscription.js +0 -26
  103. package/package.json +55 -34
  104. package/packageInfo.js +1 -1
  105. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  106. package/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  107. package/services/chain-service/handler/light-client/index.js +8 -6
  108. package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
  109. package/services/chain-service/index.js +0 -2
  110. package/services/chain-service/utils.js +3 -0
  111. package/services/history-service/helpers/recoverHistoryStatus.d.ts +17 -0
  112. package/services/history-service/helpers/recoverHistoryStatus.js +214 -0
  113. package/services/history-service/index.d.ts +6 -0
  114. package/services/history-service/index.js +69 -7
  115. package/services/history-service/subsquid-multi-chain-history.js +3 -2
  116. package/services/history-service/testChainMap.d.ts +3 -0
  117. package/services/history-service/testChainMap.js +716 -0
  118. package/services/keyring-service/index.js +0 -2
  119. package/services/migration-service/index.js +0 -3
  120. package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
  121. package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
  122. package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
  123. package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
  124. package/services/migration-service/scripts/index.js +5 -1
  125. package/services/notification-service/NotificationService.js +1 -1
  126. package/services/price-service/coingecko.js +1 -1
  127. package/services/price-service/index.js +0 -3
  128. package/services/request-service/handler/AuthRequestHandler.js +1 -1
  129. package/services/setting-service/constants.d.ts +4 -2
  130. package/services/setting-service/constants.js +5 -1
  131. package/services/storage-service/DatabaseService.d.ts +1 -1
  132. package/services/storage-service/DatabaseService.js +3 -45
  133. package/services/transaction-service/constants.d.ts +1 -0
  134. package/services/transaction-service/constants.js +4 -0
  135. package/services/transaction-service/index.d.ts +1 -0
  136. package/services/transaction-service/index.js +61 -21
  137. package/services/transaction-service/types.d.ts +2 -0
  138. package/services/transaction-service/utils.d.ts +1 -1
  139. package/services/transaction-service/utils.js +24 -13
  140. package/utils/index.js +3 -0
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.0.4-1",
20
+ "version": "1.0.5-2",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -1190,11 +1190,21 @@
1190
1190
  "require": "./cjs/services/history-service/index.js",
1191
1191
  "default": "./services/history-service/index.js"
1192
1192
  },
1193
+ "./services/history-service/helpers/recoverHistoryStatus": {
1194
+ "types": "./services/history-service/helpers/recoverHistoryStatus.d.ts",
1195
+ "require": "./cjs/services/history-service/helpers/recoverHistoryStatus.js",
1196
+ "default": "./services/history-service/helpers/recoverHistoryStatus.js"
1197
+ },
1193
1198
  "./services/history-service/subsquid-multi-chain-history": {
1194
1199
  "types": "./services/history-service/subsquid-multi-chain-history.d.ts",
1195
1200
  "require": "./cjs/services/history-service/subsquid-multi-chain-history.js",
1196
1201
  "default": "./services/history-service/subsquid-multi-chain-history.js"
1197
1202
  },
1203
+ "./services/history-service/testChainMap": {
1204
+ "types": "./services/history-service/testChainMap.d.ts",
1205
+ "require": "./cjs/services/history-service/testChainMap.js",
1206
+ "default": "./services/history-service/testChainMap.js"
1207
+ },
1198
1208
  "./services/keyring-service": {
1199
1209
  "types": "./services/keyring-service/index.d.ts",
1200
1210
  "require": "./cjs/services/keyring-service/index.js",
@@ -1230,6 +1240,16 @@
1230
1240
  "require": "./cjs/services/migration-service/scripts/MigrateAuthUrls.js",
1231
1241
  "default": "./services/migration-service/scripts/MigrateAuthUrls.js"
1232
1242
  },
1243
+ "./services/migration-service/scripts/MigrateAutoLock": {
1244
+ "types": "./services/migration-service/scripts/MigrateAutoLock.d.ts",
1245
+ "require": "./cjs/services/migration-service/scripts/MigrateAutoLock.js",
1246
+ "default": "./services/migration-service/scripts/MigrateAutoLock.js"
1247
+ },
1248
+ "./services/migration-service/scripts/MigrateChainPatrol": {
1249
+ "types": "./services/migration-service/scripts/MigrateChainPatrol.d.ts",
1250
+ "require": "./cjs/services/migration-service/scripts/MigrateChainPatrol.js",
1251
+ "default": "./services/migration-service/scripts/MigrateChainPatrol.js"
1252
+ },
1233
1253
  "./services/migration-service/scripts/MigrateImportedToken": {
1234
1254
  "types": "./services/migration-service/scripts/MigrateImportedToken.d.ts",
1235
1255
  "require": "./cjs/services/migration-service/scripts/MigrateImportedToken.js",
@@ -1435,6 +1455,11 @@
1435
1455
  "require": "./cjs/services/transaction-service/index.js",
1436
1456
  "default": "./services/transaction-service/index.js"
1437
1457
  },
1458
+ "./services/transaction-service/constants": {
1459
+ "types": "./services/transaction-service/constants.d.ts",
1460
+ "require": "./cjs/services/transaction-service/constants.js",
1461
+ "default": "./services/transaction-service/constants.js"
1462
+ },
1438
1463
  "./services/transaction-service/event-parser": {
1439
1464
  "types": "./services/transaction-service/event-parser/index.d.ts",
1440
1465
  "require": "./cjs/services/transaction-service/event-parser/index.js",
@@ -1617,8 +1642,8 @@
1617
1642
  }
1618
1643
  },
1619
1644
  "dependencies": {
1620
- "@acala-network/api": "^4.1.8-2.3",
1621
- "@acala-network/type-definitions": "^4.1.5",
1645
+ "@acala-network/api": "^5.0.2",
1646
+ "@acala-network/type-definitions": "^5.0.2",
1622
1647
  "@apollo/client": "^3.7.14",
1623
1648
  "@babel/runtime": "^7.20.6",
1624
1649
  "@bifrost-finance/type-definitions": "^1.7.2",
@@ -1628,7 +1653,7 @@
1628
1653
  "@digitalnative/type-definitions": "^1.1.27",
1629
1654
  "@docknetwork/node-types": "^0.15.0",
1630
1655
  "@edgeware/node-types": "^3.6.2-wako",
1631
- "@equilab/api": "^1.14.12",
1656
+ "@equilab/api": "^1.14.25",
1632
1657
  "@equilab/definitions": "^1.4.18",
1633
1658
  "@ethereumjs/common": "^2.6.5",
1634
1659
  "@ethereumjs/tx": "^4.0.2",
@@ -1639,47 +1664,43 @@
1639
1664
  "@fortawesome/free-solid-svg-icons": "^6.2.1",
1640
1665
  "@fortawesome/react-fontawesome": "^0.2.0",
1641
1666
  "@google/model-viewer": "^2.0.2",
1642
- "@interlay/interbtc-types": "^1.11.0",
1643
- "@kiltprotocol/type-definitions": "^0.30.0",
1667
+ "@interlay/interbtc-types": "^1.12.0",
1668
+ "@kiltprotocol/type-definitions": "^0.32.0",
1644
1669
  "@laminar/type-definitions": "^0.3.1",
1645
1670
  "@metamask/safe-event-emitter": "^2.0.0",
1646
1671
  "@metaverse-network-sdk/type-definitions": "^0.0.1-13",
1647
1672
  "@oak-foundation/api-augment": "^0.0.23",
1648
1673
  "@oak-foundation/types": "^0.0.23",
1649
- "@parallel-finance/type-definitions": "^1.7.14",
1650
- "@phala/typedefs": "^0.2.32",
1651
- "@polkadot/api": "^9.10.3",
1652
- "@polkadot/api-contract": "^9.10.3",
1653
- "@polkadot/api-derive": "^9.10.3",
1654
- "@polkadot/hw-ledger": "^10.1.9",
1655
- "@polkadot/keyring": "^10.2.1",
1656
- "@polkadot/networks": "^10.2.1",
1657
- "@polkadot/phishing": "^0.21.2",
1658
- "@polkadot/react-identicon": "^2.9.14",
1659
- "@polkadot/react-qr": "^2.9.14",
1660
- "@polkadot/rpc-provider": "^9.10.3",
1661
- "@polkadot/types": "^9.10.3",
1662
- "@polkadot/types-augment": "^9.10.3",
1663
- "@polkadot/ui-keyring": "^2.9.14",
1664
- "@polkadot/ui-settings": "^2.9.14",
1665
- "@polkadot/util": "^10.2.1",
1666
- "@polkadot/util-crypto": "^10.2.1",
1674
+ "@parallel-finance/type-definitions": "^1.7.17",
1675
+ "@phala/typedefs": "^0.2.33",
1676
+ "@polkadot/api": "^10.7.1",
1677
+ "@polkadot/api-contract": "^10.7.1",
1678
+ "@polkadot/api-derive": "^10.7.1",
1679
+ "@polkadot/hw-ledger": "^12.2.1",
1680
+ "@polkadot/networks": "^12.2.1",
1681
+ "@polkadot/phishing": "^0.21.3",
1682
+ "@polkadot/rpc-provider": "^10.7.1",
1683
+ "@polkadot/types": "^10.7.1",
1684
+ "@polkadot/types-augment": "^10.7.1",
1685
+ "@polkadot/ui-settings": "^3.4.1",
1686
+ "@polkadot/util": "^12.2.1",
1687
+ "@polkadot/util-crypto": "^12.2.1",
1667
1688
  "@polymathnetwork/polymesh-types": "^0.0.2",
1668
1689
  "@ramonak/react-progress-bar": "^5.0.3",
1669
1690
  "@reduxjs/toolkit": "^1.9.1",
1670
1691
  "@snowfork/snowbridge-types": "^0.2.7",
1671
- "@sora-substrate/type-definitions": "^1.12.4",
1692
+ "@sora-substrate/type-definitions": "^1.17.7",
1672
1693
  "@subsocial/types": "^0.6.8",
1673
- "@substrate/connect": "^0.7.18",
1694
+ "@substrate/connect": "^0.7.26",
1674
1695
  "@subwallet/chain-list": "^0.1.2",
1675
- "@subwallet/extension-base": "^1.0.4-1",
1676
- "@subwallet/extension-chains": "^1.0.4-1",
1677
- "@subwallet/extension-dapp": "^1.0.4-1",
1678
- "@subwallet/extension-inject": "^1.0.4-1",
1679
- "@subwallet/keyring": "^0.0.5",
1680
- "@subwallet/ui-keyring": "^0.0.7",
1696
+ "@subwallet/extension-base": "^1.0.5-2",
1697
+ "@subwallet/extension-chains": "^1.0.5-2",
1698
+ "@subwallet/extension-dapp": "^1.0.5-2",
1699
+ "@subwallet/extension-inject": "^1.0.5-2",
1700
+ "@subwallet/keyring": "^0.0.9",
1701
+ "@subwallet/ui-keyring": "^0.0.9",
1681
1702
  "@unique-nft/types": "^0.6.0-4",
1682
- "@zeitgeistpm/type-defs": "^0.10.0",
1703
+ "@zeitgeistpm/type-defs": "^1.0.0",
1683
1704
  "@zeroio/type-definitions": "^0.0.14",
1684
1705
  "axios": "^1.2.1",
1685
1706
  "bignumber.js": "^9.1.1",
@@ -1701,7 +1722,7 @@
1701
1722
  "is-buffer": "^2.0.5",
1702
1723
  "json-rpc-engine": "^6.1.0",
1703
1724
  "moment": "^2.29.4",
1704
- "moonbeam-types-bundle": "^2.0.9",
1725
+ "moonbeam-types-bundle": "^2.0.10",
1705
1726
  "phosphor-react": "^1.4.1",
1706
1727
  "pontem-types-bundle": "^1.0.15",
1707
1728
  "protobufjs": "^7.1.2",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.0.4-1'
10
+ version: '1.0.5-2'
11
11
  };
@@ -124,7 +124,7 @@ export class EvmChainHandler {
124
124
  contractError
125
125
  };
126
126
  } catch (e) {
127
- this.logger.error('Error response while validating EVM contract', e);
127
+ this.logger.error(e);
128
128
  return {
129
129
  name,
130
130
  decimals,
@@ -30,7 +30,6 @@ export class SubstrateChainHandler {
30
30
  resumeAllApis() {
31
31
  return Promise.all(Object.values(this.getSubstrateApiMap()).map(async substrateApi => {
32
32
  if (!substrateApi.api.isConnected && substrateApi.api.connect) {
33
- this.logger.log(`[Substrate] Resuming network [${substrateApi.specName}]`);
34
33
  await substrateApi.api.connect();
35
34
  }
36
35
  }));
@@ -39,7 +38,6 @@ export class SubstrateChainHandler {
39
38
  return Promise.all(Object.values(this.getSubstrateApiMap()).map(async substrateApi => {
40
39
  if (substrateApi.api.isConnected) {
41
40
  var _substrateApi$api, _substrateApi$api2;
42
- this.logger.log(`[Substrate] Stopping network [${substrateApi.chainSlug}]`);
43
41
  ((_substrateApi$api = substrateApi.api) === null || _substrateApi$api === void 0 ? void 0 : _substrateApi$api.disconnect) && (await ((_substrateApi$api2 = substrateApi.api) === null || _substrateApi$api2 === void 0 ? void 0 : _substrateApi$api2.disconnect()));
44
42
  }
45
43
  }));
@@ -97,7 +95,6 @@ export class SubstrateChainHandler {
97
95
  gasLimit: getDefaultWeightV2(substrateApi.api)
98
96
  })]);
99
97
  if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
100
- this.logger.error('Error response while validating WASM contract');
101
98
  return {
102
99
  name: '',
103
100
  decimals: -1,
@@ -124,7 +121,6 @@ export class SubstrateChainHandler {
124
121
  }); // read-only operation so no gas limit
125
122
 
126
123
  if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
127
- this.logger.error('Error response while validating WASM contract');
128
124
  return {
129
125
  name: '',
130
126
  decimals: -1,
@@ -149,7 +145,7 @@ export class SubstrateChainHandler {
149
145
  contractError
150
146
  };
151
147
  } catch (e) {
152
- this.logger.error('Error validating WASM contract', e);
148
+ this.logger.error(e);
153
149
  return {
154
150
  name: '',
155
151
  decimals: -1,
@@ -215,7 +211,6 @@ export class SubstrateChainHandler {
215
211
  defaultFormatBalance: undefined,
216
212
  recoverConnect: () => {
217
213
  substrateApi.apiRetry = 0;
218
- this.logger.log('Recover connect to ', apiUrl);
219
214
  provider.connect().then(this.logger.log).catch(this.logger.error);
220
215
  },
221
216
  get isReady() {
@@ -237,7 +232,6 @@ export class SubstrateChainHandler {
237
232
  }
238
233
  };
239
234
  api.on('connected', () => {
240
- this.logger.log('Substrate API connected to ', apiUrl);
241
235
  substrateApi.apiRetry = 0;
242
236
  if (substrateApi.isApiReadyOnce) {
243
237
  substrateApi.isApiReady = true;
@@ -255,7 +249,6 @@ export class SubstrateChainHandler {
255
249
  }
256
250
  });
257
251
  api.on('ready', () => {
258
- this.logger.log('Substrate API ready with', apiUrl);
259
252
  this.loadOnReady(registry, api).then(rs => {
260
253
  objectSpread(substrateApi, rs);
261
254
  }).catch(error => {
@@ -307,7 +300,7 @@ export class SubstrateChainHandler {
307
300
  const tokenSymbol = properties.tokenSymbol.unwrapOr([formatBalance.getDefaults().unit, ...DEFAULT_AUX]);
308
301
  const tokenDecimals = properties.tokenDecimals.unwrapOr([DEFAULT_DECIMALS]);
309
302
  const isDevelopment = systemChainType.isDevelopment || systemChainType.isLocal || isTestChain(systemChain);
310
- this.logger.log(`chain: ${systemChain} (${systemChainType.toString()}), ${stringify(properties)}`);
303
+ this.logger.log(`Connected to ${systemChain} (${systemChainType.toString()}), ${stringify(properties)}`);
311
304
 
312
305
  // explicitly override the ss58Format as specified
313
306
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -1,12 +1,14 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import * as Sc from '@substrate/connect';
5
+ import { WellKnownChain } from '@substrate/connect';
4
6
  import { ScProvider } from '@polkadot/rpc-provider';
5
7
  export const relayChainSpecs = {
6
- kusama: ScProvider.WellKnownChain.ksmcc3,
7
- polkadot: ScProvider.WellKnownChain.polkadot,
8
- rococo: ScProvider.WellKnownChain.rococo_v2_2,
9
- westend: ScProvider.WellKnownChain.westend2
8
+ kusama: WellKnownChain.ksmcc3,
9
+ polkadot: WellKnownChain.polkadot,
10
+ rococo: WellKnownChain.rococo_v2_2,
11
+ westend: WellKnownChain.westend2
10
12
  };
11
13
 
12
14
  // Direct get spec data from @polkadot/react-api repository
@@ -97,14 +99,14 @@ class ProviderPlaceholder {
97
99
  export function getSubstrateConnectProvider(specLink) {
98
100
  const [relayName, paraName] = specLink.split('/');
99
101
  const relaySpec = relayChainSpecs[relayName];
100
- const relayProvider = new ScProvider(relaySpec);
102
+ const relayProvider = new ScProvider(Sc, relaySpec);
101
103
  if (!paraName) {
102
104
  return relayProvider;
103
105
  }
104
106
  const paraChainData = paraChainSpecs[specLink];
105
107
  let scProvider;
106
108
  const scPromise = fetch(paraChainData).then(rs => rs.text()).then(spec => {
107
- scProvider = new ScProvider(spec, relayProvider);
109
+ scProvider = new ScProvider(Sc, spec);
108
110
  return scProvider;
109
111
  }).catch(console.error);
110
112
  return new ProviderPlaceholder(scPromise);
@@ -5,7 +5,7 @@ declare const _default: {
5
5
  council: string[];
6
6
  };
7
7
  types: {
8
- minmax: [number | null | undefined, number | null | undefined] | [(number | undefined)?, (number | undefined)?] | (number | null | undefined)[];
8
+ minmax: number[] | [(number | undefined)?, (number | undefined)?] | [number, number];
9
9
  types: {
10
10
  Keys: string;
11
11
  };
@@ -18,7 +18,7 @@ declare const _default: {
18
18
  council: string[];
19
19
  };
20
20
  types: {
21
- minmax: [number | null | undefined, number | null | undefined] | [(number | undefined)?, (number | undefined)?] | (number | null | undefined)[];
21
+ minmax: number[] | [(number | undefined)?, (number | undefined)?] | [number, number];
22
22
  types: {
23
23
  Keys: string;
24
24
  };
@@ -31,7 +31,7 @@ declare const _default: {
31
31
  council: string[];
32
32
  };
33
33
  types: {
34
- minmax: [number | null | undefined, number | null | undefined] | [(number | undefined)?, (number | undefined)?] | (number | null | undefined)[];
34
+ minmax: number[] | [(number | undefined)?, (number | undefined)?] | [number, number];
35
35
  types: {
36
36
  Keys: string;
37
37
  };
@@ -358,7 +358,6 @@ export class ChainService {
358
358
  this.assetRegistrySubject.next(this.getAssetRegistry());
359
359
  this.initApis();
360
360
  await this.initAssetSettings();
361
- this.logger.log('Initiated chains, assets and APIs');
362
361
  }
363
362
  initApis() {
364
363
  // TODO: this might be async
@@ -1140,7 +1139,6 @@ export class ChainService {
1140
1139
  });
1141
1140
  await Promise.all(promiseList);
1142
1141
  if (update) {
1143
- console.log('Update chain connection state');
1144
1142
  this.chainStateMapSubject.next(chainStateMap);
1145
1143
  }
1146
1144
  }
@@ -285,6 +285,9 @@ export function _getAssetDecimals(assetInfo) {
285
285
  }
286
286
  export function _getBlockExplorerFromChain(chainInfo) {
287
287
  let blockExplorer;
288
+ if (!chainInfo) {
289
+ return;
290
+ }
288
291
  if (_isPureEvmChain(chainInfo)) {
289
292
  var _chainInfo$evmInfo4;
290
293
  blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.blockExplorer;
@@ -0,0 +1,17 @@
1
+ import { TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { ChainService } from '@subwallet/extension-base/services/chain-service';
3
+ export declare enum HistoryRecoverStatus {
4
+ SUCCESS = "SUCCESS",
5
+ FAILED = "FAILED",
6
+ API_INACTIVE = "API_INACTIVE",
7
+ LACK_INFO = "LACK_INFO",
8
+ FAIL_DETECT = "FAIL_DETECT",
9
+ UNKNOWN = "UNKNOWN"
10
+ }
11
+ export interface TransactionRecoverResult {
12
+ status: HistoryRecoverStatus;
13
+ extrinsicHash?: string;
14
+ blockHash?: string;
15
+ blockNumber?: number;
16
+ }
17
+ export declare const historyRecover: (history: TransactionHistoryItem, chainService: ChainService) => Promise<TransactionRecoverResult>;
@@ -0,0 +1,214 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { isSameAddress } from '@subwallet/extension-base/utils';
5
+ export let HistoryRecoverStatus;
6
+ (function (HistoryRecoverStatus) {
7
+ HistoryRecoverStatus["SUCCESS"] = "SUCCESS";
8
+ HistoryRecoverStatus["FAILED"] = "FAILED";
9
+ HistoryRecoverStatus["API_INACTIVE"] = "API_INACTIVE";
10
+ HistoryRecoverStatus["LACK_INFO"] = "LACK_INFO";
11
+ HistoryRecoverStatus["FAIL_DETECT"] = "FAIL_DETECT";
12
+ HistoryRecoverStatus["UNKNOWN"] = "UNKNOWN";
13
+ })(HistoryRecoverStatus || (HistoryRecoverStatus = {}));
14
+ const BLOCK_LIMIT = 6;
15
+ const substrateRecover = async (history, chainService) => {
16
+ const {
17
+ address,
18
+ blockHash,
19
+ chain,
20
+ extrinsicHash,
21
+ from,
22
+ nonce,
23
+ startBlock
24
+ } = history;
25
+ const result = {
26
+ status: HistoryRecoverStatus.UNKNOWN
27
+ };
28
+ try {
29
+ const substrateApi = chainService.getSubstrateApi(chain);
30
+ if (substrateApi) {
31
+ const _api = await substrateApi.isReady;
32
+ const api = _api.api;
33
+ if (!blockHash) {
34
+ if (!nonce || !startBlock) {
35
+ console.log(`Fail to find extrinsic for ${address} on ${chain}: With nonce ${nonce || 'undefined'} from block ${startBlock || 'undefined'}`);
36
+ return {
37
+ status: HistoryRecoverStatus.LACK_INFO
38
+ };
39
+ }
40
+ const currentBlock = (await api.query.system.number()).toPrimitive();
41
+ for (let i = 1, found = false; i < BLOCK_LIMIT && !found && startBlock + i <= currentBlock; i++) {
42
+ const blockHash = (await api.rpc.chain.getBlockHash(startBlock + i)).toHex();
43
+ const block = await api.rpc.chain.getBlock(blockHash);
44
+ const extrinsics = block.block.extrinsics;
45
+ let index;
46
+ for (const [idx, extrinsic] of Object.entries(extrinsics)) {
47
+ if (extrinsic.signer && isSameAddress(from, extrinsic.signer.toString()) && nonce === extrinsic.nonce.toNumber()) {
48
+ index = parseInt(idx);
49
+ found = true;
50
+ result.extrinsicHash = extrinsic.hash.toHex();
51
+ result.blockHash = block.block.hash.toHex();
52
+ result.blockNumber = block.block.header.number.toNumber();
53
+ break;
54
+ }
55
+ }
56
+ if (index !== undefined) {
57
+ const allEvents = await api.query.system.events.at(blockHash);
58
+ const events = allEvents.filter(({
59
+ phase
60
+ }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index));
61
+ for (const {
62
+ event
63
+ } of events) {
64
+ if (api.events.system.ExtrinsicSuccess.is(event)) {
65
+ return {
66
+ ...result,
67
+ status: HistoryRecoverStatus.SUCCESS
68
+ };
69
+ } else if (api.events.system.ExtrinsicFailed.is(event)) {
70
+ return {
71
+ ...result,
72
+ status: HistoryRecoverStatus.FAILED
73
+ };
74
+ }
75
+ }
76
+ }
77
+ }
78
+ } else {
79
+ const block = await api.rpc.chain.getBlock(blockHash);
80
+ const allEvents = await api.query.system.events.at(blockHash);
81
+ const extrinsics = block.block.extrinsics;
82
+ let index;
83
+ for (const [idx, extrinsic] of Object.entries(extrinsics)) {
84
+ if (extrinsicHash === extrinsic.hash.toHex()) {
85
+ index = parseInt(idx);
86
+ break;
87
+ }
88
+ }
89
+ if (index === undefined) {
90
+ console.log(`Fail to find extrinsic ${extrinsicHash} on ${chain}`);
91
+ return {
92
+ status: HistoryRecoverStatus.FAIL_DETECT
93
+ };
94
+ }
95
+ const events = allEvents.filter(({
96
+ phase
97
+ }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index));
98
+ for (const {
99
+ event
100
+ } of events) {
101
+ if (api.events.system.ExtrinsicSuccess.is(event)) {
102
+ return {
103
+ ...result,
104
+ status: HistoryRecoverStatus.SUCCESS
105
+ };
106
+ } else if (api.events.system.ExtrinsicFailed.is(event)) {
107
+ return {
108
+ ...result,
109
+ status: HistoryRecoverStatus.FAILED
110
+ };
111
+ }
112
+ }
113
+ }
114
+ return {
115
+ status: HistoryRecoverStatus.FAIL_DETECT
116
+ };
117
+ } else {
118
+ console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
119
+ return {
120
+ status: HistoryRecoverStatus.API_INACTIVE
121
+ };
122
+ }
123
+ } catch (e) {
124
+ console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
125
+ return {
126
+ status: HistoryRecoverStatus.UNKNOWN
127
+ };
128
+ }
129
+ };
130
+ const evmRecover = async (history, chainService) => {
131
+ const {
132
+ address,
133
+ chain,
134
+ extrinsicHash,
135
+ from,
136
+ nonce,
137
+ startBlock
138
+ } = history;
139
+ const result = {
140
+ status: HistoryRecoverStatus.UNKNOWN
141
+ };
142
+ try {
143
+ const evmApi = chainService.getEvmApi(chain);
144
+ if (evmApi) {
145
+ const _api = await evmApi.isReady;
146
+ const api = _api.api;
147
+ if (extrinsicHash) {
148
+ const transactionReceipt = await api.eth.getTransactionReceipt(extrinsicHash);
149
+ return {
150
+ ...result,
151
+ status: transactionReceipt.status ? HistoryRecoverStatus.SUCCESS : HistoryRecoverStatus.FAILED
152
+ };
153
+ } else {
154
+ if (!nonce || !startBlock) {
155
+ console.log(`Fail to find extrinsic for ${address} on ${chain}: With nonce ${nonce || 'undefined'} from block ${startBlock || 'undefined'}`);
156
+ return {
157
+ ...result,
158
+ status: HistoryRecoverStatus.LACK_INFO
159
+ };
160
+ }
161
+ const currentBlock = await api.eth.getBlockNumber();
162
+ for (let i = 1, found = false; i < BLOCK_LIMIT && !found && startBlock + i <= currentBlock; i++) {
163
+ const block = await api.eth.getBlock(startBlock + i, true);
164
+ for (const transaction of block.transactions) {
165
+ if (isSameAddress(transaction.from, from) && nonce === transaction.nonce) {
166
+ result.extrinsicHash = transaction.hash;
167
+ result.blockHash = block.hash;
168
+ result.blockNumber = block.number;
169
+ found = true;
170
+ break;
171
+ }
172
+ }
173
+ if (result.extrinsicHash) {
174
+ const transactionReceipt = await api.eth.getTransactionReceipt(result.extrinsicHash);
175
+ return {
176
+ ...result,
177
+ status: transactionReceipt.status ? HistoryRecoverStatus.SUCCESS : HistoryRecoverStatus.FAILED
178
+ };
179
+ }
180
+ }
181
+ }
182
+ return {
183
+ status: HistoryRecoverStatus.FAIL_DETECT
184
+ };
185
+ } else {
186
+ console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
187
+ return {
188
+ status: HistoryRecoverStatus.API_INACTIVE
189
+ };
190
+ }
191
+ } catch (e) {
192
+ console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
193
+ return {
194
+ status: HistoryRecoverStatus.UNKNOWN
195
+ };
196
+ }
197
+ };
198
+
199
+ // undefined: Cannot check status
200
+ // true: Transaction success
201
+ // false: Transaction failed
202
+ export const historyRecover = async (history, chainService) => {
203
+ const {
204
+ chainType
205
+ } = history;
206
+ if (chainType) {
207
+ const checkFunction = chainType === 'substrate' ? substrateRecover : evmRecover;
208
+ return await checkFunction(history, chainService);
209
+ } else {
210
+ return {
211
+ status: HistoryRecoverStatus.LACK_INFO
212
+ };
213
+ }
214
+ };
@@ -6,6 +6,7 @@ import { KeyringService } from '@subwallet/extension-base/services/keyring-servi
6
6
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
7
7
  import { BehaviorSubject } from 'rxjs';
8
8
  export declare class HistoryService implements StoppableServiceInterface, PersistDataServiceInterface, CronServiceInterface {
9
+ #private;
9
10
  private dbService;
10
11
  private chainService;
11
12
  private eventService;
@@ -14,6 +15,7 @@ export declare class HistoryService implements StoppableServiceInterface, Persis
14
15
  constructor(dbService: DatabaseService, chainService: ChainService, eventService: EventService, keyringService: KeyringService);
15
16
  private fetchPromise;
16
17
  private interval;
18
+ private recoverInterval;
17
19
  private fetchAndLoadHistories;
18
20
  getHistories(): Promise<TransactionHistoryItem<import("@subwallet/extension-base/background/KoniTypes").ExtrinsicType.TRANSFER_BALANCE>[]>;
19
21
  getHistorySubject(): Promise<BehaviorSubject<TransactionHistoryItem<import("@subwallet/extension-base/background/KoniTypes").ExtrinsicType.TRANSFER_BALANCE>[]>>;
@@ -27,12 +29,16 @@ export declare class HistoryService implements StoppableServiceInterface, Persis
27
29
  persistData(): Promise<void>;
28
30
  startCron(): Promise<void>;
29
31
  stopCron(): Promise<void>;
32
+ startRecoverHistories(): Promise<void>;
33
+ stopRecoverHistories(): Promise<void>;
34
+ recoverHistories(): Promise<void>;
30
35
  startPromiseHandler: {
31
36
  resolve: (value: void) => void;
32
37
  reject: (reason?: unknown) => void;
33
38
  promise: Promise<void>;
34
39
  };
35
40
  init(): Promise<void>;
41
+ recoverProcessingHistory(): Promise<void>;
36
42
  start(): Promise<void>;
37
43
  waitForStarted(): Promise<void>;
38
44
  stopPromiseHandler: {