@0xsquid/react-hooks 8.7.2 → 8.8.1-beta-canton.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 +1 -0
- package/dist/core/constants.d.ts +2 -0
- package/dist/core/types/canton.d.ts +2 -0
- package/dist/core/types/cosmos.d.ts +5 -0
- package/dist/core/types/wallet.d.ts +9 -6
- package/dist/hooks/chains/useSquidChains.d.ts +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/store/useDepositAddressStore.d.ts +15 -3
- package/dist/hooks/swap/useDepositAddress.d.ts +2 -4
- package/dist/hooks/tokens/useSquidTokens.d.ts +1 -0
- package/dist/hooks/transaction/useDepositTransactionStatus.d.ts +25 -0
- package/dist/hooks/transaction/useSwapStatusQuery.d.ts +26 -0
- package/dist/hooks/wallet/useMultiChainWallet.d.ts +41 -15
- package/dist/hooks/wallet/useWallet.d.ts +45 -15
- package/dist/{index-DaYYG81O.js → index-CtTVUC-R.js} +331 -169
- package/dist/index-CtTVUC-R.js.map +1 -0
- package/dist/{index-D3bbd13Z.js → index-D1udDcRZ.js} +334 -169
- package/dist/index-D1udDcRZ.js.map +1 -0
- package/dist/{index.es-Bn83pLT9.js → index.es-DFjaMQJG.js} +2 -2
- package/dist/{index.es-Bn83pLT9.js.map → index.es-DFjaMQJG.js.map} +1 -1
- package/dist/{index.es-Ds1lt_e4.js → index.es-Q71H7cJa.js} +2 -2
- package/dist/{index.es-Ds1lt_e4.js.map → index.es-Q71H7cJa.js.map} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/{secretService-CM6noWhX.js → secretService-BJNdJc-J.js} +2 -2
- package/dist/{secretService-CM6noWhX.js.map → secretService-BJNdJc-J.js.map} +1 -1
- package/dist/{secretService-CKReaNYo.js → secretService-Dg5_VwtW.js} +2 -2
- package/dist/{secretService-CKReaNYo.js.map → secretService-Dg5_VwtW.js.map} +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.esm.js +8 -1
- package/dist/server.esm.js.map +1 -1
- package/dist/server.js +8 -0
- package/dist/server.js.map +1 -1
- package/dist/services/internal/assetsService.d.ts +1 -1
- package/dist/services/internal/cantonService.d.ts +2 -0
- package/dist/services/internal/estimateService.d.ts +18 -8
- package/dist/services/internal/transactionService.d.ts +12 -2
- package/dist/{stellarService.client-Ko2roGXL.js → stellarService.client-B9xCCNV0.js} +2 -2
- package/dist/{stellarService.client-Ko2roGXL.js.map → stellarService.client-B9xCCNV0.js.map} +1 -1
- package/dist/{stellarService.client-0dfuo3PJ.js → stellarService.client-BFUfF3-j.js} +2 -2
- package/dist/{stellarService.client-0dfuo3PJ.js.map → stellarService.client-BFUfF3-j.js.map} +1 -1
- package/package.json +2 -2
- package/dist/index-D3bbd13Z.js.map +0 -1
- package/dist/index-DaYYG81O.js.map +0 -1
|
@@ -78,6 +78,8 @@ 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";
|
|
81
83
|
const chainTypeToZeroAddressMap = {
|
|
82
84
|
[squidTypes.ChainType.EVM]: viem.zeroAddress,
|
|
83
85
|
[squidTypes.ChainType.COSMOS]: cosmosZeroAddress,
|
|
@@ -86,6 +88,7 @@ const chainTypeToZeroAddressMap = {
|
|
|
86
88
|
[squidTypes.ChainType.SUI]: suiZeroAddress,
|
|
87
89
|
[squidTypes.ChainType.XRPL]: xrplZeroAddress,
|
|
88
90
|
[squidTypes.ChainType.STELLAR]: stellarZeroAddress,
|
|
91
|
+
[squidTypes.ChainType.CANTON]: cantonZeroAddress,
|
|
89
92
|
};
|
|
90
93
|
const nativeEvmTokenAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
91
94
|
const nativeCosmosTokenAddress = "uosmo";
|
|
@@ -94,6 +97,7 @@ const nativeBitcoinTokenAddress = "satoshi";
|
|
|
94
97
|
const nativeSuiTokenAddress = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
95
98
|
const nativeXrplTokenAddress = "xrp";
|
|
96
99
|
const nativeStellarTokenAddress = "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA";
|
|
100
|
+
const nativeCantonTokenAddress = "DSO::1220b1431ef217342db44d516bb9befde802be7d8899637d290895fa58880f19accc";
|
|
97
101
|
// by setting slippage to undefined, it's set to "auto"
|
|
98
102
|
const defaultSlippage = undefined;
|
|
99
103
|
const destinationAddressResetValue = "null";
|
|
@@ -157,6 +161,7 @@ const CHAIN_IDS = {
|
|
|
157
161
|
XRPL_TESTNET: "xrpl-testnet",
|
|
158
162
|
STELLAR: "stellar-mainnet",
|
|
159
163
|
STELLAR_TESTNET: "stellar-testnet",
|
|
164
|
+
CANTON: "canton",
|
|
160
165
|
};
|
|
161
166
|
const chainTypeToDefaultChainIdMap = {
|
|
162
167
|
[squidTypes.ChainType.EVM]: CHAIN_IDS.ETHEREUM,
|
|
@@ -166,6 +171,7 @@ const chainTypeToDefaultChainIdMap = {
|
|
|
166
171
|
[squidTypes.ChainType.SUI]: CHAIN_IDS.SUI,
|
|
167
172
|
[squidTypes.ChainType.XRPL]: CHAIN_IDS.XRPL,
|
|
168
173
|
[squidTypes.ChainType.STELLAR]: CHAIN_IDS.STELLAR,
|
|
174
|
+
[squidTypes.ChainType.CANTON]: CHAIN_IDS.CANTON,
|
|
169
175
|
};
|
|
170
176
|
const chainTypeToNativeTokenAddressMap = {
|
|
171
177
|
[squidTypes.ChainType.EVM]: nativeEvmTokenAddress,
|
|
@@ -175,6 +181,7 @@ const chainTypeToNativeTokenAddressMap = {
|
|
|
175
181
|
[squidTypes.ChainType.SUI]: nativeSuiTokenAddress,
|
|
176
182
|
[squidTypes.ChainType.XRPL]: nativeXrplTokenAddress,
|
|
177
183
|
[squidTypes.ChainType.STELLAR]: nativeStellarTokenAddress,
|
|
184
|
+
[squidTypes.ChainType.CANTON]: nativeCantonTokenAddress,
|
|
178
185
|
};
|
|
179
186
|
const defaultConfigValues = {
|
|
180
187
|
integratorId: INTEGRATOR_ID,
|
|
@@ -20872,6 +20879,18 @@ const isBitcoinAddressValid = (address) => {
|
|
|
20872
20879
|
}
|
|
20873
20880
|
};
|
|
20874
20881
|
|
|
20882
|
+
// Canton PartyID = address
|
|
20883
|
+
const CANTON_PARTY_ID_SEPARATOR = "::";
|
|
20884
|
+
function isCantonAddressValid(address) {
|
|
20885
|
+
// Canton address format: `name::fingerprint`, where name is an arbitrary string
|
|
20886
|
+
// and fingerprint is a 64-character hex string with a 1220 prefix (SHA-256 hash of the public key)
|
|
20887
|
+
const parts = address.split(CANTON_PARTY_ID_SEPARATOR);
|
|
20888
|
+
if (parts.length !== 2)
|
|
20889
|
+
return false;
|
|
20890
|
+
const [name, fingerprint] = parts;
|
|
20891
|
+
return name.length > 0 && /^1220[0-9a-f]{64}$/.test(fingerprint);
|
|
20892
|
+
}
|
|
20893
|
+
|
|
20875
20894
|
exports.HistoryTxType = void 0;
|
|
20876
20895
|
(function (HistoryTxType) {
|
|
20877
20896
|
HistoryTxType[HistoryTxType["SWAP"] = 0] = "SWAP";
|
|
@@ -21128,13 +21147,23 @@ const compareTransactionIds = (idA, idB) => {
|
|
|
21128
21147
|
*/
|
|
21129
21148
|
function isCoralBridgeAction(action) {
|
|
21130
21149
|
return (action.type === squidTypes.ActionType.RFQ &&
|
|
21131
|
-
// TODO: update types
|
|
21132
|
-
action.provider
|
|
21150
|
+
// TODO: update types to use enum
|
|
21151
|
+
action.provider === "Squid Intents");
|
|
21152
|
+
}
|
|
21153
|
+
/**
|
|
21154
|
+
* Determines if a given action completes as part of the user's source transaction.
|
|
21155
|
+
* Action types like RFQ are fulfilled by a solver in a separate transaction,
|
|
21156
|
+
* so they are NOT completed on source even if they share the same chain.
|
|
21157
|
+
*/
|
|
21158
|
+
function isActionCompletedOnSourceTx(action, fromChainId) {
|
|
21159
|
+
if (action.type === squidTypes.ActionType.RFQ)
|
|
21160
|
+
return false;
|
|
21161
|
+
return action.fromChain === fromChainId && action.toChain === fromChainId;
|
|
21133
21162
|
}
|
|
21134
21163
|
function sleep(ms) {
|
|
21135
21164
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
21136
21165
|
}
|
|
21137
|
-
const
|
|
21166
|
+
const isChainflipDepositRoute = (route) => {
|
|
21138
21167
|
return (!!route &&
|
|
21139
21168
|
route.transactionRequest?.type === squidTypes.SquidDataType.ChainflipDepositAddress);
|
|
21140
21169
|
};
|
|
@@ -21159,6 +21188,12 @@ function isOnChainTxData(squidData) {
|
|
|
21159
21188
|
squidTypes.SquidDataType.DepositAddressWithMemo,
|
|
21160
21189
|
].includes(squidData.type);
|
|
21161
21190
|
}
|
|
21191
|
+
/**
|
|
21192
|
+
* Checks if a route is of type DepositAddressDirectTransfer
|
|
21193
|
+
*/
|
|
21194
|
+
function isDepositAddressDirectTransferRoute(squidData) {
|
|
21195
|
+
return (squidData.type === squidTypes.SquidDataType.DepositAddressDirectTransfer);
|
|
21196
|
+
}
|
|
21162
21197
|
function getHistoryTransactionId(tx) {
|
|
21163
21198
|
switch (tx.txType) {
|
|
21164
21199
|
case exports.HistoryTxType.SWAP:
|
|
@@ -21661,7 +21696,17 @@ const chainTypeToTrimLength = {
|
|
|
21661
21696
|
start: 4,
|
|
21662
21697
|
end: 4,
|
|
21663
21698
|
},
|
|
21699
|
+
// abc...123::abc...123
|
|
21700
|
+
[squidTypes.ChainType.CANTON]: {
|
|
21701
|
+
start: 3,
|
|
21702
|
+
end: 3,
|
|
21703
|
+
},
|
|
21664
21704
|
};
|
|
21705
|
+
const truncateWithEllipsis = (value, startLength, endLength) => value.length <= startLength + endLength
|
|
21706
|
+
? value
|
|
21707
|
+
: value.slice(0, startLength) +
|
|
21708
|
+
"..." +
|
|
21709
|
+
value.slice(value.length - endLength);
|
|
21665
21710
|
const formatHash = ({ chainType, hash }) => {
|
|
21666
21711
|
if (!hash)
|
|
21667
21712
|
return "";
|
|
@@ -21674,14 +21719,15 @@ const formatHash = ({ chainType, hash }) => {
|
|
|
21674
21719
|
chainTypeFormat = squidTypes.ChainType.COSMOS;
|
|
21675
21720
|
}
|
|
21676
21721
|
}
|
|
21677
|
-
const
|
|
21678
|
-
|
|
21679
|
-
|
|
21680
|
-
|
|
21681
|
-
return
|
|
21682
|
-
|
|
21683
|
-
|
|
21684
|
-
|
|
21722
|
+
const { start, end } = chainTypeToTrimLength[chainTypeFormat];
|
|
21723
|
+
if (chainTypeFormat === squidTypes.ChainType.CANTON &&
|
|
21724
|
+
hash.includes(CANTON_PARTY_ID_SEPARATOR)) {
|
|
21725
|
+
const [namespace, identifier] = hash.split(CANTON_PARTY_ID_SEPARATOR);
|
|
21726
|
+
return (truncateWithEllipsis(namespace, start, end) +
|
|
21727
|
+
CANTON_PARTY_ID_SEPARATOR +
|
|
21728
|
+
truncateWithEllipsis(identifier, start, end));
|
|
21729
|
+
}
|
|
21730
|
+
return truncateWithEllipsis(hash, start, end);
|
|
21685
21731
|
};
|
|
21686
21732
|
const isWalletAddressValid = (chainData, address) => {
|
|
21687
21733
|
if (!address || !chainData?.chainType)
|
|
@@ -21701,6 +21747,8 @@ const isWalletAddressValid = (chainData, address) => {
|
|
|
21701
21747
|
return isXrplAddressValid(address);
|
|
21702
21748
|
case squidTypes.ChainType.STELLAR:
|
|
21703
21749
|
return isStellarAddressValid(address);
|
|
21750
|
+
case squidTypes.ChainType.CANTON:
|
|
21751
|
+
return isCantonAddressValid(address);
|
|
21704
21752
|
}
|
|
21705
21753
|
};
|
|
21706
21754
|
const redirectToExtensionsStore = (wallet) => {
|
|
@@ -21962,6 +22010,8 @@ const connectByChainType = async (chainType, wallet, defaultChain, params) => {
|
|
|
21962
22010
|
connector,
|
|
21963
22011
|
},
|
|
21964
22012
|
});
|
|
22013
|
+
case squidTypes.ChainType.CANTON:
|
|
22014
|
+
return null;
|
|
21965
22015
|
}
|
|
21966
22016
|
};
|
|
21967
22017
|
const getChainTypesToConnect = (selectedChainTypes, defaultChain, supportedChains) => {
|
|
@@ -23036,7 +23086,10 @@ const getNewSwapParamsFromInput = ({ inputParams, initialSwapRoute, tokens, chai
|
|
|
23036
23086
|
else {
|
|
23037
23087
|
newFallbackAddress = fallbackAddress ?? initialSwapRoute?.fallbackAddress;
|
|
23038
23088
|
}
|
|
23039
|
-
const
|
|
23089
|
+
const sourceChainChanged = fromChainId !== undefined && fromChainId !== initialSwapRoute?.fromChainId;
|
|
23090
|
+
const newDepositRefundAddress = sourceChainChanged
|
|
23091
|
+
? undefined
|
|
23092
|
+
: depositRefundAddress || initialSwapRoute?.depositRefundAddress;
|
|
23040
23093
|
return {
|
|
23041
23094
|
fromChainId: srcChainId,
|
|
23042
23095
|
fromTokenAddress: sourceTokenAddress,
|
|
@@ -23315,7 +23368,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23315
23368
|
};
|
|
23316
23369
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
23317
23370
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
23318
|
-
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-
|
|
23371
|
+
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-Dg5_VwtW.js'); });
|
|
23319
23372
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
23320
23373
|
};
|
|
23321
23374
|
function getTokenAssetsKey(token) {
|
|
@@ -25289,7 +25342,7 @@ const useSquidTokens = (direction) => {
|
|
|
25289
25342
|
config.availableChains,
|
|
25290
25343
|
direction,
|
|
25291
25344
|
]);
|
|
25292
|
-
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = React.useMemo(() => {
|
|
25345
|
+
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, cantonTokens, } = React.useMemo(() => {
|
|
25293
25346
|
return tokens?.reduce((acc, token) => {
|
|
25294
25347
|
switch (token.type) {
|
|
25295
25348
|
case squidTypes.ChainType.EVM:
|
|
@@ -25313,6 +25366,9 @@ const useSquidTokens = (direction) => {
|
|
|
25313
25366
|
case squidTypes.ChainType.STELLAR:
|
|
25314
25367
|
acc.stellarTokens.push(token);
|
|
25315
25368
|
break;
|
|
25369
|
+
case squidTypes.ChainType.CANTON:
|
|
25370
|
+
acc.cantonTokens.push(token);
|
|
25371
|
+
break;
|
|
25316
25372
|
}
|
|
25317
25373
|
return acc;
|
|
25318
25374
|
}, {
|
|
@@ -25323,6 +25379,7 @@ const useSquidTokens = (direction) => {
|
|
|
25323
25379
|
suiTokens: [],
|
|
25324
25380
|
xrplTokens: [],
|
|
25325
25381
|
stellarTokens: [],
|
|
25382
|
+
cantonTokens: [],
|
|
25326
25383
|
});
|
|
25327
25384
|
}, [tokens]);
|
|
25328
25385
|
const findToken = React.useCallback((address, chainId) => {
|
|
@@ -25340,6 +25397,7 @@ const useSquidTokens = (direction) => {
|
|
|
25340
25397
|
suiTokens,
|
|
25341
25398
|
xrplTokens,
|
|
25342
25399
|
stellarTokens,
|
|
25400
|
+
cantonTokens,
|
|
25343
25401
|
};
|
|
25344
25402
|
};
|
|
25345
25403
|
|
|
@@ -25877,6 +25935,7 @@ const chainTypeToRefetchInterval = {
|
|
|
25877
25935
|
[squidTypes.ChainType.SUI]: 1_000,
|
|
25878
25936
|
[squidTypes.ChainType.XRPL]: 1_000,
|
|
25879
25937
|
[squidTypes.ChainType.STELLAR]: 1_000,
|
|
25938
|
+
[squidTypes.ChainType.CANTON]: 1_000,
|
|
25880
25939
|
};
|
|
25881
25940
|
/**
|
|
25882
25941
|
* Returns the status refetch interval of a Send transaction
|
|
@@ -26143,7 +26202,7 @@ const useSquidChains = (direction) => {
|
|
|
26143
26202
|
const chain = findChain(chainId);
|
|
26144
26203
|
return chain?.chainType;
|
|
26145
26204
|
}, [findChain]);
|
|
26146
|
-
const { evmChains, cosmosChains, suiChains, stellarChains, xrplChains } = React.useMemo(() => {
|
|
26205
|
+
const { evmChains, cosmosChains, suiChains, stellarChains, xrplChains, cantonChains, } = React.useMemo(() => {
|
|
26147
26206
|
return chains.reduce((acc, chain) => {
|
|
26148
26207
|
switch (chain.chainType) {
|
|
26149
26208
|
case squidTypes.ChainType.EVM:
|
|
@@ -26161,6 +26220,9 @@ const useSquidChains = (direction) => {
|
|
|
26161
26220
|
case squidTypes.ChainType.STELLAR:
|
|
26162
26221
|
acc.stellarChains.push(chain);
|
|
26163
26222
|
break;
|
|
26223
|
+
case squidTypes.ChainType.CANTON:
|
|
26224
|
+
acc.cantonChains.push(chain);
|
|
26225
|
+
break;
|
|
26164
26226
|
}
|
|
26165
26227
|
return acc;
|
|
26166
26228
|
}, {
|
|
@@ -26169,6 +26231,7 @@ const useSquidChains = (direction) => {
|
|
|
26169
26231
|
suiChains: [],
|
|
26170
26232
|
xrplChains: [],
|
|
26171
26233
|
stellarChains: [],
|
|
26234
|
+
cantonChains: [],
|
|
26172
26235
|
});
|
|
26173
26236
|
}, [chains]);
|
|
26174
26237
|
const { supportedSourceChains, supportedDestinationChains } = React.useMemo(() => {
|
|
@@ -26189,6 +26252,7 @@ const useSquidChains = (direction) => {
|
|
|
26189
26252
|
suiChains,
|
|
26190
26253
|
xrplChains,
|
|
26191
26254
|
stellarChains,
|
|
26255
|
+
cantonChains,
|
|
26192
26256
|
getChainType,
|
|
26193
26257
|
findChain,
|
|
26194
26258
|
};
|
|
@@ -26713,7 +26777,7 @@ function useStellarWallets() {
|
|
|
26713
26777
|
try {
|
|
26714
26778
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
26715
26779
|
const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module.mjs');
|
|
26716
|
-
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-
|
|
26780
|
+
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-BFUfF3-j.js'); });
|
|
26717
26781
|
const modules = [...initializeAllModules(), new LedgerModule()];
|
|
26718
26782
|
const promises = modules.map(async (module) => {
|
|
26719
26783
|
const isAvailable = await module.isAvailable();
|
|
@@ -27412,6 +27476,7 @@ const useMultiChainWallet = (chain) => {
|
|
|
27412
27476
|
const suiAddress = connectedAddresses[squidTypes.ChainType.SUI];
|
|
27413
27477
|
const xrplAddress = connectedAddresses[squidTypes.ChainType.XRPL];
|
|
27414
27478
|
const stellarAddress = connectedAddresses[squidTypes.ChainType.STELLAR];
|
|
27479
|
+
const cantonAddress = connectedAddresses[squidTypes.ChainType.CANTON];
|
|
27415
27480
|
// Cosmos is a special case because the address changes on every chain
|
|
27416
27481
|
// so we can't use the default cosmos connected address
|
|
27417
27482
|
const { data: cosmosAddress } = useCosmosForChain(chain);
|
|
@@ -27499,6 +27564,16 @@ const useMultiChainWallet = (chain) => {
|
|
|
27499
27564
|
chainType: chain.chainType,
|
|
27500
27565
|
}),
|
|
27501
27566
|
};
|
|
27567
|
+
case squidTypes.ChainType.CANTON:
|
|
27568
|
+
if (!cantonAddress)
|
|
27569
|
+
return {};
|
|
27570
|
+
return {
|
|
27571
|
+
address: cantonAddress,
|
|
27572
|
+
formatted: formatHash({
|
|
27573
|
+
hash: cantonAddress,
|
|
27574
|
+
chainType: chain.chainType,
|
|
27575
|
+
}),
|
|
27576
|
+
};
|
|
27502
27577
|
}
|
|
27503
27578
|
}, [
|
|
27504
27579
|
chain?.chainType,
|
|
@@ -27510,6 +27585,7 @@ const useMultiChainWallet = (chain) => {
|
|
|
27510
27585
|
suiAddress,
|
|
27511
27586
|
xrplAddress,
|
|
27512
27587
|
stellarAddress,
|
|
27588
|
+
cantonAddress,
|
|
27513
27589
|
]);
|
|
27514
27590
|
/**
|
|
27515
27591
|
* Change current network for desired chain
|
|
@@ -28334,6 +28410,8 @@ async function createClient(chain) {
|
|
|
28334
28410
|
return new XrplRpcClient(chain.rpc);
|
|
28335
28411
|
case squidTypes.ChainType.STELLAR:
|
|
28336
28412
|
return new StellarRpcClient(chain.rpc);
|
|
28413
|
+
case squidTypes.ChainType.CANTON:
|
|
28414
|
+
return null;
|
|
28337
28415
|
}
|
|
28338
28416
|
}
|
|
28339
28417
|
|
|
@@ -29526,7 +29604,7 @@ const useStellarBalance = ({ userAddress, chain, enabled, token, refreshInterval
|
|
|
29526
29604
|
};
|
|
29527
29605
|
|
|
29528
29606
|
function useNativeTokenForChain(chain) {
|
|
29529
|
-
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = useSquidTokens();
|
|
29607
|
+
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, cantonTokens, } = useSquidTokens();
|
|
29530
29608
|
const getTokensForChainType = () => {
|
|
29531
29609
|
if (!chain?.chainType)
|
|
29532
29610
|
return [];
|
|
@@ -29545,6 +29623,8 @@ function useNativeTokenForChain(chain) {
|
|
|
29545
29623
|
return xrplTokens;
|
|
29546
29624
|
case squidTypes.ChainType.STELLAR:
|
|
29547
29625
|
return stellarTokens;
|
|
29626
|
+
case squidTypes.ChainType.CANTON:
|
|
29627
|
+
return cantonTokens;
|
|
29548
29628
|
}
|
|
29549
29629
|
};
|
|
29550
29630
|
const nativeTokenForChainType = React.useMemo(() => {
|
|
@@ -29569,14 +29649,20 @@ const useEvmNativeBalance = ({ address, chain, }) => {
|
|
|
29569
29649
|
},
|
|
29570
29650
|
});
|
|
29571
29651
|
const balance = React.useMemo(() => {
|
|
29572
|
-
if (nativeEvmBalance?.decimals && nativeEvmBalance?.value) {
|
|
29652
|
+
if (nativeEvmBalance?.decimals != null && nativeEvmBalance?.value != null) {
|
|
29653
|
+
if (chain?.chainId === CHAIN_IDS.HEDERA) {
|
|
29654
|
+
return {
|
|
29655
|
+
decimals: 8,
|
|
29656
|
+
value: scaleWeiToHbar(nativeEvmBalance.value),
|
|
29657
|
+
};
|
|
29658
|
+
}
|
|
29573
29659
|
return {
|
|
29574
29660
|
decimals: nativeEvmBalance.decimals,
|
|
29575
29661
|
value: nativeEvmBalance.value,
|
|
29576
29662
|
};
|
|
29577
29663
|
}
|
|
29578
29664
|
return;
|
|
29579
|
-
}, [nativeEvmBalance?.decimals, nativeEvmBalance?.value]);
|
|
29665
|
+
}, [nativeEvmBalance?.decimals, nativeEvmBalance?.value, chain?.chainId]);
|
|
29580
29666
|
return {
|
|
29581
29667
|
balance,
|
|
29582
29668
|
isLoading,
|
|
@@ -29773,6 +29859,11 @@ const useNativeBalance = (chain) => {
|
|
|
29773
29859
|
break;
|
|
29774
29860
|
case squidTypes.ChainType.STELLAR:
|
|
29775
29861
|
balance = nativeStellarBalance;
|
|
29862
|
+
break;
|
|
29863
|
+
case squidTypes.ChainType.CANTON:
|
|
29864
|
+
// TODO: implement canton balance fetching
|
|
29865
|
+
balance = undefined;
|
|
29866
|
+
break;
|
|
29776
29867
|
}
|
|
29777
29868
|
const balanceFormatted = !!balance
|
|
29778
29869
|
? formatBNToReadable(balance.value, balance.decimals)
|
|
@@ -29809,6 +29900,9 @@ const useNativeBalance = (chain) => {
|
|
|
29809
29900
|
return isXrpLoading;
|
|
29810
29901
|
case squidTypes.ChainType.STELLAR:
|
|
29811
29902
|
return isStellarLoading;
|
|
29903
|
+
case squidTypes.ChainType.CANTON:
|
|
29904
|
+
// TODO: implement canton balance fetching
|
|
29905
|
+
return false;
|
|
29812
29906
|
}
|
|
29813
29907
|
}, [
|
|
29814
29908
|
chain?.chainType,
|
|
@@ -30033,7 +30127,7 @@ function hederaWalletConnect(parameters) {
|
|
|
30033
30127
|
const optionalChains = config.chains.map((x) => x.id);
|
|
30034
30128
|
if (!optionalChains.length)
|
|
30035
30129
|
return;
|
|
30036
|
-
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-
|
|
30130
|
+
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-Q71H7cJa.js'); });
|
|
30037
30131
|
const rawProvider = await EthereumProvider.init({
|
|
30038
30132
|
...restParameters,
|
|
30039
30133
|
disableProviderPing: true,
|
|
@@ -30263,6 +30357,8 @@ const useSigner = ({ chain }) => {
|
|
|
30263
30357
|
return isXrplSignerReady;
|
|
30264
30358
|
case squidTypes.ChainType.STELLAR:
|
|
30265
30359
|
return isStellarSignerReady;
|
|
30360
|
+
case squidTypes.ChainType.CANTON:
|
|
30361
|
+
return false;
|
|
30266
30362
|
}
|
|
30267
30363
|
}, [
|
|
30268
30364
|
chain?.chainType,
|
|
@@ -30735,6 +30831,7 @@ function useDepositAddress(squidRoute) {
|
|
|
30735
30831
|
const chainsSupportingDepositAddress = [
|
|
30736
30832
|
CHAIN_IDS.BITCOIN,
|
|
30737
30833
|
CHAIN_IDS.SOLANA,
|
|
30834
|
+
CHAIN_IDS.CANTON,
|
|
30738
30835
|
];
|
|
30739
30836
|
return chainsSupportingDepositAddress.includes(fromChain.chainId);
|
|
30740
30837
|
}, [fromChain?.chainId]);
|
|
@@ -30749,20 +30846,33 @@ function useDepositAddress(squidRoute) {
|
|
|
30749
30846
|
toggleDepositFlow(false);
|
|
30750
30847
|
}, [toggleDepositFlow]);
|
|
30751
30848
|
const closeDepositChannel = React.useCallback(() => {
|
|
30752
|
-
toggleDepositFlow(false);
|
|
30753
30849
|
setDeposit(null);
|
|
30754
|
-
}, [
|
|
30850
|
+
}, [setDeposit]);
|
|
30755
30851
|
const getRouteWithDeposit = reactQuery.useMutation(async ({ route }) => {
|
|
30756
|
-
if (!squid)
|
|
30757
|
-
throw new Error("
|
|
30758
|
-
|
|
30759
|
-
|
|
30760
|
-
|
|
30761
|
-
|
|
30762
|
-
|
|
30763
|
-
|
|
30764
|
-
|
|
30765
|
-
|
|
30852
|
+
if (!squid || !route.transactionRequest)
|
|
30853
|
+
throw new Error("Missing required params");
|
|
30854
|
+
if (isChainflipDepositRoute(route)) {
|
|
30855
|
+
const depositAddressResponse = (await squid.executeRoute({
|
|
30856
|
+
signer: {},
|
|
30857
|
+
route,
|
|
30858
|
+
}));
|
|
30859
|
+
setDeposit({
|
|
30860
|
+
amount: depositAddressResponse.amount,
|
|
30861
|
+
depositAddress: depositAddressResponse.depositAddress,
|
|
30862
|
+
statusTrackingId: depositAddressResponse.chainflipStatusTrackingId,
|
|
30863
|
+
});
|
|
30864
|
+
return;
|
|
30865
|
+
}
|
|
30866
|
+
else if (isDepositAddressDirectTransferRoute(route.transactionRequest)) {
|
|
30867
|
+
const orderHash = route.transactionRequest.data;
|
|
30868
|
+
setDeposit({
|
|
30869
|
+
amount: route.params.fromAmount ?? "",
|
|
30870
|
+
depositAddress: route.transactionRequest.target,
|
|
30871
|
+
statusTrackingId: orderHash,
|
|
30872
|
+
memo: orderHash,
|
|
30873
|
+
});
|
|
30874
|
+
return;
|
|
30875
|
+
}
|
|
30766
30876
|
});
|
|
30767
30877
|
return {
|
|
30768
30878
|
isEnabled,
|
|
@@ -30801,7 +30911,7 @@ const useUrlSwapParams = () => {
|
|
|
30801
30911
|
|
|
30802
30912
|
const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, queryOptions, }) => {
|
|
30803
30913
|
const { evmChains, cosmosChains, suiChains, xrplChains, stellarChains } = useSquidChains(direction);
|
|
30804
|
-
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = useSquidTokens(direction);
|
|
30914
|
+
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, cantonTokens, } = useSquidTokens(direction);
|
|
30805
30915
|
const { keplrTypeWallet } = useCosmosContext();
|
|
30806
30916
|
const placeholderData = React.useMemo(() => {
|
|
30807
30917
|
const tokens = {
|
|
@@ -30812,6 +30922,7 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
30812
30922
|
[squidTypes.ChainType.SUI]: suiTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30813
30923
|
[squidTypes.ChainType.XRPL]: xrplTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30814
30924
|
[squidTypes.ChainType.STELLAR]: stellarTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30925
|
+
[squidTypes.ChainType.CANTON]: cantonTokens.map((t) => ({ ...t, balance: "0" })),
|
|
30815
30926
|
};
|
|
30816
30927
|
if (!chainType) {
|
|
30817
30928
|
// Return all tokens with zero balance
|
|
@@ -30833,6 +30944,7 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
30833
30944
|
suiTokens,
|
|
30834
30945
|
xrplTokens,
|
|
30835
30946
|
stellarTokens,
|
|
30947
|
+
cantonTokens,
|
|
30836
30948
|
]);
|
|
30837
30949
|
const isQueryEnabled = React.useMemo(() => {
|
|
30838
30950
|
// Respect the queryOptions.enabled override if provided
|
|
@@ -30855,6 +30967,8 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
30855
30967
|
return xrplTokens.length > 0;
|
|
30856
30968
|
case squidTypes.ChainType.STELLAR:
|
|
30857
30969
|
return stellarTokens.length > 0;
|
|
30970
|
+
case squidTypes.ChainType.CANTON:
|
|
30971
|
+
return cantonTokens.length > 0;
|
|
30858
30972
|
}
|
|
30859
30973
|
}, [
|
|
30860
30974
|
chainType,
|
|
@@ -30867,6 +30981,7 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
30867
30981
|
suiTokens.length,
|
|
30868
30982
|
xrplTokens.length,
|
|
30869
30983
|
stellarTokens.length,
|
|
30984
|
+
cantonTokens.length,
|
|
30870
30985
|
]);
|
|
30871
30986
|
const query = reactQuery.useQuery(keys().allTokensBalance(address, chainType, direction), async () => {
|
|
30872
30987
|
// Return zero balances if no address
|
|
@@ -30976,6 +31091,12 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
|
30976
31091
|
direction,
|
|
30977
31092
|
queryOptions,
|
|
30978
31093
|
});
|
|
31094
|
+
const cantonBalancesQuery = useAllTokensWithBalanceForChainType({
|
|
31095
|
+
chainType: squidTypes.ChainType.CANTON,
|
|
31096
|
+
address: connectedAddresses?.[squidTypes.ChainType.CANTON],
|
|
31097
|
+
direction,
|
|
31098
|
+
queryOptions,
|
|
31099
|
+
});
|
|
30979
31100
|
// Create a map of chain type to balance query results
|
|
30980
31101
|
const balanceQueries = React.useMemo(() => ({
|
|
30981
31102
|
[squidTypes.ChainType.EVM]: evmBalancesQuery,
|
|
@@ -30985,6 +31106,7 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
|
30985
31106
|
[squidTypes.ChainType.SUI]: suiBalancesQuery,
|
|
30986
31107
|
[squidTypes.ChainType.XRPL]: xrplBalancesQuery,
|
|
30987
31108
|
[squidTypes.ChainType.STELLAR]: stellarBalancesQuery,
|
|
31109
|
+
[squidTypes.ChainType.CANTON]: cantonBalancesQuery,
|
|
30988
31110
|
}), [
|
|
30989
31111
|
evmBalancesQuery,
|
|
30990
31112
|
cosmosBalancesQuery,
|
|
@@ -30993,6 +31115,7 @@ const useAllConnectedWalletBalances = ({ direction, queryOptions = {
|
|
|
30993
31115
|
suiBalancesQuery,
|
|
30994
31116
|
xrplBalancesQuery,
|
|
30995
31117
|
stellarBalancesQuery,
|
|
31118
|
+
cantonBalancesQuery,
|
|
30996
31119
|
]);
|
|
30997
31120
|
// Combine all tokens from different chains
|
|
30998
31121
|
const allTokens = React.useMemo(() => Object.values(balanceQueries).flatMap((query) => query.data?.tokens ?? []), [balanceQueries]);
|
|
@@ -31092,6 +31215,9 @@ const useMultiChainBalance = ({ chain, token, userAddress, enabled = true, }) =>
|
|
|
31092
31215
|
return xrplBalance;
|
|
31093
31216
|
case squidTypes.ChainType.STELLAR:
|
|
31094
31217
|
return stellarBalance;
|
|
31218
|
+
case squidTypes.ChainType.CANTON:
|
|
31219
|
+
// TODO: implement canton balance fetching
|
|
31220
|
+
return "0";
|
|
31095
31221
|
}
|
|
31096
31222
|
}, [
|
|
31097
31223
|
chain?.chainType,
|
|
@@ -31524,19 +31650,6 @@ const formatEstimatedRouteDuration = ({ estimatedRouteDuration, isSingleChainRou
|
|
|
31524
31650
|
format: (sTemplate, mTemplate, hTemplate) => formatSeconds(durationInSeconds, sTemplate, mTemplate, hTemplate),
|
|
31525
31651
|
};
|
|
31526
31652
|
};
|
|
31527
|
-
/**
|
|
31528
|
-
* Calculates and formats various estimate results based on the provided Squid route and additional parameters.
|
|
31529
|
-
*
|
|
31530
|
-
* @param {RouteResponse["route"]} squidRoute - The Squid route containing estimate information.
|
|
31531
|
-
* @param {Token[]} tokens - An array of token objects.
|
|
31532
|
-
* @param {ChainData} fromChain - The source chain object.
|
|
31533
|
-
* @param {ChainData} toChain - The destination chain object.
|
|
31534
|
-
* @param {boolean} collectFees - Flag indicating whether to collect fees.
|
|
31535
|
-
* @param {string} nativeTokenBalanceFromChain - The native token balance on the source chain.
|
|
31536
|
-
* @param {boolean} expressActivatedUI - Flag indicating whether express mode is activated in the UI.
|
|
31537
|
-
* @returns {Object} An object containing various estimate results and calculations, including token information,
|
|
31538
|
-
* amounts, fees, gas costs, and other relevant data for the transaction.
|
|
31539
|
-
*/
|
|
31540
31653
|
const calculateEstimateResults = ({ squidRoute, tokens, fromChain, toChain, collectFees, chainFeeParams, gasToken, }) => {
|
|
31541
31654
|
const fromToken = findToken(tokens, squidRoute?.params.fromChain, squidRoute?.params.fromToken);
|
|
31542
31655
|
const fromAmount = squidRoute?.estimate?.fromAmount;
|
|
@@ -31555,7 +31668,7 @@ const calculateEstimateResults = ({ squidRoute, tokens, fromChain, toChain, coll
|
|
|
31555
31668
|
const integratorFeeCost = allFeeCosts.length > 0 && collectFees
|
|
31556
31669
|
? allFeeCosts.find((f) => f.name === "Integrator fee")
|
|
31557
31670
|
: undefined;
|
|
31558
|
-
const expectedGasRefundCost = calculateExpectedGasRefundCost(firstFeeCost, fromChain?.chainType, estimate?.actions
|
|
31671
|
+
const expectedGasRefundCost = calculateExpectedGasRefundCost(firstFeeCost, fromChain?.chainType, estimate?.actions?.map(simplifyRouteAction));
|
|
31559
31672
|
const expectedGasRefundCostUSD = convertTokenAmountToUSD(formatBNToReadable(expectedGasRefundCost, firstFeeCost?.token.decimals ?? 18), firstFeeCost?.token.usdPrice ?? "0");
|
|
31560
31673
|
const sameTokenBetweenFees = firstFeeCost?.token.address === firstGasCost?.token.address &&
|
|
31561
31674
|
firstFeeCost?.token.chainId === firstGasCost?.token.chainId;
|
|
@@ -32213,6 +32326,9 @@ function useSendTransaction({ to, amount, token, chain, }) {
|
|
|
32213
32326
|
chain,
|
|
32214
32327
|
});
|
|
32215
32328
|
break;
|
|
32329
|
+
case squidTypes.ChainType.CANTON: {
|
|
32330
|
+
throw new Error("Not implemented");
|
|
32331
|
+
}
|
|
32216
32332
|
}
|
|
32217
32333
|
return {
|
|
32218
32334
|
amount,
|
|
@@ -32416,6 +32532,8 @@ async function getSendTransactionStatus({ chain, txHash, }) {
|
|
|
32416
32532
|
txHash,
|
|
32417
32533
|
chain,
|
|
32418
32534
|
});
|
|
32535
|
+
case squidTypes.ChainType.CANTON:
|
|
32536
|
+
throw new Error("Not implemented");
|
|
32419
32537
|
}
|
|
32420
32538
|
}
|
|
32421
32539
|
|
|
@@ -32439,7 +32557,7 @@ const useHistory = (txType) => {
|
|
|
32439
32557
|
fromChain: tx.params.fromChain,
|
|
32440
32558
|
fromToken: tx.params.fromToken,
|
|
32441
32559
|
fromAddress: tx.params.fromAddress,
|
|
32442
|
-
fromAmount: tx.params.fromAmount,
|
|
32560
|
+
fromAmount: tx.params.fromAmount ?? "",
|
|
32443
32561
|
toChain: tx.params.toChain,
|
|
32444
32562
|
toToken: tx.params.toToken,
|
|
32445
32563
|
toAddress: tx.params.toAddress,
|
|
@@ -32867,6 +32985,125 @@ const useApproval = ({ squidRoute, }) => {
|
|
|
32867
32985
|
};
|
|
32868
32986
|
};
|
|
32869
32987
|
|
|
32988
|
+
const useSwapStatusQuery = ({ transaction, retry = 25, refetchOnWindowFocus = "always", enabled = true, onStatus, onEndStatus, onNotFound, onError, }) => {
|
|
32989
|
+
const config = useConfigStore((state) => state.config);
|
|
32990
|
+
const isInitialized = useConfigStore((state) => state.isInitialized);
|
|
32991
|
+
const [isTransactionComplete, setIsTransactionComplete] = React.useState(false);
|
|
32992
|
+
const [refetchInterval, setRefetchInterval] = React.useState(getSwapTxStatusRefetchInterval(transaction));
|
|
32993
|
+
const { getChainType } = useSquidChains();
|
|
32994
|
+
const fetchTransactionStatusWithLatestConfig = React.useCallback(async () => {
|
|
32995
|
+
const latestConfig = useConfigStore.getState().config;
|
|
32996
|
+
return fetchSwapTransactionStatus({
|
|
32997
|
+
transaction,
|
|
32998
|
+
integratorId: latestConfig.integratorId,
|
|
32999
|
+
apiUrl: latestConfig.apiUrl,
|
|
33000
|
+
});
|
|
33001
|
+
}, [transaction]);
|
|
33002
|
+
const transactionStatusQuery = reactQuery.useQuery(keys().swapTransactionStatus(transaction?.transactionId), fetchTransactionStatusWithLatestConfig, {
|
|
33003
|
+
enabled: enabled &&
|
|
33004
|
+
transaction?.transactionId !== "0" &&
|
|
33005
|
+
!!transaction?.transactionId &&
|
|
33006
|
+
!!transaction.fromAddress &&
|
|
33007
|
+
!!config.apiUrl &&
|
|
33008
|
+
transaction !== undefined &&
|
|
33009
|
+
!isTransactionComplete &&
|
|
33010
|
+
isInitialized,
|
|
33011
|
+
refetchInterval(statusResponse) {
|
|
33012
|
+
if (statusResponse &&
|
|
33013
|
+
transactionEndStatuses.includes(getTransactionStatus(statusResponse) ?? "")) {
|
|
33014
|
+
return false;
|
|
33015
|
+
}
|
|
33016
|
+
return refetchInterval;
|
|
33017
|
+
},
|
|
33018
|
+
retryDelay: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 5000 : 3000,
|
|
33019
|
+
retry: getChainType(transaction?.fromChain) === squidTypes.ChainType.COSMOS ? 6 : retry,
|
|
33020
|
+
refetchOnWindowFocus,
|
|
33021
|
+
onSuccess: (statusResponse) => {
|
|
33022
|
+
WidgetEvents.getInstance().dispatchSwapStatus(statusResponse.squidTransactionStatus ?? "");
|
|
33023
|
+
onStatus?.({
|
|
33024
|
+
status: getTransactionStatus(statusResponse) ?? "",
|
|
33025
|
+
statusResponse,
|
|
33026
|
+
});
|
|
33027
|
+
const endStatus = getTransactionEndStatus({ statusResponse });
|
|
33028
|
+
if (endStatus) {
|
|
33029
|
+
setIsTransactionComplete(true);
|
|
33030
|
+
onEndStatus?.({ status: endStatus, statusResponse });
|
|
33031
|
+
}
|
|
33032
|
+
},
|
|
33033
|
+
onError: (error) => {
|
|
33034
|
+
if (is404Error(error.cause)) {
|
|
33035
|
+
onNotFound?.();
|
|
33036
|
+
return;
|
|
33037
|
+
}
|
|
33038
|
+
setRefetchInterval(-1);
|
|
33039
|
+
setIsTransactionComplete(true);
|
|
33040
|
+
onError?.();
|
|
33041
|
+
},
|
|
33042
|
+
});
|
|
33043
|
+
return {
|
|
33044
|
+
transactionStatusQuery,
|
|
33045
|
+
};
|
|
33046
|
+
};
|
|
33047
|
+
|
|
33048
|
+
// Statuses that indicate the source deposit has been received and the swap is
|
|
33049
|
+
// now progressing — the point at which it becomes a history-backed transaction.
|
|
33050
|
+
const sourceReceivedStatuses = [
|
|
33051
|
+
"DEPOSIT_RECEIVED",
|
|
33052
|
+
"BROADCAST_REQUESTED",
|
|
33053
|
+
"COMPLETE",
|
|
33054
|
+
];
|
|
33055
|
+
/**
|
|
33056
|
+
* Tracks a generated deposit address before it becomes a persisted swap history item.
|
|
33057
|
+
*
|
|
33058
|
+
* Mirrors the hooks-first pattern of `useExecuteTransaction`: once the source deposit
|
|
33059
|
+
* is received, it registers the transaction in the transaction + history stores, then
|
|
33060
|
+
* signals the view (via `onReceived`) to navigate. The view never writes to the stores.
|
|
33061
|
+
*/
|
|
33062
|
+
const useDepositTransactionStatus = ({ transaction, route, retry = 25, refetchOnWindowFocus = "always", enabled = true, onReceived, }) => {
|
|
33063
|
+
const { fromChain, toChain } = useSwap();
|
|
33064
|
+
const { addSwapTransaction } = useHistory();
|
|
33065
|
+
const getTransaction = useTransactionStore((state) => state.getTransaction);
|
|
33066
|
+
const setTransactionStoreState = useTransactionStore((state) => state.setTransactionState);
|
|
33067
|
+
return useSwapStatusQuery({
|
|
33068
|
+
transaction,
|
|
33069
|
+
retry,
|
|
33070
|
+
refetchOnWindowFocus,
|
|
33071
|
+
enabled,
|
|
33072
|
+
onStatus: ({ status }) => {
|
|
33073
|
+
if (!sourceReceivedStatuses.includes(status))
|
|
33074
|
+
return;
|
|
33075
|
+
if (!transaction?.transactionId || !route?.transactionRequest)
|
|
33076
|
+
return;
|
|
33077
|
+
const txLocalId = transaction.transactionId;
|
|
33078
|
+
if (getTransaction(txLocalId))
|
|
33079
|
+
return;
|
|
33080
|
+
useTransactionStore.setState({
|
|
33081
|
+
txLocalId,
|
|
33082
|
+
currentTransaction: undefined,
|
|
33083
|
+
});
|
|
33084
|
+
const tx = {
|
|
33085
|
+
routeType: route.transactionRequest.type,
|
|
33086
|
+
fromChain,
|
|
33087
|
+
toChain,
|
|
33088
|
+
fromAddress: transaction.fromAddress,
|
|
33089
|
+
transactionId: txLocalId,
|
|
33090
|
+
transactionIdForStatus: transaction.transactionIdForStatus,
|
|
33091
|
+
quoteId: route.quoteId,
|
|
33092
|
+
status: exports.TransactionStatus.ONGOING,
|
|
33093
|
+
sourceStatus: exports.TransactionStatus.SUCCESS,
|
|
33094
|
+
timestamp: Date.now(),
|
|
33095
|
+
};
|
|
33096
|
+
setTransactionStoreState(txLocalId, tx);
|
|
33097
|
+
addSwapTransaction({
|
|
33098
|
+
...tx,
|
|
33099
|
+
params: route.params,
|
|
33100
|
+
estimate: route.estimate,
|
|
33101
|
+
});
|
|
33102
|
+
onReceived?.();
|
|
33103
|
+
},
|
|
33104
|
+
});
|
|
33105
|
+
};
|
|
33106
|
+
|
|
32870
33107
|
const DEFAULT_PROVIDER_IMAGE_URL = "https://raw.githubusercontent.com/0xsquid/assets/main/images/webp128/providers/squid.webp";
|
|
32871
33108
|
const AXELAR_PROVIDER_IMAGE_URL = "https://raw.githubusercontent.com/0xsquid/assets/main/images/webp128/providers/axelar.webp";
|
|
32872
33109
|
const useEstimate = (squidRoute) => {
|
|
@@ -35915,6 +36152,12 @@ coin.DecProto = {
|
|
|
35915
36152
|
|
|
35916
36153
|
const useExecuteTransaction = (squidRoute) => {
|
|
35917
36154
|
const { fromChain, toChain, fromToken, toToken, isSameChain } = useSwap();
|
|
36155
|
+
// A route completes on source tx only if it's same-chain AND
|
|
36156
|
+
// every action is fulfilled in the user's source transaction
|
|
36157
|
+
const isCompletedOnSourceTx = isSameChain &&
|
|
36158
|
+
!!fromChain &&
|
|
36159
|
+
!!squidRoute &&
|
|
36160
|
+
squidRoute.estimate.actions.every((a) => isActionCompletedOnSourceTx(a, fromChain.chainId));
|
|
35918
36161
|
const { evmSigner, cosmosSigner, solanaSigner, bitcoinSigner, suiSigner, xrplSigner, stellarSigner, } = useSigner({
|
|
35919
36162
|
chain: fromChain,
|
|
35920
36163
|
});
|
|
@@ -35949,7 +36192,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
35949
36192
|
routeType: route.transactionRequest.type,
|
|
35950
36193
|
nonce,
|
|
35951
36194
|
transactionId: txHash,
|
|
35952
|
-
transactionIdForStatus
|
|
36195
|
+
transactionIdForStatus,
|
|
35953
36196
|
quoteId,
|
|
35954
36197
|
status,
|
|
35955
36198
|
sourceStatus,
|
|
@@ -36179,7 +36422,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36179
36422
|
if (!route.params.fromAddress || !route.params.toAddress) {
|
|
36180
36423
|
throw new Error("From or to address is required");
|
|
36181
36424
|
}
|
|
36182
|
-
const isDirectTransfer =
|
|
36425
|
+
const isDirectTransfer = isChainflipDepositRoute(route);
|
|
36183
36426
|
// Means it's a transfer to a deposit address
|
|
36184
36427
|
// Instead of a Swap/Contract call using a DEX like Jupiter
|
|
36185
36428
|
if (isDirectTransfer) {
|
|
@@ -36190,7 +36433,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36190
36433
|
throw new Error("Deposit address is required");
|
|
36191
36434
|
}
|
|
36192
36435
|
const signature = await executeSolanaTransfer({
|
|
36193
|
-
amount: BigInt(route.params.fromAmount),
|
|
36436
|
+
amount: BigInt(route.params.fromAmount ?? ""),
|
|
36194
36437
|
target: depositData.depositAddress,
|
|
36195
36438
|
signer: solanaSigner,
|
|
36196
36439
|
connection: solanaConnection,
|
|
@@ -36200,7 +36443,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36200
36443
|
const txParams = setTransactionState({
|
|
36201
36444
|
route,
|
|
36202
36445
|
txHash,
|
|
36203
|
-
transactionIdForStatus: depositData.
|
|
36446
|
+
transactionIdForStatus: depositData.statusTrackingId,
|
|
36204
36447
|
userAddress: sourceUserAddress,
|
|
36205
36448
|
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
36206
36449
|
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
@@ -36249,46 +36492,9 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36249
36492
|
? error
|
|
36250
36493
|
: new Error("Failed to execute Solana transaction");
|
|
36251
36494
|
}
|
|
36252
|
-
}, {
|
|
36253
|
-
onError: (error, variables) => {
|
|
36254
|
-
const currentTx = getTransaction(variables.id);
|
|
36255
|
-
const errorObject = getTransactionError(error);
|
|
36256
|
-
setTransactionStoreState(variables.id, {
|
|
36257
|
-
...currentTx,
|
|
36258
|
-
status: exports.TransactionStatus.ERROR,
|
|
36259
|
-
sourceStatus: exports.TransactionStatus.ERROR,
|
|
36260
|
-
error: errorObject,
|
|
36261
|
-
});
|
|
36262
|
-
if (currentTx?.transactionId &&
|
|
36263
|
-
errorObject.type === exports.TransactionErrorType.CALL_EXCEPTION) {
|
|
36264
|
-
replaceSwapTransactionStatus({
|
|
36265
|
-
transactionId: currentTx.transactionId,
|
|
36266
|
-
statusResponse: currentTx.statusResponse,
|
|
36267
|
-
status: exports.TransactionStatus.ERROR,
|
|
36268
|
-
});
|
|
36269
|
-
}
|
|
36270
|
-
},
|
|
36271
|
-
onSuccess: (_data, variables) => {
|
|
36272
|
-
const currentTx = getTransaction(variables.id);
|
|
36273
|
-
queryClient.invalidateQueries(getPrefixKey(exports.QueryKeys.Balances));
|
|
36274
|
-
if (isSameChain && currentTx?.transactionId) {
|
|
36275
|
-
replaceSwapTransactionStatus({
|
|
36276
|
-
transactionId: currentTx.transactionId,
|
|
36277
|
-
statusResponse: currentTx.statusResponse,
|
|
36278
|
-
status: exports.TransactionStatus.SUCCESS,
|
|
36279
|
-
});
|
|
36280
|
-
}
|
|
36281
|
-
setTransactionStoreState(variables.id, {
|
|
36282
|
-
...currentTx,
|
|
36283
|
-
sourceStatus: exports.TransactionStatus.SUCCESS,
|
|
36284
|
-
status: isSameChain
|
|
36285
|
-
? exports.TransactionStatus.SUCCESS
|
|
36286
|
-
: exports.TransactionStatus.ONGOING,
|
|
36287
|
-
});
|
|
36288
|
-
},
|
|
36289
36495
|
});
|
|
36290
36496
|
const swapMutationBitcoin = reactQuery.useMutation(async ({ id, route }) => {
|
|
36291
|
-
const { depositAddress, amount: sendAmount,
|
|
36497
|
+
const { depositAddress, amount: sendAmount, statusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
|
|
36292
36498
|
if (!depositAddress) {
|
|
36293
36499
|
throw new Error(`Invalid deposit address: ${depositAddress}`);
|
|
36294
36500
|
}
|
|
@@ -36311,7 +36517,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36311
36517
|
txHash,
|
|
36312
36518
|
// When bridging from Bitcoin we need to send the chainflipId to the status endpoint
|
|
36313
36519
|
// instead of the Bitcoin transaction hash
|
|
36314
|
-
transactionIdForStatus:
|
|
36520
|
+
transactionIdForStatus: statusTrackingId,
|
|
36315
36521
|
userAddress: sourceUserAddress,
|
|
36316
36522
|
status: exports.TransactionStatus.INITIAL_LOADING,
|
|
36317
36523
|
sourceStatus: exports.TransactionStatus.ONGOING,
|
|
@@ -36506,7 +36712,7 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36506
36712
|
const handleTransactionSuccess = React.useCallback((id) => {
|
|
36507
36713
|
const currentTx = getTransaction(id);
|
|
36508
36714
|
queryClient.invalidateQueries(getPrefixKey(exports.QueryKeys.Balances));
|
|
36509
|
-
if (
|
|
36715
|
+
if (isCompletedOnSourceTx && currentTx?.transactionId) {
|
|
36510
36716
|
replaceSwapTransactionStatus({
|
|
36511
36717
|
transactionId: currentTx.transactionId,
|
|
36512
36718
|
statusResponse: currentTx.statusResponse,
|
|
@@ -36516,13 +36722,13 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36516
36722
|
setTransactionStoreState(id, {
|
|
36517
36723
|
...currentTx,
|
|
36518
36724
|
sourceStatus: exports.TransactionStatus.SUCCESS,
|
|
36519
|
-
status:
|
|
36725
|
+
status: isCompletedOnSourceTx
|
|
36520
36726
|
? exports.TransactionStatus.SUCCESS
|
|
36521
36727
|
: exports.TransactionStatus.ONGOING,
|
|
36522
36728
|
});
|
|
36523
36729
|
}, [
|
|
36524
36730
|
getTransaction,
|
|
36525
|
-
|
|
36731
|
+
isCompletedOnSourceTx,
|
|
36526
36732
|
queryClient,
|
|
36527
36733
|
replaceSwapTransactionStatus,
|
|
36528
36734
|
setTransactionStoreState,
|
|
@@ -36545,8 +36751,8 @@ const useExecuteTransaction = (squidRoute) => {
|
|
|
36545
36751
|
if (currentTx?.transactionId &&
|
|
36546
36752
|
errorObject.type === exports.TransactionErrorType.CALL_EXCEPTION) {
|
|
36547
36753
|
replaceSwapTransactionStatus({
|
|
36548
|
-
transactionId: currentTx
|
|
36549
|
-
statusResponse: currentTx
|
|
36754
|
+
transactionId: currentTx.transactionId,
|
|
36755
|
+
statusResponse: currentTx.statusResponse,
|
|
36550
36756
|
status: exports.TransactionStatus.ERROR,
|
|
36551
36757
|
});
|
|
36552
36758
|
}
|
|
@@ -36912,94 +37118,50 @@ function useSendTransactionStatus({ chain, txHash, }) {
|
|
|
36912
37118
|
* Fetch status of a Swap transaction
|
|
36913
37119
|
*/
|
|
36914
37120
|
const useSwapTransactionStatus = ({ transaction, retry = 25, refetchOnWindowFocus = "always", enabled = true, }) => {
|
|
36915
|
-
const config = useConfigStore((state) => state.config);
|
|
36916
|
-
const isInitialized = useConfigStore((state) => state.isInitialized);
|
|
36917
37121
|
const { replaceSwapTransactionStatus } = useHistory();
|
|
36918
37122
|
const findTransaction = useHistoryStore((state) => state.findTransaction);
|
|
36919
|
-
const [isTransactionComplete, setIsTransactionComplete] = React.useState(false);
|
|
36920
|
-
const [refetchInterval, setRefetchInterval] = React.useState(getSwapTxStatusRefetchInterval(transaction));
|
|
36921
|
-
const { getChainType } = useSquidChains();
|
|
36922
37123
|
const currentHistoryItem = React.useMemo(() => findTransaction({
|
|
36923
37124
|
transactionId: transaction?.transactionId,
|
|
36924
37125
|
txType: exports.HistoryTxType.SWAP,
|
|
36925
37126
|
}), [findTransaction, transaction?.transactionId]);
|
|
36926
|
-
|
|
36927
|
-
|
|
36928
|
-
|
|
36929
|
-
|
|
36930
|
-
*/
|
|
36931
|
-
const fetchTransactionStatusWithLatestConfig = React.useCallback(async () => {
|
|
36932
|
-
const latestConfig = useConfigStore.getState().config;
|
|
36933
|
-
return fetchSwapTransactionStatus({
|
|
36934
|
-
transaction,
|
|
36935
|
-
integratorId: latestConfig.integratorId,
|
|
36936
|
-
apiUrl: latestConfig.apiUrl,
|
|
36937
|
-
});
|
|
36938
|
-
}, [transaction]);
|
|
36939
|
-
const transactionStatusQuery = reactQuery.useQuery(keys().swapTransactionStatus(transaction?.transactionId), fetchTransactionStatusWithLatestConfig, {
|
|
37127
|
+
const transactionStatusQuery = useSwapStatusQuery({
|
|
37128
|
+
transaction,
|
|
37129
|
+
retry,
|
|
37130
|
+
refetchOnWindowFocus,
|
|
36940
37131
|
enabled: enabled &&
|
|
36941
|
-
transaction?.transactionId !== "0" &&
|
|
36942
|
-
!!transaction?.transactionId &&
|
|
36943
|
-
!!transaction.fromAddress &&
|
|
36944
|
-
!!config.apiUrl &&
|
|
36945
|
-
transaction !== undefined &&
|
|
36946
|
-
!isTransactionComplete &&
|
|
36947
|
-
isInitialized &&
|
|
36948
37132
|
!!currentHistoryItem &&
|
|
36949
37133
|
!isHistoryTransactionEnded({
|
|
36950
37134
|
data: currentHistoryItem?.data,
|
|
36951
37135
|
txType: exports.HistoryTxType.SWAP,
|
|
36952
37136
|
}),
|
|
36953
|
-
|
|
36954
|
-
|
|
36955
|
-
|
|
36956
|
-
|
|
36957
|
-
|
|
36958
|
-
|
|
36959
|
-
|
|
36960
|
-
}
|
|
36961
|
-
return refetchInterval; // Had to handle a variable here because after onError, we want the interval to stop
|
|
37137
|
+
onEndStatus: ({ status, statusResponse }) => {
|
|
37138
|
+
if (!transaction?.transactionId)
|
|
37139
|
+
return;
|
|
37140
|
+
replaceSwapTransactionStatus({
|
|
37141
|
+
transactionId: transaction.transactionId,
|
|
37142
|
+
statusResponse,
|
|
37143
|
+
status,
|
|
37144
|
+
});
|
|
36962
37145
|
},
|
|
36963
|
-
|
|
36964
|
-
|
|
36965
|
-
|
|
36966
|
-
|
|
36967
|
-
|
|
36968
|
-
|
|
36969
|
-
|
|
36970
|
-
|
|
36971
|
-
if (endStatus && transaction?.transactionId) {
|
|
36972
|
-
setIsTransactionComplete(true);
|
|
36973
|
-
replaceSwapTransactionStatus({
|
|
36974
|
-
transactionId: transaction.transactionId,
|
|
36975
|
-
statusResponse,
|
|
36976
|
-
status: endStatus,
|
|
36977
|
-
});
|
|
36978
|
-
}
|
|
37146
|
+
onNotFound: () => {
|
|
37147
|
+
if (!transaction?.transactionId)
|
|
37148
|
+
return;
|
|
37149
|
+
replaceSwapTransactionStatus({
|
|
37150
|
+
transactionId: transaction.transactionId,
|
|
37151
|
+
statusResponse: undefined,
|
|
37152
|
+
status: exports.TransactionStatus.NOT_FOUND,
|
|
37153
|
+
});
|
|
36979
37154
|
},
|
|
36980
|
-
onError: (
|
|
36981
|
-
// `fetchTransactionStatus` throws an error with a cause being an AxiosError
|
|
36982
|
-
const is404 = is404Error(error.cause);
|
|
37155
|
+
onError: () => {
|
|
36983
37156
|
if (!transaction?.transactionId)
|
|
36984
37157
|
return;
|
|
36985
|
-
|
|
36986
|
-
|
|
36987
|
-
|
|
36988
|
-
|
|
36989
|
-
|
|
36990
|
-
});
|
|
36991
|
-
}
|
|
36992
|
-
else {
|
|
36993
|
-
setRefetchInterval(-1);
|
|
36994
|
-
setIsTransactionComplete(true);
|
|
36995
|
-
replaceSwapTransactionStatus({
|
|
36996
|
-
transactionId: transaction.transactionId,
|
|
36997
|
-
statusResponse: undefined,
|
|
36998
|
-
status: exports.TransactionStatus.ERROR,
|
|
36999
|
-
});
|
|
37000
|
-
}
|
|
37158
|
+
replaceSwapTransactionStatus({
|
|
37159
|
+
transactionId: transaction.transactionId,
|
|
37160
|
+
statusResponse: undefined,
|
|
37161
|
+
status: exports.TransactionStatus.ERROR,
|
|
37162
|
+
});
|
|
37001
37163
|
},
|
|
37002
|
-
});
|
|
37164
|
+
}).transactionStatusQuery;
|
|
37003
37165
|
return {
|
|
37004
37166
|
transactionStatusQuery,
|
|
37005
37167
|
latestStatus: transactionStatusQuery.data
|
|
@@ -37590,10 +37752,12 @@ exports.groupTokensBySymbol = groupTokensBySymbol;
|
|
|
37590
37752
|
exports.handleTransactionErrorEvents = handleTransactionErrorEvents;
|
|
37591
37753
|
exports.initializeSquidWithAssetsColors = initializeSquidWithAssetsColors;
|
|
37592
37754
|
exports.is404Error = is404Error;
|
|
37755
|
+
exports.isActionCompletedOnSourceTx = isActionCompletedOnSourceTx;
|
|
37593
37756
|
exports.isChainflipBridgeTransaction = isChainflipBridgeTransaction;
|
|
37757
|
+
exports.isChainflipDepositRoute = isChainflipDepositRoute;
|
|
37594
37758
|
exports.isCoralBridgeAction = isCoralBridgeAction;
|
|
37595
37759
|
exports.isCosmosAddressValid = isCosmosAddressValid;
|
|
37596
|
-
exports.
|
|
37760
|
+
exports.isDepositAddressDirectTransferRoute = isDepositAddressDirectTransferRoute;
|
|
37597
37761
|
exports.isEmptyObject = isEmptyObject;
|
|
37598
37762
|
exports.isEvmChainNotSupportedError = isEvmChainNotSupportedError;
|
|
37599
37763
|
exports.isEvmosChain = isEvmosChain;
|
|
@@ -37673,6 +37837,7 @@ exports.useCountryDetails = useCountryDetails;
|
|
|
37673
37837
|
exports.useCurrencyDetails = useCurrencyDetails;
|
|
37674
37838
|
exports.useDebouncedValue = useDebouncedValue;
|
|
37675
37839
|
exports.useDepositAddress = useDepositAddress;
|
|
37840
|
+
exports.useDepositTransactionStatus = useDepositTransactionStatus;
|
|
37676
37841
|
exports.useEnsDataForAddress = useEnsDataForAddress;
|
|
37677
37842
|
exports.useEnsSearch = useEnsSearch;
|
|
37678
37843
|
exports.useEstimate = useEstimate;
|
|
@@ -37739,4 +37904,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
|
|
|
37739
37904
|
exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
|
|
37740
37905
|
exports.walletIconBaseUrl = walletIconBaseUrl;
|
|
37741
37906
|
exports.walletSupportsChainType = walletSupportsChainType;
|
|
37742
|
-
//# sourceMappingURL=index-
|
|
37907
|
+
//# sourceMappingURL=index-D1udDcRZ.js.map
|