@subwallet/extension-base 1.3.41-0 → 1.3.43-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 (219) hide show
  1. package/background/KoniTypes.d.ts +134 -5
  2. package/background/KoniTypes.js +18 -0
  3. package/background/errors/BitcoinProviderError.d.ts +6 -0
  4. package/background/errors/BitcoinProviderError.js +47 -0
  5. package/background/types.d.ts +1 -1
  6. package/cjs/background/KoniTypes.js +20 -1
  7. package/cjs/background/errors/BitcoinProviderError.js +54 -0
  8. package/cjs/constants/bitcoin.js +22 -0
  9. package/cjs/constants/index.js +16 -1
  10. package/cjs/core/logic-validation/recipientAddress.js +9 -0
  11. package/cjs/core/logic-validation/request.js +316 -3
  12. package/cjs/core/logic-validation/transfer.js +25 -5
  13. package/cjs/core/types.js +1 -0
  14. package/cjs/core/utils.js +15 -1
  15. package/cjs/koni/background/handlers/Extension.js +477 -93
  16. package/cjs/koni/background/handlers/State.js +249 -16
  17. package/cjs/koni/background/handlers/Tabs.js +119 -6
  18. package/cjs/packageInfo.js +1 -1
  19. package/cjs/page/bitcoin/index.js +67 -0
  20. package/cjs/page/index.js +5 -0
  21. package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
  22. package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
  23. package/cjs/services/balance-service/index.js +32 -4
  24. package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
  25. package/cjs/services/balance-service/transfer/token.js +2 -0
  26. package/cjs/services/base/types.js +2 -0
  27. package/cjs/services/buy-service/index.js +17 -2
  28. package/cjs/services/chain-service/constants.js +14 -3
  29. package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
  30. package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
  31. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
  32. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
  33. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
  34. package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
  35. package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  36. package/cjs/services/chain-service/index.js +27 -3
  37. package/cjs/services/chain-service/utils/index.js +57 -4
  38. package/cjs/services/chain-service/utils/patch.js +1 -1
  39. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +27 -5
  40. package/cjs/services/event-service/index.js +4 -0
  41. package/cjs/services/fee-service/service.js +8 -3
  42. package/cjs/services/hiro-service/index.js +96 -0
  43. package/cjs/services/hiro-service/utils/index.js +85 -0
  44. package/cjs/services/history-service/bitcoin-history.js +58 -0
  45. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  46. package/cjs/services/history-service/index.js +41 -3
  47. package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
  48. package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
  49. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  50. package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
  51. package/cjs/services/migration-service/scripts/index.js +3 -1
  52. package/cjs/services/request-service/handler/AuthRequestHandler.js +18 -0
  53. package/cjs/services/request-service/handler/BitcoinRequestHandler.js +427 -0
  54. package/cjs/services/request-service/index.js +29 -3
  55. package/cjs/services/rune-service/index.js +105 -0
  56. package/cjs/services/transaction-service/helpers/index.js +7 -1
  57. package/cjs/services/transaction-service/index.js +206 -16
  58. package/cjs/services/transaction-service/utils.js +6 -3
  59. package/cjs/strategy/api-request-strategy/context/base.js +31 -0
  60. package/cjs/strategy/api-request-strategy/index.js +90 -0
  61. package/cjs/strategy/api-request-strategy/types.js +1 -0
  62. package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
  63. package/cjs/types/account/info/keyring.js +1 -1
  64. package/cjs/types/bitcoin.js +24 -0
  65. package/cjs/types/fee/bitcoin.js +1 -0
  66. package/cjs/types/fee/index.js +11 -0
  67. package/cjs/types/index.js +11 -0
  68. package/cjs/utils/account/analyze.js +3 -3
  69. package/cjs/utils/account/common.js +16 -6
  70. package/cjs/utils/account/derive/info/solo.js +68 -19
  71. package/cjs/utils/account/derive/info/unified.js +2 -0
  72. package/cjs/utils/account/derive/validate.js +70 -2
  73. package/cjs/utils/account/transform.js +11 -5
  74. package/cjs/utils/auth.js +2 -1
  75. package/cjs/utils/bitcoin/common.js +98 -0
  76. package/cjs/utils/bitcoin/fee.js +21 -0
  77. package/cjs/utils/bitcoin/index.js +38 -0
  78. package/cjs/utils/bitcoin/utxo-management.js +281 -0
  79. package/cjs/utils/fee/transfer.js +48 -0
  80. package/cjs/utils/index.js +15 -1
  81. package/constants/bitcoin.d.ts +3 -0
  82. package/constants/bitcoin.js +13 -0
  83. package/constants/index.d.ts +2 -0
  84. package/constants/index.js +3 -1
  85. package/core/logic-validation/recipientAddress.js +10 -1
  86. package/core/logic-validation/request.d.ts +6 -2
  87. package/core/logic-validation/request.js +309 -3
  88. package/core/logic-validation/transfer.d.ts +2 -2
  89. package/core/logic-validation/transfer.js +27 -7
  90. package/core/types.d.ts +1 -0
  91. package/core/types.js +1 -0
  92. package/core/utils.d.ts +1 -0
  93. package/core/utils.js +15 -2
  94. package/koni/background/handlers/Extension.d.ts +5 -0
  95. package/koni/background/handlers/Extension.js +387 -9
  96. package/koni/background/handlers/State.d.ts +10 -3
  97. package/koni/background/handlers/State.js +240 -15
  98. package/koni/background/handlers/Tabs.d.ts +7 -2
  99. package/koni/background/handlers/Tabs.js +119 -9
  100. package/package.json +149 -8
  101. package/packageInfo.js +1 -1
  102. package/page/bitcoin/index.d.ts +17 -0
  103. package/page/bitcoin/index.js +60 -0
  104. package/page/index.d.ts +2 -1
  105. package/page/index.js +4 -0
  106. package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
  107. package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
  108. package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
  109. package/services/balance-service/helpers/subscribe/index.js +20 -8
  110. package/services/balance-service/index.d.ts +2 -0
  111. package/services/balance-service/index.js +32 -4
  112. package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
  113. package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
  114. package/services/balance-service/transfer/cardano-transfer.d.ts +2 -0
  115. package/services/balance-service/transfer/token.js +2 -0
  116. package/services/base/types.d.ts +2 -0
  117. package/services/base/types.js +2 -0
  118. package/services/buy-service/index.js +17 -2
  119. package/services/chain-service/constants.d.ts +6 -0
  120. package/services/chain-service/constants.js +8 -2
  121. package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
  122. package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
  123. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
  124. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
  125. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
  126. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
  127. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
  128. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
  129. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
  130. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
  131. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
  132. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
  133. package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
  134. package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  135. package/services/chain-service/index.d.ts +3 -0
  136. package/services/chain-service/index.js +31 -5
  137. package/services/chain-service/types.d.ts +20 -0
  138. package/services/chain-service/utils/index.d.ts +4 -0
  139. package/services/chain-service/utils/index.js +50 -4
  140. package/services/chain-service/utils/patch.js +1 -1
  141. package/services/earning-service/handlers/native-staking/para-chain.js +27 -5
  142. package/services/event-service/index.d.ts +3 -0
  143. package/services/event-service/index.js +4 -0
  144. package/services/event-service/types.d.ts +3 -0
  145. package/services/fee-service/service.js +8 -3
  146. package/services/hiro-service/index.d.ts +17 -0
  147. package/services/hiro-service/index.js +88 -0
  148. package/services/hiro-service/utils/index.d.ts +6 -0
  149. package/services/hiro-service/utils/index.js +72 -0
  150. package/services/history-service/bitcoin-history.d.ts +4 -0
  151. package/services/history-service/bitcoin-history.js +52 -0
  152. package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
  153. package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  154. package/services/history-service/index.d.ts +1 -0
  155. package/services/history-service/index.js +42 -4
  156. package/services/keyring-service/context/handlers/Derive.js +2 -2
  157. package/services/keyring-service/context/handlers/Migration.js +2 -2
  158. package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  159. package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
  160. package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
  161. package/services/migration-service/scripts/index.js +3 -1
  162. package/services/request-service/handler/AuthRequestHandler.js +19 -1
  163. package/services/request-service/handler/BitcoinRequestHandler.d.ts +22 -0
  164. package/services/request-service/handler/BitcoinRequestHandler.js +414 -0
  165. package/services/request-service/index.d.ts +8 -2
  166. package/services/request-service/index.js +25 -3
  167. package/services/rune-service/index.d.ts +17 -0
  168. package/services/rune-service/index.js +97 -0
  169. package/services/transaction-service/helpers/index.d.ts +3 -1
  170. package/services/transaction-service/helpers/index.js +5 -0
  171. package/services/transaction-service/index.d.ts +4 -5
  172. package/services/transaction-service/index.js +205 -17
  173. package/services/transaction-service/types.d.ts +13 -2
  174. package/services/transaction-service/utils.js +7 -4
  175. package/strategy/api-request-strategy/context/base.d.ts +15 -0
  176. package/strategy/api-request-strategy/context/base.js +24 -0
  177. package/strategy/api-request-strategy/index.d.ts +15 -0
  178. package/strategy/api-request-strategy/index.js +83 -0
  179. package/strategy/api-request-strategy/types.d.ts +22 -0
  180. package/strategy/api-request-strategy/types.js +1 -0
  181. package/strategy/api-request-strategy/utils/index.d.ts +2 -0
  182. package/strategy/api-request-strategy/utils/index.js +23 -0
  183. package/types/account/info/keyring.d.ts +1 -1
  184. package/types/account/info/keyring.js +1 -1
  185. package/types/balance/index.d.ts +4 -1
  186. package/types/balance/transfer.d.ts +19 -0
  187. package/types/bitcoin.d.ts +93 -0
  188. package/types/bitcoin.js +17 -0
  189. package/types/buy.d.ts +1 -1
  190. package/types/fee/base.d.ts +4 -1
  191. package/types/fee/bitcoin.d.ts +18 -0
  192. package/types/fee/bitcoin.js +1 -0
  193. package/types/fee/index.d.ts +1 -0
  194. package/types/fee/index.js +2 -1
  195. package/types/fee/subscription.d.ts +4 -3
  196. package/types/index.d.ts +1 -0
  197. package/types/index.js +1 -0
  198. package/utils/account/analyze.js +4 -4
  199. package/utils/account/common.d.ts +7 -8
  200. package/utils/account/common.js +16 -6
  201. package/utils/account/derive/info/solo.js +70 -21
  202. package/utils/account/derive/info/unified.js +2 -0
  203. package/utils/account/derive/validate.d.ts +1 -0
  204. package/utils/account/derive/validate.js +68 -1
  205. package/utils/account/transform.d.ts +1 -1
  206. package/utils/account/transform.js +11 -5
  207. package/utils/auth.js +3 -2
  208. package/utils/bitcoin/common.d.ts +22 -0
  209. package/utils/bitcoin/common.js +88 -0
  210. package/utils/bitcoin/fee.d.ts +2 -0
  211. package/utils/bitcoin/fee.js +14 -0
  212. package/utils/bitcoin/index.d.ts +3 -0
  213. package/utils/bitcoin/index.js +6 -0
  214. package/utils/bitcoin/utxo-management.d.ts +33 -0
  215. package/utils/bitcoin/utxo-management.js +266 -0
  216. package/utils/fee/transfer.d.ts +3 -1
  217. package/utils/fee/transfer.js +47 -1
  218. package/utils/index.d.ts +1 -0
  219. package/utils/index.js +6 -3
@@ -8,6 +8,7 @@ exports.filterAssetInfoMap = exports.ChainService = void 0;
8
8
  var _chainList = require("@subwallet/chain-list");
9
9
  var _types = require("@subwallet/chain-list/types");
10
10
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
11
+ var _BitcoinChainHandler = require("@subwallet/extension-base/services/chain-service/handler/bitcoin/BitcoinChainHandler");
11
12
  var _CardanoChainHandler = require("@subwallet/extension-base/services/chain-service/handler/CardanoChainHandler");
12
13
  var _EvmChainHandler = require("@subwallet/extension-base/services/chain-service/handler/EvmChainHandler");
13
14
  var _MantaPrivateHandler = require("@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler");
@@ -30,13 +31,19 @@ var _logger = require("@polkadot/util/logger");
30
31
  const filterChainInfoMap = (data, ignoredChains) => {
31
32
  return Object.fromEntries(Object.entries(data).filter(_ref => {
32
33
  let [slug, info] = _ref;
33
- return !info.bitcoinInfo && !ignoredChains.includes(slug);
34
+ return !ignoredChains.includes(slug);
34
35
  }));
35
36
  };
37
+ // .filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug))
38
+
36
39
  const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet', 'storyPartner_testnet'];
37
40
  const filterAssetInfoMap = (chainInfo, assets, addedChains) => {
38
41
  return Object.fromEntries(Object.entries(assets).filter(_ref2 => {
39
42
  let [, info] = _ref2;
43
+ const isBitcoinChain = (chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo[info.originChain]) && (0, _utils._isChainBitcoinCompatible)(chainInfo[info.originChain]);
44
+ if (isBitcoinChain) {
45
+ return ![_types._AssetType.RUNE, _types._AssetType.BRC20].includes(info.assetType);
46
+ }
40
47
  return chainInfo[info.originChain] || (addedChains === null || addedChains === void 0 ? void 0 : addedChains.includes(info.originChain));
41
48
  }));
42
49
  };
@@ -87,6 +94,7 @@ class ChainService {
87
94
  this.evmChainHandler = new _EvmChainHandler.EvmChainHandler(this);
88
95
  this.tonChainHandler = new _TonChainHandler.TonChainHandler(this);
89
96
  this.cardanoChainHandler = new _CardanoChainHandler.CardanoChainHandler(this);
97
+ this.bitcoinChainHandler = new _BitcoinChainHandler.BitcoinChainHandler(this);
90
98
  this.logger = (0, _logger.logger)('chain-service');
91
99
  }
92
100
  get value() {
@@ -164,6 +172,12 @@ class ChainService {
164
172
  getSubstrateApiMap() {
165
173
  return this.substrateChainHandler.getSubstrateApiMap();
166
174
  }
175
+ getBitcoinApi(slug) {
176
+ return this.bitcoinChainHandler.getApiByChain(slug);
177
+ }
178
+ getBitcoinApiMap() {
179
+ return this.bitcoinChainHandler.getApiMap();
180
+ }
167
181
  getTonApi(slug) {
168
182
  return this.tonChainHandler.getTonApiByChain(slug);
169
183
  }
@@ -849,6 +863,13 @@ class ChainService {
849
863
  });
850
864
  this.cardanoChainHandler.setCardanoApi(chainInfo.slug, chainApi);
851
865
  }
866
+ if (chainInfo.bitcoinInfo !== null && chainInfo.bitcoinInfo !== undefined) {
867
+ const chainApi = await this.bitcoinChainHandler.initApi(chainInfo.slug, endpoint, {
868
+ providerName,
869
+ onUpdateStatus
870
+ });
871
+ this.bitcoinChainHandler.setApi(chainInfo.slug, chainApi);
872
+ }
852
873
  }
853
874
  destroyApiForChain(chainInfo) {
854
875
  if (chainInfo.substrateInfo !== null) {
@@ -863,6 +884,9 @@ class ChainService {
863
884
  if (chainInfo.cardanoInfo !== null) {
864
885
  this.cardanoChainHandler.destroyCardanoApi(chainInfo.slug);
865
886
  }
887
+ if (chainInfo.bitcoinInfo !== null && chainInfo.bitcoinInfo !== undefined) {
888
+ this.bitcoinChainHandler.destroyApi(chainInfo.slug);
889
+ }
866
890
  }
867
891
  async enableChain(chainSlug) {
868
892
  const chainInfo = this.getChainInfoByKey(chainSlug);
@@ -1722,11 +1746,11 @@ class ChainService {
1722
1746
  this.evmChainHandler.recoverApi(slug).catch(console.error);
1723
1747
  }
1724
1748
  async stopAllChainApis() {
1725
- await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep(), this.cardanoChainHandler.sleep()]);
1749
+ await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep(), this.cardanoChainHandler.sleep(), this.bitcoinChainHandler.sleep()]);
1726
1750
  this.stopCheckLatestChainData();
1727
1751
  }
1728
1752
  async resumeAllChainApis() {
1729
- await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp(), this.cardanoChainHandler.wakeUp()]);
1753
+ await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp(), this.cardanoChainHandler.wakeUp(), this.bitcoinChainHandler.wakeUp()]);
1730
1754
  this.checkLatestData();
1731
1755
  }
1732
1756
  initAssetSettings() {
@@ -13,6 +13,7 @@ var _exportNames = {
13
13
  _isPureSubstrateChain: true,
14
14
  _isPureTonChain: true,
15
15
  _isPureCardanoChain: true,
16
+ _isPureBitcoinChain: true,
16
17
  _getOriginChainOfAsset: true,
17
18
  _getContractAddressOfToken: true,
18
19
  _isNativeTokenTransferredByEvm: true,
@@ -21,6 +22,7 @@ var _exportNames = {
21
22
  _isJettonToken: true,
22
23
  _isTokenTransferredByTon: true,
23
24
  _isTokenTransferredByCardano: true,
25
+ _isTokenTransferredByBitcoin: true,
24
26
  _getTokenOnChainAssetId: true,
25
27
  _getTokenOnChainInfo: true,
26
28
  _isBridgedToken: true,
@@ -99,6 +101,7 @@ var _exportNames = {
99
101
  _isAssetCanPayTxFee: true,
100
102
  updateLatestChainInfo: true,
101
103
  _chainInfoToChainType: true,
104
+ _isChainInfoCompatibleWithAccountInfo: true,
102
105
  _getAssetNetuid: true
103
106
  };
104
107
  exports._chainInfoToChainType = void 0;
@@ -151,6 +154,7 @@ exports._isChainBitcoinCompatible = _isChainBitcoinCompatible;
151
154
  exports._isChainCardanoCompatible = _isChainCardanoCompatible;
152
155
  exports._isChainEnabled = _isChainEnabled;
153
156
  exports._isChainEvmCompatible = _isChainEvmCompatible;
157
+ exports._isChainInfoCompatibleWithAccountInfo = void 0;
154
158
  exports._isChainSubstrateCompatible = _isChainSubstrateCompatible;
155
159
  exports._isChainSupportEvmERC20 = _isChainSupportEvmERC20;
156
160
  exports._isChainSupportEvmNft = _isChainSupportEvmNft;
@@ -173,6 +177,7 @@ exports._isMantaZkAsset = _isMantaZkAsset;
173
177
  exports._isNativeToken = _isNativeToken;
174
178
  exports._isNativeTokenBySlug = _isNativeTokenBySlug;
175
179
  exports._isNativeTokenTransferredByEvm = _isNativeTokenTransferredByEvm;
180
+ exports._isPureBitcoinChain = _isPureBitcoinChain;
176
181
  exports._isPureCardanoChain = _isPureCardanoChain;
177
182
  exports._isPureEvmChain = _isPureEvmChain;
178
183
  exports._isPureSubstrateChain = _isPureSubstrateChain;
@@ -185,6 +190,7 @@ exports._isSupportOrdinal = void 0;
185
190
  exports._isTokenEvmSmartContract = _isTokenEvmSmartContract;
186
191
  exports._isTokenGearSmartContract = _isTokenGearSmartContract;
187
192
  exports._isTokenTonSmartContract = _isTokenTonSmartContract;
193
+ exports._isTokenTransferredByBitcoin = _isTokenTransferredByBitcoin;
188
194
  exports._isTokenTransferredByCardano = _isTokenTransferredByCardano;
189
195
  exports._isTokenTransferredByEvm = _isTokenTransferredByEvm;
190
196
  exports._isTokenTransferredByTon = _isTokenTransferredByTon;
@@ -200,6 +206,7 @@ var _types = require("@subwallet/chain-list/types");
200
206
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
201
207
  var _types2 = require("@subwallet/extension-base/services/chain-service/types");
202
208
  var _types3 = require("@subwallet/extension-base/types");
209
+ var _types4 = require("@subwallet/keyring/types");
203
210
  var _utilCrypto = require("@polkadot/util-crypto");
204
211
  var _patch = require("./patch");
205
212
  Object.keys(_patch).forEach(function (key) {
@@ -258,16 +265,19 @@ function _isEqualSmartContractAsset(asset1, asset2) {
258
265
  return false;
259
266
  }
260
267
  function _isPureEvmChain(chainInfo) {
261
- return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
268
+ return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
262
269
  }
263
270
  function _isPureSubstrateChain(chainInfo) {
264
- return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
271
+ return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
265
272
  }
266
273
  function _isPureTonChain(chainInfo) {
267
- return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo && !chainInfo.cardanoInfo;
274
+ return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo && !chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
268
275
  }
269
276
  function _isPureCardanoChain(chainInfo) {
270
- return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !!chainInfo.cardanoInfo;
277
+ return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !!chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
278
+ }
279
+ function _isPureBitcoinChain(chainInfo) {
280
+ return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo && !!chainInfo.bitcoinInfo;
271
281
  }
272
282
  function _getOriginChainOfAsset(assetSlug) {
273
283
  if (assetSlug.startsWith(_types2._CUSTOM_PREFIX)) {
@@ -324,6 +334,11 @@ function _isTokenTransferredByCardano(tokenInfo) {
324
334
  return _isCIP26Token(tokenInfo) || _isNativeToken(tokenInfo);
325
335
  }
326
336
 
337
+ // TODO [Review]: Currently supports transferring only the native token, Bitcoin.
338
+ function _isTokenTransferredByBitcoin(tokenInfo) {
339
+ return _isNativeToken(tokenInfo);
340
+ }
341
+
327
342
  // Utils for balance functions
328
343
  function _getTokenOnChainAssetId(tokenInfo) {
329
344
  var _tokenInfo$metadata5;
@@ -500,6 +515,11 @@ function _getChainNativeTokenBasicInfo(chainInfo) {
500
515
  symbol: chainInfo.cardanoInfo.symbol,
501
516
  decimals: chainInfo.cardanoInfo.decimals
502
517
  };
518
+ } else if (chainInfo.bitcoinInfo) {
519
+ return {
520
+ symbol: chainInfo.bitcoinInfo.symbol,
521
+ decimals: chainInfo.bitcoinInfo.decimals
522
+ };
503
523
  }
504
524
  return defaultTokenInfo;
505
525
  }
@@ -613,6 +633,9 @@ function _getBlockExplorerFromChain(chainInfo) {
613
633
  } else if (_isPureCardanoChain(chainInfo)) {
614
634
  var _chainInfo$cardanoInf;
615
635
  blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$cardanoInf = chainInfo.cardanoInfo) === null || _chainInfo$cardanoInf === void 0 ? void 0 : _chainInfo$cardanoInf.blockExplorer;
636
+ } else if (_isPureBitcoinChain(chainInfo)) {
637
+ var _chainInfo$bitcoinInf;
638
+ blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$bitcoinInf = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf === void 0 ? void 0 : _chainInfo$bitcoinInf.blockExplorer;
616
639
  } else {
617
640
  var _chainInfo$substrateI18;
618
641
  blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.blockExplorer;
@@ -793,6 +816,36 @@ const _chainInfoToChainType = chainInfo => {
793
816
  return _types3.AccountChainType.SUBSTRATE;
794
817
  };
795
818
  exports._chainInfoToChainType = _chainInfoToChainType;
819
+ const _isChainInfoCompatibleWithAccountInfo = (chainInfo, accountChainType, accountType) => {
820
+ if (accountChainType === _types3.AccountChainType.SUBSTRATE) {
821
+ return _isPureSubstrateChain(chainInfo) && _types4.SubstrateKeypairTypes.includes(accountType);
822
+ }
823
+ if (accountChainType === _types3.AccountChainType.ETHEREUM) {
824
+ return _isChainEvmCompatible(chainInfo) && _types4.EthereumKeypairTypes.includes(accountType);
825
+ }
826
+ if (accountChainType === _types3.AccountChainType.TON) {
827
+ return _isChainTonCompatible(chainInfo) && _types4.TonKeypairTypes.includes(accountType);
828
+ }
829
+ if (accountChainType === _types3.AccountChainType.CARDANO) {
830
+ return _isChainCardanoCompatible(chainInfo) && _types4.CardanoKeypairTypes.includes(accountType);
831
+ }
832
+ if (accountChainType === _types3.AccountChainType.BITCOIN) {
833
+ var _chainInfo$bitcoinInf2;
834
+ if (!_isChainBitcoinCompatible(chainInfo) || ![..._types4.BitcoinMainnetKeypairTypes, ..._types4.BitcoinTestnetKeypairTypes].includes(accountType)) {
835
+ return false;
836
+ }
837
+ const network = (_chainInfo$bitcoinInf2 = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf2 === void 0 ? void 0 : _chainInfo$bitcoinInf2.bitcoinNetwork;
838
+ if (_types4.BitcoinMainnetKeypairTypes.includes(accountType)) {
839
+ return network === 'mainnet';
840
+ }
841
+ if (_types4.BitcoinTestnetKeypairTypes.includes(accountType)) {
842
+ return network === 'testnet';
843
+ }
844
+ return false;
845
+ }
846
+ return false;
847
+ };
848
+ exports._isChainInfoCompatibleWithAccountInfo = _isChainInfoCompatibleWithAccountInfo;
796
849
  const _getAssetNetuid = assetInfo => {
797
850
  var _assetInfo$metadata$n, _assetInfo$metadata;
798
851
  // @ts-ignore
@@ -11,7 +11,7 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
11
11
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
12
12
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
13
13
  const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
14
- const ChainListVersion = '0.2.105'; // update this when build chainlist
14
+ const ChainListVersion = '0.2.107'; // update this when build chainlist
15
15
 
16
16
  // todo: move this interface to chainlist
17
17
 
@@ -433,6 +433,10 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
433
433
  const apiPromise = await this.substrateApi.isReady;
434
434
  const binaryAmount = new _util.BN(amount);
435
435
  const selectedCollatorInfo = selectedValidators[0];
436
+ const {
437
+ address: selectedCollatorAddress,
438
+ nominatorCount: selectedCollatorNominatorCount
439
+ } = selectedCollatorInfo;
436
440
 
437
441
  // eslint-disable-next-line @typescript-eslint/require-await
438
442
  const compoundResult = async extrinsic => {
@@ -447,8 +451,17 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
447
451
  }];
448
452
  };
449
453
  if (!positionInfo) {
450
- const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorInfo.address, binaryAmount, new _util.BN(selectedCollatorInfo.nominatorCount), 0);
451
- return compoundResult(extrinsic);
454
+ var _apiPromise$api;
455
+ const isTxSupportedDelegate = !!((_apiPromise$api = apiPromise.api) !== null && _apiPromise$api !== void 0 && _apiPromise$api.tx.parachainStaking.delegate);
456
+ if (isTxSupportedDelegate) {
457
+ const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorAddress, binaryAmount, new _util.BN(selectedCollatorNominatorCount), 0);
458
+ return compoundResult(extrinsic);
459
+ } else {
460
+ var _apiPromise$api$query, _apiPromise$api$query2;
461
+ const autoCompoundingDelegation = await ((_apiPromise$api$query = apiPromise.api.query) === null || _apiPromise$api$query === void 0 ? void 0 : (_apiPromise$api$query2 = _apiPromise$api$query.parachainStaking) === null || _apiPromise$api$query2 === void 0 ? void 0 : _apiPromise$api$query2.autoCompoundingDelegations(selectedCollatorAddress));
462
+ const extrinsic = apiPromise.api.tx.parachainStaking.delegateWithAutoCompound(selectedCollatorAddress, binaryAmount, 100, new _util.BN(selectedCollatorNominatorCount), new _util.BN(autoCompoundingDelegation.length), 0);
463
+ return compoundResult(extrinsic);
464
+ }
452
465
  }
453
466
  const {
454
467
  bondedValidators,
@@ -456,10 +469,19 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
456
469
  } = (0, _utils.getBondedValidators)(positionInfo.nominations);
457
470
  const parsedSelectedCollatorAddress = (0, _utils3.reformatAddress)(selectedCollatorInfo.address, 0);
458
471
  if (!bondedValidators.includes(parsedSelectedCollatorAddress)) {
459
- const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorInfo.address, binaryAmount, new _util.BN(selectedCollatorInfo.nominatorCount), nominationCount);
460
- return compoundResult(extrinsic);
472
+ var _apiPromise$api2;
473
+ const isTxSupportedDelegate = !!((_apiPromise$api2 = apiPromise.api) !== null && _apiPromise$api2 !== void 0 && _apiPromise$api2.tx.parachainStaking.delegate);
474
+ if (isTxSupportedDelegate) {
475
+ const extrinsic = apiPromise.api.tx.parachainStaking.delegate(selectedCollatorAddress, binaryAmount, new _util.BN(selectedCollatorNominatorCount), nominationCount);
476
+ return compoundResult(extrinsic);
477
+ } else {
478
+ var _apiPromise$api$query3, _apiPromise$api$query4;
479
+ const autoCompoundingDelegation = await ((_apiPromise$api$query3 = apiPromise.api.query) === null || _apiPromise$api$query3 === void 0 ? void 0 : (_apiPromise$api$query4 = _apiPromise$api$query3.parachainStaking) === null || _apiPromise$api$query4 === void 0 ? void 0 : _apiPromise$api$query4.autoCompoundingDelegations(selectedCollatorAddress));
480
+ const extrinsic = apiPromise.api.tx.parachainStaking.delegateWithAutoCompound(selectedCollatorAddress, binaryAmount, 100, new _util.BN(selectedCollatorNominatorCount), new _util.BN(autoCompoundingDelegation.length), nominationCount);
481
+ return compoundResult(extrinsic);
482
+ }
461
483
  } else {
462
- const extrinsic = apiPromise.api.tx.parachainStaking.delegatorBondMore(selectedCollatorInfo.address, binaryAmount);
484
+ const extrinsic = apiPromise.api.tx.parachainStaking.delegatorBondMore(selectedCollatorAddress, binaryAmount);
463
485
  return compoundResult(extrinsic);
464
486
  }
465
487
  }
@@ -25,6 +25,10 @@ class EventService extends _eventemitter.default {
25
25
  this.waitDatabaseReady = this.generateWaitPromise('database.ready');
26
26
  this.waitKeyringReady = this.generateWaitPromise('keyring.ready');
27
27
  this.waitAccountReady = this.generateWaitPromise('account.ready');
28
+ this.waitAppInitialized = this.generateWaitPromise('general.init');
29
+ this.waitAppStart = this.generateWaitPromise('general.start');
30
+ this.waitAppStartFull = this.generateWaitPromise('general.start_full');
31
+
28
32
  // TODO: Need to merge logic on web-runner file
29
33
  this.waitInjectReady = _utils.TARGET_ENV === 'webapp' ? this.generateWaitPromise('inject.ready') : Promise.resolve(true);
30
34
  this.waitChainReady = this.generateWaitPromise('chain.ready');
@@ -16,7 +16,8 @@ class FeeService {
16
16
  evm: {},
17
17
  substrate: {},
18
18
  ton: {},
19
- cardano: {}
19
+ cardano: {},
20
+ bitcoin: {}
20
21
  };
21
22
  constructor(state) {
22
23
  this.state = state;
@@ -107,10 +108,9 @@ class FeeService {
107
108
  if (cancel) {
108
109
  clearInterval(interval);
109
110
  } else {
110
- const api = this.state.getEvmApi(chain);
111
-
112
111
  // TODO: Handle case type === evm and not have api
113
112
  if (type === 'evm') {
113
+ const api = this.state.getEvmApi(chain);
114
114
  if (api) {
115
115
  (0, _utils2.calculateGasFeeParams)(api, chain).then(info => {
116
116
  observer.next(info);
@@ -132,6 +132,11 @@ class FeeService {
132
132
  options: undefined
133
133
  });
134
134
  }
135
+ } else if (type === 'bitcoin') {
136
+ const api = this.state.getBitcoinApi(chain);
137
+ api.api.getRecommendedFeeRate().then(info => {
138
+ observer.next(info);
139
+ }).catch(console.error);
135
140
  } else {
136
141
  observer.next({
137
142
  type,
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HiroService = void 0;
7
+ var _SWError = require("@subwallet/extension-base/background/errors/SWError");
8
+ var _constants = require("@subwallet/extension-base/services/chain-service/constants");
9
+ var _apiRequestStrategy = require("@subwallet/extension-base/strategy/api-request-strategy");
10
+ var _base = require("@subwallet/extension-base/strategy/api-request-strategy/context/base");
11
+ var _utils = require("@subwallet/extension-base/strategy/api-request-strategy/utils");
12
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
13
+ // SPDX-License-Identifier: Apache-2.0
14
+
15
+ const BITCOIN_API_URL = 'https://btc-api.koni.studio';
16
+ const BITCOIN_API_URL_TEST = 'https://api-testnet.openbit.app';
17
+ class HiroService extends _apiRequestStrategy.BaseApiRequestStrategy {
18
+ constructor(url) {
19
+ const context = new _base.BaseApiRequestContext();
20
+ super(context);
21
+ this.baseUrl = url;
22
+ }
23
+ headers = {
24
+ 'Content-Type': 'application/json',
25
+ Authorization: `Bearer ${_constants._BTC_SERVICE_TOKEN}`
26
+ };
27
+ isRateLimited() {
28
+ return false;
29
+ }
30
+ getUrl(path) {
31
+ return `${this.baseUrl}/${path}`;
32
+ }
33
+ getBRC20Metadata(ticker) {
34
+ return this.addRequest(async () => {
35
+ const _rs = await (0, _utils.getRequest)(this.getUrl(`brc-20/tokens/${ticker}`), undefined, this.headers);
36
+ const rs = await _rs.json();
37
+ if (rs.status_code !== 200) {
38
+ throw new _SWError.SWError('HiroService.getBRC20Metadata', rs.message);
39
+ }
40
+ return rs.result;
41
+ }, 3);
42
+ }
43
+ getAddressBRC20BalanceInfo(address, params) {
44
+ return this.addRequest(async () => {
45
+ const _rs = await (0, _utils.getRequest)(this.getUrl(`brc-20/balances/${address}`), params, this.headers);
46
+ const rs = await _rs.json();
47
+ if (rs.status_code !== 200) {
48
+ throw new _SWError.SWError('HiroService.getAddressBRC20BalanceInfo', rs.message);
49
+ }
50
+ return rs.result;
51
+ }, 3);
52
+ }
53
+ getAddressInscriptionsInfo(params) {
54
+ return this.addRequest(async () => {
55
+ const _rs = await (0, _utils.getRequest)(this.getUrl('inscriptions'), params, this.headers);
56
+ const rs = await _rs.json();
57
+ if (rs.status_code !== 200) {
58
+ throw new _SWError.SWError('HiroService.getAddressInscriptionsInfo', rs.message);
59
+ }
60
+ return rs.result;
61
+ }, 0);
62
+ }
63
+ getInscriptionContent(inscriptionId) {
64
+ return this.addRequest(async () => {
65
+ const _rs = await (0, _utils.getRequest)(this.getUrl(`inscriptions/${inscriptionId}/content`), undefined, this.headers);
66
+ const rs = await _rs.json();
67
+ if (rs.status_code !== 200) {
68
+ throw new _SWError.SWError('HiroService.getInscriptionContent', rs.message);
69
+ }
70
+ return rs.result;
71
+ }, 0);
72
+ }
73
+
74
+ // todo: handle token authen for url preview
75
+ getPreviewUrl(inscriptionId) {
76
+ return `${BITCOIN_API_URL}/inscriptions/${inscriptionId}/content`;
77
+ }
78
+
79
+ // Singleton
80
+
81
+ static getInstance() {
82
+ let isTestnet = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
83
+ if (isTestnet) {
84
+ if (!HiroService.testnet) {
85
+ HiroService.testnet = new HiroService(BITCOIN_API_URL_TEST);
86
+ }
87
+ return HiroService.testnet;
88
+ } else {
89
+ if (!HiroService.mainnet) {
90
+ HiroService.mainnet = new HiroService(BITCOIN_API_URL);
91
+ }
92
+ return HiroService.mainnet;
93
+ }
94
+ }
95
+ }
96
+ exports.HiroService = HiroService;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAddressInscriptions = getAddressInscriptions;
7
+ exports.getBrc20Metadata = getBrc20Metadata;
8
+ exports.getInscriptionContent = getInscriptionContent;
9
+ exports.getPreviewUrl = getPreviewUrl;
10
+ exports.isValidBrc20Ticker = isValidBrc20Ticker;
11
+ var _hiroService = require("@subwallet/extension-base/services/hiro-service");
12
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
13
+ // SPDX-License-Identifier: Apache-2.0
14
+
15
+ // todo: handle inscription testnet
16
+ async function getBrc20Metadata() {
17
+ let isTestnet = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
18
+ let ticker = arguments.length > 1 ? arguments[1] : undefined;
19
+ const hiroService = _hiroService.HiroService.getInstance(isTestnet);
20
+ const defaultMetadata = {
21
+ ticker: '',
22
+ decimals: 0
23
+ };
24
+ try {
25
+ const response = await hiroService.getBRC20Metadata(ticker);
26
+ const rs = response === null || response === void 0 ? void 0 : response.token;
27
+ if (rs) {
28
+ return {
29
+ ticker: rs.ticker,
30
+ decimals: rs.decimals
31
+ };
32
+ }
33
+ return defaultMetadata;
34
+ } catch (error) {
35
+ console.log(`Error on request brc20 metadata with ticker ${ticker}`);
36
+ return defaultMetadata;
37
+ }
38
+ }
39
+ async function getInscriptionContent(isTestnet, inscriptionId) {
40
+ const hiroService = _hiroService.HiroService.getInstance(isTestnet);
41
+ try {
42
+ return await hiroService.getInscriptionContent(inscriptionId);
43
+ } catch (error) {
44
+ console.log(`Error on request inscription ${inscriptionId} content`);
45
+ return {};
46
+ }
47
+ }
48
+
49
+ // todo: handle large inscriptions
50
+ async function getAddressInscriptions(address, isTestnet) {
51
+ let offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
52
+ let limit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 25;
53
+ const hiroService = _hiroService.HiroService.getInstance(isTestnet);
54
+ try {
55
+ const response = await hiroService.getAddressInscriptionsInfo({
56
+ limit: String(limit),
57
+ offset: String(offset),
58
+ address: String(address)
59
+ });
60
+ return response.results;
61
+ } catch (error) {
62
+ console.error(`Failed to get ${address} inscriptions with offset ${offset} and limit ${limit}`, error);
63
+ throw error;
64
+ }
65
+ }
66
+ function getPreviewUrl(inscriptionId) {
67
+ const hiroService = _hiroService.HiroService.getInstance();
68
+ try {
69
+ return hiroService.getPreviewUrl(inscriptionId);
70
+ } catch (error) {
71
+ console.error(`Failed to get inscription ${inscriptionId} preview url`, error);
72
+ throw error;
73
+ }
74
+ }
75
+ function isValidBrc20Ticker(ticker) {
76
+ const bytesLength = getByteLength(ticker);
77
+ return bytesLength === 4 || bytesLength === 5;
78
+ }
79
+ function getByteLength(str) {
80
+ const encoder = new TextEncoder();
81
+ const encodedStr = encoder.encode(str);
82
+
83
+ // Return the length of the encoded array, which represents the number of bytes
84
+ return encodedStr.length;
85
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseBitcoinTransferData = parseBitcoinTransferData;
7
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
9
+ // SPDX-License-Identifier: Apache-2.0
10
+
11
+ function isSender(address, transferItem) {
12
+ return transferItem.vin.some(i => i.prevout.scriptpubkey_address === address);
13
+ }
14
+ function parseBitcoinTransferData(address, transferItem, chainInfo) {
15
+ var _chainInfo$bitcoinInf, _chainInfo$bitcoinInf2, _transferItem$vin$, _transferItem$vin$$pr, _transferItem$vout$;
16
+ const chainType = _KoniTypes.ChainType.BITCOIN;
17
+ const nativeDecimals = ((_chainInfo$bitcoinInf = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf === void 0 ? void 0 : _chainInfo$bitcoinInf.decimals) || 8;
18
+ const nativeSymbol = ((_chainInfo$bitcoinInf2 = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf2 === void 0 ? void 0 : _chainInfo$bitcoinInf2.symbol) || '';
19
+ const isCurrentAddressSender = isSender(address, transferItem);
20
+ const sender = isCurrentAddressSender ? address : ((_transferItem$vin$ = transferItem.vin[0]) === null || _transferItem$vin$ === void 0 ? void 0 : (_transferItem$vin$$pr = _transferItem$vin$.prevout) === null || _transferItem$vin$$pr === void 0 ? void 0 : _transferItem$vin$$pr.scriptpubkey_address) || '';
21
+ const receiver = isCurrentAddressSender ? ((_transferItem$vout$ = transferItem.vout[0]) === null || _transferItem$vout$ === void 0 ? void 0 : _transferItem$vout$.scriptpubkey_address) || '' : address;
22
+ const amountValue = (() => {
23
+ const targetAddress = isCurrentAddressSender ? receiver : address;
24
+ const vouts = transferItem.vout.filter(i => i.scriptpubkey_address === targetAddress);
25
+ if (vouts.length) {
26
+ return vouts.reduce((total, item) => total + item.value, 0).toString();
27
+ } else {
28
+ return '0';
29
+ }
30
+ })();
31
+ return {
32
+ address,
33
+ origin: 'blockstream',
34
+ time: 0,
35
+ // From api, cannot get time submit transaction
36
+ blockTime: transferItem.status.block_time ? transferItem.status.block_time * 1000 : undefined,
37
+ chainType,
38
+ type: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE,
39
+ extrinsicHash: transferItem.txid,
40
+ chain: chainInfo.slug,
41
+ direction: address === sender ? _KoniTypes.TransactionDirection.SEND : _KoniTypes.TransactionDirection.RECEIVED,
42
+ fee: {
43
+ value: `${transferItem.fee}`,
44
+ decimals: nativeDecimals,
45
+ symbol: nativeSymbol
46
+ },
47
+ from: sender,
48
+ to: receiver,
49
+ blockNumber: transferItem.status.block_height || 0,
50
+ blockHash: transferItem.status.block_hash || '',
51
+ amount: {
52
+ value: amountValue,
53
+ decimals: nativeDecimals,
54
+ symbol: nativeSymbol
55
+ },
56
+ status: transferItem.status.confirmed ? _KoniTypes.ExtrinsicStatus.SUCCESS : _KoniTypes.ExtrinsicStatus.PROCESSING
57
+ };
58
+ }