@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.
Files changed (134) hide show
  1. package/background/KoniTypes.d.ts +46 -38
  2. package/background/KoniTypes.js +8 -8
  3. package/background/errors/TransactionError.js +25 -1
  4. package/background/types.d.ts +10 -5
  5. package/cjs/background/KoniTypes.js +8 -8
  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 +382 -207
  34. package/cjs/koni/background/handlers/State.js +41 -33
  35. package/cjs/koni/background/handlers/Tabs.js +50 -17
  36. package/cjs/koni/background/subscription.js +32 -29
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  39. package/cjs/services/chain-service/index.js +59 -45
  40. package/cjs/services/event-service/index.js +5 -1
  41. package/cjs/services/event-service/types.js +11 -1
  42. package/cjs/services/history-service/index.js +19 -13
  43. package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
  44. package/cjs/services/keyring-service/index.js +11 -13
  45. package/cjs/services/price-service/coingecko.js +0 -1
  46. package/cjs/services/price-service/index.js +2 -3
  47. package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
  48. package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
  49. package/cjs/services/request-service/index.js +14 -5
  50. package/cjs/services/storage-service/DatabaseService.js +56 -34
  51. package/cjs/services/storage-service/db-stores/Nft.js +7 -15
  52. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  53. package/cjs/services/transaction-service/index.js +26 -15
  54. package/cjs/utils/address.js +10 -1
  55. package/cjs/utils/index.js +9 -15
  56. package/constants/index.d.ts +7 -13
  57. package/constants/index.js +7 -13
  58. package/koni/api/dotsama/balance.d.ts +0 -1
  59. package/koni/api/dotsama/balance.js +22 -197
  60. package/koni/api/dotsama/transfer.js +11 -16
  61. package/koni/api/nft/acala_nft/index.js +7 -7
  62. package/koni/api/nft/bit.country/index.js +7 -6
  63. package/koni/api/nft/evm_nft/index.js +7 -3
  64. package/koni/api/nft/index.d.ts +1 -2
  65. package/koni/api/nft/index.js +3 -6
  66. package/koni/api/nft/karura_nft/index.js +7 -6
  67. package/koni/api/nft/nft.d.ts +1 -0
  68. package/koni/api/nft/rmrk_nft/index.js +11 -1
  69. package/koni/api/nft/statemine_nft/index.js +7 -6
  70. package/koni/api/nft/unique_nft/index.js +5 -1
  71. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  72. package/koni/api/nft/wasm_nft/index.js +168 -109
  73. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  74. package/koni/api/nft/wasm_nft/utils.js +7 -5
  75. package/koni/api/staking/bonding/amplitude.d.ts +0 -1
  76. package/koni/api/staking/bonding/amplitude.js +15 -10
  77. package/koni/api/staking/bonding/astar.js +8 -6
  78. package/koni/api/staking/bonding/index.d.ts +4 -1
  79. package/koni/api/staking/bonding/index.js +23 -13
  80. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  81. package/koni/api/staking/bonding/paraChain.js +86 -5
  82. package/koni/api/staking/bonding/relayChain.d.ts +5 -1
  83. package/koni/api/staking/bonding/relayChain.js +121 -18
  84. package/koni/api/staking/bonding/utils.d.ts +3 -2
  85. package/koni/api/staking/bonding/utils.js +27 -9
  86. package/koni/api/tokens/wasm/index.js +5 -4
  87. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  88. package/koni/api/tokens/wasm/utils.js +54 -0
  89. package/koni/api/xcm/polkadotXcm.js +2 -2
  90. package/koni/api/xcm/utils.d.ts +5 -6
  91. package/koni/api/xcm/utils.js +15 -10
  92. package/koni/api/xcm/xTokens.js +2 -2
  93. package/koni/api/xcm/xcmPallet.js +10 -9
  94. package/koni/background/cron.d.ts +6 -1
  95. package/koni/background/cron.js +172 -62
  96. package/koni/background/handlers/Extension.d.ts +8 -3
  97. package/koni/background/handlers/Extension.js +297 -126
  98. package/koni/background/handlers/State.d.ts +5 -6
  99. package/koni/background/handlers/State.js +43 -33
  100. package/koni/background/handlers/Tabs.js +50 -17
  101. package/koni/background/subscription.js +31 -30
  102. package/package.json +18 -13
  103. package/packageInfo.js +1 -1
  104. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  105. package/services/chain-service/helper/psp22_abi.json +1041 -881
  106. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  107. package/services/chain-service/index.d.ts +3 -2
  108. package/services/chain-service/index.js +53 -40
  109. package/services/chain-service/types.d.ts +1 -0
  110. package/services/event-service/index.js +5 -1
  111. package/services/event-service/types.d.ts +5 -9
  112. package/services/event-service/types.js +4 -1
  113. package/services/history-service/index.d.ts +4 -2
  114. package/services/history-service/index.js +19 -13
  115. package/services/history-service/subsquid-multi-chain-history.js +16 -12
  116. package/services/keyring-service/index.d.ts +4 -2
  117. package/services/keyring-service/index.js +11 -13
  118. package/services/price-service/coingecko.js +0 -1
  119. package/services/price-service/index.js +2 -3
  120. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
  121. package/services/request-service/handler/AuthRequestHandler.js +13 -7
  122. package/services/request-service/handler/EvmRequestHandler.js +8 -12
  123. package/services/request-service/index.d.ts +3 -1
  124. package/services/request-service/index.js +14 -5
  125. package/services/storage-service/DatabaseService.d.ts +1 -0
  126. package/services/storage-service/DatabaseService.js +56 -34
  127. package/services/storage-service/db-stores/Nft.d.ts +2 -2
  128. package/services/storage-service/db-stores/Nft.js +7 -14
  129. package/services/transaction-service/event-parser/index.js +21 -49
  130. package/services/transaction-service/index.js +26 -15
  131. package/utils/address.d.ts +3 -0
  132. package/utils/address.js +8 -1
  133. package/utils/index.d.ts +2 -2
  134. package/utils/index.js +7 -13
@@ -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) {