@0xsquid/react-hooks 8.3.1-beta-update-ethers.0 → 8.3.1-beta-bitcoin-coralv2.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 (27) hide show
  1. package/dist/core/connectors/bitcoin/wallets/keplr.d.ts +3 -0
  2. package/dist/core/connectors/bitcoin/wallets/phantom.d.ts +3 -1
  3. package/dist/core/connectors/bitcoin/wallets/unisat.d.ts +3 -0
  4. package/dist/core/types/bitcoin.d.ts +3 -0
  5. package/dist/{index-qAOvcSon.js → index-D9ejMike.js} +111 -46
  6. package/dist/index-D9ejMike.js.map +1 -0
  7. package/dist/{index-CMrdTYeW.js → index-DW9wT497.js} +111 -47
  8. package/dist/index-DW9wT497.js.map +1 -0
  9. package/dist/{index.es-Cu_QQTg-.js → index.es-BWWDAnQe.js} +2 -2
  10. package/dist/{index.es-Cu_QQTg-.js.map → index.es-BWWDAnQe.js.map} +1 -1
  11. package/dist/{index.es-DRgOycmm.js → index.es-kZEFPxkm.js} +2 -2
  12. package/dist/{index.es-DRgOycmm.js.map → index.es-kZEFPxkm.js.map} +1 -1
  13. package/dist/index.esm.js +1 -1
  14. package/dist/index.js +2 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/{secretService-B_-XWo1F.js → secretService-0aEFG8v1.js} +2 -2
  17. package/dist/{secretService-B_-XWo1F.js.map → secretService-0aEFG8v1.js.map} +1 -1
  18. package/dist/{secretService-B3sc6ibT.js → secretService-B46DBNsN.js} +2 -2
  19. package/dist/{secretService-B3sc6ibT.js.map → secretService-B46DBNsN.js.map} +1 -1
  20. package/dist/services/internal/transactionService.d.ts +7 -1
  21. package/dist/{stellarService.client-sRzC5VSD.js → stellarService.client-BUoaW_gK.js} +2 -2
  22. package/dist/{stellarService.client-sRzC5VSD.js.map → stellarService.client-BUoaW_gK.js.map} +1 -1
  23. package/dist/{stellarService.client-Ciqw9lmL.js → stellarService.client-dfwlhLiK.js} +2 -2
  24. package/dist/{stellarService.client-Ciqw9lmL.js.map → stellarService.client-dfwlhLiK.js.map} +1 -1
  25. package/package.json +4 -4
  26. package/dist/index-CMrdTYeW.js.map +0 -1
  27. package/dist/index-qAOvcSon.js.map +0 -1
@@ -8,4 +8,7 @@ export declare class KeplrConnector implements BitcoinConnector {
8
8
  requestAccount(): Promise<{
9
9
  address: string;
10
10
  }>;
11
+ signPsbt(_: string): Promise<{
12
+ txHash: string;
13
+ }>;
11
14
  }
@@ -22,6 +22,8 @@ export declare class PhantomConnector implements BitcoinConnector {
22
22
  sendBTC(to: string, amount: number): Promise<{
23
23
  txHash: string;
24
24
  }>;
25
- private signPsbt;
25
+ signPsbt(psbtHex: string): Promise<{
26
+ txHash: string;
27
+ }>;
26
28
  }
27
29
  export {};
@@ -11,5 +11,8 @@ export declare class UnisatConnector implements BitcoinConnector {
11
11
  requestAccount(): Promise<{
12
12
  address: string;
13
13
  }>;
14
+ signPsbt(_: string): Promise<{
15
+ txHash: string;
16
+ }>;
14
17
  }
15
18
  export {};
@@ -2,6 +2,9 @@ export interface BitcoinConnector {
2
2
  sendBTC(to: string, amount: number): Promise<{
3
3
  txHash: string;
4
4
  }>;
5
+ signPsbt(psbtHex: string): Promise<{
6
+ txHash: string;
7
+ }>;
5
8
  requestAccount(): Promise<{
6
9
  address: string;
7
10
  }>;
@@ -4752,6 +4752,9 @@ class KeplrConnector {
4752
4752
  address: account,
4753
4753
  };
4754
4754
  }
4755
+ async signPsbt(_) {
4756
+ throw new Error("Method not implemented.");
4757
+ }
4755
4758
  }
4756
4759
 
4757
4760
  bitcoin__namespace.initEccLib(ecc__namespace);
@@ -4866,10 +4869,8 @@ class PhantomConnector {
4866
4869
  async sendBTC(to, amount) {
4867
4870
  const { address } = await this.requestAccount();
4868
4871
  const { psbtHex } = await createSendBtcPsbt(address, to, amount);
4869
- const { txId } = await this.signPsbt(psbtHex);
4870
- if (!txId)
4871
- throw new BitcoinConnectorTransactionFailedError();
4872
- return { txHash: txId };
4872
+ const { txHash } = await this.signPsbt(psbtHex);
4873
+ return { txHash };
4873
4874
  }
4874
4875
  async signPsbt(psbtHex) {
4875
4876
  const { address: paymentAddress } = await this.requestAccount();
@@ -4890,8 +4891,10 @@ class PhantomConnector {
4890
4891
  const signedPsbt = bitcoin__namespace.Psbt.fromBuffer(signedPsbtBytes);
4891
4892
  signedPsbt.finalizeAllInputs();
4892
4893
  const tx = signedPsbt.extractTransaction();
4893
- const txId = await broadcastTx(tx.toHex());
4894
- return { txId };
4894
+ const txHash = await broadcastTx(tx.toHex());
4895
+ if (!txHash)
4896
+ throw new BitcoinConnectorTransactionFailedError();
4897
+ return { txHash };
4895
4898
  }
4896
4899
  }
4897
4900
 
@@ -4920,6 +4923,9 @@ class UnisatConnector {
4920
4923
  address: account,
4921
4924
  };
4922
4925
  }
4926
+ async signPsbt(_) {
4927
+ throw new Error("Method not implemented.");
4928
+ }
4923
4929
  }
4924
4930
 
4925
4931
  var XrplTransactionType;
@@ -22174,6 +22180,20 @@ function isChainflipBridgeTransaction(actions = []) {
22174
22180
  return actions.some((action) => action.type === squidTypes.ActionType.BRIDGE &&
22175
22181
  action.data?.type === squidTypes.BridgeType.CHAINFLIP);
22176
22182
  }
22183
+ /**
22184
+ * Checks if a route is of type {@link OnChainExecutionData}
22185
+ *
22186
+ * On-chain routes require calling a smart contract to execute
22187
+ */
22188
+ function isOnChainTxData(squidData) {
22189
+ return [
22190
+ squidTypes.SquidDataType.OnChainExecution,
22191
+ squidTypes.SquidDataType.DepositAddressWithSignature,
22192
+ squidTypes.SquidDataType.DepositAddressCalldata,
22193
+ squidTypes.SquidDataType.DepositAddressWithSignature,
22194
+ squidTypes.SquidDataType.DepositAddressWithMemo,
22195
+ ].includes(squidData.type);
22196
+ }
22177
22197
  function getHistoryTransactionId(tx) {
22178
22198
  switch (tx.txType) {
22179
22199
  case exports.HistoryTxType.SWAP:
@@ -23153,7 +23173,7 @@ const filterViewableTokens = (tokens, config, direction) => {
23153
23173
  };
23154
23174
  const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
23155
23175
  const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
23156
- const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-B_-XWo1F.js'); });
23176
+ const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-0aEFG8v1.js'); });
23157
23177
  return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
23158
23178
  };
23159
23179
  function getTokenAssetsKey(token) {
@@ -26438,7 +26458,7 @@ function useStellarWallets() {
26438
26458
  try {
26439
26459
  const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
26440
26460
  const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module');
26441
- const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-sRzC5VSD.js'); });
26461
+ const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-BUoaW_gK.js'); });
26442
26462
  const modules = [...initializeAllModules(), new LedgerModule()];
26443
26463
  const promises = modules.map(async (module) => {
26444
26464
  const isAvailable = await module.isAvailable();
@@ -27938,7 +27958,7 @@ function hederaWalletConnect(parameters) {
27938
27958
  const optionalChains = config.chains.map((x) => x.id);
27939
27959
  if (!optionalChains.length)
27940
27960
  return;
27941
- const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-Cu_QQTg-.js'); });
27961
+ const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-BWWDAnQe.js'); });
27942
27962
  const rawProvider = await EthereumProvider.init({
27943
27963
  ...restParameters,
27944
27964
  disableProviderPing: true,
@@ -35626,47 +35646,91 @@ const useExecuteTransaction = (squidRoute) => {
35626
35646
  },
35627
35647
  });
35628
35648
  const swapMutationBitcoin = reactQuery.useMutation(async ({ id, route }) => {
35629
- const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
35630
- if (!depositAddress) {
35631
- throw new Error(`Invalid deposit address: ${depositAddress}`);
35632
- }
35633
- if (!sendAmount) {
35634
- throw new Error(`Invalid send amount: ${sendAmount}`);
35649
+ console.log("Validating route", {
35650
+ bitcoinSigner,
35651
+ route,
35652
+ });
35653
+ if (!bitcoinSigner || !route?.transactionRequest) {
35654
+ throw new Error("Need all parameters");
35635
35655
  }
35636
- const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
35637
- await changeNetworkIfNeeded.mutateAsync();
35638
- if (allParamsValid) {
35639
- dispatchSignatureRequestEvent(route);
35640
- const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
35641
- if (txHash) {
35642
- resetQueriesAfterTxSigned();
35656
+ switch (route.transactionRequest.type) {
35657
+ case squidTypes.SquidDataType.ChainflipDepositAddress: {
35658
+ const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
35659
+ const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
35660
+ if (!allParamsValid) {
35661
+ throw new Error("Need all parameters");
35662
+ }
35663
+ await changeNetworkIfNeeded.mutateAsync();
35664
+ dispatchSignatureRequestEvent(route);
35665
+ const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
35666
+ if (txHash) {
35667
+ resetQueriesAfterTxSigned();
35668
+ }
35669
+ // Dispatch event so it can be listened from outside the widget
35670
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
35671
+ if (route.transactionRequest) {
35672
+ const txParams = setTransactionState({
35673
+ route,
35674
+ txHash,
35675
+ // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
35676
+ // instead of the Bitcoin transaction hash
35677
+ transactionIdForStatus: chainflipStatusTrackingId,
35678
+ userAddress: sourceUserAddress,
35679
+ status: exports.TransactionStatus.INITIAL_LOADING,
35680
+ sourceStatus: exports.TransactionStatus.ONGOING,
35681
+ axelarUrl: undefined,
35682
+ id,
35683
+ });
35684
+ if (txParams) {
35685
+ addSwapTransaction({
35686
+ ...txParams,
35687
+ params: route.params,
35688
+ estimate: route.estimate,
35689
+ });
35690
+ }
35691
+ }
35692
+ break;
35643
35693
  }
35644
- // Dispatch event so it can be listened from outside the widget
35645
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
35646
- if (route.transactionRequest) {
35647
- const txParams = setTransactionState({
35648
- route,
35649
- txHash,
35650
- // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
35651
- // instead of the Bitcoin transaction hash
35652
- transactionIdForStatus: chainflipStatusTrackingId,
35653
- userAddress: sourceUserAddress,
35654
- status: exports.TransactionStatus.INITIAL_LOADING,
35655
- sourceStatus: exports.TransactionStatus.ONGOING,
35656
- axelarUrl: undefined,
35657
- id,
35658
- });
35659
- if (txParams) {
35660
- addSwapTransaction({
35661
- ...txParams,
35662
- params: route.params,
35663
- estimate: route.estimate,
35694
+ case squidTypes.SquidDataType.DepositAddressCalldata: {
35695
+ console.log(`Route type: ${route.transactionRequest?.type}`);
35696
+ if (!isOnChainTxData(route.transactionRequest)) {
35697
+ console.log("Invalid route data", route.transactionRequest);
35698
+ throw new Error("Invalid route data");
35699
+ }
35700
+ const { data: transactionHex } = route.transactionRequest;
35701
+ await changeNetworkIfNeeded.mutateAsync();
35702
+ dispatchSignatureRequestEvent(route);
35703
+ console.log("Signing psbt", { transactionHex });
35704
+ const { txHash } = await bitcoinSigner.signPsbt(transactionHex);
35705
+ console.log("Signed psbt", { txHash });
35706
+ if (txHash) {
35707
+ resetQueriesAfterTxSigned();
35708
+ }
35709
+ // Dispatch event so it can be listened from outside the widget
35710
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
35711
+ if (route.transactionRequest) {
35712
+ const txParams = setTransactionState({
35713
+ route,
35714
+ txHash,
35715
+ userAddress: sourceUserAddress,
35716
+ status: exports.TransactionStatus.INITIAL_LOADING,
35717
+ sourceStatus: exports.TransactionStatus.ONGOING,
35718
+ axelarUrl: undefined,
35719
+ id,
35664
35720
  });
35721
+ if (txParams) {
35722
+ addSwapTransaction({
35723
+ ...txParams,
35724
+ params: route.params,
35725
+ estimate: route.estimate,
35726
+ });
35727
+ }
35665
35728
  }
35729
+ break;
35730
+ }
35731
+ default: {
35732
+ throw new Error(`Unhandled route type ${route.transactionRequest.type}`);
35666
35733
  }
35667
- }
35668
- else {
35669
- throw new Error("Need all parameters");
35670
35734
  }
35671
35735
  });
35672
35736
  const swapMutationXrpl = reactQuery.useMutation(async ({ id, route }) => {
@@ -36933,6 +36997,7 @@ exports.isHistoryTransactionEnded = isHistoryTransactionEnded;
36933
36997
  exports.isHistoryTransactionFailed = isHistoryTransactionFailed;
36934
36998
  exports.isHistoryTransactionPending = isHistoryTransactionPending;
36935
36999
  exports.isHistoryTransactionWarning = isHistoryTransactionWarning;
37000
+ exports.isOnChainTxData = isOnChainTxData;
36936
37001
  exports.isProblematicConnector = isProblematicConnector;
36937
37002
  exports.isSolanaAddressValid = isSolanaAddressValid;
36938
37003
  exports.isStatusError = isStatusError;
@@ -37048,4 +37113,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
37048
37113
  exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
37049
37114
  exports.walletIconBaseUrl = walletIconBaseUrl;
37050
37115
  exports.walletSupportsChainType = walletSupportsChainType;
37051
- //# sourceMappingURL=index-qAOvcSon.js.map
37116
+ //# sourceMappingURL=index-D9ejMike.js.map