@0xsquid/react-hooks 8.8.1-beta-canton.4 → 8.9.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.
- package/dist/core/client/index.d.ts +0 -1
- package/dist/core/constants.d.ts +0 -2
- package/dist/core/types/wallet.d.ts +6 -9
- package/dist/hooks/chains/useSquidChains.d.ts +0 -1
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/store/useDepositAddressStore.d.ts +5 -23
- package/dist/hooks/swap/useDepositAddress.d.ts +7 -6
- package/dist/hooks/tokens/useSquidTokens.d.ts +0 -1
- package/dist/hooks/wallet/useMultiChainWallet.d.ts +15 -41
- package/dist/hooks/wallet/useWallet.d.ts +15 -45
- package/dist/{index-D5QOR7JT.js → index-BL_AUWQg.js} +217 -394
- package/dist/index-BL_AUWQg.js.map +1 -0
- package/dist/{index-mgE1SeE-.js → index-DcBFug8t.js} +216 -396
- package/dist/index-DcBFug8t.js.map +1 -0
- package/dist/{index.es-3JPbTFKq.js → index.es-1XEAWjab.js} +2 -2
- package/dist/{index.es-3JPbTFKq.js.map → index.es-1XEAWjab.js.map} +1 -1
- package/dist/{index.es-Cq4mUT_n.js → index.es-DSQHpime.js} +2 -2
- package/dist/{index.es-Cq4mUT_n.js.map → index.es-DSQHpime.js.map} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/{secretService-DWq78rM5.js → secretService-B1SDXLS1.js} +2 -2
- package/dist/{secretService-DWq78rM5.js.map → secretService-B1SDXLS1.js.map} +1 -1
- package/dist/{secretService-DOOg6zVn.js → secretService-DxQ78j5I.js} +2 -2
- package/dist/{secretService-DOOg6zVn.js.map → secretService-DxQ78j5I.js.map} +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.esm.js +1 -8
- package/dist/server.esm.js.map +1 -1
- package/dist/server.js +0 -8
- package/dist/server.js.map +1 -1
- package/dist/services/internal/assetsService.d.ts +1 -10
- package/dist/services/internal/solanaTokenProgramService.d.ts +9 -0
- package/dist/services/internal/transactionService.d.ts +1 -5
- package/dist/{stellarService.client-DBROJ4yf.js → stellarService.client-C4TLBEpm.js} +2 -2
- package/dist/{stellarService.client-DBROJ4yf.js.map → stellarService.client-C4TLBEpm.js.map} +1 -1
- package/dist/{stellarService.client-C-pOt34O.js → stellarService.client-CkP5ng2n.js} +2 -2
- package/dist/{stellarService.client-C-pOt34O.js.map → stellarService.client-CkP5ng2n.js.map} +1 -1
- package/dist/tests/rpcServiceSolana.test.d.ts +1 -0
- package/dist/tests/solanaTokenProgramService.test.d.ts +1 -0
- package/package.json +2 -2
- package/dist/core/types/canton.d.ts +0 -2
- package/dist/core/types/cosmos.d.ts +0 -5
- package/dist/hooks/transaction/useDepositTransactionStatus.d.ts +0 -25
- package/dist/hooks/transaction/useSwapStatusQuery.d.ts +0 -26
- package/dist/index-D5QOR7JT.js.map +0 -1
- package/dist/index-mgE1SeE-.js.map +0 -1
- package/dist/services/internal/cantonService.d.ts +0 -2
|
@@ -78,8 +78,6 @@ const solanaZeroAddress = "11111111111111111111111111111111";
|
|
|
78
78
|
const suiZeroAddress = "0x0000000000000000000000000000000000000000";
|
|
79
79
|
const xrplZeroAddress = "rrrrrrrrrrrrrrrrrrrrrhoLvTp";
|
|
80
80
|
const stellarZeroAddress = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF";
|
|
81
|
-
// TODO: check
|
|
82
|
-
const cantonZeroAddress = "none::12200000000000000000000000000000000000000000000000000000000000000000";
|
|
83
81
|
const chainTypeToZeroAddressMap = {
|
|
84
82
|
[squidTypes.ChainType.EVM]: viem.zeroAddress,
|
|
85
83
|
[squidTypes.ChainType.COSMOS]: cosmosZeroAddress,
|
|
@@ -88,7 +86,6 @@ const chainTypeToZeroAddressMap = {
|
|
|
88
86
|
[squidTypes.ChainType.SUI]: suiZeroAddress,
|
|
89
87
|
[squidTypes.ChainType.XRPL]: xrplZeroAddress,
|
|
90
88
|
[squidTypes.ChainType.STELLAR]: stellarZeroAddress,
|
|
91
|
-
[squidTypes.ChainType.CANTON]: cantonZeroAddress,
|
|
92
89
|
};
|
|
93
90
|
const nativeEvmTokenAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
94
91
|
const nativeCosmosTokenAddress = "uosmo";
|
|
@@ -97,7 +94,6 @@ const nativeBitcoinTokenAddress = "satoshi";
|
|
|
97
94
|
const nativeSuiTokenAddress = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
98
95
|
const nativeXrplTokenAddress = "xrp";
|
|
99
96
|
const nativeStellarTokenAddress = "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA";
|
|
100
|
-
const nativeCantonTokenAddress = "DSO::1220b1431ef217342db44d516bb9befde802be7d8899637d290895fa58880f19accc";
|
|
101
97
|
// by setting slippage to undefined, it's set to "auto"
|
|
102
98
|
const defaultSlippage = undefined;
|
|
103
99
|
const destinationAddressResetValue = "null";
|
|
@@ -161,7 +157,6 @@ const CHAIN_IDS = {
|
|
|
161
157
|
XRPL_TESTNET: "xrpl-testnet",
|
|
162
158
|
STELLAR: "stellar-mainnet",
|
|
163
159
|
STELLAR_TESTNET: "stellar-testnet",
|
|
164
|
-
CANTON: "canton",
|
|
165
160
|
};
|
|
166
161
|
const chainTypeToDefaultChainIdMap = {
|
|
167
162
|
[squidTypes.ChainType.EVM]: CHAIN_IDS.ETHEREUM,
|
|
@@ -171,7 +166,6 @@ const chainTypeToDefaultChainIdMap = {
|
|
|
171
166
|
[squidTypes.ChainType.SUI]: CHAIN_IDS.SUI,
|
|
172
167
|
[squidTypes.ChainType.XRPL]: CHAIN_IDS.XRPL,
|
|
173
168
|
[squidTypes.ChainType.STELLAR]: CHAIN_IDS.STELLAR,
|
|
174
|
-
[squidTypes.ChainType.CANTON]: CHAIN_IDS.CANTON,
|
|
175
169
|
};
|
|
176
170
|
const chainTypeToNativeTokenAddressMap = {
|
|
177
171
|
[squidTypes.ChainType.EVM]: nativeEvmTokenAddress,
|
|
@@ -181,7 +175,6 @@ const chainTypeToNativeTokenAddressMap = {
|
|
|
181
175
|
[squidTypes.ChainType.SUI]: nativeSuiTokenAddress,
|
|
182
176
|
[squidTypes.ChainType.XRPL]: nativeXrplTokenAddress,
|
|
183
177
|
[squidTypes.ChainType.STELLAR]: nativeStellarTokenAddress,
|
|
184
|
-
[squidTypes.ChainType.CANTON]: nativeCantonTokenAddress,
|
|
185
178
|
};
|
|
186
179
|
const defaultConfigValues = {
|
|
187
180
|
integratorId: INTEGRATOR_ID,
|
|
@@ -20879,17 +20872,31 @@ const isBitcoinAddressValid = (address) => {
|
|
|
20879
20872
|
}
|
|
20880
20873
|
};
|
|
20881
20874
|
|
|
20882
|
-
|
|
20883
|
-
|
|
20884
|
-
|
|
20885
|
-
|
|
20886
|
-
|
|
20887
|
-
|
|
20888
|
-
if (
|
|
20889
|
-
return
|
|
20890
|
-
|
|
20891
|
-
|
|
20892
|
-
}
|
|
20875
|
+
const solanaTokenProgramIdByAddress = {
|
|
20876
|
+
[splToken.TOKEN_PROGRAM_ID.toBase58()]: splToken.TOKEN_PROGRAM_ID,
|
|
20877
|
+
[splToken.TOKEN_2022_PROGRAM_ID.toBase58()]: splToken.TOKEN_2022_PROGRAM_ID,
|
|
20878
|
+
};
|
|
20879
|
+
const isSupportedSolanaTokenProgramId = (programId) => programId.toBase58() in solanaTokenProgramIdByAddress;
|
|
20880
|
+
const getSupportedSolanaTokenProgramId = (tokenProgramId) => {
|
|
20881
|
+
if (!tokenProgramId)
|
|
20882
|
+
return undefined;
|
|
20883
|
+
return solanaTokenProgramIdByAddress[tokenProgramId];
|
|
20884
|
+
};
|
|
20885
|
+
const resolveSolanaTokenProgramId = async ({ connection, token, }) => {
|
|
20886
|
+
const tokenProgramId = getSupportedSolanaTokenProgramId(token.tokenProgramId);
|
|
20887
|
+
if (tokenProgramId) {
|
|
20888
|
+
return tokenProgramId;
|
|
20889
|
+
}
|
|
20890
|
+
const mint = new web3_js.PublicKey(token.address);
|
|
20891
|
+
const mintAccount = await connection.getAccountInfo(mint);
|
|
20892
|
+
if (!mintAccount) {
|
|
20893
|
+
throw new Error(`Solana mint account not found: ${token.address}`);
|
|
20894
|
+
}
|
|
20895
|
+
if (!isSupportedSolanaTokenProgramId(mintAccount.owner)) {
|
|
20896
|
+
throw new Error(`Unsupported Solana token program for mint ${token.address}: ${mintAccount.owner.toBase58()}`);
|
|
20897
|
+
}
|
|
20898
|
+
return mintAccount.owner;
|
|
20899
|
+
};
|
|
20893
20900
|
|
|
20894
20901
|
exports.HistoryTxType = void 0;
|
|
20895
20902
|
(function (HistoryTxType) {
|
|
@@ -21004,7 +21011,6 @@ const getSourceExplorerTxUrl = (chain, txID) => {
|
|
|
21004
21011
|
case CHAIN_IDS.AGORIC:
|
|
21005
21012
|
case CHAIN_IDS.XRPL:
|
|
21006
21013
|
case CHAIN_IDS.XRPL_TESTNET:
|
|
21007
|
-
case CHAIN_IDS.CANTON:
|
|
21008
21014
|
txSuffix = "/transactions/";
|
|
21009
21015
|
break;
|
|
21010
21016
|
case CHAIN_IDS.HEDERA:
|
|
@@ -21114,16 +21120,10 @@ const simplifyRouteAction = (action) => {
|
|
|
21114
21120
|
};
|
|
21115
21121
|
const fetchSwapTransactionStatus = async ({ transaction, integratorId, apiUrl, }) => {
|
|
21116
21122
|
const statusEndpoint = `${apiUrl}/v2/status`;
|
|
21117
|
-
const isCanton = transaction?.fromChain === CHAIN_IDS.CANTON;
|
|
21118
|
-
// For Canton, the backend handles all tx detection/submission from the quoteId
|
|
21119
|
-
// alone, so no transactionId is sent — only the quoteId param below.
|
|
21120
|
-
const transactionId = isCanton
|
|
21121
|
-
? undefined
|
|
21122
|
-
: transaction?.transactionIdForStatus ?? transaction?.transactionId;
|
|
21123
21123
|
try {
|
|
21124
21124
|
const response = await axios.get(statusEndpoint, {
|
|
21125
21125
|
params: {
|
|
21126
|
-
transactionId,
|
|
21126
|
+
transactionId: transaction?.transactionIdForStatus ?? transaction?.transactionId,
|
|
21127
21127
|
fromChainId: transaction?.fromChain,
|
|
21128
21128
|
toChainId: transaction?.toChain,
|
|
21129
21129
|
bridgeType: transaction?.bridgeType,
|
|
@@ -21170,7 +21170,7 @@ function isActionCompletedOnSourceTx(action, fromChainId) {
|
|
|
21170
21170
|
function sleep(ms) {
|
|
21171
21171
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
21172
21172
|
}
|
|
21173
|
-
const
|
|
21173
|
+
const isDepositRoute = (route) => {
|
|
21174
21174
|
return (!!route &&
|
|
21175
21175
|
route.transactionRequest?.type === squidTypes.SquidDataType.ChainflipDepositAddress);
|
|
21176
21176
|
};
|
|
@@ -21195,12 +21195,6 @@ function isOnChainTxData(squidData) {
|
|
|
21195
21195
|
squidTypes.SquidDataType.DepositAddressWithMemo,
|
|
21196
21196
|
].includes(squidData.type);
|
|
21197
21197
|
}
|
|
21198
|
-
/**
|
|
21199
|
-
* Checks if a route is of type DepositAddressDirectTransfer
|
|
21200
|
-
*/
|
|
21201
|
-
function isDepositAddressDirectTransferRoute(squidData) {
|
|
21202
|
-
return (squidData.type === squidTypes.SquidDataType.DepositAddressDirectTransfer);
|
|
21203
|
-
}
|
|
21204
21198
|
function getHistoryTransactionId(tx) {
|
|
21205
21199
|
switch (tx.txType) {
|
|
21206
21200
|
case exports.HistoryTxType.SWAP:
|
|
@@ -21383,6 +21377,16 @@ const isSolanaAddressValid = (address) => {
|
|
|
21383
21377
|
return false;
|
|
21384
21378
|
}
|
|
21385
21379
|
};
|
|
21380
|
+
const deserializeSolanaTransaction = (transactionBuffer) => {
|
|
21381
|
+
// Squid can return legacy Solana transactions (ITS) or versioned transactions
|
|
21382
|
+
// (Jupiter/Chainflip). Deserialize once to detect the payload type. Legacy
|
|
21383
|
+
// transactions need to be converted to Transaction because their blockhash is
|
|
21384
|
+
// mutable and must be refreshed before signing.
|
|
21385
|
+
const versionedTransaction = web3_js.VersionedTransaction.deserialize(transactionBuffer);
|
|
21386
|
+
return versionedTransaction.version === "legacy"
|
|
21387
|
+
? web3_js.Transaction.from(transactionBuffer)
|
|
21388
|
+
: versionedTransaction;
|
|
21389
|
+
};
|
|
21386
21390
|
/**
|
|
21387
21391
|
* Execute a Solana swap transaction
|
|
21388
21392
|
* This will be used for the swap flow - Using Jupiter Dex under the hood
|
|
@@ -21393,13 +21397,16 @@ const executeSolanaSwap = async ({ route, signer, connection, onSigned, }) => {
|
|
|
21393
21397
|
}
|
|
21394
21398
|
const swapRequest = route.transactionRequest.data;
|
|
21395
21399
|
const swapTransactionBuf = Buffer.from(swapRequest, "base64");
|
|
21396
|
-
|
|
21397
|
-
// const transaction = VersionedTransaction.deserialize(
|
|
21398
|
-
// Uint8Array.from(swapTransactionBuf)
|
|
21399
|
-
// );
|
|
21400
|
-
const transaction = web3_js.VersionedTransaction.deserialize(swapTransactionBuf);
|
|
21400
|
+
const transaction = deserializeSolanaTransaction(swapTransactionBuf);
|
|
21401
21401
|
try {
|
|
21402
21402
|
const latestBlockhash = await connection.getLatestBlockhash();
|
|
21403
|
+
if (transaction instanceof web3_js.Transaction) {
|
|
21404
|
+
// ITS legacy transactions arrive with the placeholder blockhash
|
|
21405
|
+
// 11111111111111111111111111111111.
|
|
21406
|
+
// Refresh it right before signing so the submitted transaction
|
|
21407
|
+
// uses a valid blockhash. Versioned transactions are not mutable here.
|
|
21408
|
+
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
21409
|
+
}
|
|
21403
21410
|
const signature = await signer.sendTransaction(transaction, connection);
|
|
21404
21411
|
onSigned?.(signature);
|
|
21405
21412
|
await connection.confirmTransaction({
|
|
@@ -21448,16 +21455,20 @@ const executeSolanaTransfer = async ({ amount, target, signer, connection, sourc
|
|
|
21448
21455
|
else {
|
|
21449
21456
|
// Handle SPL token transfer
|
|
21450
21457
|
const mint = new web3_js.PublicKey(sourceToken.address);
|
|
21458
|
+
const tokenProgramId = await resolveSolanaTokenProgramId({
|
|
21459
|
+
connection,
|
|
21460
|
+
token: sourceToken,
|
|
21461
|
+
});
|
|
21451
21462
|
// Get Associated Token Accounts (ATAs) for both source and target
|
|
21452
|
-
const sourceATA = await splToken.getAssociatedTokenAddress(mint, signer.publicKey, true);
|
|
21453
|
-
const targetATA = await splToken.getAssociatedTokenAddress(mint, targetPubKey, true);
|
|
21463
|
+
const sourceATA = await splToken.getAssociatedTokenAddress(mint, signer.publicKey, true, tokenProgramId);
|
|
21464
|
+
const targetATA = await splToken.getAssociatedTokenAddress(mint, targetPubKey, true, tokenProgramId);
|
|
21454
21465
|
// Check if target ATA exists and create if needed
|
|
21455
21466
|
const targetAccount = await connection.getAccountInfo(targetATA);
|
|
21456
21467
|
if (!targetAccount) {
|
|
21457
|
-
transaction.add(splToken.createAssociatedTokenAccountInstruction(signer.publicKey, targetATA, targetPubKey, mint));
|
|
21468
|
+
transaction.add(splToken.createAssociatedTokenAccountInstruction(signer.publicKey, targetATA, targetPubKey, mint, tokenProgramId));
|
|
21458
21469
|
}
|
|
21459
21470
|
// Add the token transfer instruction
|
|
21460
|
-
transaction.add(splToken.createTransferInstruction(sourceATA, targetATA, signer.publicKey, amount));
|
|
21471
|
+
transaction.add(splToken.createTransferInstruction(sourceATA, targetATA, signer.publicKey, amount, [], tokenProgramId));
|
|
21461
21472
|
}
|
|
21462
21473
|
// Get latest blockhash and sign transaction
|
|
21463
21474
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
|
|
@@ -21703,17 +21714,7 @@ const chainTypeToTrimLength = {
|
|
|
21703
21714
|
start: 4,
|
|
21704
21715
|
end: 4,
|
|
21705
21716
|
},
|
|
21706
|
-
// abc...123::abc...123
|
|
21707
|
-
[squidTypes.ChainType.CANTON]: {
|
|
21708
|
-
start: 3,
|
|
21709
|
-
end: 3,
|
|
21710
|
-
},
|
|
21711
21717
|
};
|
|
21712
|
-
const truncateWithEllipsis = (value, startLength, endLength) => value.length <= startLength + endLength
|
|
21713
|
-
? value
|
|
21714
|
-
: value.slice(0, startLength) +
|
|
21715
|
-
"..." +
|
|
21716
|
-
value.slice(value.length - endLength);
|
|
21717
21718
|
const formatHash = ({ chainType, hash }) => {
|
|
21718
21719
|
if (!hash)
|
|
21719
21720
|
return "";
|
|
@@ -21726,15 +21727,14 @@ const formatHash = ({ chainType, hash }) => {
|
|
|
21726
21727
|
chainTypeFormat = squidTypes.ChainType.COSMOS;
|
|
21727
21728
|
}
|
|
21728
21729
|
}
|
|
21729
|
-
const
|
|
21730
|
-
|
|
21731
|
-
|
|
21732
|
-
|
|
21733
|
-
return
|
|
21734
|
-
|
|
21735
|
-
|
|
21736
|
-
|
|
21737
|
-
return truncateWithEllipsis(hash, start, end);
|
|
21730
|
+
const trimLengthStart = chainTypeToTrimLength[chainTypeFormat].start;
|
|
21731
|
+
const trimLengthEnd = chainTypeToTrimLength[chainTypeFormat].end;
|
|
21732
|
+
// return the same hash if its length is less than the trim length
|
|
21733
|
+
if (hash.length <= trimLengthStart + trimLengthEnd)
|
|
21734
|
+
return hash;
|
|
21735
|
+
return (hash.slice(0, trimLengthStart) +
|
|
21736
|
+
"..." +
|
|
21737
|
+
hash.slice(hash.length - trimLengthEnd, hash.length));
|
|
21738
21738
|
};
|
|
21739
21739
|
const isWalletAddressValid = (chainData, address) => {
|
|
21740
21740
|
if (!address || !chainData?.chainType)
|
|
@@ -21754,8 +21754,6 @@ const isWalletAddressValid = (chainData, address) => {
|
|
|
21754
21754
|
return isXrplAddressValid(address);
|
|
21755
21755
|
case squidTypes.ChainType.STELLAR:
|
|
21756
21756
|
return isStellarAddressValid(address);
|
|
21757
|
-
case squidTypes.ChainType.CANTON:
|
|
21758
|
-
return isCantonAddressValid(address);
|
|
21759
21757
|
}
|
|
21760
21758
|
};
|
|
21761
21759
|
const redirectToExtensionsStore = (wallet) => {
|
|
@@ -22017,8 +22015,6 @@ const connectByChainType = async (chainType, wallet, defaultChain, params) => {
|
|
|
22017
22015
|
connector,
|
|
22018
22016
|
},
|
|
22019
22017
|
});
|
|
22020
|
-
case squidTypes.ChainType.CANTON:
|
|
22021
|
-
return null;
|
|
22022
22018
|
}
|
|
22023
22019
|
};
|
|
22024
22020
|
const getChainTypesToConnect = (selectedChainTypes, defaultChain, supportedChains) => {
|
|
@@ -23093,10 +23089,7 @@ const getNewSwapParamsFromInput = ({ inputParams, initialSwapRoute, tokens, chai
|
|
|
23093
23089
|
else {
|
|
23094
23090
|
newFallbackAddress = fallbackAddress ?? initialSwapRoute?.fallbackAddress;
|
|
23095
23091
|
}
|
|
23096
|
-
const
|
|
23097
|
-
const newDepositRefundAddress = sourceChainChanged
|
|
23098
|
-
? undefined
|
|
23099
|
-
: depositRefundAddress || initialSwapRoute?.depositRefundAddress;
|
|
23092
|
+
const newDepositRefundAddress = depositRefundAddress || initialSwapRoute?.depositRefundAddress;
|
|
23100
23093
|
return {
|
|
23101
23094
|
fromChainId: srcChainId,
|
|
23102
23095
|
fromTokenAddress: sourceTokenAddress,
|
|
@@ -23375,7 +23368,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23375
23368
|
};
|
|
23376
23369
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
23377
23370
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
23378
|
-
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-
|
|
23371
|
+
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-B1SDXLS1.js'); });
|
|
23379
23372
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
23380
23373
|
};
|
|
23381
23374
|
function getTokenAssetsKey(token) {
|
|
@@ -23402,29 +23395,9 @@ async function fetchAssetsColors() {
|
|
|
23402
23395
|
};
|
|
23403
23396
|
}
|
|
23404
23397
|
}
|
|
23405
|
-
|
|
23406
|
-
|
|
23407
|
-
|
|
23408
|
-
}
|
|
23409
|
-
/**
|
|
23410
|
-
* Normalizes SDK data after each init/refetch before the rest of hooks consumes it.
|
|
23411
|
-
*
|
|
23412
|
-
* - Removes chains whose chainType is not supported by the local package.
|
|
23413
|
-
* - Drops tokens for those removed chains.
|
|
23414
|
-
* - Converts Evmos chains/tokens to EVM.
|
|
23415
|
-
* - Applies optional asset colors.
|
|
23416
|
-
*/
|
|
23417
|
-
function initializeSquidData(squid, assetsColors = {
|
|
23418
|
-
chains: {},
|
|
23419
|
-
tokens: {},
|
|
23420
|
-
}) {
|
|
23421
|
-
const supportedChains = squid.chains.filter((chain) => isSupportedChainType(chain.chainType));
|
|
23422
|
-
const supportedChainIds = new Set(supportedChains.map((chain) => chain.chainId));
|
|
23423
|
-
const evmosChainIds = supportedChains
|
|
23424
|
-
.filter(isEvmosChain)
|
|
23425
|
-
.map((c) => c.chainId);
|
|
23426
|
-
const supportedTokens = squid.tokens.filter((token) => supportedChainIds.has(token.chainId));
|
|
23427
|
-
squid.tokens = supportedTokens.map((token) => {
|
|
23398
|
+
function initializeSquidWithAssetsColors(squid, assetsColors) {
|
|
23399
|
+
const evmosChainIds = squid.chains.filter(isEvmosChain).map((c) => c.chainId);
|
|
23400
|
+
squid.tokens = squid.tokens.map((token) => {
|
|
23428
23401
|
const isEvmosToken = evmosChainIds.includes(token.chainId);
|
|
23429
23402
|
return {
|
|
23430
23403
|
...token,
|
|
@@ -23433,7 +23406,7 @@ function initializeSquidData(squid, assetsColors = {
|
|
|
23433
23406
|
textColor: assetsColors.tokens[getTokenAssetsKey(token)]?.textColor,
|
|
23434
23407
|
};
|
|
23435
23408
|
});
|
|
23436
|
-
squid.chains =
|
|
23409
|
+
squid.chains = squid.chains.map((chain) => {
|
|
23437
23410
|
const bgColor = assetsColors.chains[chain.chainId]?.bgColor;
|
|
23438
23411
|
// convert evmos cosmos chains to evm chains
|
|
23439
23412
|
// TODO: this will be fixed in the backend
|
|
@@ -25310,7 +25283,7 @@ const useSquid = () => {
|
|
|
25310
25283
|
queryFn: async () => {
|
|
25311
25284
|
if (squid) {
|
|
25312
25285
|
await squid?.init();
|
|
25313
|
-
|
|
25286
|
+
initializeSquidWithAssetsColors(squid, assetsColors);
|
|
25314
25287
|
return squid;
|
|
25315
25288
|
}
|
|
25316
25289
|
return null;
|
|
@@ -25369,7 +25342,7 @@ const useSquidTokens = (direction) => {
|
|
|
25369
25342
|
config.availableChains,
|
|
25370
25343
|
direction,
|
|
25371
25344
|
]);
|
|
25372
|
-
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens,
|
|
25345
|
+
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = React.useMemo(() => {
|
|
25373
25346
|
return tokens?.reduce((acc, token) => {
|
|
25374
25347
|
switch (token.type) {
|
|
25375
25348
|
case squidTypes.ChainType.EVM:
|
|
@@ -25393,9 +25366,6 @@ const useSquidTokens = (direction) => {
|
|
|
25393
25366
|
case squidTypes.ChainType.STELLAR:
|
|
25394
25367
|
acc.stellarTokens.push(token);
|
|
25395
25368
|
break;
|
|
25396
|
-
case squidTypes.ChainType.CANTON:
|
|
25397
|
-
acc.cantonTokens.push(token);
|
|
25398
|
-
break;
|
|
25399
25369
|
}
|
|
25400
25370
|
return acc;
|
|
25401
25371
|
}, {
|
|
@@ -25406,7 +25376,6 @@ const useSquidTokens = (direction) => {
|
|
|
25406
25376
|
suiTokens: [],
|
|
25407
25377
|
xrplTokens: [],
|
|
25408
25378
|
stellarTokens: [],
|
|
25409
|
-
cantonTokens: [],
|
|
25410
25379
|
});
|
|
25411
25380
|
}, [tokens]);
|
|
25412
25381
|
const findToken = React.useCallback((address, chainId) => {
|
|
@@ -25424,7 +25393,6 @@ const useSquidTokens = (direction) => {
|
|
|
25424
25393
|
suiTokens,
|
|
25425
25394
|
xrplTokens,
|
|
25426
25395
|
stellarTokens,
|
|
25427
|
-
cantonTokens,
|
|
25428
25396
|
};
|
|
25429
25397
|
};
|
|
25430
25398
|
|
|
@@ -25962,7 +25930,6 @@ const chainTypeToRefetchInterval = {
|
|
|
25962
25930
|
[squidTypes.ChainType.SUI]: 1_000,
|
|
25963
25931
|
[squidTypes.ChainType.XRPL]: 1_000,
|
|
25964
25932
|
[squidTypes.ChainType.STELLAR]: 1_000,
|
|
25965
|
-
[squidTypes.ChainType.CANTON]: 1_000,
|
|
25966
25933
|
};
|
|
25967
25934
|
/**
|
|
25968
25935
|
* Returns the status refetch interval of a Send transaction
|
|
@@ -26229,7 +26196,7 @@ const useSquidChains = (direction) => {
|
|
|
26229
26196
|
const chain = findChain(chainId);
|
|
26230
26197
|
return chain?.chainType;
|
|
26231
26198
|
}, [findChain]);
|
|
26232
|
-
const { evmChains, cosmosChains, suiChains, stellarChains, xrplChains
|
|
26199
|
+
const { evmChains, cosmosChains, suiChains, stellarChains, xrplChains } = React.useMemo(() => {
|
|
26233
26200
|
return chains.reduce((acc, chain) => {
|
|
26234
26201
|
switch (chain.chainType) {
|
|
26235
26202
|
case squidTypes.ChainType.EVM:
|
|
@@ -26247,9 +26214,6 @@ const useSquidChains = (direction) => {
|
|
|
26247
26214
|
case squidTypes.ChainType.STELLAR:
|
|
26248
26215
|
acc.stellarChains.push(chain);
|
|
26249
26216
|
break;
|
|
26250
|
-
case squidTypes.ChainType.CANTON:
|
|
26251
|
-
acc.cantonChains.push(chain);
|
|
26252
|
-
break;
|
|
26253
26217
|
}
|
|
26254
26218
|
return acc;
|
|
26255
26219
|
}, {
|
|
@@ -26258,7 +26222,6 @@ const useSquidChains = (direction) => {
|
|
|
26258
26222
|
suiChains: [],
|
|
26259
26223
|
xrplChains: [],
|
|
26260
26224
|
stellarChains: [],
|
|
26261
|
-
cantonChains: [],
|
|
26262
26225
|
});
|
|
26263
26226
|
}, [chains]);
|
|
26264
26227
|
const { supportedSourceChains, supportedDestinationChains } = React.useMemo(() => {
|
|
@@ -26279,7 +26242,6 @@ const useSquidChains = (direction) => {
|
|
|
26279
26242
|
suiChains,
|
|
26280
26243
|
xrplChains,
|
|
26281
26244
|
stellarChains,
|
|
26282
|
-
cantonChains,
|
|
26283
26245
|
getChainType,
|
|
26284
26246
|
findChain,
|
|
26285
26247
|
};
|
|
@@ -26804,7 +26766,7 @@ function useStellarWallets() {
|
|
|
26804
26766
|
try {
|
|
26805
26767
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
26806
26768
|
const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module.mjs');
|
|
26807
|
-
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-
|
|
26769
|
+
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-C4TLBEpm.js'); });
|
|
26808
26770
|
const modules = [...initializeAllModules(), new LedgerModule()];
|
|
26809
26771
|
const promises = modules.map(async (module) => {
|
|
26810
26772
|
const isAvailable = await module.isAvailable();
|
|
@@ -27503,7 +27465,6 @@ const useMultiChainWallet = (chain) => {
|
|
|
27503
27465
|
const suiAddress = connectedAddresses[squidTypes.ChainType.SUI];
|
|
27504
27466
|
const xrplAddress = connectedAddresses[squidTypes.ChainType.XRPL];
|
|
27505
27467
|
const stellarAddress = connectedAddresses[squidTypes.ChainType.STELLAR];
|
|
27506
|
-
const cantonAddress = connectedAddresses[squidTypes.ChainType.CANTON];
|
|
27507
27468
|
// Cosmos is a special case because the address changes on every chain
|
|
27508
27469
|
// so we can't use the default cosmos connected address
|
|
27509
27470
|
const { data: cosmosAddress } = useCosmosForChain(chain);
|
|
@@ -27591,16 +27552,6 @@ const useMultiChainWallet = (chain) => {
|
|
|
27591
27552
|
chainType: chain.chainType,
|
|
27592
27553
|
}),
|
|
27593
27554
|
};
|
|
27594
|
-
case squidTypes.ChainType.CANTON:
|
|
27595
|
-
if (!cantonAddress)
|
|
27596
|
-
return {};
|
|
27597
|
-
return {
|
|
27598
|
-
address: cantonAddress,
|
|
27599
|
-
formatted: formatHash({
|
|
27600
|
-
hash: cantonAddress,
|
|
27601
|
-
chainType: chain.chainType,
|
|
27602
|
-
}),
|
|
27603
|
-
};
|
|
27604
27555
|
}
|
|
27605
27556
|
}, [
|
|
27606
27557
|
chain?.chainType,
|
|
@@ -27612,7 +27563,6 @@ const useMultiChainWallet = (chain) => {
|
|
|
27612
27563
|
suiAddress,
|
|
27613
27564
|
xrplAddress,
|
|
27614
27565
|
stellarAddress,
|
|
27615
|
-
cantonAddress,
|
|
27616
27566
|
]);
|
|
27617
27567
|
/**
|
|
27618
27568
|
* Change current network for desired chain
|
|
@@ -28437,8 +28387,6 @@ async function createClient(chain) {
|
|
|
28437
28387
|
return new XrplRpcClient(chain.rpc);
|
|
28438
28388
|
case squidTypes.ChainType.STELLAR:
|
|
28439
28389
|
return new StellarRpcClient(chain.rpc);
|
|
28440
|
-
case squidTypes.ChainType.CANTON:
|
|
28441
|
-
return null;
|
|
28442
28390
|
}
|
|
28443
28391
|
}
|
|
28444
28392
|
|
|
@@ -29275,6 +29223,10 @@ const getSolanaTokenBalance = async (userAddress, tokenAddress) => {
|
|
|
29275
29223
|
if (tokenAddress.toLowerCase() === nativeSolanaTokenAddress.toLowerCase()) {
|
|
29276
29224
|
return getSolanaNativeBalance(userAddress);
|
|
29277
29225
|
}
|
|
29226
|
+
const balances = await getSolanaTokensBalance(userAddress, [tokenAddress]);
|
|
29227
|
+
return balances[tokenAddress] || BigInt(0);
|
|
29228
|
+
};
|
|
29229
|
+
const getSolanaTokenAccountsByProgram = async (userAddress, programId) => {
|
|
29278
29230
|
const response = await fetch(SOLANA_RPC_URL, {
|
|
29279
29231
|
method: "POST",
|
|
29280
29232
|
headers: { "Content-Type": "application/json" },
|
|
@@ -29284,43 +29236,45 @@ const getSolanaTokenBalance = async (userAddress, tokenAddress) => {
|
|
|
29284
29236
|
method: "getTokenAccountsByOwner",
|
|
29285
29237
|
params: [
|
|
29286
29238
|
userAddress,
|
|
29287
|
-
{ programId
|
|
29239
|
+
{ programId },
|
|
29288
29240
|
{ encoding: "jsonParsed" },
|
|
29289
29241
|
],
|
|
29290
29242
|
}),
|
|
29291
29243
|
});
|
|
29292
29244
|
const data = await response.json();
|
|
29293
|
-
|
|
29294
|
-
|
|
29295
|
-
|
|
29245
|
+
if (data.error) {
|
|
29246
|
+
throw new Error(data.error.message || "Failed to fetch Solana balances");
|
|
29247
|
+
}
|
|
29248
|
+
return data.result?.value || [];
|
|
29296
29249
|
};
|
|
29297
29250
|
const getSolanaTokensBalance = async (userAddress, tokenAddresses) => {
|
|
29298
|
-
const
|
|
29299
|
-
|
|
29300
|
-
headers: { "Content-Type": "application/json" },
|
|
29301
|
-
body: JSON.stringify({
|
|
29302
|
-
jsonrpc: "2.0",
|
|
29303
|
-
id: 1,
|
|
29304
|
-
method: "getTokenAccountsByOwner",
|
|
29305
|
-
params: [
|
|
29306
|
-
userAddress,
|
|
29307
|
-
{ programId: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
|
|
29308
|
-
{ encoding: "jsonParsed" },
|
|
29309
|
-
],
|
|
29310
|
-
}),
|
|
29311
|
-
});
|
|
29312
|
-
const data = await response.json();
|
|
29313
|
-
return tokenAddresses.reduce((acc, address) => {
|
|
29314
|
-
const tokenAccount = data.result?.value?.find((accountInfo) => accountInfo.account.data.parsed.info.mint.toLowerCase() ===
|
|
29315
|
-
address.toLowerCase());
|
|
29316
|
-
acc[address] = BigInt(tokenAccount?.account.data.parsed.info.tokenAmount.amount || 0);
|
|
29251
|
+
const balancesByAddress = tokenAddresses.reduce((acc, address) => {
|
|
29252
|
+
acc[address] = BigInt(0);
|
|
29317
29253
|
return acc;
|
|
29318
29254
|
}, {});
|
|
29255
|
+
if (tokenAddresses.length === 0) {
|
|
29256
|
+
return balancesByAddress;
|
|
29257
|
+
}
|
|
29258
|
+
const addressByLowercase = tokenAddresses.reduce((acc, address) => {
|
|
29259
|
+
acc[address.toLowerCase()] = address;
|
|
29260
|
+
return acc;
|
|
29261
|
+
}, {});
|
|
29262
|
+
const tokenAccountsByProgram = await Promise.all([splToken.TOKEN_PROGRAM_ID, splToken.TOKEN_2022_PROGRAM_ID].map((programId) => getSolanaTokenAccountsByProgram(userAddress, programId.toBase58())));
|
|
29263
|
+
tokenAccountsByProgram.flat().forEach((tokenAccount) => {
|
|
29264
|
+
const tokenInfo = tokenAccount.account?.data?.parsed?.info;
|
|
29265
|
+
const address = tokenInfo?.mint
|
|
29266
|
+
? addressByLowercase[tokenInfo.mint.toLowerCase()]
|
|
29267
|
+
: undefined;
|
|
29268
|
+
if (!address)
|
|
29269
|
+
return;
|
|
29270
|
+
balancesByAddress[address] += BigInt(tokenInfo?.tokenAmount?.amount || 0);
|
|
29271
|
+
});
|
|
29272
|
+
return balancesByAddress;
|
|
29319
29273
|
};
|
|
29320
29274
|
const getAllSolanaTokensBalance = async (solanaTokens, userAddress) => {
|
|
29321
29275
|
try {
|
|
29322
|
-
const nativeToken = solanaTokens.find((t) => t.address ===
|
|
29323
|
-
const otherTokens = solanaTokens.filter((t) => t.address !==
|
|
29276
|
+
const nativeToken = solanaTokens.find((t) => t.address.toLowerCase() === nativeSolanaTokenAddress.toLowerCase());
|
|
29277
|
+
const otherTokens = solanaTokens.filter((t) => t.address.toLowerCase() !== nativeSolanaTokenAddress.toLowerCase());
|
|
29324
29278
|
const [nativeBalance, tokenBalances] = await Promise.all([
|
|
29325
29279
|
nativeToken
|
|
29326
29280
|
? getSolanaNativeBalance(userAddress)
|
|
@@ -29329,7 +29283,7 @@ const getAllSolanaTokensBalance = async (solanaTokens, userAddress) => {
|
|
|
29329
29283
|
]);
|
|
29330
29284
|
return solanaTokens.map((token) => ({
|
|
29331
29285
|
...token,
|
|
29332
|
-
balance: token.address ===
|
|
29286
|
+
balance: token.address.toLowerCase() === nativeSolanaTokenAddress.toLowerCase()
|
|
29333
29287
|
? formatBNToReadable(nativeBalance, token.decimals)
|
|
29334
29288
|
: formatBNToReadable(tokenBalances[token.address], token.decimals),
|
|
29335
29289
|
}));
|
|
@@ -29631,7 +29585,7 @@ const useStellarBalance = ({ userAddress, chain, enabled, token, refreshInterval
|
|
|
29631
29585
|
};
|
|
29632
29586
|
|
|
29633
29587
|
function useNativeTokenForChain(chain) {
|
|
29634
|
-
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens,
|
|
29588
|
+
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = useSquidTokens();
|
|
29635
29589
|
const getTokensForChainType = () => {
|
|
29636
29590
|
if (!chain?.chainType)
|
|
29637
29591
|
return [];
|
|
@@ -29650,8 +29604,6 @@ function useNativeTokenForChain(chain) {
|
|
|
29650
29604
|
return xrplTokens;
|
|
29651
29605
|
case squidTypes.ChainType.STELLAR:
|
|
29652
29606
|
return stellarTokens;
|
|
29653
|
-
case squidTypes.ChainType.CANTON:
|
|
29654
|
-
return cantonTokens;
|
|
29655
29607
|
}
|
|
29656
29608
|
};
|
|
29657
29609
|
const nativeTokenForChainType = React.useMemo(() => {
|
|
@@ -29886,11 +29838,6 @@ const useNativeBalance = (chain) => {
|
|
|
29886
29838
|
break;
|
|
29887
29839
|
case squidTypes.ChainType.STELLAR:
|
|
29888
29840
|
balance = nativeStellarBalance;
|
|
29889
|
-
break;
|
|
29890
|
-
case squidTypes.ChainType.CANTON:
|
|
29891
|
-
// TODO: implement canton balance fetching
|
|
29892
|
-
balance = undefined;
|
|
29893
|
-
break;
|
|
29894
29841
|
}
|
|
29895
29842
|
const balanceFormatted = !!balance
|
|
29896
29843
|
? formatBNToReadable(balance.value, balance.decimals)
|
|
@@ -29927,9 +29874,6 @@ const useNativeBalance = (chain) => {
|
|
|
29927
29874
|
return isXrpLoading;
|
|
29928
29875
|
case squidTypes.ChainType.STELLAR:
|
|
29929
29876
|
return isStellarLoading;
|
|
29930
|
-
case squidTypes.ChainType.CANTON:
|
|
29931
|
-
// TODO: implement canton balance fetching
|
|
29932
|
-
return false;
|
|
29933
29877
|
}
|
|
29934
29878
|
}, [
|
|
29935
29879
|
chain?.chainType,
|
|
@@ -30154,7 +30098,7 @@ function hederaWalletConnect(parameters) {
|
|
|
30154
30098
|
const optionalChains = config.chains.map((x) => x.id);
|
|
30155
30099
|
if (!optionalChains.length)
|
|
30156
30100
|
return;
|
|
30157
|
-
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-
|
|
30101
|
+
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-1XEAWjab.js'); });
|
|
30158
30102
|
const rawProvider = await EthereumProvider.init({
|
|
30159
30103
|
...restParameters,
|
|
30160
30104
|
disableProviderPing: true,
|
|
@@ -30384,8 +30328,6 @@ const useSigner = ({ chain }) => {
|
|
|
30384
30328
|
return isXrplSignerReady;
|
|
30385
30329
|
case squidTypes.ChainType.STELLAR:
|
|
30386
30330
|
return isStellarSignerReady;
|
|
30387
|
-
case squidTypes.ChainType.CANTON:
|
|
30388
|
-
return false;
|
|
30389
30331
|
}
|
|
30390
30332
|
}, [
|
|
30391
30333
|
chain?.chainType,
|
|
@@ -30835,21 +30777,21 @@ const useSendTransactionStore = zustand.create((set, get) => ({
|
|
|
30835
30777
|
|
|
30836
30778
|
const useDepositAddressStore = zustand.create((set) => ({
|
|
30837
30779
|
deposit: null,
|
|
30838
|
-
|
|
30780
|
+
isEnabled: false,
|
|
30839
30781
|
setDeposit: (data) => {
|
|
30840
30782
|
set({ deposit: data });
|
|
30841
30783
|
},
|
|
30842
|
-
|
|
30843
|
-
set({
|
|
30784
|
+
toggleDepositFlow: (enabled) => {
|
|
30785
|
+
set({ isEnabled: enabled });
|
|
30844
30786
|
},
|
|
30845
30787
|
}));
|
|
30846
30788
|
|
|
30847
30789
|
function useDepositAddress(squidRoute) {
|
|
30848
|
-
const {
|
|
30849
|
-
|
|
30790
|
+
const { isEnabled, depositAddress } = useDepositAddressStore((state) => ({
|
|
30791
|
+
isEnabled: state.isEnabled,
|
|
30850
30792
|
depositAddress: state.deposit?.depositAddress,
|
|
30851
30793
|
}));
|
|
30852
|
-
const { setDeposit,
|
|
30794
|
+
const { setDeposit, toggleDepositFlow, deposit } = useDepositAddressStore();
|
|
30853
30795
|
const { squid } = useSquidStore();
|
|
30854
30796
|
const { fromChain } = useSwap();
|
|
30855
30797
|
const isAvailableAsPaymentMethod = React.useMemo(() => {
|
|
@@ -30858,7 +30800,6 @@ function useDepositAddress(squidRoute) {
|
|
|
30858
30800
|
const chainsSupportingDepositAddress = [
|
|
30859
30801
|
CHAIN_IDS.BITCOIN,
|
|
30860
30802
|
CHAIN_IDS.SOLANA,
|
|
30861
|
-
CHAIN_IDS.CANTON,
|
|
30862
30803
|
];
|
|
30863
30804
|
return chainsSupportingDepositAddress.includes(fromChain.chainId);
|
|
30864
30805
|
}, [fromChain?.chainId]);
|
|
@@ -30866,50 +30807,34 @@ function useDepositAddress(squidRoute) {
|
|
|
30866
30807
|
return (squidRoute?.transactionRequest?.type ===
|
|
30867
30808
|
squidTypes.SquidDataType.ChainflipDepositAddress);
|
|
30868
30809
|
}, [squidRoute?.transactionRequest?.type]);
|
|
30869
|
-
|
|
30870
|
-
|
|
30871
|
-
|
|
30872
|
-
|
|
30873
|
-
|
|
30874
|
-
|
|
30875
|
-
: "connectedWallet";
|
|
30876
|
-
const isDepositAddressActive = paymentMethod === "depositAddress";
|
|
30810
|
+
const enable = React.useCallback(() => {
|
|
30811
|
+
toggleDepositFlow(true);
|
|
30812
|
+
}, [toggleDepositFlow]);
|
|
30813
|
+
const disable = React.useCallback(() => {
|
|
30814
|
+
toggleDepositFlow(false);
|
|
30815
|
+
}, [toggleDepositFlow]);
|
|
30877
30816
|
const closeDepositChannel = React.useCallback(() => {
|
|
30817
|
+
toggleDepositFlow(false);
|
|
30878
30818
|
setDeposit(null);
|
|
30879
|
-
}, [setDeposit]);
|
|
30819
|
+
}, [toggleDepositFlow, setDeposit]);
|
|
30880
30820
|
const getRouteWithDeposit = reactQuery.useMutation(async ({ route }) => {
|
|
30881
|
-
if (!squid
|
|
30882
|
-
throw new Error("
|
|
30883
|
-
|
|
30884
|
-
|
|
30885
|
-
|
|
30886
|
-
|
|
30887
|
-
|
|
30888
|
-
|
|
30889
|
-
|
|
30890
|
-
|
|
30891
|
-
statusTrackingId: depositAddressResponse.chainflipStatusTrackingId,
|
|
30892
|
-
});
|
|
30893
|
-
return;
|
|
30894
|
-
}
|
|
30895
|
-
else if (isDepositAddressDirectTransferRoute(route.transactionRequest)) {
|
|
30896
|
-
const orderHash = route.transactionRequest.data;
|
|
30897
|
-
setDeposit({
|
|
30898
|
-
amount: route.params.fromAmount ?? "",
|
|
30899
|
-
depositAddress: route.transactionRequest.target,
|
|
30900
|
-
// Squid Scan indexes the Canton tx by the orderHash
|
|
30901
|
-
statusTrackingId: orderHash,
|
|
30902
|
-
memo: orderHash,
|
|
30903
|
-
});
|
|
30904
|
-
return;
|
|
30905
|
-
}
|
|
30821
|
+
if (!squid)
|
|
30822
|
+
throw new Error("Squid SDK not initialized");
|
|
30823
|
+
const depositAddressResponse = (await squid.executeRoute({
|
|
30824
|
+
signer: {},
|
|
30825
|
+
route,
|
|
30826
|
+
}));
|
|
30827
|
+
setDeposit(depositAddressResponse);
|
|
30828
|
+
return {
|
|
30829
|
+
depositAddress: depositAddressResponse,
|
|
30830
|
+
};
|
|
30906
30831
|
});
|
|
30907
30832
|
return {
|
|
30908
|
-
|
|
30909
|
-
isDepositAddressActive,
|
|
30833
|
+
isEnabled,
|
|
30910
30834
|
isAvailableAsPaymentMethod,
|
|
30911
30835
|
swapWillGenerateDepositAddress,
|
|
30912
|
-
|
|
30836
|
+
enable,
|
|
30837
|
+
disable,
|
|
30913
30838
|
getRouteWithDeposit,
|
|
30914
30839
|
depositAddress,
|
|
30915
30840
|
closeDepositChannel,
|
|
@@ -30941,7 +30866,7 @@ const useUrlSwapParams = () => {
|
|
|
30941
30866
|
|
|
30942
30867
|
const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, queryOptions, }) => {
|
|
30943
30868
|
const { evmChains, cosmosChains, suiChains, xrplChains, stellarChains } = useSquidChains(direction);
|
|
30944
|
-
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens,
|
|
30869
|
+
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = useSquidTokens(direction);
|
|
30945
30870
|
const { keplrTypeWallet } = useCosmosContext();
|
|
30946
30871
|
const placeholderData = React.useMemo(() => {
|
|
30947
30872
|
const tokens = {
|
|
@@ -30952,7 +30877,6 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
30952
30877
|
[squidTypes.ChainType.SUI]: suiTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30953
30878
|
[squidTypes.ChainType.XRPL]: xrplTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30954
30879
|
[squidTypes.ChainType.STELLAR]: stellarTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30955
|
-
[squidTypes.ChainType.CANTON]: cantonTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30956
30880
|
};
|
|
30957
30881
|
if (!chainType) {
|
|
30958
30882
|
// Return all tokens with zero balance
|
|
@@ -30974,7 +30898,6 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
30974
30898
|
suiTokens,
|
|
30975
30899
|
xrplTokens,
|
|
30976
30900
|
stellarTokens,
|
|
30977
|
-
cantonTokens,
|
|
30978
30901
|
]);
|
|
30979
30902
|
const isQueryEnabled = React.useMemo(() => {
|
|
30980
30903
|
// Respect the queryOptions.enabled override if provided
|
|
@@ -30997,8 +30920,6 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
30997
30920
|
return xrplTokens.length > 0;
|
|
30998
30921
|
case squidTypes.ChainType.STELLAR:
|
|
30999
30922
|
return stellarTokens.length > 0;
|
|
31000
|
-
case squidTypes.ChainType.CANTON:
|
|
31001
|
-
return cantonTokens.length > 0;
|
|
31002
30923
|
}
|
|
31003
30924
|
}, [
|
|
31004
30925
|
chainType,
|
|
@@ -31011,7 +30932,6 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
31011
30932
|
suiTokens.length,
|
|
31012
30933
|
xrplTokens.length,
|
|
31013
30934
|
stellarTokens.length,
|
|
31014
|
-
cantonTokens.length,
|
|
31015
30935
|
]);
|
|
31016
30936
|
const query = reactQuery.useQuery(keys().allTokensBalance(address, chainType, direction), async () => {
|
|
31017
30937
|
// Return zero balances if no address
|
|
@@ -31121,12 +31041,6 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
|
31121
31041
|
direction,
|
|
31122
31042
|
queryOptions,
|
|
31123
31043
|
});
|
|
31124
|
-
const cantonBalancesQuery = useAllTokensWithBalanceForChainType({
|
|
31125
|
-
chainType: squidTypes.ChainType.CANTON,
|
|
31126
|
-
address: connectedAddresses?.[squidTypes.ChainType.CANTON],
|
|
31127
|
-
direction,
|
|
31128
|
-
queryOptions,
|
|
31129
|
-
});
|
|
31130
31044
|
// Create a map of chain type to balance query results
|
|
31131
31045
|
const balanceQueries = React.useMemo(() => ({
|
|
31132
31046
|
[squidTypes.ChainType.EVM]: evmBalancesQuery,
|
|
@@ -31136,7 +31050,6 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
|
31136
31050
|
[squidTypes.ChainType.SUI]: suiBalancesQuery,
|
|
31137
31051
|
[squidTypes.ChainType.XRPL]: xrplBalancesQuery,
|
|
31138
31052
|
[squidTypes.ChainType.STELLAR]: stellarBalancesQuery,
|
|
31139
|
-
[squidTypes.ChainType.CANTON]: cantonBalancesQuery,
|
|
31140
31053
|
}), [
|
|
31141
31054
|
evmBalancesQuery,
|
|
31142
31055
|
cosmosBalancesQuery,
|
|
@@ -31145,7 +31058,6 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
|
31145
31058
|
suiBalancesQuery,
|
|
31146
31059
|
xrplBalancesQuery,
|
|
31147
31060
|
stellarBalancesQuery,
|
|
31148
|
-
cantonBalancesQuery,
|
|
31149
31061
|
]);
|
|
31150
31062
|
// Combine all tokens from different chains
|
|
31151
31063
|
const allTokens = React.useMemo(() => Object.values(balanceQueries).flatMap((query) => query.data?.tokens ?? []), [balanceQueries]);
|
|
@@ -31245,9 +31157,6 @@ const useMultiChainBalance = ({ chain, token, userAddress, enabled = true, }) =>
|
|
|
31245
31157
|
return xrplBalance;
|
|
31246
31158
|
case squidTypes.ChainType.STELLAR:
|
|
31247
31159
|
return stellarBalance;
|
|
31248
|
-
case squidTypes.ChainType.CANTON:
|
|
31249
|
-
// TODO: implement canton balance fetching
|
|
31250
|
-
return "0";
|
|
31251
31160
|
}
|
|
31252
31161
|
}, [
|
|
31253
31162
|
chain?.chainType,
|
|
@@ -32356,9 +32265,6 @@ function useSendTransaction({ to, amount, token, chain, }) {
|
|
|
32356
32265
|
chain,
|
|
32357
32266
|
});
|
|
32358
32267
|
break;
|
|
32359
|
-
case squidTypes.ChainType.CANTON: {
|
|
32360
|
-
throw new Error("Not implemented");
|
|
32361
|
-
}
|
|
32362
32268
|
}
|
|
32363
32269
|
return {
|
|
32364
32270
|
amount,
|
|
@@ -32562,8 +32468,6 @@ async function getSendTransactionStatus({ chain, txHash, }) {
|
|
|
32562
32468
|
txHash,
|
|
32563
32469
|
chain,
|
|
32564
32470
|
});
|
|
32565
|
-
case squidTypes.ChainType.CANTON:
|
|
32566
|
-
throw new Error("Not implemented");
|
|
32567
32471
|
}
|
|
32568
32472
|
}
|
|
32569
32473
|
|
|
@@ -32587,7 +32491,7 @@ const useHistory = (txType) => {
|
|
|
32587
32491
|
fromChain: tx.params.fromChain,
|
|
32588
32492
|
fromToken: tx.params.fromToken,
|
|
32589
32493
|
fromAddress: tx.params.fromAddress,
|
|
32590
|
-
fromAmount: tx.params.fromAmount
|
|
32494
|
+
fromAmount: tx.params.fromAmount,
|
|
32591
32495
|
toChain: tx.params.toChain,
|
|
32592
32496
|
toToken: tx.params.toToken,
|
|
32593
32497
|
toAddress: tx.params.toAddress,
|
|
@@ -33015,129 +32919,6 @@ const useApproval = ({ squidRoute, }) => {
|
|
|
33015
32919
|
};
|
|
33016
32920
|
};
|
|
33017
32921
|
|
|
33018
|
-
const useSwapStatusQuery = ({ transaction, retry = 25, refetchOnWindowFocus = "always", enabled = true, onStatus, onEndStatus, onNotFound, onError, }) => {
|
|
33019
|
-
const config = useConfigStore((state) => state.config);
|
|
33020
|
-
const isInitialized = useConfigStore((state) => state.isInitialized);
|
|
33021
|
-
const [isTransactionComplete, setIsTransactionComplete] = React.useState(false);
|
|
33022
|
-
const [refetchInterval, setRefetchInterval] = React.useState(getSwapTxStatusRefetchInterval(transaction));
|
|
33023
|
-
const { getChainType } = useSquidChains();
|
|
33024
|
-
const fetchTransactionStatusWithLatestConfig = React.useCallback(async () => {
|
|
33025
|
-
const latestConfig = useConfigStore.getState().config;
|
|
33026
|
-
return fetchSwapTransactionStatus({
|
|
33027
|
-
transaction,
|
|
33028
|
-
integratorId: latestConfig.integratorId,
|
|
33029
|
-
apiUrl: latestConfig.apiUrl,
|
|
33030
|
-
});
|
|
33031
|
-
}, [transaction]);
|
|
33032
|
-
const transactionStatusQuery = reactQuery.useQuery(keys().swapTransactionStatus(transaction?.transactionId), fetchTransactionStatusWithLatestConfig, {
|
|
33033
|
-
enabled: enabled &&
|
|
33034
|
-
transaction?.transactionId !== "0" &&
|
|
33035
|
-
!!transaction?.transactionId &&
|
|
33036
|
-
!!transaction.fromAddress &&
|
|
33037
|
-
!!config.apiUrl &&
|
|
33038
|
-
transaction !== undefined &&
|
|
33039
|
-
!isTransactionComplete &&
|
|
33040
|
-
isInitialized,
|
|
33041
|
-
refetchInterval(statusResponse) {
|
|
33042
|
-
if (statusResponse &&
|
|
33043
|
-
transactionEndStatuses.includes(getTransactionStatus(statusResponse) ?? "")) {
|
|
33044
|
-
return false;
|
|
33045
|
-
}
|
|
33046
|
-
return refetchInterval;
|
|
33047
|
-
},
|
|
33048
|
-
retryDelay: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 5000 : 3000,
|
|
33049
|
-
retry: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 6 : retry,
|
|
33050
|
-
refetchOnWindowFocus,
|
|
33051
|
-
onSuccess: (statusResponse) => {
|
|
33052
|
-
WidgetEvents.getInstance().dispatchSwapStatus(statusResponse.squidTransactionStatus ?? "");
|
|
33053
|
-
onStatus?.({
|
|
33054
|
-
status: getTransactionStatus(statusResponse) ?? "",
|
|
33055
|
-
statusResponse,
|
|
33056
|
-
});
|
|
33057
|
-
const endStatus = getTransactionEndStatus({ statusResponse });
|
|
33058
|
-
if (endStatus) {
|
|
33059
|
-
setIsTransactionComplete(true);
|
|
33060
|
-
onEndStatus?.({ status: endStatus, statusResponse });
|
|
33061
|
-
}
|
|
33062
|
-
},
|
|
33063
|
-
onError: (error) => {
|
|
33064
|
-
if (is404Error(error.cause)) {
|
|
33065
|
-
onNotFound?.();
|
|
33066
|
-
return;
|
|
33067
|
-
}
|
|
33068
|
-
setRefetchInterval(-1);
|
|
33069
|
-
setIsTransactionComplete(true);
|
|
33070
|
-
onError?.();
|
|
33071
|
-
},
|
|
33072
|
-
});
|
|
33073
|
-
return {
|
|
33074
|
-
transactionStatusQuery,
|
|
33075
|
-
};
|
|
33076
|
-
};
|
|
33077
|
-
|
|
33078
|
-
// Statuses that indicate the source deposit has been received and the swap is
|
|
33079
|
-
// now progressing — the point at which it becomes a history-backed transaction.
|
|
33080
|
-
const sourceReceivedStatuses = [
|
|
33081
|
-
// Chainflip
|
|
33082
|
-
"DEPOSIT_RECEIVED",
|
|
33083
|
-
"BROADCAST_REQUESTED",
|
|
33084
|
-
"COMPLETE",
|
|
33085
|
-
// Canton (Squid Intents)
|
|
33086
|
-
"awaiting",
|
|
33087
|
-
"success",
|
|
33088
|
-
];
|
|
33089
|
-
/**
|
|
33090
|
-
* Tracks a generated deposit address before it becomes a persisted swap history item.
|
|
33091
|
-
*
|
|
33092
|
-
* Mirrors the hooks-first pattern of `useExecuteTransaction`: once the source deposit
|
|
33093
|
-
* is received, it registers the transaction in the transaction + history stores, then
|
|
33094
|
-
* signals the view (via `onReceived`) to navigate. The view never writes to the stores.
|
|
33095
|
-
*/
|
|
33096
|
-
const useDepositTransactionStatus = ({ transaction, route, retry = 25, refetchOnWindowFocus = "always", enabled = true, onReceived, }) => {
|
|
33097
|
-
const { fromChain, toChain } = useSwap();
|
|
33098
|
-
const { addSwapTransaction } = useHistory();
|
|
33099
|
-
const getTransaction = useTransactionStore((state) => state.getTransaction);
|
|
33100
|
-
const setTransactionStoreState = useTransactionStore((state) => state.setTransactionState);
|
|
33101
|
-
return useSwapStatusQuery({
|
|
33102
|
-
transaction,
|
|
33103
|
-
retry,
|
|
33104
|
-
refetchOnWindowFocus,
|
|
33105
|
-
enabled,
|
|
33106
|
-
onStatus: ({ status }) => {
|
|
33107
|
-
if (!sourceReceivedStatuses.includes(status))
|
|
33108
|
-
return;
|
|
33109
|
-
if (!transaction?.transactionId || !route?.transactionRequest)
|
|
33110
|
-
return;
|
|
33111
|
-
const txLocalId = transaction.transactionId;
|
|
33112
|
-
if (getTransaction(txLocalId))
|
|
33113
|
-
return;
|
|
33114
|
-
useTransactionStore.setState({
|
|
33115
|
-
txLocalId,
|
|
33116
|
-
currentTransaction: undefined,
|
|
33117
|
-
});
|
|
33118
|
-
const tx = {
|
|
33119
|
-
routeType: route.transactionRequest.type,
|
|
33120
|
-
fromChain,
|
|
33121
|
-
toChain,
|
|
33122
|
-
fromAddress: transaction.fromAddress,
|
|
33123
|
-
transactionId: txLocalId,
|
|
33124
|
-
transactionIdForStatus: transaction.transactionIdForStatus,
|
|
33125
|
-
quoteId: transaction.quoteId ?? "",
|
|
33126
|
-
status: exports.TransactionStatus.ONGOING,
|
|
33127
|
-
sourceStatus: exports.TransactionStatus.SUCCESS,
|
|
33128
|
-
timestamp: Date.now(),
|
|
33129
|
-
};
|
|
33130
|
-
setTransactionStoreState(txLocalId, tx);
|
|
33131
|
-
addSwapTransaction({
|
|
33132
|
-
...tx,
|
|
33133
|
-
params: route.params,
|
|
33134
|
-
estimate: route.estimate,
|
|
33135
|
-
});
|
|
33136
|
-
onReceived?.();
|
|
33137
|
-
},
|
|
33138
|
-
});
|
|
33139
|
-
};
|
|
33140
|
-
|
|
33141
32922
|
const DEFAULT_PROVIDER_IMAGE_URL = "https://raw.githubusercontent.com/0xsquid/assets/main/images/webp128/providers/squid.webp";
|
|
33142
32923
|
const AXELAR_PROVIDER_IMAGE_URL = "https://raw.githubusercontent.com/0xsquid/assets/main/images/webp128/providers/axelar.webp";
|
|
33143
32924
|
const useEstimate = (squidRoute) => {
|
|
@@ -36456,7 +36237,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36456
36237
|
if (!route.params.fromAddress || !route.params.toAddress) {
|
|
36457
36238
|
throw new Error("From or to address is required");
|
|
36458
36239
|
}
|
|
36459
|
-
const isDirectTransfer =
|
|
36240
|
+
const isDirectTransfer = isDepositRoute(route);
|
|
36460
36241
|
// Means it's a transfer to a deposit address
|
|
36461
36242
|
// Instead of a Swap/Contract call using a DEX like Jupiter
|
|
36462
36243
|
if (isDirectTransfer) {
|
|
@@ -36467,7 +36248,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36467
36248
|
throw new Error("Deposit address is required");
|
|
36468
36249
|
}
|
|
36469
36250
|
const signature = await executeSolanaTransfer({
|
|
36470
|
-
amount: BigInt(route.params.fromAmount
|
|
36251
|
+
amount: BigInt(route.params.fromAmount),
|
|
36471
36252
|
target: depositData.depositAddress,
|
|
36472
36253
|
signer: solanaSigner,
|
|
36473
36254
|
connection: solanaConnection,
|
|
@@ -36477,7 +36258,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36477
36258
|
const txParams = setTransactionState({
|
|
36478
36259
|
route,
|
|
36479
36260
|
txHash,
|
|
36480
|
-
transactionIdForStatus: depositData.
|
|
36261
|
+
transactionIdForStatus: depositData.chainflipStatusTrackingId,
|
|
36481
36262
|
userAddress: sourceUserAddress,
|
|
36482
36263
|
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
36483
36264
|
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
@@ -36528,7 +36309,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36528
36309
|
}
|
|
36529
36310
|
});
|
|
36530
36311
|
const swapMutationBitcoin = reactQuery.useMutation(async ({ id, route }) => {
|
|
36531
|
-
const { depositAddress, amount: sendAmount,
|
|
36312
|
+
const { depositAddress, amount: sendAmount, chainflipStatusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
|
|
36532
36313
|
if (!depositAddress) {
|
|
36533
36314
|
throw new Error(`Invalid deposit address: ${depositAddress}`);
|
|
36534
36315
|
}
|
|
@@ -36551,7 +36332,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36551
36332
|
txHash,
|
|
36552
36333
|
// When bridging from Bitcoin we need to send the chainflipId to the status endpoint
|
|
36553
36334
|
// instead of the Bitcoin transaction hash
|
|
36554
|
-
transactionIdForStatus:
|
|
36335
|
+
transactionIdForStatus: chainflipStatusTrackingId,
|
|
36555
36336
|
userAddress: sourceUserAddress,
|
|
36556
36337
|
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
36557
36338
|
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
@@ -36999,7 +36780,7 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
|
|
|
36999
36780
|
const squid = useSquidStore((state) => state.squid);
|
|
37000
36781
|
const fallbackAddress = useSwapRoutePersistStore((store) => store.swapRoute?.fallbackAddress);
|
|
37001
36782
|
const depositRefundAddress = useSwapRoutePersistStore((store) => store.swapRoute?.depositRefundAddress);
|
|
37002
|
-
const {
|
|
36783
|
+
const { isAvailableAsPaymentMethod, isEnabled: isDepositAddressEnabled } = useDepositAddress();
|
|
37003
36784
|
const getRouteMutation = useGetRoute();
|
|
37004
36785
|
const { fromChain, toChain, fromPrice, destinationAddress: { address: destinationAddress } = {}, fromToken, toToken, } = useSwap();
|
|
37005
36786
|
const { connectedAddress: { address: sourceConnectedAddress }, } = useMultiChainWallet(fromChain);
|
|
@@ -37007,7 +36788,7 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
|
|
|
37007
36788
|
// Tokens will be sent to this address in case of swap failure
|
|
37008
36789
|
//
|
|
37009
36790
|
// If deposit address is not selected, we use the connected address as the source address instead
|
|
37010
|
-
const sourceUserAddress =
|
|
36791
|
+
const sourceUserAddress = isDepositAddressEnabled && isAvailableAsPaymentMethod
|
|
37011
36792
|
? depositRefundAddress ?? sourceConnectedAddress
|
|
37012
36793
|
: sourceConnectedAddress;
|
|
37013
36794
|
const squidRouteQueryKeys = React.useMemo(() => keys().transaction(fromChain?.chainId, toChain?.chainId, toToken?.address, fromToken?.address, fromPrice, config.slippage, sourceUserAddress, config.degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChain?.chainType, config.preHook, config.postHook, config.overrideGasRefundAddress), [
|
|
@@ -37152,50 +36933,94 @@ function useSendTransactionStatus({ chain, txHash, }) {
|
|
|
37152
36933
|
* Fetch status of a Swap transaction
|
|
37153
36934
|
*/
|
|
37154
36935
|
const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocus = "always", enabled = true, }) => {
|
|
36936
|
+
const config = useConfigStore((state) => state.config);
|
|
36937
|
+
const isInitialized = useConfigStore((state) => state.isInitialized);
|
|
37155
36938
|
const { replaceSwapTransactionStatus } = useHistory();
|
|
37156
36939
|
const findTransaction = useHistoryStore((state) => state.findTransaction);
|
|
36940
|
+
const [isTransactionComplete, setIsTransactionComplete] = React.useState(false);
|
|
36941
|
+
const [refetchInterval, setRefetchInterval] = React.useState(getSwapTxStatusRefetchInterval(transaction));
|
|
36942
|
+
const { getChainType } = useSquidChains();
|
|
37157
36943
|
const currentHistoryItem = React.useMemo(() => findTransaction({
|
|
37158
36944
|
transactionId: transaction?.transactionId,
|
|
37159
36945
|
txType: exports.HistoryTxType.SWAP,
|
|
37160
36946
|
}), [findTransaction, transaction?.transactionId]);
|
|
37161
|
-
|
|
37162
|
-
|
|
37163
|
-
|
|
37164
|
-
|
|
36947
|
+
/**
|
|
36948
|
+
* Transaction status endpoint
|
|
36949
|
+
* Squid api is using axelar endpoint and parsing the response
|
|
36950
|
+
* @returns {StatusResponse} Status response
|
|
36951
|
+
*/
|
|
36952
|
+
const fetchTransactionStatusWithLatestConfig = React.useCallback(async () => {
|
|
36953
|
+
const latestConfig = useConfigStore.getState().config;
|
|
36954
|
+
return fetchSwapTransactionStatus({
|
|
36955
|
+
transaction,
|
|
36956
|
+
integratorId: latestConfig.integratorId,
|
|
36957
|
+
apiUrl: latestConfig.apiUrl,
|
|
36958
|
+
});
|
|
36959
|
+
}, [transaction]);
|
|
36960
|
+
const transactionStatusQuery = reactQuery.useQuery(keys().swapTransactionStatus(transaction?.transactionId), fetchTransactionStatusWithLatestConfig, {
|
|
37165
36961
|
enabled: enabled &&
|
|
36962
|
+
transaction?.transactionId !== "0" &&
|
|
36963
|
+
!!transaction?.transactionId &&
|
|
36964
|
+
!!transaction.fromAddress &&
|
|
36965
|
+
!!config.apiUrl &&
|
|
36966
|
+
transaction !== undefined &&
|
|
36967
|
+
!isTransactionComplete &&
|
|
36968
|
+
isInitialized &&
|
|
37166
36969
|
!!currentHistoryItem &&
|
|
37167
36970
|
!isHistoryTransactionEnded({
|
|
37168
36971
|
data: currentHistoryItem?.data,
|
|
37169
36972
|
txType: exports.HistoryTxType.SWAP,
|
|
37170
36973
|
}),
|
|
37171
|
-
|
|
37172
|
-
|
|
37173
|
-
|
|
37174
|
-
|
|
37175
|
-
|
|
37176
|
-
statusResponse
|
|
37177
|
-
|
|
37178
|
-
}
|
|
36974
|
+
refetchInterval(statusResponse) {
|
|
36975
|
+
// If the status response is something telling that the transaction
|
|
36976
|
+
// is finished, then store transaction history state if success
|
|
36977
|
+
// And return false to indicate refetcher to stop
|
|
36978
|
+
if (statusResponse &&
|
|
36979
|
+
transactionEndStatuses.includes(getTransactionStatus(statusResponse) ?? "")) {
|
|
36980
|
+
return false;
|
|
36981
|
+
}
|
|
36982
|
+
return refetchInterval; // Had to handle a variable here because after onError, we want the interval to stop
|
|
37179
36983
|
},
|
|
37180
|
-
|
|
37181
|
-
|
|
37182
|
-
|
|
37183
|
-
|
|
37184
|
-
|
|
37185
|
-
|
|
37186
|
-
|
|
37187
|
-
});
|
|
36984
|
+
// At the moment Cosmos indexing takes more time, so need more time between retries
|
|
36985
|
+
retryDelay: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 5000 : 3000,
|
|
36986
|
+
retry: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 6 : retry,
|
|
36987
|
+
refetchOnWindowFocus,
|
|
36988
|
+
onSuccess: (statusResponse) => {
|
|
36989
|
+
// Dispatch event
|
|
36990
|
+
WidgetEvents.getInstance().dispatchSwapStatus(statusResponse.squidTransactionStatus ?? "");
|
|
36991
|
+
const endStatus = getTransactionEndStatus({ statusResponse });
|
|
36992
|
+
if (endStatus && transaction?.transactionId) {
|
|
36993
|
+
setIsTransactionComplete(true);
|
|
36994
|
+
replaceSwapTransactionStatus({
|
|
36995
|
+
transactionId: transaction.transactionId,
|
|
36996
|
+
statusResponse,
|
|
36997
|
+
status: endStatus,
|
|
36998
|
+
});
|
|
36999
|
+
}
|
|
37188
37000
|
},
|
|
37189
|
-
onError: () => {
|
|
37001
|
+
onError: (error) => {
|
|
37002
|
+
// `fetchTransactionStatus` throws an error with a cause being an AxiosError
|
|
37003
|
+
const is404 = is404Error(error.cause);
|
|
37190
37004
|
if (!transaction?.transactionId)
|
|
37191
37005
|
return;
|
|
37192
|
-
|
|
37193
|
-
|
|
37194
|
-
|
|
37195
|
-
|
|
37196
|
-
|
|
37006
|
+
if (is404) {
|
|
37007
|
+
replaceSwapTransactionStatus({
|
|
37008
|
+
transactionId: transaction.transactionId,
|
|
37009
|
+
statusResponse: undefined,
|
|
37010
|
+
status: exports.TransactionStatus.NOT_FOUND,
|
|
37011
|
+
});
|
|
37012
|
+
}
|
|
37013
|
+
else {
|
|
37014
|
+
setRefetchInterval(-1);
|
|
37015
|
+
setIsTransactionComplete(true);
|
|
37016
|
+
replaceSwapTransactionStatus({
|
|
37017
|
+
transactionId: transaction.transactionId,
|
|
37018
|
+
statusResponse: undefined,
|
|
37019
|
+
status: exports.TransactionStatus.ERROR,
|
|
37020
|
+
});
|
|
37021
|
+
}
|
|
37197
37022
|
},
|
|
37198
|
-
})
|
|
37023
|
+
});
|
|
37199
37024
|
return {
|
|
37200
37025
|
transactionStatusQuery,
|
|
37201
37026
|
latestStatus: transactionStatusQuery.data
|
|
@@ -37594,10 +37419,8 @@ const SquidProvider = ({ children, config, placeholder, }) => {
|
|
|
37594
37419
|
}
|
|
37595
37420
|
if (assetsColorsResponse.status === "fulfilled") {
|
|
37596
37421
|
useAssetsColorsStore.setState(assetsColorsResponse.value);
|
|
37422
|
+
initializeSquidWithAssetsColors(squid, assetsColorsResponse.value);
|
|
37597
37423
|
}
|
|
37598
|
-
initializeSquidData(squid, assetsColorsResponse.status === "fulfilled"
|
|
37599
|
-
? assetsColorsResponse.value
|
|
37600
|
-
: undefined);
|
|
37601
37424
|
const shouldResetSwapRouteStore =
|
|
37602
37425
|
// reset swap route if specified in config
|
|
37603
37426
|
!config?.loadPreviousStateFromLocalStorage ||
|
|
@@ -37786,14 +37609,13 @@ exports.getXummClient = getXummClient;
|
|
|
37786
37609
|
exports.groupTokensByChainId = groupTokensByChainId;
|
|
37787
37610
|
exports.groupTokensBySymbol = groupTokensBySymbol;
|
|
37788
37611
|
exports.handleTransactionErrorEvents = handleTransactionErrorEvents;
|
|
37789
|
-
exports.
|
|
37612
|
+
exports.initializeSquidWithAssetsColors = initializeSquidWithAssetsColors;
|
|
37790
37613
|
exports.is404Error = is404Error;
|
|
37791
37614
|
exports.isActionCompletedOnSourceTx = isActionCompletedOnSourceTx;
|
|
37792
37615
|
exports.isChainflipBridgeTransaction = isChainflipBridgeTransaction;
|
|
37793
|
-
exports.isChainflipDepositRoute = isChainflipDepositRoute;
|
|
37794
37616
|
exports.isCoralBridgeAction = isCoralBridgeAction;
|
|
37795
37617
|
exports.isCosmosAddressValid = isCosmosAddressValid;
|
|
37796
|
-
exports.
|
|
37618
|
+
exports.isDepositRoute = isDepositRoute;
|
|
37797
37619
|
exports.isEmptyObject = isEmptyObject;
|
|
37798
37620
|
exports.isEvmChainNotSupportedError = isEvmChainNotSupportedError;
|
|
37799
37621
|
exports.isEvmosChain = isEvmosChain;
|
|
@@ -37809,7 +37631,6 @@ exports.isStatusError = isStatusError;
|
|
|
37809
37631
|
exports.isStellarAddressValid = isStellarAddressValid;
|
|
37810
37632
|
exports.isStellarIssuedToken = isStellarIssuedToken;
|
|
37811
37633
|
exports.isStellarToken = isStellarToken;
|
|
37812
|
-
exports.isSupportedChainType = isSupportedChainType;
|
|
37813
37634
|
exports.isSwapRouteError = isSwapRouteError;
|
|
37814
37635
|
exports.isUserRejectionError = isUserRejectionError;
|
|
37815
37636
|
exports.isValidHorizonAsset = isValidHorizonAsset;
|
|
@@ -37874,7 +37695,6 @@ exports.useCountryDetails = useCountryDetails;
|
|
|
37874
37695
|
exports.useCurrencyDetails = useCurrencyDetails;
|
|
37875
37696
|
exports.useDebouncedValue = useDebouncedValue;
|
|
37876
37697
|
exports.useDepositAddress = useDepositAddress;
|
|
37877
|
-
exports.useDepositTransactionStatus = useDepositTransactionStatus;
|
|
37878
37698
|
exports.useEnsDataForAddress = useEnsDataForAddress;
|
|
37879
37699
|
exports.useEnsSearch = useEnsSearch;
|
|
37880
37700
|
exports.useEstimate = useEstimate;
|
|
@@ -37941,4 +37761,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
|
|
|
37941
37761
|
exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
|
|
37942
37762
|
exports.walletIconBaseUrl = walletIconBaseUrl;
|
|
37943
37763
|
exports.walletSupportsChainType = walletSupportsChainType;
|
|
37944
|
-
//# sourceMappingURL=index-
|
|
37764
|
+
//# sourceMappingURL=index-DcBFug8t.js.map
|