@subwallet/extension-base 1.0.2-2 → 1.0.3-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/background/KoniTypes.d.ts +56 -40
  2. package/background/KoniTypes.js +11 -9
  3. package/background/errors/TransactionError.js +25 -1
  4. package/background/types.d.ts +10 -5
  5. package/cjs/background/KoniTypes.js +11 -9
  6. package/cjs/background/errors/TransactionError.js +24 -0
  7. package/cjs/constants/index.js +8 -26
  8. package/cjs/koni/api/dotsama/balance.js +49 -224
  9. package/cjs/koni/api/dotsama/transfer.js +34 -39
  10. package/cjs/koni/api/nft/acala_nft/index.js +7 -7
  11. package/cjs/koni/api/nft/bit.country/index.js +7 -6
  12. package/cjs/koni/api/nft/evm_nft/index.js +8 -3
  13. package/cjs/koni/api/nft/index.js +3 -6
  14. package/cjs/koni/api/nft/karura_nft/index.js +7 -6
  15. package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
  16. package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
  17. package/cjs/koni/api/nft/unique_nft/index.js +5 -1
  18. package/cjs/koni/api/nft/wasm_nft/index.js +170 -111
  19. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  20. package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
  21. package/cjs/koni/api/staking/bonding/astar.js +15 -13
  22. package/cjs/koni/api/staking/bonding/index.js +22 -10
  23. package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
  24. package/cjs/koni/api/staking/bonding/relayChain.js +122 -16
  25. package/cjs/koni/api/staking/bonding/utils.js +27 -8
  26. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  27. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  28. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +1 -1
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +171 -61
  33. package/cjs/koni/background/handlers/Extension.js +391 -207
  34. package/cjs/koni/background/handlers/State.js +49 -34
  35. package/cjs/koni/background/handlers/Tabs.js +50 -17
  36. package/cjs/koni/background/subscription.js +53 -28
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/services/base/types.js +20 -0
  39. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  40. package/cjs/services/chain-service/index.js +73 -49
  41. package/cjs/services/event-service/index.js +5 -1
  42. package/cjs/services/event-service/types.js +11 -1
  43. package/cjs/services/history-service/index.js +101 -50
  44. package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
  45. package/cjs/services/keyring-service/index.js +11 -13
  46. package/cjs/services/migration-service/scripts/MigrateImportedToken.js +2 -1
  47. package/cjs/services/price-service/coingecko.js +0 -1
  48. package/cjs/services/price-service/index.js +71 -24
  49. package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
  50. package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
  51. package/cjs/services/request-service/index.js +14 -5
  52. package/cjs/services/storage-service/DatabaseService.js +66 -34
  53. package/cjs/services/storage-service/db-stores/Nft.js +7 -15
  54. package/cjs/services/storage-service/db-stores/Transaction.js +6 -10
  55. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  56. package/cjs/services/transaction-service/index.js +104 -48
  57. package/cjs/services/transaction-service/utils.js +10 -8
  58. package/cjs/utils/address.js +10 -1
  59. package/cjs/utils/index.js +9 -15
  60. package/cjs/utils/promise.js +26 -0
  61. package/constants/index.d.ts +7 -13
  62. package/constants/index.js +7 -13
  63. package/koni/api/dotsama/balance.d.ts +0 -1
  64. package/koni/api/dotsama/balance.js +22 -197
  65. package/koni/api/dotsama/transfer.js +11 -16
  66. package/koni/api/nft/acala_nft/index.js +7 -7
  67. package/koni/api/nft/bit.country/index.js +7 -6
  68. package/koni/api/nft/evm_nft/index.js +7 -3
  69. package/koni/api/nft/index.d.ts +1 -2
  70. package/koni/api/nft/index.js +3 -6
  71. package/koni/api/nft/karura_nft/index.js +7 -6
  72. package/koni/api/nft/nft.d.ts +1 -0
  73. package/koni/api/nft/rmrk_nft/index.js +11 -1
  74. package/koni/api/nft/statemine_nft/index.js +7 -6
  75. package/koni/api/nft/unique_nft/index.js +5 -1
  76. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  77. package/koni/api/nft/wasm_nft/index.js +168 -109
  78. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  79. package/koni/api/nft/wasm_nft/utils.js +7 -5
  80. package/koni/api/staking/bonding/amplitude.d.ts +0 -1
  81. package/koni/api/staking/bonding/amplitude.js +15 -10
  82. package/koni/api/staking/bonding/astar.js +8 -6
  83. package/koni/api/staking/bonding/index.d.ts +4 -1
  84. package/koni/api/staking/bonding/index.js +23 -13
  85. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  86. package/koni/api/staking/bonding/paraChain.js +86 -5
  87. package/koni/api/staking/bonding/relayChain.d.ts +5 -1
  88. package/koni/api/staking/bonding/relayChain.js +121 -18
  89. package/koni/api/staking/bonding/utils.d.ts +3 -2
  90. package/koni/api/staking/bonding/utils.js +27 -9
  91. package/koni/api/tokens/wasm/index.js +5 -4
  92. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  93. package/koni/api/tokens/wasm/utils.js +54 -0
  94. package/koni/api/xcm/polkadotXcm.js +2 -2
  95. package/koni/api/xcm/utils.d.ts +5 -6
  96. package/koni/api/xcm/utils.js +15 -10
  97. package/koni/api/xcm/xTokens.js +2 -2
  98. package/koni/api/xcm/xcmPallet.js +10 -9
  99. package/koni/background/cron.d.ts +6 -1
  100. package/koni/background/cron.js +172 -62
  101. package/koni/background/handlers/Extension.d.ts +9 -3
  102. package/koni/background/handlers/Extension.js +306 -126
  103. package/koni/background/handlers/State.d.ts +5 -6
  104. package/koni/background/handlers/State.js +51 -34
  105. package/koni/background/handlers/Tabs.js +50 -17
  106. package/koni/background/subscription.d.ts +2 -0
  107. package/koni/background/subscription.js +51 -29
  108. package/package.json +29 -14
  109. package/packageInfo.js +1 -1
  110. package/services/base/types.d.ts +34 -0
  111. package/services/base/types.js +15 -0
  112. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  113. package/services/chain-service/helper/psp22_abi.json +1041 -881
  114. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  115. package/services/chain-service/index.d.ts +5 -2
  116. package/services/chain-service/index.js +68 -45
  117. package/services/chain-service/types.d.ts +1 -0
  118. package/services/event-service/index.js +5 -1
  119. package/services/event-service/types.d.ts +5 -9
  120. package/services/event-service/types.js +4 -1
  121. package/services/history-service/index.d.ts +28 -7
  122. package/services/history-service/index.js +101 -50
  123. package/services/history-service/subsquid-multi-chain-history.js +16 -12
  124. package/services/keyring-service/index.d.ts +4 -2
  125. package/services/keyring-service/index.js +11 -13
  126. package/services/migration-service/scripts/MigrateImportedToken.js +2 -1
  127. package/services/price-service/coingecko.js +0 -1
  128. package/services/price-service/index.d.ts +22 -1
  129. package/services/price-service/index.js +71 -24
  130. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
  131. package/services/request-service/handler/AuthRequestHandler.js +13 -7
  132. package/services/request-service/handler/EvmRequestHandler.js +8 -12
  133. package/services/request-service/index.d.ts +3 -1
  134. package/services/request-service/index.js +14 -5
  135. package/services/storage-service/DatabaseService.d.ts +2 -0
  136. package/services/storage-service/DatabaseService.js +66 -34
  137. package/services/storage-service/db-stores/Nft.d.ts +2 -2
  138. package/services/storage-service/db-stores/Nft.js +7 -14
  139. package/services/storage-service/db-stores/Transaction.d.ts +2 -0
  140. package/services/storage-service/db-stores/Transaction.js +6 -10
  141. package/services/transaction-service/event-parser/index.js +21 -49
  142. package/services/transaction-service/index.d.ts +2 -0
  143. package/services/transaction-service/index.js +86 -32
  144. package/services/transaction-service/types.d.ts +2 -0
  145. package/services/transaction-service/utils.js +10 -8
  146. package/utils/address.d.ts +3 -0
  147. package/utils/address.js +8 -1
  148. package/utils/index.d.ts +2 -2
  149. package/utils/index.js +7 -13
  150. package/utils/promise.d.ts +6 -0
  151. package/utils/promise.js +20 -0
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.0.2-2",
20
+ "version": "1.0.3-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -369,6 +369,11 @@
369
369
  "require": "./cjs/koni/api/tokens/wasm/index.js",
370
370
  "default": "./koni/api/tokens/wasm/index.js"
371
371
  },
372
+ "./koni/api/tokens/wasm/utils": {
373
+ "types": "./koni/api/tokens/wasm/utils.d.ts",
374
+ "require": "./cjs/koni/api/tokens/wasm/utils.js",
375
+ "default": "./koni/api/tokens/wasm/utils.js"
376
+ },
372
377
  "./koni/api/xcm": {
373
378
  "types": "./koni/api/xcm/index.d.ts",
374
379
  "require": "./cjs/koni/api/xcm/index.js",
@@ -490,6 +495,11 @@
490
495
  "require": "./cjs/services/balance-service/index.js",
491
496
  "default": "./services/balance-service/index.js"
492
497
  },
498
+ "./services/base/types": {
499
+ "types": "./services/base/types.d.ts",
500
+ "require": "./cjs/services/base/types.js",
501
+ "default": "./services/base/types.js"
502
+ },
493
503
  "./services/chain-service": {
494
504
  "types": "./services/chain-service/index.d.ts",
495
505
  "require": "./cjs/services/chain-service/index.js",
@@ -1590,6 +1600,11 @@
1590
1600
  "require": "./cjs/utils/keyring.js",
1591
1601
  "default": "./utils/keyring.js"
1592
1602
  },
1603
+ "./utils/promise": {
1604
+ "types": "./utils/promise.d.ts",
1605
+ "require": "./cjs/utils/promise.js",
1606
+ "default": "./utils/promise.js"
1607
+ },
1593
1608
  "./utils/request": {
1594
1609
  "types": "./utils/request.d.ts",
1595
1610
  "require": "./cjs/utils/request.js",
@@ -1599,7 +1614,7 @@
1599
1614
  "dependencies": {
1600
1615
  "@acala-network/api": "^4.1.8-2.3",
1601
1616
  "@acala-network/type-definitions": "^4.1.5",
1602
- "@apollo/client": "^3.7.3",
1617
+ "@apollo/client": "^3.7.14",
1603
1618
  "@babel/runtime": "^7.20.6",
1604
1619
  "@bifrost-finance/type-definitions": "^1.7.2",
1605
1620
  "@crustio/type-definitions": "^1.3.0",
@@ -1634,7 +1649,7 @@
1634
1649
  "@polkadot/hw-ledger": "^10.1.9",
1635
1650
  "@polkadot/keyring": "^10.2.1",
1636
1651
  "@polkadot/networks": "^10.2.1",
1637
- "@polkadot/phishing": "^0.20.3",
1652
+ "@polkadot/phishing": "^0.21.1",
1638
1653
  "@polkadot/react-identicon": "^2.9.14",
1639
1654
  "@polkadot/react-qr": "^2.9.14",
1640
1655
  "@polkadot/rpc-provider": "^9.10.3",
@@ -1651,12 +1666,12 @@
1651
1666
  "@sora-substrate/type-definitions": "^1.12.4",
1652
1667
  "@subsocial/types": "^0.6.8",
1653
1668
  "@substrate/connect": "^0.7.18",
1654
- "@subwallet/chain-list": "^0.0.27",
1655
- "@subwallet/extension-base": "^1.0.2-2",
1656
- "@subwallet/extension-chains": "^1.0.2-2",
1657
- "@subwallet/extension-dapp": "^1.0.2-2",
1658
- "@subwallet/extension-inject": "^1.0.2-2",
1659
- "@subwallet/keyring": "^0.0.4",
1669
+ "@subwallet/chain-list": "^0.1.2",
1670
+ "@subwallet/extension-base": "^1.0.3-0",
1671
+ "@subwallet/extension-chains": "^1.0.3-0",
1672
+ "@subwallet/extension-dapp": "^1.0.3-0",
1673
+ "@subwallet/extension-inject": "^1.0.3-0",
1674
+ "@subwallet/keyring": "^0.0.5",
1660
1675
  "@subwallet/ui-keyring": "^0.0.3",
1661
1676
  "@unique-nft/types": "^0.6.0-4",
1662
1677
  "@zeitgeistpm/type-defs": "^0.10.0",
@@ -1687,10 +1702,10 @@
1687
1702
  "protobufjs": "^7.1.2",
1688
1703
  "rlp": "^3.0.0",
1689
1704
  "rxjs": "^7.8.0",
1690
- "web3": "^1.8.1",
1691
- "web3-core": "^1.8.1",
1692
- "web3-core-helpers": "^1.8.1",
1693
- "web3-eth-contract": "^1.8.1",
1694
- "web3-utils": "^1.8.1"
1705
+ "web3": "^1.9.0",
1706
+ "web3-core": "^1.9.0",
1707
+ "web3-core-helpers": "^1.9.0",
1708
+ "web3-eth-contract": "^1.9.0",
1709
+ "web3-utils": "^1.9.0"
1695
1710
  }
1696
1711
  }
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.2-2'
10
+ version: '1.0.3-0'
11
11
  };
@@ -0,0 +1,34 @@
1
+ import { PromiseHandler } from '@subwallet/extension-base/utils/promise';
2
+ export declare enum ServiceStatus {
3
+ NOT_INITIALIZED = "not_initialized",
4
+ INITIALIZING = "initializing",
5
+ INITIALIZED = "initialized",
6
+ STARTED = "started",
7
+ STARTING = "starting",
8
+ STOPPED = "stopped",
9
+ STOPPING = "stopping"
10
+ }
11
+ export interface CoreServiceInterface {
12
+ status: ServiceStatus;
13
+ init: () => Promise<void>;
14
+ startPromiseHandler: PromiseHandler<void>;
15
+ start: () => Promise<void>;
16
+ waitForStarted: () => Promise<void>;
17
+ }
18
+ export interface StoppableServiceInterface extends CoreServiceInterface {
19
+ stopPromiseHandler: PromiseHandler<void>;
20
+ stop: () => Promise<void>;
21
+ waitForStopped: () => Promise<void>;
22
+ }
23
+ export interface PersistDataServiceInterface {
24
+ loadData: () => Promise<void>;
25
+ persistData: () => Promise<void>;
26
+ }
27
+ export interface SubscribeServiceInterface {
28
+ subscribe: () => Promise<void>;
29
+ unsubscribe: () => Promise<void>;
30
+ }
31
+ export interface CronServiceInterface {
32
+ startCron: () => Promise<void>;
33
+ stopCron: () => Promise<void>;
34
+ }
@@ -0,0 +1,15 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // 'init' | 'started' | 'starting' | 'stopped' | 'stopping'
5
+
6
+ export let ServiceStatus;
7
+ (function (ServiceStatus) {
8
+ ServiceStatus["NOT_INITIALIZED"] = "not_initialized";
9
+ ServiceStatus["INITIALIZING"] = "initializing";
10
+ ServiceStatus["INITIALIZED"] = "initialized";
11
+ ServiceStatus["STARTED"] = "started";
12
+ ServiceStatus["STARTING"] = "starting";
13
+ ServiceStatus["STOPPED"] = "stopped";
14
+ ServiceStatus["STOPPING"] = "stopping";
15
+ })(ServiceStatus || (ServiceStatus = {}));
@@ -4,11 +4,12 @@
4
4
  import { options as acalaOptions } from '@acala-network/api';
5
5
  import { rpc as oakRpc, types as oakTypes } from '@oak-foundation/types';
6
6
  import { _AssetType } from '@subwallet/chain-list/types';
7
+ import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
7
8
  import { getSubstrateConnectProvider } from '@subwallet/extension-base/services/chain-service/handler/light-client';
8
9
  import { ApiPromise, WsProvider } from '@polkadot/api';
9
10
  import { ContractPromise } from '@polkadot/api-contract';
10
11
  import { TypeRegistry } from '@polkadot/types/create';
11
- import { formatBalance, isTestChain, objectSpread, stringify } from '@polkadot/util';
12
+ import { BN, formatBalance, isTestChain, objectSpread, stringify } from '@polkadot/util';
12
13
  import { logger as createLogger } from '@polkadot/util/logger';
13
14
  import { defaults as addressDefaults } from '@polkadot/util-crypto/address/defaults';
14
15
  import { _API_OPTIONS_CHAIN_GROUP, API_AUTO_CONNECT_MS, API_MAX_RETRY } from "../constants.js";
@@ -87,13 +88,13 @@ export class SubstrateChainHandler {
87
88
  if (tokenType === _AssetType.PSP22) {
88
89
  tokenContract = new ContractPromise(substrateApi.api, _PSP22_ABI, contractAddress);
89
90
  const [nameResp, symbolResp, decimalsResp] = await Promise.all([tokenContract.query['psp22Metadata::tokenName'](contractCaller || contractAddress, {
90
- gasLimit: -1
91
+ gasLimit: getDefaultWeightV2(substrateApi.api)
91
92
  }),
92
93
  // read-only operation so no gas limit
93
94
  tokenContract.query['psp22Metadata::tokenSymbol'](contractCaller || contractAddress, {
94
- gasLimit: -1
95
+ gasLimit: getDefaultWeightV2(substrateApi.api)
95
96
  }), tokenContract.query['psp22Metadata::tokenDecimals'](contractCaller || contractAddress, {
96
- gasLimit: -1
97
+ gasLimit: getDefaultWeightV2(substrateApi.api)
97
98
  })]);
98
99
  if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
99
100
  this.logger.error('Error response while validating WASM contract');
@@ -104,18 +105,22 @@ export class SubstrateChainHandler {
104
105
  contractError: true
105
106
  };
106
107
  } else {
107
- var _symbolResp$output, _decimalsResp$output, _symbolResp$output2;
108
- name = (_symbolResp$output = symbolResp.output) === null || _symbolResp$output === void 0 ? void 0 : _symbolResp$output.toHuman();
109
- decimals = parseInt((_decimalsResp$output = decimalsResp.output) === null || _decimalsResp$output === void 0 ? void 0 : _decimalsResp$output.toHuman());
110
- symbol = (_symbolResp$output2 = symbolResp.output) === null || _symbolResp$output2 === void 0 ? void 0 : _symbolResp$output2.toHuman();
108
+ var _symbolResp$output, _decimalsResp$output, _nameResp$output;
109
+ const symbolObj = (_symbolResp$output = symbolResp.output) === null || _symbolResp$output === void 0 ? void 0 : _symbolResp$output.toHuman();
110
+ const decimalsObj = (_decimalsResp$output = decimalsResp.output) === null || _decimalsResp$output === void 0 ? void 0 : _decimalsResp$output.toHuman();
111
+ const nameObj = (_nameResp$output = nameResp.output) === null || _nameResp$output === void 0 ? void 0 : _nameResp$output.toHuman();
112
+ name = nameResp.output ? nameObj.Ok || nameObj.ok : '';
113
+ decimals = decimalsResp.output ? new BN(decimalsObj.Ok || decimalsObj.ok).toNumber() : 0;
114
+ symbol = decimalsResp.output ? symbolObj.Ok || symbolObj.ok : '';
111
115
  if (name === '' || symbol === '') {
112
116
  contractError = true;
113
117
  }
118
+ console.log('validate PSP22', name, symbol, decimals);
114
119
  }
115
120
  } else {
116
121
  tokenContract = new ContractPromise(substrateApi.api, _PSP34_ABI, contractAddress);
117
122
  const collectionIdResp = await tokenContract.query['psp34::collectionId'](contractCaller || contractAddress, {
118
- gasLimit: -1
123
+ gasLimit: getDefaultWeightV2(substrateApi.api)
119
124
  }); // read-only operation so no gas limit
120
125
 
121
126
  if (!collectionIdResp.result.isOk || !collectionIdResp.output) {