@subwallet/extension-base 1.0.1 → 1.0.2-1b

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 (220) hide show
  1. package/background/KoniTypes.d.ts +25 -36
  2. package/background/KoniTypes.js +12 -7
  3. package/background/errors/TransactionError.js +21 -1
  4. package/cjs/background/KoniTypes.js +14 -8
  5. package/cjs/background/errors/TransactionError.js +20 -0
  6. package/cjs/constants/index.js +13 -28
  7. package/cjs/koni/api/dotsama/balance.js +60 -224
  8. package/cjs/koni/api/dotsama/transfer.js +30 -29
  9. package/cjs/koni/api/nft/acala_nft/index.js +4 -1
  10. package/cjs/koni/api/nft/bit.country/index.js +4 -1
  11. package/cjs/koni/api/nft/evm_nft/index.js +7 -3
  12. package/cjs/koni/api/nft/index.js +3 -6
  13. package/cjs/koni/api/nft/karura_nft/index.js +4 -1
  14. package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
  15. package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
  16. package/cjs/koni/api/nft/unique_nft/index.js +6 -1
  17. package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
  18. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  19. package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
  20. package/cjs/koni/api/staking/bonding/astar.js +37 -238
  21. package/cjs/koni/api/staking/bonding/index.js +26 -14
  22. package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
  23. package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
  24. package/cjs/koni/api/staking/bonding/utils.js +55 -10
  25. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  26. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  27. package/cjs/koni/api/xcm/index.js +0 -111
  28. package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +3 -5
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +179 -77
  33. package/cjs/koni/background/handlers/Extension.js +231 -195
  34. package/cjs/koni/background/handlers/State.js +147 -111
  35. package/cjs/koni/background/handlers/Tabs.js +48 -39
  36. package/cjs/koni/background/subscription.js +64 -56
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/page/index.js +5 -0
  39. package/cjs/services/chain-service/constants.js +1 -11
  40. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  41. package/cjs/services/chain-service/handler/light-client/index.js +2 -0
  42. package/cjs/services/chain-service/index.js +39 -6
  43. package/cjs/services/chain-service/utils.js +4 -0
  44. package/cjs/services/event-service/index.js +75 -0
  45. package/cjs/services/event-service/types.js +11 -0
  46. package/cjs/services/history-service/index.js +46 -21
  47. package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
  48. package/cjs/services/keyring-service/index.js +101 -0
  49. package/cjs/services/migration-service/index.js +13 -10
  50. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  51. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  52. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  53. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  54. package/cjs/services/migration-service/scripts/index.js +13 -4
  55. package/cjs/services/price-service/coingecko.js +15 -3
  56. package/cjs/services/price-service/index.js +15 -18
  57. package/cjs/services/request-service/constants.js +8 -2
  58. package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
  59. package/cjs/services/request-service/index.js +3 -0
  60. package/cjs/services/storage-service/DatabaseService.js +53 -34
  61. package/cjs/services/storage-service/databases/index.js +1 -1
  62. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  63. package/cjs/services/storage-service/db-stores/Nft.js +8 -18
  64. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  65. package/cjs/services/subscan-service/index.js +107 -0
  66. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  67. package/cjs/services/subscan-service/types.js +1 -0
  68. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  69. package/cjs/services/transaction-service/index.js +66 -22
  70. package/cjs/services/transaction-service/utils.js +4 -6
  71. package/cjs/utils/address.js +9 -1
  72. package/cjs/utils/index.js +30 -26
  73. package/constants/index.d.ts +8 -13
  74. package/constants/index.js +8 -13
  75. package/koni/api/dotsama/balance.d.ts +0 -1
  76. package/koni/api/dotsama/balance.js +33 -197
  77. package/koni/api/dotsama/transfer.js +5 -4
  78. package/koni/api/nft/acala_nft/index.js +3 -1
  79. package/koni/api/nft/bit.country/index.js +3 -1
  80. package/koni/api/nft/evm_nft/index.js +6 -3
  81. package/koni/api/nft/index.d.ts +1 -2
  82. package/koni/api/nft/index.js +3 -6
  83. package/koni/api/nft/karura_nft/index.js +3 -1
  84. package/koni/api/nft/nft.d.ts +1 -0
  85. package/koni/api/nft/rmrk_nft/index.js +8 -1
  86. package/koni/api/nft/statemine_nft/index.js +3 -1
  87. package/koni/api/nft/unique_nft/index.js +5 -1
  88. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  89. package/koni/api/nft/wasm_nft/index.js +167 -109
  90. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  91. package/koni/api/nft/wasm_nft/utils.js +7 -5
  92. package/koni/api/staking/bonding/amplitude.d.ts +1 -2
  93. package/koni/api/staking/bonding/amplitude.js +22 -13
  94. package/koni/api/staking/bonding/astar.d.ts +2 -11
  95. package/koni/api/staking/bonding/astar.js +39 -231
  96. package/koni/api/staking/bonding/index.d.ts +5 -2
  97. package/koni/api/staking/bonding/index.js +27 -17
  98. package/koni/api/staking/bonding/paraChain.d.ts +4 -1
  99. package/koni/api/staking/bonding/paraChain.js +101 -14
  100. package/koni/api/staking/bonding/relayChain.d.ts +6 -2
  101. package/koni/api/staking/bonding/relayChain.js +172 -17
  102. package/koni/api/staking/bonding/utils.d.ts +15 -2
  103. package/koni/api/staking/bonding/utils.js +53 -11
  104. package/koni/api/tokens/wasm/index.js +5 -4
  105. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  106. package/koni/api/tokens/wasm/utils.js +54 -0
  107. package/koni/api/xcm/index.js +1 -112
  108. package/koni/api/xcm/polkadotXcm.js +3 -3
  109. package/koni/api/xcm/utils.d.ts +5 -6
  110. package/koni/api/xcm/utils.js +15 -10
  111. package/koni/api/xcm/xTokens.js +5 -7
  112. package/koni/api/xcm/xcmPallet.js +10 -9
  113. package/koni/background/cron.d.ts +6 -1
  114. package/koni/background/cron.js +179 -76
  115. package/koni/background/handlers/Extension.d.ts +2 -2
  116. package/koni/background/handlers/Extension.js +161 -125
  117. package/koni/background/handlers/State.d.ts +21 -20
  118. package/koni/background/handlers/State.js +144 -111
  119. package/koni/background/handlers/Tabs.js +30 -20
  120. package/koni/background/subscription.d.ts +1 -1
  121. package/koni/background/subscription.js +64 -58
  122. package/package.json +63 -18
  123. package/packageInfo.js +1 -1
  124. package/page/index.d.ts +2 -0
  125. package/page/index.js +4 -0
  126. package/services/chain-service/constants.d.ts +0 -1
  127. package/services/chain-service/constants.js +0 -9
  128. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  129. package/services/chain-service/handler/light-client/index.d.ts +17 -1
  130. package/services/chain-service/handler/light-client/index.js +1 -1
  131. package/services/chain-service/helper/psp22_abi.json +1041 -881
  132. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  133. package/services/chain-service/index.d.ts +6 -4
  134. package/services/chain-service/index.js +40 -9
  135. package/services/chain-service/utils.d.ts +1 -0
  136. package/services/chain-service/utils.js +3 -0
  137. package/services/event-service/index.d.ts +22 -0
  138. package/services/event-service/index.js +63 -0
  139. package/services/event-service/types.d.ts +28 -0
  140. package/services/event-service/types.js +4 -0
  141. package/services/history-service/index.d.ts +5 -3
  142. package/services/history-service/index.js +46 -21
  143. package/services/history-service/subsquid-multi-chain-history.js +22 -13
  144. package/services/keyring-service/index.d.ts +19 -0
  145. package/services/keyring-service/index.js +93 -0
  146. package/services/migration-service/index.js +11 -9
  147. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  148. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  149. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  150. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  151. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  152. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  153. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  154. package/services/migration-service/scripts/index.d.ts +1 -0
  155. package/services/migration-service/scripts/index.js +10 -3
  156. package/services/price-service/coingecko.js +15 -3
  157. package/services/price-service/index.d.ts +5 -3
  158. package/services/price-service/index.js +15 -18
  159. package/services/request-service/constants.d.ts +1 -0
  160. package/services/request-service/constants.js +6 -1
  161. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  162. package/services/request-service/handler/AuthRequestHandler.js +44 -13
  163. package/services/request-service/index.d.ts +7 -1
  164. package/services/request-service/index.js +3 -0
  165. package/services/storage-service/DatabaseService.d.ts +1 -0
  166. package/services/storage-service/DatabaseService.js +53 -34
  167. package/services/storage-service/databases/index.js +1 -1
  168. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  169. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  170. package/services/storage-service/db-stores/Nft.d.ts +3 -3
  171. package/services/storage-service/db-stores/Nft.js +8 -17
  172. package/services/storage-service/db-stores/Transaction.js +10 -7
  173. package/services/subscan-service/index.d.ts +20 -0
  174. package/services/subscan-service/index.js +99 -0
  175. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  176. package/services/subscan-service/subscan-chain-map.js +63 -0
  177. package/services/subscan-service/types.d.ts +27 -0
  178. package/services/subscan-service/types.js +1 -0
  179. package/services/transaction-service/event-parser/index.d.ts +2 -2
  180. package/services/transaction-service/event-parser/index.js +21 -49
  181. package/services/transaction-service/index.d.ts +4 -2
  182. package/services/transaction-service/index.js +66 -22
  183. package/services/transaction-service/utils.js +5 -6
  184. package/utils/address.d.ts +1 -0
  185. package/utils/address.js +9 -2
  186. package/utils/index.d.ts +2 -1
  187. package/utils/index.js +26 -23
  188. package/cjs/background/errors/EvmRpcError.js +0 -21
  189. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  190. package/cjs/constants/ethereum.js +0 -19
  191. package/cjs/errors/SubWalletProviderError.js +0 -17
  192. package/cjs/koni/api/xcm/astar.js +0 -160
  193. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  194. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  195. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  196. package/cjs/koni/migration/Base.js +0 -20
  197. package/cjs/koni/migration/index.js +0 -45
  198. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  199. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  200. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  201. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  202. package/cjs/koni/migration/scripts/index.js +0 -22
  203. package/cjs/koni/page/index.js +0 -16
  204. package/cjs/services/asset-service/index.js +0 -91
  205. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  206. package/cjs/stores/Balance.js +0 -18
  207. package/cjs/stores/Crowdloan.js +0 -18
  208. package/cjs/stores/CustomEvmToken.js +0 -18
  209. package/cjs/stores/NetworkMap.js +0 -18
  210. package/cjs/stores/Nft.js +0 -18
  211. package/cjs/stores/NftCollection.js +0 -18
  212. package/cjs/stores/Price.js +0 -18
  213. package/cjs/stores/Staking.js +0 -18
  214. package/cjs/stores/StakingReward.js +0 -18
  215. package/cjs/utils/eth/parseTransactionData.js +0 -284
  216. package/koni/page/index.d.ts +0 -2
  217. package/koni/page/index.js +0 -9
  218. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  219. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  220. /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
@@ -7,12 +7,12 @@ import { ASTAR_REFRESH_BALANCE_INTERVAL, SUB_TOKEN_REFRESH_BALANCE_INTERVAL } fr
7
7
  import { getEVMBalance } from '@subwallet/extension-base/koni/api/tokens/evm/balance';
8
8
  import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
9
9
  import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
10
+ import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
10
11
  import { state } from '@subwallet/extension-base/koni/background/handlers';
11
- import { _BALANCE_CHAIN_GROUP, _BALANCE_TOKEN_GROUP, _PURE_EVM_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
12
- import { _checkSmartContractSupportByChain, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isNativeToken, _isPureEvmChain, _isSmartContractToken, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
12
+ import { _BALANCE_CHAIN_GROUP, _PURE_EVM_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
13
+ import { _checkSmartContractSupportByChain, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isPureEvmChain, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
13
14
  import { categoryAddresses, sumBN } from '@subwallet/extension-base/utils';
14
15
  import { BN, BN_ZERO } from '@polkadot/util';
15
- import { isEthereumAddress } from '@polkadot/util-crypto';
16
16
  // main subscription
17
17
  export function subscribeBalance(addresses, chainInfoMap, substrateApiMap, evmApiMap, callback) {
18
18
  const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
@@ -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;
@@ -84,11 +95,16 @@ async function subscribeWithSystemAccountPallet(addresses, chainInfo, networkAPI
84
95
  let pooledStakingBalance = BN_ZERO;
85
96
  if (_isSubstrateRelayChain(chainInfo) && networkAPI.query.nominationPools) {
86
97
  const poolMemberDatas = await networkAPI.query.nominationPools.poolMembers.multi(addresses);
87
- for (const _poolMemberData of poolMemberDatas) {
88
- const poolMemberData = _poolMemberData.toPrimitive();
89
- if (poolMemberData) {
90
- const pooledBalance = new BN(poolMemberData.points.toString());
91
- pooledStakingBalance = pooledStakingBalance.add(pooledBalance);
98
+ if (poolMemberDatas) {
99
+ for (const _poolMemberData of poolMemberDatas) {
100
+ const poolMemberData = _poolMemberData.toPrimitive();
101
+ if (poolMemberData) {
102
+ const pooledBalance = new BN(poolMemberData.points.toString());
103
+ pooledStakingBalance = pooledStakingBalance.add(pooledBalance);
104
+ Object.entries(poolMemberData.unbondingEras).forEach(([, amount]) => {
105
+ pooledStakingBalance = pooledStakingBalance.add(new BN(amount));
106
+ });
107
+ }
92
108
  }
93
109
  }
94
110
  }
@@ -109,7 +125,7 @@ async function subscribeWithSystemAccountPallet(addresses, chainInfo, networkAPI
109
125
  const free = total.sub(locked);
110
126
  callBack({
111
127
  tokenSlug: chainNativeTokenSlug,
112
- free: free.toString(),
128
+ free: free.gte(BN_ZERO) ? free.toString() : '0',
113
129
  locked: locked.toString(),
114
130
  state: APIItemState.READY,
115
131
  substrateInfo: {
@@ -123,79 +139,6 @@ async function subscribeWithSystemAccountPallet(addresses, chainInfo, networkAPI
123
139
  unsub();
124
140
  };
125
141
  }
126
-
127
- // deprecated
128
- // function subscribeDarwiniaBalance (addresses: string[], chainInfo: _ChainInfo, chain: string, networkAPI: ApiPromise, callBack: (rs: BalanceItem) => void) {
129
- // const tokenMap = state.getAssetByChainAndAsset(chain, [_AssetType.LOCAL]);
130
- // const nativeTokenSlug = _getChainNativeTokenSlug(chainInfo);
131
- //
132
- // let totalBalance: BN = new BN(0);
133
- // let freeBalance: BN = new BN(0);
134
- // let miscFrozen: BN = new BN(0);
135
- // let reservedKtonBalance: BN = new BN(0);
136
- // let totalKtonBalance: BN = new BN(0);
137
- //
138
- // const unsubProms = addresses.map((address) => {
139
- // return networkAPI.derive.balances?.all(address, async (balance: DeriveBalancesAll) => {
140
- // // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
141
- // freeBalance = freeBalance.add(balance.availableBalance?.toBn() || new BN(0));
142
- // miscFrozen = miscFrozen.add(balance.lockedBalance?.toBn() || new BN(0));
143
- // totalBalance = totalBalance.add(balance.freeBalance?.toBn() || new BN(0));
144
- //
145
- // const _systemBalance = await networkAPI.query.system.account(address);
146
- // const systemBalance = _systemBalance.toHuman() as unknown as AccountInfo;
147
- //
148
- // // @ts-ignore
149
- // const rawTotalKton = (systemBalance.data?.freeKton as string).replaceAll(',', '');
150
- // // @ts-ignore
151
- // const rawReservedKton = (systemBalance.data?.reservedKton as string).replaceAll(',', '');
152
- //
153
- // // @ts-ignore
154
- // // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
155
- // totalKtonBalance = totalKtonBalance.add(new BN(rawTotalKton) || new BN(0));
156
- // // @ts-ignore
157
- // // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
158
- // reservedKtonBalance = reservedKtonBalance.add(new BN(rawReservedKton) || new BN(0));
159
- //
160
- // if (Object.keys(tokenMap).length > 1) {
161
- // for (const tokenInfo of Object.values(tokenMap)) {
162
- // if (_BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
163
- // const freeKton = totalKtonBalance.sub(reservedKtonBalance);
164
- //
165
- // callBack({
166
- // free: freeKton.toString(),
167
- // locked: reservedKtonBalance.toString(),
168
- // state: APIItemState.READY,
169
- // tokenSlug: tokenInfo.slug
170
- // });
171
- // break;
172
- // }
173
- // }
174
- // }
175
- //
176
- // const free = totalBalance.sub(miscFrozen);
177
- //
178
- // callBack({
179
- // tokenSlug: nativeTokenSlug,
180
- // free: free.toString(),
181
- // locked: miscFrozen.toString(),
182
- // state: APIItemState.READY,
183
- // substrateInfo: {
184
- // miscFrozen: miscFrozen.toString()
185
- // }
186
- // });
187
- // });
188
- // });
189
- //
190
- // return () => {
191
- // Promise.all(unsubProms).then((unsubs) => {
192
- // unsubs.forEach((unsub) => {
193
- // unsub && unsub();
194
- // });
195
- // }).catch(console.error);
196
- // };
197
- // }
198
-
199
142
  function subscribeERC20Interval(addresses, chain, evmApiMap, callBack) {
200
143
  let tokenList = {};
201
144
  const erc20ContractMap = {};
@@ -239,10 +182,12 @@ function subscribePSP22Balance(addresses, chain, api, callBack) {
239
182
  try {
240
183
  const contract = psp22ContractMap[tokenInfo.slug];
241
184
  const balances = await Promise.all(addresses.map(async address => {
185
+ var _balanceOf$output;
242
186
  const _balanceOf = await contract.query['psp22::balanceOf'](address, {
243
- gasLimit: -1
187
+ gasLimit: getDefaultWeightV2(api)
244
188
  }, address);
245
- return _balanceOf.output ? _balanceOf.output.toString() : '0';
189
+ const balanceObj = _balanceOf === null || _balanceOf === void 0 ? void 0 : (_balanceOf$output = _balanceOf.output) === null || _balanceOf$output === void 0 ? void 0 : _balanceOf$output.toPrimitive();
190
+ return _balanceOf.output ? balanceObj.ok || balanceObj.Ok : '0';
246
191
  }));
247
192
  free = sumBN(balances.map(bal => new BN(bal || 0)));
248
193
  callBack({
@@ -252,10 +197,11 @@ function subscribePSP22Balance(addresses, chain, api, callBack) {
252
197
  state: APIItemState.READY
253
198
  });
254
199
  } catch (err) {
255
- console.log('There is a problem fetching ' + tokenInfo.slug + ' PSP-22 token balance', err);
200
+ console.warn('Problem fetching ' + tokenInfo.slug + ' PSP-22 token balance', err); // TODO: error createType
256
201
  }
257
202
  });
258
203
  };
204
+
259
205
  tokenList = state.getAssetByChainAndAsset(chain, [_AssetType.PSP22]);
260
206
  Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
261
207
  psp22ContractMap[slug] = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
@@ -385,11 +331,11 @@ async function subscribeAssetsAccountPallet(addresses, chain, api, callBack) {
385
331
  balances.forEach(b => {
386
332
  // @ts-ignore
387
333
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
388
- const bdata = b === null || b === void 0 ? void 0 : b.toJSON();
334
+ const bdata = b === null || b === void 0 ? void 0 : b.toHuman();
389
335
  if (bdata) {
390
336
  // @ts-ignore
391
337
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
392
- const addressBalance = new BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance) || '0');
338
+ const addressBalance = new BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
393
339
 
394
340
  // @ts-ignore
395
341
  if (bdata !== null && bdata !== void 0 && bdata.isFrozen) {
@@ -443,114 +389,4 @@ export function subscribeEVMBalance(chain, addresses, evmApiMap, callback, token
443
389
  clearInterval(interval);
444
390
  unsub2 && unsub2();
445
391
  };
446
- }
447
- export async function getFreeBalance(chain, address, substrateApiMap, evmApiMap, tokenSlug) {
448
- const substrateApi = await substrateApiMap[chain].isReady;
449
- const api = substrateApi.api;
450
- const web3Api = evmApiMap[chain];
451
- const tokenInfo = tokenSlug ? state.getAssetBySlug(tokenSlug) : state.getNativeTokenInfo(chain);
452
- const chainInfo = state.getChainInfo(chain);
453
-
454
- // Only EVM Address use with EVM network
455
- if (Boolean(web3Api || _isChainEvmCompatible(chainInfo)) !== isEthereumAddress(address)) {
456
- if (!isEthereumAddress(address)) {
457
- return '0';
458
- }
459
- }
460
-
461
- // web3Api support mean isEthereum Network support
462
- if (web3Api) {
463
- if (_isNativeToken(tokenInfo)) {
464
- var _web3Api$api;
465
- return (await ((_web3Api$api = web3Api.api) === null || _web3Api$api === void 0 ? void 0 : _web3Api$api.eth.getBalance(address))) || '0';
466
- } else {
467
- if (_getContractAddressOfToken(tokenInfo).length > 0) {
468
- return '0';
469
- }
470
- const contract = getERC20Contract(chain, _getContractAddressOfToken(tokenInfo), evmApiMap);
471
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
472
- const free = await contract.methods.balanceOf(address).call();
473
-
474
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
475
- return (free === null || free === void 0 ? void 0 : free.toString()) || '0';
476
- }
477
- } else {
478
- var _balance$availableBal, _balance$availableBal2;
479
- if (tokenSlug) {
480
- if (_isSmartContractToken(tokenInfo)) {
481
- if (_getContractAddressOfToken(tokenInfo).length > 0) {
482
- return '0';
483
- }
484
- const contractPromise = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
485
- const balanceOf = await contractPromise.query['psp22::balanceOf'](address, {
486
- gasLimit: -1
487
- }, address);
488
- return balanceOf.output ? balanceOf.output.toString() : '0';
489
- } else if (_BALANCE_CHAIN_GROUP.genshiro.includes(chain)) {
490
- var _balance$asPositive;
491
- const onChainInfo = _getTokenOnChainInfo(tokenInfo);
492
- const balance = await api.query.eqBalances.account(address, onChainInfo);
493
-
494
- // @ts-ignore
495
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
496
- return ((_balance$asPositive = balance.asPositive) === null || _balance$asPositive === void 0 ? void 0 : _balance$asPositive.toString()) || '0';
497
- } else if (_BALANCE_CHAIN_GROUP.equilibrium_parachain.includes(chain)) {
498
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
499
- const balance = await api.query.system.account(address);
500
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
501
- const balancesData = JSON.parse(balance.data.toString());
502
- const balanceList = balancesData.v0.balance;
503
- let freeTokenBalance;
504
- const assetId = _getTokenOnChainAssetId(tokenInfo);
505
- if (!_isNativeToken(tokenInfo)) {
506
- // @ts-ignore
507
- freeTokenBalance = balanceList.find(data => data[0] === assetId);
508
- } else {
509
- freeTokenBalance = balanceList[0];
510
- }
511
- return freeTokenBalance ? freeTokenBalance[1].positive.toString() : '0';
512
- } else if (_BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
513
- var _balance$data5, _balance$data5$freeKt;
514
- // @ts-ignore
515
- const balance = await api.query.system.account(address);
516
- return ((_balance$data5 = balance.data) === null || _balance$data5 === void 0 ? void 0 : (_balance$data5$freeKt = _balance$data5.freeKton) === null || _balance$data5$freeKt === void 0 ? void 0 : _balance$data5$freeKt.toString()) || '0';
517
- } else if (!_isNativeToken(tokenInfo) && _BALANCE_CHAIN_GROUP.statemine.includes(chain)) {
518
- var _balanceInfo$balance;
519
- const assetId = _getTokenOnChainAssetId(tokenInfo);
520
- const balanceInfo = (await api.query.assets.account(assetId, address)).toHuman();
521
-
522
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
523
- return (balanceInfo === null || balanceInfo === void 0 ? void 0 : (_balanceInfo$balance = balanceInfo.balance) === null || _balanceInfo$balance === void 0 ? void 0 : _balanceInfo$balance.replaceAll(',', '')) || '0';
524
- } else if (!_isNativeToken(tokenInfo) || _BALANCE_CHAIN_GROUP.kintsugi.includes(chain)) {
525
- var _balance$free;
526
- const onChainInfo = _getTokenOnChainInfo(tokenInfo);
527
- // @ts-ignore
528
- const balance = await api.query.tokens.accounts(address, onChainInfo);
529
- return ((_balance$free = balance.free) === null || _balance$free === void 0 ? void 0 : _balance$free.toString()) || '0';
530
- }
531
- }
532
- if (_BALANCE_CHAIN_GROUP.kusama.includes(chain)) {
533
- var _balance$data6, _balance$data7;
534
- // @ts-ignore
535
- const _balance = await api.query.system.account(address);
536
-
537
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
538
- const balance = _balance.toHuman();
539
-
540
- // @ts-ignore
541
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
542
- const freeBalance = new BN((_balance$data6 = balance.data) === null || _balance$data6 === void 0 ? void 0 : _balance$data6.free.replaceAll(',', ''));
543
-
544
- // @ts-ignore
545
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
546
- const miscFrozen = new BN((_balance$data7 = balance.data) === null || _balance$data7 === void 0 ? void 0 : _balance$data7.miscFrozen.replaceAll(',', ''));
547
- const transferable = freeBalance.sub(miscFrozen);
548
-
549
- // @ts-ignore
550
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
551
- return transferable.toString() || '0';
552
- }
553
- const balance = await api.derive.balances.all(address);
554
- return ((_balance$availableBal = balance.availableBalance) === null || _balance$availableBal === void 0 ? void 0 : (_balance$availableBal2 = _balance$availableBal.toBn()) === null || _balance$availableBal2 === void 0 ? void 0 : _balance$availableBal2.toString()) || '0';
555
- }
556
392
  }
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
5
+ import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
5
6
  import { _BALANCE_TOKEN_GROUP, _TRANSFER_CHAIN_GROUP, _TRANSFER_NOT_SUPPORTED_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
6
7
  import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isChainEvmCompatible, _isNativeToken, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
7
8
  import { BN } from '@polkadot/util';
@@ -104,10 +105,10 @@ export const createTransferExtrinsic = async ({
104
105
 
105
106
  if (_isTokenWasmSmartContract(tokenInfo) && api.query.contracts) {
106
107
  const contractPromise = getPSP22ContractPromise(api, _getContractAddressOfToken(tokenInfo));
107
- const transferQuery = await contractPromise.query['psp22::transfer'](from, {
108
- gasLimit: -1
109
- }, to, value, {});
110
- const gasLimit = transferQuery.gasRequired.toString();
108
+ // @ts-ignore
109
+ const gasLimit = await getWasmContractGasLimit(api, from, 'psp22::transfer', contractPromise, {}, [from, value, {}]);
110
+
111
+ // @ts-ignore
111
112
  transfer = contractPromise.tx['psp22::transfer']({
112
113
  gasLimit
113
114
  }, to, value, {});
@@ -110,8 +110,10 @@ export class AcalaNftApi extends BaseNftApi {
110
110
  };
111
111
  params.updateItem(this.chain, parsedNft, address);
112
112
  params.updateCollection(this.chain, parsedCollection);
113
- // params.updateReady(true);
114
113
  }));
114
+ Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
115
+ params.cleanUpNfts(this.chain, address, collectionId, nftIds);
116
+ });
115
117
  } catch (e) {
116
118
  console.error('Failed to fetch acala nft', e);
117
119
  }
@@ -107,8 +107,10 @@ export class BitCountryNftApi extends BaseNftApi {
107
107
  };
108
108
  params.updateItem(this.chain, parsedNft, address);
109
109
  params.updateCollection(this.chain, parsedCollection);
110
- // params.updateReady(true);
111
110
  }));
111
+ Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
112
+ params.cleanUpNfts(this.chain, address, collectionId, nftIds);
113
+ });
112
114
  } catch (e) {
113
115
  console.error('Failed to fetch bit.country nft', e);
114
116
  }
@@ -75,6 +75,7 @@ export class EvmNftApi extends BaseNftApi {
75
75
  const contract = new this.evmApi.api.eth.Contract(_ERC721_ABI, smartContract);
76
76
  let ownItem = false;
77
77
  let collectionImage;
78
+ const nftOwnerMap = {};
78
79
  await Promise.all(this.addresses.map(async address => {
79
80
  if (!isEthereumAddress(address)) {
80
81
  return;
@@ -125,8 +126,9 @@ export class EvmNftApi extends BaseNftApi {
125
126
  }
126
127
  }
127
128
  }));
129
+ nftOwnerMap[address] = nftIds;
128
130
  } catch (e) {
129
- console.error('evm nft error', e);
131
+ console.error('EVM NFT error', e);
130
132
  }
131
133
  }));
132
134
  if (ownItem) {
@@ -138,10 +140,11 @@ export class EvmNftApi extends BaseNftApi {
138
140
  originAsset: tokenInfo.slug
139
141
  };
140
142
  nftParams.updateCollection(this.chain, nftCollection);
141
- // nftParams.updateReady(true);
143
+ Object.entries(nftOwnerMap).forEach(([owner, nftIds]) => {
144
+ nftParams.cleanUpNfts(this.chain, owner, smartContract, nftIds);
145
+ });
142
146
  }
143
147
  }
144
-
145
148
  async handleNfts(params) {
146
149
  if (!this.evmContracts || this.evmContracts.length === 0) {
147
150
  return;
@@ -17,6 +17,5 @@ export declare class NftHandler {
17
17
  setAddresses(addresses: string[]): void;
18
18
  private setupNftContracts;
19
19
  private setupApi;
20
- handleNfts(nftContracts: _ChainAsset[], updateItem: (chain: string, data: NftItem, owner: string) => void, updateCollection: (chain: string, data: NftCollection) => void): Promise<void>;
21
- parseAssetId(id: string): string;
20
+ handleNfts(nftContracts: _ChainAsset[], updateItem: (chain: string, data: NftItem, owner: string) => void, updateCollection: (chain: string, data: NftCollection) => void, cleanUpNfts: (chain: string, owner: string, collectionId: string, nftIds: string[]) => void): Promise<void>;
22
21
  }
@@ -124,18 +124,15 @@ export class NftHandler {
124
124
  console.error('error setting up nft handlers', e);
125
125
  }
126
126
  }
127
- async handleNfts(nftContracts, updateItem, updateCollection) {
127
+ async handleNfts(nftContracts, updateItem, updateCollection, cleanUpNfts) {
128
128
  this.setupApi();
129
129
  this.setupNftContracts(nftContracts);
130
130
  await Promise.all(this.handlers.map(async handler => {
131
131
  await handler.fetchNfts({
132
132
  updateItem,
133
- updateCollection
133
+ updateCollection,
134
+ cleanUpNfts
134
135
  });
135
136
  }));
136
137
  }
137
- parseAssetId(id) {
138
- const numberId = parseInt(id);
139
- return numberId.toString();
140
- }
141
138
  }
@@ -114,8 +114,10 @@ export class KaruraNftApi extends BaseNftApi {
114
114
  };
115
115
  params.updateItem(this.chain, parsedNft, address);
116
116
  params.updateCollection(this.chain, parsedCollection);
117
- // params.updateReady(true);
118
117
  }));
118
+ Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
119
+ params.cleanUpNfts(this.chain, address, collectionId, nftIds);
120
+ });
119
121
  } catch (e) {
120
122
  console.error('Failed to fetch karura nft', e);
121
123
  }
@@ -3,6 +3,7 @@ import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain
3
3
  export interface HandleNftParams {
4
4
  updateItem: (chain: string, data: NftItem, owner: string) => void;
5
5
  updateCollection: (chain: string, data: NftCollection) => void;
6
+ cleanUpNfts: (chain: string, owner: string, collectionId: string, nftIds: string[]) => void;
6
7
  }
7
8
  export declare abstract class BaseNftApi {
8
9
  chain: string;
@@ -231,8 +231,15 @@ export class RmrkNftApi extends BaseNftApi {
231
231
  image: allCollectionMeta[item.collectionId] ? this.parseUrl(allCollectionMeta[item.collectionId].image) : null,
232
232
  chain: this.chain
233
233
  };
234
+ const nftIds = [];
235
+ allNfts.forEach(nft => {
236
+ const nftCollectionId = nft === null || nft === void 0 ? void 0 : nft.collectionId;
237
+ if (nftCollectionId === item.collectionId) {
238
+ nftIds.push(nft === null || nft === void 0 ? void 0 : nft.id);
239
+ }
240
+ });
234
241
  params.updateCollection(this.chain, parsedCollection);
235
- // params.updateReady(true);
242
+ params.cleanUpNfts(this.chain, address, item.collectionId, nftIds);
236
243
  });
237
244
  } catch (e) {
238
245
  console.error('Failed to fetch rmrk nft', e);
@@ -115,8 +115,10 @@ export default class StatemineNftApi extends BaseNftApi {
115
115
  image: collectionMeta && collectionMeta.image ? this.parseUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image) : undefined
116
116
  };
117
117
  params.updateCollection(this.chain, parsedCollection);
118
- // params.updateReady(true);
119
118
  }));
119
+ Object.entries(collectionNftIds).forEach(([collectionId, nftIds]) => {
120
+ params.cleanUpNfts(this.chain, address, collectionId, nftIds);
121
+ });
120
122
  } catch (e) {
121
123
  console.error('Failed to fetch statemine nft', e);
122
124
  }
@@ -133,6 +133,7 @@ export default class UniqueNftApi extends BaseNftApi {
133
133
  }
134
134
  }
135
135
  }));
136
+ const nftCollectionMap = {};
136
137
  await Promise.all(allCollectionId.map(async collectionId => {
137
138
  const collectionIdStr = collectionId.toString();
138
139
 
@@ -140,6 +141,7 @@ export default class UniqueNftApi extends BaseNftApi {
140
141
  const collection = (await this.substrateApi.api.query.nft.collectionById(collectionId)).toJSON();
141
142
  collectionMap[collectionIdStr] = collection;
142
143
  const nftIds = Object.entries(nftMap).filter(item => item[1] === collectionId).map(item => item[0]);
144
+ nftCollectionMap[collectionIdStr] = nftIds;
143
145
  const parsedCollection = {
144
146
  collectionId: collectionIdStr,
145
147
  chain: this.chain
@@ -166,10 +168,12 @@ export default class UniqueNftApi extends BaseNftApi {
166
168
  }
167
169
  params.updateItem(this.chain, parsedItem, address);
168
170
  params.updateCollection(this.chain, parsedCollection);
169
- // params.updateReady(true);
170
171
  }
171
172
  }));
172
173
  }));
174
+ Object.entries(nftCollectionMap).forEach(([collectionId, nftIds]) => {
175
+ params.cleanUpNfts(this.chain, address, collectionId, nftIds);
176
+ });
173
177
  } catch (e) {
174
178
  console.error('Failed to fetch unique nft', e);
175
179
  }
@@ -8,8 +8,6 @@ export declare class WasmNftApi extends BaseNftApi {
8
8
  private parseFeaturedTokenUri;
9
9
  private parseFeaturedNftImage;
10
10
  private parseFeaturedCollectionImage;
11
- private getCollectionAttributes;
12
- private processOnChainMetadata;
13
11
  private processOffChainMetadata;
14
12
  private getItemsByCollection;
15
13
  fetchNfts(params: HandleNftParams): Promise<number>;