@subwallet/extension-base 1.3.40-0 → 1.3.42-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 (232) hide show
  1. package/background/KoniTypes.d.ts +121 -4
  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/cjs/background/KoniTypes.js +20 -1
  6. package/cjs/background/errors/BitcoinProviderError.js +54 -0
  7. package/cjs/constants/bitcoin.js +22 -0
  8. package/cjs/constants/environment.js +4 -2
  9. package/cjs/constants/index.js +16 -1
  10. package/cjs/core/logic-validation/recipientAddress.js +9 -0
  11. package/cjs/core/logic-validation/transfer.js +25 -5
  12. package/cjs/core/types.js +1 -0
  13. package/cjs/core/utils.js +15 -1
  14. package/cjs/koni/background/handlers/Extension.js +96 -41
  15. package/cjs/koni/background/handlers/State.js +52 -11
  16. package/cjs/packageInfo.js +1 -1
  17. package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
  18. package/cjs/services/balance-service/helpers/subscribe/evm.js +6 -1
  19. package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
  20. package/cjs/services/balance-service/index.js +32 -4
  21. package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
  22. package/cjs/services/balance-service/transfer/token.js +2 -0
  23. package/cjs/services/balance-service/transfer/xcm/index.js +15 -9
  24. package/cjs/services/balance-service/transfer/xcm/utils.js +12 -14
  25. package/cjs/services/base/types.js +2 -0
  26. package/cjs/services/chain-service/constants.js +18 -6
  27. package/cjs/services/chain-service/handler/CardanoApi.js +25 -35
  28. package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
  29. package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
  30. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
  31. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
  32. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
  33. package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
  34. package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  35. package/cjs/services/chain-service/index.js +27 -3
  36. package/cjs/services/chain-service/utils/index.js +57 -4
  37. package/cjs/services/chain-service/utils/patch.js +1 -1
  38. package/cjs/services/earning-service/handlers/native-staking/tao.js +4 -38
  39. package/cjs/services/event-service/index.js +4 -0
  40. package/cjs/services/fee-service/service.js +8 -3
  41. package/cjs/services/hiro-service/index.js +96 -0
  42. package/cjs/services/hiro-service/utils/index.js +85 -0
  43. package/cjs/services/history-service/bitcoin-history.js +58 -0
  44. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  45. package/cjs/services/history-service/index.js +41 -3
  46. package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
  47. package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
  48. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  49. package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
  50. package/cjs/services/migration-service/scripts/index.js +3 -1
  51. package/cjs/services/request-service/handler/BitcoinRequestHandler.js +440 -0
  52. package/cjs/services/request-service/index.js +29 -3
  53. package/cjs/services/rune-service/index.js +105 -0
  54. package/cjs/services/swap-service/handler/chainflip-handler.js +29 -18
  55. package/cjs/services/swap-service/handler/kyber-handler.js +5 -9
  56. package/cjs/services/swap-service/handler/simpleswap-handler.js +4 -7
  57. package/cjs/services/swap-service/handler/uniswap-handler.js +5 -12
  58. package/cjs/services/swap-service/utils.js +46 -37
  59. package/cjs/services/transaction-service/helpers/index.js +7 -1
  60. package/cjs/services/transaction-service/index.js +136 -15
  61. package/cjs/services/transaction-service/utils.js +6 -3
  62. package/cjs/strategy/api-request-strategy/context/base.js +31 -0
  63. package/cjs/strategy/api-request-strategy/index.js +90 -0
  64. package/cjs/strategy/api-request-strategy/types.js +1 -0
  65. package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
  66. package/cjs/types/account/info/keyring.js +1 -1
  67. package/cjs/types/bitcoin.js +24 -0
  68. package/cjs/types/environment.js +19 -0
  69. package/cjs/types/fee/bitcoin.js +1 -0
  70. package/cjs/types/fee/index.js +11 -0
  71. package/cjs/types/index.js +11 -0
  72. package/cjs/utils/account/analyze.js +3 -3
  73. package/cjs/utils/account/common.js +16 -6
  74. package/cjs/utils/account/derive/info/solo.js +68 -19
  75. package/cjs/utils/account/derive/info/unified.js +2 -0
  76. package/cjs/utils/account/derive/validate.js +70 -2
  77. package/cjs/utils/account/transform.js +11 -5
  78. package/cjs/utils/bitcoin/common.js +98 -0
  79. package/cjs/utils/bitcoin/fee.js +21 -0
  80. package/cjs/utils/bitcoin/index.js +38 -0
  81. package/cjs/utils/bitcoin/utxo-management.js +281 -0
  82. package/cjs/utils/environment.js +30 -2
  83. package/cjs/utils/fee/transfer.js +48 -0
  84. package/cjs/utils/index.js +15 -1
  85. package/constants/bitcoin.d.ts +3 -0
  86. package/constants/bitcoin.js +13 -0
  87. package/constants/environment.d.ts +1 -0
  88. package/constants/environment.js +2 -1
  89. package/constants/index.d.ts +2 -0
  90. package/constants/index.js +3 -1
  91. package/core/logic-validation/recipientAddress.js +10 -1
  92. package/core/logic-validation/transfer.d.ts +2 -2
  93. package/core/logic-validation/transfer.js +27 -7
  94. package/core/types.d.ts +1 -0
  95. package/core/types.js +1 -0
  96. package/core/utils.d.ts +1 -0
  97. package/core/utils.js +15 -2
  98. package/koni/background/handlers/Extension.d.ts +2 -0
  99. package/koni/background/handlers/Extension.js +95 -42
  100. package/koni/background/handlers/State.d.ts +7 -3
  101. package/koni/background/handlers/State.js +52 -12
  102. package/package.json +149 -8
  103. package/packageInfo.js +1 -1
  104. package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
  105. package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
  106. package/services/balance-service/helpers/subscribe/evm.js +6 -1
  107. package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
  108. package/services/balance-service/helpers/subscribe/index.js +20 -8
  109. package/services/balance-service/index.d.ts +2 -0
  110. package/services/balance-service/index.js +32 -4
  111. package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
  112. package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
  113. package/services/balance-service/transfer/token.js +2 -0
  114. package/services/balance-service/transfer/xcm/index.js +15 -9
  115. package/services/balance-service/transfer/xcm/utils.d.ts +2 -0
  116. package/services/balance-service/transfer/xcm/utils.js +12 -14
  117. package/services/base/types.d.ts +2 -0
  118. package/services/base/types.js +2 -0
  119. package/services/chain-service/constants.d.ts +7 -0
  120. package/services/chain-service/constants.js +12 -5
  121. package/services/chain-service/handler/CardanoApi.d.ts +1 -5
  122. package/services/chain-service/handler/CardanoApi.js +26 -34
  123. package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
  124. package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
  125. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
  126. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
  127. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
  128. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
  129. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
  130. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
  131. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
  132. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
  133. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
  134. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
  135. package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
  136. package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  137. package/services/chain-service/index.d.ts +3 -0
  138. package/services/chain-service/index.js +31 -5
  139. package/services/chain-service/types.d.ts +20 -0
  140. package/services/chain-service/utils/index.d.ts +4 -0
  141. package/services/chain-service/utils/index.js +50 -4
  142. package/services/chain-service/utils/patch.js +1 -1
  143. package/services/earning-service/handlers/native-staking/tao.d.ts +0 -11
  144. package/services/earning-service/handlers/native-staking/tao.js +4 -24
  145. package/services/event-service/index.d.ts +3 -0
  146. package/services/event-service/index.js +4 -0
  147. package/services/event-service/types.d.ts +3 -0
  148. package/services/fee-service/service.js +8 -3
  149. package/services/hiro-service/index.d.ts +17 -0
  150. package/services/hiro-service/index.js +88 -0
  151. package/services/hiro-service/utils/index.d.ts +6 -0
  152. package/services/hiro-service/utils/index.js +72 -0
  153. package/services/history-service/bitcoin-history.d.ts +4 -0
  154. package/services/history-service/bitcoin-history.js +52 -0
  155. package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
  156. package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  157. package/services/history-service/index.d.ts +1 -0
  158. package/services/history-service/index.js +42 -4
  159. package/services/keyring-service/context/handlers/Derive.js +2 -2
  160. package/services/keyring-service/context/handlers/Migration.js +2 -2
  161. package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  162. package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
  163. package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
  164. package/services/migration-service/scripts/index.js +3 -1
  165. package/services/request-service/handler/BitcoinRequestHandler.d.ts +23 -0
  166. package/services/request-service/handler/BitcoinRequestHandler.js +427 -0
  167. package/services/request-service/index.d.ts +9 -2
  168. package/services/request-service/index.js +25 -3
  169. package/services/rune-service/index.d.ts +17 -0
  170. package/services/rune-service/index.js +97 -0
  171. package/services/swap-service/handler/chainflip-handler.d.ts +0 -2
  172. package/services/swap-service/handler/chainflip-handler.js +25 -13
  173. package/services/swap-service/handler/kyber-handler.d.ts +0 -1
  174. package/services/swap-service/handler/kyber-handler.js +5 -8
  175. package/services/swap-service/handler/simpleswap-handler.d.ts +0 -1
  176. package/services/swap-service/handler/simpleswap-handler.js +4 -6
  177. package/services/swap-service/handler/uniswap-handler.js +6 -13
  178. package/services/swap-service/utils.d.ts +0 -13
  179. package/services/swap-service/utils.js +46 -34
  180. package/services/transaction-service/helpers/index.d.ts +3 -1
  181. package/services/transaction-service/helpers/index.js +5 -0
  182. package/services/transaction-service/index.d.ts +3 -5
  183. package/services/transaction-service/index.js +135 -16
  184. package/services/transaction-service/types.d.ts +12 -2
  185. package/services/transaction-service/utils.js +7 -4
  186. package/strategy/api-request-strategy/context/base.d.ts +15 -0
  187. package/strategy/api-request-strategy/context/base.js +24 -0
  188. package/strategy/api-request-strategy/index.d.ts +15 -0
  189. package/strategy/api-request-strategy/index.js +83 -0
  190. package/strategy/api-request-strategy/types.d.ts +22 -0
  191. package/strategy/api-request-strategy/types.js +1 -0
  192. package/strategy/api-request-strategy/utils/index.d.ts +2 -0
  193. package/strategy/api-request-strategy/utils/index.js +23 -0
  194. package/types/account/info/keyring.d.ts +1 -1
  195. package/types/account/info/keyring.js +1 -1
  196. package/types/balance/index.d.ts +4 -1
  197. package/types/balance/transfer.d.ts +17 -0
  198. package/types/bitcoin.d.ts +93 -0
  199. package/types/bitcoin.js +17 -0
  200. package/types/environment.d.ts +9 -0
  201. package/types/environment.js +13 -0
  202. package/types/fee/base.d.ts +4 -1
  203. package/types/fee/bitcoin.d.ts +18 -0
  204. package/types/fee/bitcoin.js +1 -0
  205. package/types/fee/index.d.ts +1 -0
  206. package/types/fee/index.js +2 -1
  207. package/types/fee/subscription.d.ts +4 -3
  208. package/types/index.d.ts +1 -0
  209. package/types/index.js +1 -0
  210. package/utils/account/analyze.js +4 -4
  211. package/utils/account/common.d.ts +7 -8
  212. package/utils/account/common.js +16 -6
  213. package/utils/account/derive/info/solo.js +70 -21
  214. package/utils/account/derive/info/unified.js +2 -0
  215. package/utils/account/derive/validate.d.ts +1 -0
  216. package/utils/account/derive/validate.js +68 -1
  217. package/utils/account/transform.d.ts +1 -1
  218. package/utils/account/transform.js +11 -5
  219. package/utils/bitcoin/common.d.ts +22 -0
  220. package/utils/bitcoin/common.js +88 -0
  221. package/utils/bitcoin/fee.d.ts +2 -0
  222. package/utils/bitcoin/fee.js +14 -0
  223. package/utils/bitcoin/index.d.ts +3 -0
  224. package/utils/bitcoin/index.js +6 -0
  225. package/utils/bitcoin/utxo-management.d.ts +33 -0
  226. package/utils/bitcoin/utxo-management.js +266 -0
  227. package/utils/environment.d.ts +2 -0
  228. package/utils/environment.js +27 -1
  229. package/utils/fee/transfer.d.ts +3 -1
  230. package/utils/fee/transfer.js +47 -1
  231. package/utils/index.d.ts +1 -0
  232. package/utils/index.js +6 -3
@@ -18,6 +18,7 @@ export declare class BalanceService implements StoppableServiceInterface {
18
18
  stopPromiseHandler: PromiseHandler<void>;
19
19
  status: ServiceStatus;
20
20
  private isReload;
21
+ get isStarted(): boolean;
21
22
  private readonly detectAccountBalanceStore;
22
23
  private readonly balanceDetectSubject;
23
24
  private readonly intervalTime;
@@ -87,6 +88,7 @@ export declare class BalanceService implements StoppableServiceInterface {
87
88
  private _unsubscribeBalance;
88
89
  /** Subscribe balance subscription */
89
90
  runSubscribeBalances(): Promise<void>;
91
+ refreshBalanceForAddress(address: string, chain: string, asset: string, extrinsicType?: ExtrinsicType): Promise<void>;
90
92
  /** Unsubscribe balance subscription */
91
93
  runUnsubscribeBalances(): void;
92
94
  /** Reload balance subscription */
@@ -32,6 +32,9 @@ export class BalanceService {
32
32
  stopPromiseHandler = createPromiseHandler();
33
33
  status = ServiceStatus.NOT_INITIALIZED;
34
34
  isReload = false;
35
+ get isStarted() {
36
+ return this.status === ServiceStatus.STARTED;
37
+ }
35
38
  detectAccountBalanceStore = new DetectAccountBalanceStore();
36
39
  balanceDetectSubject = new BehaviorSubject({});
37
40
  intervalTime = 3 * 60 * 1000;
@@ -57,7 +60,7 @@ export class BalanceService {
57
60
  this.status = ServiceStatus.INITIALIZED;
58
61
 
59
62
  // Start service
60
- await this.start();
63
+ // await this.start(); // Commented out to avoid auto start when app not fully initialized
61
64
 
62
65
  // Handle events
63
66
  this.state.eventService.onLazy(this.handleEvents.bind(this));
@@ -143,7 +146,7 @@ export class BalanceService {
143
146
  }
144
147
  if (needReload) {
145
148
  addLazy('reloadBalanceByEvents', () => {
146
- if (!this.isReload) {
149
+ if (!this.isReload && this.isStarted) {
147
150
  this.runSubscribeBalances().catch(console.error);
148
151
  }
149
152
  }, lazyTime, undefined, true);
@@ -194,8 +197,9 @@ export class BalanceService {
194
197
  const substrateApiMap = this.state.chainService.getSubstrateApiMap();
195
198
  const tonApiMap = this.state.chainService.getTonApiMap();
196
199
  const cardanoApiMap = this.state.chainService.getCardanoApiMap();
200
+ const bitcoinApiMap = this.state.chainService.getBitcoinApiMap();
197
201
  let unsub = noop;
198
- unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, cardanoApiMap, result => {
202
+ unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, cardanoApiMap, bitcoinApiMap, result => {
199
203
  const rs = result[0];
200
204
  let value;
201
205
  switch (balanceType) {
@@ -366,13 +370,14 @@ export class BalanceService {
366
370
  const substrateApiMap = this.state.chainService.getSubstrateApiMap();
367
371
  const tonApiMap = this.state.chainService.getTonApiMap();
368
372
  const cardanoApiMap = this.state.chainService.getCardanoApiMap();
373
+ const bitcoinApiMap = this.state.chainService.getBitcoinApiMap();
369
374
  const activeChainSlugs = Object.keys(this.state.getActiveChainInfoMap());
370
375
  const assetState = this.state.chainService.subscribeAssetSettings().value;
371
376
  const assets = Object.values(assetMap).filter(asset => {
372
377
  var _assetState$asset$slu;
373
378
  return activeChainSlugs.includes(asset.originChain) && ((_assetState$asset$slu = assetState[asset.slug]) === null || _assetState$asset$slu === void 0 ? void 0 : _assetState$asset$slu.visible);
374
379
  }).map(asset => asset.slug);
375
- const unsub = subscribeBalance(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, cardanoApiMap, result => {
380
+ const unsub = subscribeBalance(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, cardanoApiMap, bitcoinApiMap, result => {
376
381
  !cancel && this.setBalanceItem(result);
377
382
  }, ExtrinsicType.TRANSFER_BALANCE);
378
383
  const unsub2 = this.state.subscribeMantaPayBalance();
@@ -382,6 +387,29 @@ export class BalanceService {
382
387
  unsub2 && unsub2();
383
388
  };
384
389
  }
390
+ async refreshBalanceForAddress(address, chain, asset, extrinsicType) {
391
+ // Check if address and chain are valid
392
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
393
+ if (!chainInfoMap[chain]) {
394
+ console.warn(`Chain ${chain} is not supported`);
395
+ return;
396
+ }
397
+
398
+ // Get necessary data
399
+ const assetMap = this.state.chainService.getAssetRegistry();
400
+ const evmApiMap = this.state.chainService.getEvmApiMap();
401
+ const substrateApiMap = this.state.chainService.getSubstrateApiMap();
402
+ const tonApiMap = this.state.chainService.getTonApiMap();
403
+ const cardanoApiMap = this.state.chainService.getCardanoApiMap();
404
+ const bitcoinApiMap = this.state.chainService.getBitcoinApiMap();
405
+ return new Promise(resolve => {
406
+ const unsub = subscribeBalance([address], [chain], [asset], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, cardanoApiMap, bitcoinApiMap, result => {
407
+ this.setBalanceItem(result);
408
+ unsub();
409
+ resolve();
410
+ }, extrinsicType || ExtrinsicType.TRANSFER_BALANCE);
411
+ });
412
+ }
385
413
 
386
414
  /** Unsubscribe balance subscription */
387
415
  runUnsubscribeBalances() {
@@ -0,0 +1,14 @@
1
+ import { _BitcoinApi } from '@subwallet/extension-base/services/chain-service/types';
2
+ import { FeeInfo, TransactionFee } from '@subwallet/extension-base/types';
3
+ import { Network, Psbt } from 'bitcoinjs-lib';
4
+ export interface TransferBitcoinProps extends TransactionFee {
5
+ bitcoinApi: _BitcoinApi;
6
+ chain: string;
7
+ from: string;
8
+ feeInfo: FeeInfo;
9
+ to: string;
10
+ transferAll: boolean;
11
+ value: string;
12
+ network: Network;
13
+ }
14
+ export declare function createBitcoinTransaction(params: TransferBitcoinProps): Promise<[Psbt, string, string | undefined]>;
@@ -0,0 +1,112 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
5
+ import { _BITCOIN_CHAIN_SLUG, _BITCOIN_NAME, _BITCOIN_TESTNET_NAME } from '@subwallet/extension-base/services/chain-service/constants';
6
+ import { combineBitcoinFee, determineUtxosForSpend, determineUtxosForSpendAll, getTransferableBitcoinUtxos } from '@subwallet/extension-base/utils';
7
+ import { BitcoinAddressType } from '@subwallet/keyring/types';
8
+ import { getBitcoinAddressInfo } from '@subwallet/keyring/utils';
9
+ import { keyring } from '@subwallet/ui-keyring';
10
+ import BigN from 'bignumber.js';
11
+ import { Psbt } from 'bitcoinjs-lib';
12
+ export async function createBitcoinTransaction(params) {
13
+ const {
14
+ bitcoinApi,
15
+ chain,
16
+ feeCustom: _feeCustom,
17
+ feeInfo: _feeInfo,
18
+ feeOption,
19
+ from,
20
+ network,
21
+ to,
22
+ transferAll,
23
+ value
24
+ } = params;
25
+ const feeCustom = _feeCustom;
26
+ const feeInfo = _feeInfo;
27
+ const bitcoinFee = combineBitcoinFee(feeInfo, feeOption, feeCustom);
28
+ const utxos = await getTransferableBitcoinUtxos(bitcoinApi, from);
29
+ try {
30
+ const amountValue = parseFloat(value);
31
+ const determineUtxosArgs = {
32
+ amount: amountValue,
33
+ feeRate: bitcoinFee.feeRate,
34
+ recipient: to,
35
+ sender: from,
36
+ utxos
37
+ };
38
+ const {
39
+ fee,
40
+ inputs,
41
+ isCustomFeeRate,
42
+ outputs,
43
+ size
44
+ } = transferAll ? determineUtxosForSpendAll(determineUtxosArgs) : determineUtxosForSpend(determineUtxosArgs);
45
+ const pair = keyring.getPair(from);
46
+ const tx = new Psbt({
47
+ network
48
+ });
49
+ let transferAmount = new BigN(0);
50
+ for (const input of inputs) {
51
+ const addressInfo = getBitcoinAddressInfo(pair.address);
52
+ if (addressInfo.type === BitcoinAddressType.p2pkh || addressInfo.type === BitcoinAddressType.p2sh) {
53
+ // BIP-44 (Legacy)
54
+ const hex = await bitcoinApi.api.getTxHex(input.txid);
55
+ tx.addInput({
56
+ hash: input.txid,
57
+ index: input.vout,
58
+ nonWitnessUtxo: Buffer.from(hex, 'hex')
59
+ });
60
+ } else if (addressInfo.type === BitcoinAddressType.p2wpkh) {
61
+ // BIP-84 (Native SegWit)
62
+ tx.addInput({
63
+ hash: input.txid,
64
+ index: input.vout,
65
+ witnessUtxo: {
66
+ script: pair.bitcoin.output,
67
+ value: input.value
68
+ }
69
+ });
70
+ } else if (addressInfo.type === BitcoinAddressType.p2tr) {
71
+ // BIP-86 (Taproot)
72
+ tx.addInput({
73
+ hash: input.txid,
74
+ index: input.vout,
75
+ witnessUtxo: {
76
+ script: pair.bitcoin.output,
77
+ value: input.value // UTXO value in satoshis
78
+ },
79
+
80
+ tapInternalKey: pair.bitcoin.internalPubkey // X-only public key (32 bytes)
81
+ });
82
+ } else {
83
+ throw new Error(`Unsupported address type: ${addressInfo.type}`);
84
+ }
85
+ }
86
+ for (const output of outputs) {
87
+ tx.addOutput({
88
+ address: output.address || from,
89
+ value: output.value
90
+ });
91
+ if (output.address === to) {
92
+ transferAmount = transferAmount.plus(output.value);
93
+ }
94
+ }
95
+ const customFeeRate = fee / size;
96
+ const customFeeRateResult = isCustomFeeRate ? customFeeRate.toString() : undefined;
97
+ return [tx, transferAmount.toString(), customFeeRateResult];
98
+ } catch (e) {
99
+ if (e instanceof TransactionError) {
100
+ throw e;
101
+ }
102
+ console.warn('Failed to create Bitcoin transaction:', e);
103
+ throw new Error(`You don’t have enough BTC (${convertChainToSymbol(chain)}) for the transaction. Lower your BTC amount and try again`);
104
+ }
105
+ }
106
+ function convertChainToSymbol(chain) {
107
+ if (chain === _BITCOIN_CHAIN_SLUG) {
108
+ return _BITCOIN_NAME;
109
+ } else {
110
+ return _BITCOIN_TESTNET_NAME;
111
+ }
112
+ }
@@ -108,6 +108,8 @@ export const createSubstrateExtrinsic = async ({
108
108
  transfer = api.tx.balances.transfer(to, new BN(value));
109
109
  }
110
110
  }
111
+ } else if (_TRANSFER_CHAIN_GROUP.truth.includes(networkKey)) {
112
+ transfer = api.tx.assetManager.transfer(to, _getTokenOnChainInfo(tokenInfo), value);
111
113
  }
112
114
  return [transfer, transferAmount || value];
113
115
  };
@@ -128,19 +128,25 @@ export const createXcmExtrinsicV2 = async request => {
128
128
  export const dryRunXcmExtrinsicV2 = async request => {
129
129
  try {
130
130
  const dryRunResult = await dryRunXcm(request);
131
- const originDryRunResult = dryRunResult.origin;
132
- if (originDryRunResult.success) {
133
- const destinationDryRunResult = dryRunResult.destination;
134
- if (destinationDryRunResult.success) {
135
- return true;
131
+ const originDryRunRs = dryRunResult.origin;
132
+ if (originDryRunRs.success) {
133
+ const {
134
+ assetHub,
135
+ bridgeHub,
136
+ destination
137
+ } = dryRunResult;
138
+ if ((assetHub === null || assetHub === void 0 ? void 0 : assetHub.success) === false || (bridgeHub === null || bridgeHub === void 0 ? void 0 : bridgeHub.success) === false || (destination === null || destination === void 0 ? void 0 : destination.success) === false) {
139
+ if ((destination === null || destination === void 0 ? void 0 : destination.success) === false) {
140
+ // pass dry-run in these cases
141
+ return isChainNotSupportDryRun(destination.failureReason) || isChainNotSupportPolkadotApi(destination.failureReason);
142
+ }
143
+ return false;
136
144
  }
137
-
138
- // pass dry-run in these cases
139
- return isChainNotSupportDryRun(destinationDryRunResult.failureReason) || isChainNotSupportPolkadotApi(destinationDryRunResult.failureReason);
145
+ return true;
140
146
  }
141
147
 
142
148
  // pass dry-run in these cases
143
- return isChainNotSupportDryRun(originDryRunResult.failureReason) || isChainNotSupportPolkadotApi(originDryRunResult.failureReason);
149
+ return isChainNotSupportDryRun(originDryRunRs.failureReason) || isChainNotSupportPolkadotApi(originDryRunRs.failureReason);
144
150
  } catch (e) {
145
151
  return false;
146
152
  }
@@ -14,6 +14,8 @@ export declare type DryRunNodeResult = DryRunNodeSuccess | DryRunNodeFailure;
14
14
  export declare type DryRunResult = {
15
15
  origin: DryRunNodeResult;
16
16
  destination?: DryRunNodeResult;
17
+ assetHub?: DryRunNodeResult;
18
+ bridgeHub?: DryRunNodeResult;
17
19
  };
18
20
  interface GetXcmFeeRequest {
19
21
  sender: string;
@@ -2,14 +2,15 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { fetchParaSpellChainMap } from '@subwallet/extension-base/constants/paraspell-chain-map';
5
+ import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
6
+ import { fetchFromProxyService } from '@subwallet/extension-base/utils';
5
7
  import { assert, compactToU8a, isHex, u8aConcat, u8aEq } from '@polkadot/util';
6
- const paraSpellEndpoint = 'https://api.lightspell.xyz/v3';
8
+ const version = '/v3';
7
9
  const paraSpellApi = {
8
- buildXcm: `${paraSpellEndpoint}/x-transfer`,
9
- dryRunXcm: `${paraSpellEndpoint}/dry-run`,
10
- feeXcm: `${paraSpellEndpoint}/xcm-fee`
10
+ buildXcm: `${version}/x-transfer`,
11
+ dryRunXcm: `${version}/dry-run`,
12
+ feeXcm: `${version}/xcm-fee`
11
13
  };
12
- const paraSpellKey = process.env.PARASPELL_API_KEY || '';
13
14
  function txHexToSubmittableExtrinsic(api, hex) {
14
15
  try {
15
16
  assert(isHex(hex), 'Expected a hex-encoded call');
@@ -86,13 +87,12 @@ export async function buildXcm(request) {
86
87
  to: paraSpellChainMap[destinationChain.slug],
87
88
  currency: createParaSpellCurrency(psAssetType, psAssetValue, sendingValue)
88
89
  };
89
- const response = await fetch(paraSpellApi.buildXcm, {
90
+ const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.buildXcm, {
90
91
  method: 'POST',
91
92
  body: JSON.stringify(bodyData),
92
93
  headers: {
93
94
  'Content-Type': 'application/json',
94
- Accept: 'application/json',
95
- 'X-API-KEY': paraSpellKey
95
+ Accept: 'application/json'
96
96
  }
97
97
  });
98
98
  if (!response.ok) {
@@ -126,13 +126,12 @@ export async function dryRunXcm(request) {
126
126
  to: paraSpellChainMap[destinationChain.slug],
127
127
  currency: createParaSpellCurrency(psAssetType, psAssetValue, sendingValue)
128
128
  };
129
- const response = await fetch(paraSpellApi.dryRunXcm, {
129
+ const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.dryRunXcm, {
130
130
  method: 'POST',
131
131
  body: JSON.stringify(bodyData),
132
132
  headers: {
133
133
  'Content-Type': 'application/json',
134
- Accept: 'application/json',
135
- 'X-API-KEY': paraSpellKey
134
+ Accept: 'application/json'
136
135
  }
137
136
  });
138
137
  if (!response.ok) {
@@ -170,13 +169,12 @@ export async function estimateXcmFee(request) {
170
169
  to: paraSpellChainMap[toChainInfo.slug],
171
170
  currency: createParaSpellCurrency(psAssetType, psAssetValue, value)
172
171
  };
173
- const response = await fetch(paraSpellApi.feeXcm, {
172
+ const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.feeXcm, {
174
173
  method: 'POST',
175
174
  body: JSON.stringify(bodyData),
176
175
  headers: {
177
176
  'Content-Type': 'application/json',
178
- Accept: 'application/json',
179
- 'X-API-KEY': paraSpellKey
177
+ Accept: 'application/json'
180
178
  }
181
179
  });
182
180
  if (!response.ok) {
@@ -5,6 +5,8 @@ export declare enum ServiceStatus {
5
5
  INITIALIZED = "initialized",
6
6
  STARTED = "started",
7
7
  STARTING = "starting",
8
+ STARTED_FULL = "started_full",
9
+ STARTING_FULL = "starting_full",
8
10
  STOPPED = "stopped",
9
11
  STOPPING = "stopping"
10
12
  }
@@ -10,6 +10,8 @@ export let ServiceStatus;
10
10
  ServiceStatus["INITIALIZED"] = "initialized";
11
11
  ServiceStatus["STARTED"] = "started";
12
12
  ServiceStatus["STARTING"] = "starting";
13
+ ServiceStatus["STARTED_FULL"] = "started_full";
14
+ ServiceStatus["STARTING_FULL"] = "starting_full";
13
15
  ServiceStatus["STOPPED"] = "stopped";
14
16
  ServiceStatus["STOPPING"] = "stopping";
15
17
  })(ServiceStatus || (ServiceStatus = {}));
@@ -21,6 +21,7 @@ export declare const _BALANCE_CHAIN_GROUP: {
21
21
  centrifuge: string[];
22
22
  supportBridged: string[];
23
23
  bittensor: string[];
24
+ moonbeam: string[];
24
25
  };
25
26
  export declare const _BALANCE_TOKEN_GROUP: {
26
27
  crab: string[];
@@ -71,6 +72,7 @@ export declare const _TRANSFER_CHAIN_GROUP: {
71
72
  pendulum: string[];
72
73
  centrifuge: string[];
73
74
  disable_transfer: string[];
75
+ truth: string[];
74
76
  };
75
77
  export declare const _BALANCE_PARSING_CHAIN_GROUP: {
76
78
  bobabeam: string[];
@@ -94,9 +96,14 @@ export declare const EVM_REFORMAT_DECIMALS: {
94
96
  acala: string[];
95
97
  };
96
98
  export declare const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 120000;
99
+ export declare const _BITCOIN_CHAIN_SLUG = "bitcoin";
100
+ export declare const _BITCOIN_TESTNET_CHAIN_SLUG = "bitcoinTestnet";
101
+ export declare const _BITCOIN_NAME = "Bitcoin";
102
+ export declare const _BITCOIN_TESTNET_NAME = "Bitcoin Testnet";
97
103
  export declare const _CHAIN_INFO_SRC: string;
98
104
  export declare const _CHAIN_ASSET_SRC: string;
99
105
  export declare const _ASSET_REF_SRC: string;
100
106
  export declare const _MULTI_CHAIN_ASSET_SRC: string;
101
107
  export declare const _CHAIN_LOGO_MAP_SRC: string;
102
108
  export declare const _ASSET_LOGO_MAP_SRC: string;
109
+ export declare const _BTC_SERVICE_TOKEN: string;
@@ -30,12 +30,13 @@ export const _BALANCE_CHAIN_GROUP = {
30
30
  genshiro: ['genshiro_testnet', 'genshiro'],
31
31
  equilibrium_parachain: ['equilibrium_parachain'],
32
32
  bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'hydradx_rococo', 'pendulum', 'amplitude', 'continuum_network', 'truth_network', 'jamton'],
33
- statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala', 'shibuya', 'dbcchain', 'westend_assethub'],
33
+ statemine: ['statemine', 'astar', 'shiden', 'statemint', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala', 'shibuya', 'dbcchain', 'westend_assethub', 'chainflip_assethub'],
34
34
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
35
35
  // perhaps there are some runtime updates
36
36
  centrifuge: ['centrifuge'],
37
37
  supportBridged: ['rococo_assethub', 'statemint', 'statemine', 'polimec'],
38
- bittensor: ['bittensor', 'bittensor_testnet']
38
+ bittensor: ['bittensor', 'bittensor_testnet'],
39
+ moonbeam: ['moonbeam', 'moonriver', 'moonbase']
39
40
  };
40
41
  export const _BALANCE_TOKEN_GROUP = {
41
42
  crab: ['CKTON', 'PKTON'],
@@ -254,13 +255,14 @@ export const _TRANSFER_CHAIN_GROUP = {
254
255
  genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
255
256
  // crab: ['crab', 'pangolin'],
256
257
  bitcountry: ['pioneer', 'bitcountry'],
257
- statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet', 'dbcchain', 'westend_assethub'],
258
+ statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet', 'dbcchain', 'westend_assethub', 'chainflip_assethub'],
258
259
  riochain: ['riochain'],
259
260
  sora_substrate: ['sora_substrate'],
260
261
  avail: ['kate', 'goldberg_testnet'],
261
262
  pendulum: ['pendulum', 'amplitude', 'amplitude_test', 'hydradx_main', 'bifrost', 'bifrost_dot', 'jamton'],
262
263
  centrifuge: ['centrifuge'],
263
- disable_transfer: ['crab', 'pangolin']
264
+ disable_transfer: ['crab', 'pangolin'],
265
+ truth: ['truth_network']
264
266
  };
265
267
  export const _BALANCE_PARSING_CHAIN_GROUP = {
266
268
  bobabeam: ['bobabeam', 'bobabase']
@@ -301,9 +303,14 @@ export const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 120000;
301
303
 
302
304
  // TODO: review
303
305
  const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-dev' : 'master';
306
+ export const _BITCOIN_CHAIN_SLUG = 'bitcoin';
307
+ export const _BITCOIN_TESTNET_CHAIN_SLUG = 'bitcoinTestnet';
308
+ export const _BITCOIN_NAME = 'Bitcoin';
309
+ export const _BITCOIN_TESTNET_NAME = 'Bitcoin Testnet';
304
310
  export const _CHAIN_INFO_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainInfo.json`;
305
311
  export const _CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainAsset.json`;
306
312
  export const _ASSET_REF_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetRef.json`;
307
313
  export const _MULTI_CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/MultiChainAsset.json`;
308
314
  export const _CHAIN_LOGO_MAP_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainLogoMap.json`;
309
- export const _ASSET_LOGO_MAP_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetLogoMap.json`;
315
+ export const _ASSET_LOGO_MAP_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetLogoMap.json`;
316
+ export const _BTC_SERVICE_TOKEN = process.env.BTC_SERVICE_TOKEN || '';
@@ -3,10 +3,6 @@ import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/ha
3
3
  import { _CardanoApi, _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
4
4
  import { PromiseHandler } from '@subwallet/extension-base/utils';
5
5
  import { BehaviorSubject } from 'rxjs';
6
- export declare const API_KEY: {
7
- mainnet: string;
8
- testnet: string;
9
- };
10
6
  export declare class CardanoApi implements _CardanoApi {
11
7
  chainSlug: string;
12
8
  apiUrl: string;
@@ -18,11 +14,11 @@ export declare class CardanoApi implements _CardanoApi {
18
14
  isApiReadyOnce: boolean;
19
15
  isReadyHandler: PromiseHandler<_CardanoApi>;
20
16
  isTestnet: boolean;
21
- private projectId;
22
17
  providerName: string;
23
18
  constructor(chainSlug: string, apiUrl: string, { isTestnet, providerName }: _ApiOptions);
24
19
  get isApiConnected(): boolean;
25
20
  get connectionStatus(): _ChainConnectionStatus;
21
+ private fetchCardano;
26
22
  private updateConnectionStatus;
27
23
  get isReady(): Promise<_CardanoApi>;
28
24
  updateApiUrl(apiUrl: string): Promise<void>;
@@ -3,13 +3,16 @@
3
3
 
4
4
  import { cborToBytes, retryCardanoTxStatus } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/utils';
5
5
  import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
6
- import { createPromiseHandler } from '@subwallet/extension-base/utils';
6
+ import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
7
+ import { createPromiseHandler, fetchFromProxyService } from '@subwallet/extension-base/utils';
7
8
  import { BehaviorSubject } from 'rxjs';
8
9
  import { hexAddPrefix, isHex } from '@polkadot/util';
9
- export const API_KEY = {
10
- mainnet: process.env.BLOCKFROST_API_KEY_MAIN || '',
11
- testnet: process.env.BLOCKFROST_API_KEY_PREP || ''
12
- };
10
+
11
+ // export const API_KEY = {
12
+ // mainnet: process.env.BLOCKFROST_API_KEY_MAIN || '',
13
+ // testnet: process.env.BLOCKFROST_API_KEY_PREP || ''
14
+ // };
15
+
13
16
  export class CardanoApi {
14
17
  // private api: BlockFrostAPI;
15
18
 
@@ -25,7 +28,6 @@ export class CardanoApi {
25
28
  this.chainSlug = chainSlug;
26
29
  this.apiUrl = apiUrl;
27
30
  this.isTestnet = isTestnet !== null && isTestnet !== void 0 ? isTestnet : true;
28
- this.projectId = isTestnet ? API_KEY.testnet : API_KEY.mainnet;
29
31
  this.providerName = providerName || 'unknown';
30
32
  // this.api = this.createProvider(isTestnet);
31
33
  this.isReadyHandler = createPromiseHandler();
@@ -37,6 +39,9 @@ export class CardanoApi {
37
39
  get connectionStatus() {
38
40
  return this.connectionStatusSubject.getValue();
39
41
  }
42
+ fetchCardano(path, options) {
43
+ return fetchFromProxyService(ProxyServiceRoute.CARDANO, path, options, this.isTestnet);
44
+ }
40
45
  updateConnectionStatus(status) {
41
46
  const isConnected = status === _ChainConnectionStatus.CONNECTED;
42
47
  if (isConnected !== this.isApiConnectedSubject.value) {
@@ -107,12 +112,9 @@ export class CardanoApi {
107
112
  }
108
113
  async getBalanceMap(address) {
109
114
  try {
110
- const url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/addresses/${address}` : `https://cardano-mainnet.blockfrost.io/api/v0/addresses/${address}`;
111
- const response = await fetch(url, {
112
- method: 'GET',
113
- headers: {
114
- Project_id: this.projectId
115
- }
115
+ const path = `/addresses/${address}`;
116
+ const response = await this.fetchCardano(path, {
117
+ method: 'GET'
116
118
  });
117
119
  const addressBalance = await response.json();
118
120
  return addressBalance.amount;
@@ -123,13 +125,10 @@ export class CardanoApi {
123
125
  }
124
126
  async getUtxos(address, page, limit) {
125
127
  try {
126
- let url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/addresses/${address}/utxos` : `https://cardano-mainnet.blockfrost.io/api/v0/addresses/${address}/utxos`;
127
- url += `?page=${page}&count=${limit}`;
128
- const response = await fetch(url, {
129
- method: 'GET',
130
- headers: {
131
- Project_id: this.projectId
132
- }
128
+ let path = `/addresses/${address}/utxos`;
129
+ path += `?page=${page}&count=${limit}`;
130
+ const response = await this.fetchCardano(path, {
131
+ method: 'GET'
133
132
  });
134
133
  const utxos = await response.json();
135
134
  return utxos;
@@ -140,12 +139,9 @@ export class CardanoApi {
140
139
  }
141
140
  async getSpecificUtxo(txHash) {
142
141
  try {
143
- const url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/txs/${txHash}/utxos` : `https://cardano-mainnet.blockfrost.io/api/v0/txs/${txHash}/utxos`;
144
- const response = await fetch(url, {
145
- method: 'GET',
146
- headers: {
147
- Project_id: this.projectId
148
- }
142
+ const path = `/txs/${txHash}/utxos`;
143
+ const response = await this.fetchCardano(path, {
144
+ method: 'GET'
149
145
  });
150
146
  const utxo = await response.json();
151
147
  return utxo;
@@ -156,11 +152,10 @@ export class CardanoApi {
156
152
  }
157
153
  async sendCardanoTxReturnHash(tx) {
158
154
  try {
159
- const url = this.isTestnet ? 'https://cardano-preprod.blockfrost.io/api/v0/tx/submit' : 'https://cardano-mainnet.blockfrost.io/api/v0/tx/submit';
160
- const response = await fetch(url, {
155
+ const path = '/tx/submit';
156
+ const response = await this.fetchCardano(path, {
161
157
  method: 'POST',
162
158
  headers: {
163
- Project_id: this.projectId,
164
159
  'Content-Type': 'application/cbor'
165
160
  },
166
161
  body: cborToBytes(tx)
@@ -180,12 +175,9 @@ export class CardanoApi {
180
175
  async getStatusByTxHash(txHash, ttl) {
181
176
  const cronTime = 30000;
182
177
  return retryCardanoTxStatus(async () => {
183
- const url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/txs/${txHash}` : `https://cardano-mainnet.blockfrost.io/api/v0/txs/${txHash}`;
184
- const response = await fetch(url, {
185
- method: 'GET',
186
- headers: {
187
- Project_id: this.projectId
188
- }
178
+ const path = `/txs/${txHash}`;
179
+ const response = await this.fetchCardano(path, {
180
+ method: 'GET'
189
181
  });
190
182
  const txInfo = await response.json();
191
183
  if (txInfo.block && txInfo.hash && txInfo.index >= 0) {
@@ -0,0 +1,31 @@
1
+ import { BitcoinApiStrategy } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/types';
2
+ import { PromiseHandler } from '@subwallet/extension-base/utils/promise';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ import { _ApiOptions } from '../../handler/types';
5
+ import { _BitcoinApi, _ChainConnectionStatus } from '../../types';
6
+ export declare class BitcoinApi implements _BitcoinApi {
7
+ chainSlug: string;
8
+ apiUrl: string;
9
+ apiError?: string;
10
+ apiRetry: number;
11
+ readonly isApiConnectedSubject: BehaviorSubject<boolean>;
12
+ readonly connectionStatusSubject: BehaviorSubject<_ChainConnectionStatus>;
13
+ isApiReady: boolean;
14
+ isApiReadyOnce: boolean;
15
+ isReadyHandler: PromiseHandler<_BitcoinApi>;
16
+ providerName: string;
17
+ api: BitcoinApiStrategy;
18
+ constructor(chainSlug: string, apiUrl: string, { providerName }?: _ApiOptions);
19
+ get isApiConnected(): boolean;
20
+ private createApiStrategy;
21
+ get connectionStatus(): _ChainConnectionStatus;
22
+ private updateConnectionStatus;
23
+ get isReady(): Promise<_BitcoinApi>;
24
+ updateApiUrl(apiUrl: string): Promise<void>;
25
+ recoverConnect(): Promise<void>;
26
+ connect(): void;
27
+ disconnect(): Promise<void>;
28
+ destroy(): Promise<void>;
29
+ onConnect(): void;
30
+ onDisconnect(): void;
31
+ }