@0xsquid/react-hooks 8.13.1-beta.0 → 8.14.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/types/solana.d.ts +8 -0
- package/dist/{index-OUfYMn5i.js → index-BjIX7utV.js} +218 -78
- package/dist/index-BjIX7utV.js.map +1 -0
- package/dist/{index-oLTLWI9S.js → index-DkBrtnan.js} +218 -79
- package/dist/index-DkBrtnan.js.map +1 -0
- package/dist/{index.es-CoocBNVs.js → index.es-BQULJYpe.js} +2 -2
- package/dist/{index.es-CoocBNVs.js.map → index.es-BQULJYpe.js.map} +1 -1
- package/dist/{index.es-BWO-JBU8.js → index.es-CeXN3P4q.js} +2 -2
- package/dist/{index.es-BWO-JBU8.js.map → index.es-CeXN3P4q.js.map} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/{secretService-DkpDcrSv.js → secretService-BBTgxmnG.js} +2 -2
- package/dist/{secretService-DkpDcrSv.js.map → secretService-BBTgxmnG.js.map} +1 -1
- package/dist/{secretService-C8zVh8hn.js → secretService-BebOsCud.js} +2 -2
- package/dist/{secretService-C8zVh8hn.js.map → secretService-BebOsCud.js.map} +1 -1
- package/dist/services/internal/errorService.d.ts +5 -2
- package/dist/services/internal/evmService.d.ts +1 -0
- package/dist/{stellarService.client-DE2oaaTW.js → stellarService.client-B6_2UV4u.js} +2 -2
- package/dist/{stellarService.client-DE2oaaTW.js.map → stellarService.client-B6_2UV4u.js.map} +1 -1
- package/dist/{stellarService.client-BKpjqyn_.js → stellarService.client-DlQku8Rs.js} +2 -2
- package/dist/{stellarService.client-BKpjqyn_.js.map → stellarService.client-DlQku8Rs.js.map} +1 -1
- package/dist/tests/errorService.test.d.ts +1 -0
- package/dist/tests/solanaService.test.d.ts +1 -0
- package/dist/tests/useEvmBalance.test.d.ts +1 -0
- package/dist/tests/useEvmNativeBalance.test.d.ts +1 -0
- package/package.json +1 -1
- package/dist/index-OUfYMn5i.js.map +0 -1
- package/dist/index-oLTLWI9S.js.map +0 -1
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import type { StandardWalletAdapter } from "@solana/wallet-standard-wallet-adapter-base";
|
|
2
2
|
export type SolanaConnector = StandardWalletAdapter;
|
|
3
|
+
export declare const SOLANA_ON_CHAIN_ERROR_CODE = "SOLANA_ON_CHAIN_ERROR";
|
|
4
|
+
export declare const SOLANA_BLOCKHASH_EXPIRED_CODE = "SOLANA_BLOCKHASH_EXPIRED";
|
|
5
|
+
export type SolanaTransactionErrorCode = typeof SOLANA_ON_CHAIN_ERROR_CODE | typeof SOLANA_BLOCKHASH_EXPIRED_CODE;
|
|
6
|
+
export declare class SolanaTransactionError extends Error {
|
|
7
|
+
readonly code: SolanaTransactionErrorCode;
|
|
8
|
+
readonly signature?: string;
|
|
9
|
+
constructor(code: SolanaTransactionErrorCode, message: string, signature?: string);
|
|
10
|
+
}
|
|
@@ -252,6 +252,19 @@ class QrCodeGenerationError extends Error {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
const SOLANA_ON_CHAIN_ERROR_CODE = "SOLANA_ON_CHAIN_ERROR";
|
|
256
|
+
const SOLANA_BLOCKHASH_EXPIRED_CODE = "SOLANA_BLOCKHASH_EXPIRED";
|
|
257
|
+
class SolanaTransactionError extends Error {
|
|
258
|
+
code;
|
|
259
|
+
signature;
|
|
260
|
+
constructor(code, message, signature) {
|
|
261
|
+
super(message);
|
|
262
|
+
this.name = "SolanaTransactionError";
|
|
263
|
+
this.code = code;
|
|
264
|
+
this.signature = signature;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
255
268
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
256
269
|
|
|
257
270
|
function getDefaultExportFromCjs (x) {
|
|
@@ -4224,24 +4237,38 @@ class WidgetEvents extends EventTarget {
|
|
|
4224
4237
|
}
|
|
4225
4238
|
}
|
|
4226
4239
|
|
|
4240
|
+
const isRecord$1 = (value) => typeof value === "object" && value !== null;
|
|
4241
|
+
const isErrorCode = (value) => typeof value === "string" || typeof value === "number";
|
|
4242
|
+
const toErrorLike = (value) => {
|
|
4243
|
+
if (!isRecord$1(value))
|
|
4244
|
+
return undefined;
|
|
4245
|
+
const { code, message, reason, error, data, cause } = value;
|
|
4246
|
+
return {
|
|
4247
|
+
code: isErrorCode(code) ? code : undefined,
|
|
4248
|
+
message: typeof message === "string" ? message : undefined,
|
|
4249
|
+
reason: typeof reason === "string" ? reason : undefined,
|
|
4250
|
+
error: toErrorLike(error),
|
|
4251
|
+
data: toErrorLike(data),
|
|
4252
|
+
cause: toErrorLike(cause),
|
|
4253
|
+
};
|
|
4254
|
+
};
|
|
4227
4255
|
/**
|
|
4228
4256
|
* Normalizes different error structures into a consistent format
|
|
4229
4257
|
* This helps handle different wallet error formats uniformly
|
|
4230
4258
|
*/
|
|
4231
4259
|
const normalizeError = (error) => {
|
|
4260
|
+
const errorLike = toErrorLike(error);
|
|
4261
|
+
if (!errorLike)
|
|
4262
|
+
return {};
|
|
4232
4263
|
// Handle nested error objects (like Rainbow's error.error structure)
|
|
4233
|
-
|
|
4234
|
-
return {
|
|
4235
|
-
code: error.error.code,
|
|
4236
|
-
message: error.error.message,
|
|
4237
|
-
reason: error.error.reason,
|
|
4238
|
-
};
|
|
4239
|
-
}
|
|
4240
|
-
// Handle direct error properties
|
|
4264
|
+
const source = errorLike.error ?? errorLike;
|
|
4241
4265
|
return {
|
|
4242
|
-
code:
|
|
4243
|
-
message:
|
|
4244
|
-
reason:
|
|
4266
|
+
code: source.code,
|
|
4267
|
+
message: source.message,
|
|
4268
|
+
reason: source.reason,
|
|
4269
|
+
dataCode: source.data?.code,
|
|
4270
|
+
dataMessage: source.data?.message,
|
|
4271
|
+
causeMessage: source.cause?.message,
|
|
4245
4272
|
};
|
|
4246
4273
|
};
|
|
4247
4274
|
const transactionErrorCode = {
|
|
@@ -4275,11 +4302,6 @@ const transactionErrorCode = {
|
|
|
4275
4302
|
type: exports.TransactionErrorType.REJECTED_BY_USER,
|
|
4276
4303
|
internalLabel: "EVM: REJECTED: CODE 4001",
|
|
4277
4304
|
},
|
|
4278
|
-
// Rainbow
|
|
4279
|
-
"-32603": {
|
|
4280
|
-
type: exports.TransactionErrorType.REJECTED_BY_USER,
|
|
4281
|
-
internalLabel: "EVM: REJECTED: CODE -32603",
|
|
4282
|
-
},
|
|
4283
4305
|
// Joey (XRPL)
|
|
4284
4306
|
"User rejected.": {
|
|
4285
4307
|
type: exports.TransactionErrorType.REJECTED_BY_USER,
|
|
@@ -4339,16 +4361,60 @@ const transactionErrorCode = {
|
|
|
4339
4361
|
type: exports.TransactionErrorType.CALL_EXCEPTION,
|
|
4340
4362
|
internalLabel: "EVM: CALL_EXCEPTION",
|
|
4341
4363
|
},
|
|
4364
|
+
[SOLANA_ON_CHAIN_ERROR_CODE]: {
|
|
4365
|
+
type: exports.TransactionErrorType.CALL_EXCEPTION,
|
|
4366
|
+
internalLabel: "SOL: Transaction failed on chain",
|
|
4367
|
+
},
|
|
4368
|
+
[SOLANA_BLOCKHASH_EXPIRED_CODE]: {
|
|
4369
|
+
type: exports.TransactionErrorType.UNKNOWN,
|
|
4370
|
+
internalLabel: "SOL: Transaction blockhash expired",
|
|
4371
|
+
},
|
|
4342
4372
|
UNKNOWN: {
|
|
4343
4373
|
type: exports.TransactionErrorType.UNKNOWN,
|
|
4344
4374
|
internalLabel: "UNKNOWN ERROR: Transaction failed",
|
|
4345
4375
|
},
|
|
4346
4376
|
};
|
|
4377
|
+
// Rainbow reports a user rejection with the generic JSON-RPC internal error
|
|
4378
|
+
// code, while Phantom uses the same code for real failures.
|
|
4379
|
+
const INTERNAL_RPC_ERROR_CODE = "-32603";
|
|
4380
|
+
const userRejectionMessagePatterns = [
|
|
4381
|
+
/user rejected/i,
|
|
4382
|
+
/rejected the request/i,
|
|
4383
|
+
/rejected by the user/i,
|
|
4384
|
+
/user denied/i,
|
|
4385
|
+
];
|
|
4386
|
+
const internalRpcRejectionError = {
|
|
4387
|
+
type: exports.TransactionErrorType.REJECTED_BY_USER,
|
|
4388
|
+
internalLabel: "EVM: REJECTED: CODE -32603",
|
|
4389
|
+
};
|
|
4390
|
+
const USER_REJECTED_CODE = "4001";
|
|
4391
|
+
const isUserRejectionMessage = (message) => message !== undefined &&
|
|
4392
|
+
userRejectionMessagePatterns.some((pattern) => pattern.test(message));
|
|
4393
|
+
const isInternalRpcRejection = ({ code, message, dataCode, dataMessage, causeMessage, }) => code != undefined &&
|
|
4394
|
+
code.toString() === INTERNAL_RPC_ERROR_CODE &&
|
|
4395
|
+
(dataCode?.toString() === USER_REJECTED_CODE ||
|
|
4396
|
+
[message, dataMessage, causeMessage].some(isUserRejectionMessage));
|
|
4397
|
+
// @solana/web3.js SendTransactionError carries no code; its message starts
|
|
4398
|
+
// with the preflight failure text.
|
|
4399
|
+
const messagePatternErrors = [
|
|
4400
|
+
{
|
|
4401
|
+
pattern: /^(Simulation failed|Transaction simulation failed)/i,
|
|
4402
|
+
error: {
|
|
4403
|
+
type: exports.TransactionErrorType.CALL_EXCEPTION,
|
|
4404
|
+
internalLabel: "SOL: Transaction simulation failed",
|
|
4405
|
+
},
|
|
4406
|
+
},
|
|
4407
|
+
];
|
|
4408
|
+
const matchMessagePattern = (message) => message === undefined
|
|
4409
|
+
? undefined
|
|
4410
|
+
: messagePatternErrors.find(({ pattern }) => pattern.test(message))?.error;
|
|
4347
4411
|
/**
|
|
4348
4412
|
* Detects if an error is a user rejection based on normalized error structure
|
|
4349
4413
|
*/
|
|
4350
4414
|
const isUserRejectionError = (normalizedError) => {
|
|
4351
4415
|
const { code, message } = normalizedError;
|
|
4416
|
+
if (isInternalRpcRejection(normalizedError))
|
|
4417
|
+
return true;
|
|
4352
4418
|
// Check if the error matches any known rejection patterns from transactionErrorCode
|
|
4353
4419
|
return Object.entries(transactionErrorCode).some(([key, value]) => {
|
|
4354
4420
|
if (value.type !== exports.TransactionErrorType.REJECTED_BY_USER)
|
|
@@ -4369,6 +4435,8 @@ const isUserRejectionError = (normalizedError) => {
|
|
|
4369
4435
|
*/
|
|
4370
4436
|
const getTransactionError = (error) => {
|
|
4371
4437
|
const normalizedError = normalizeError(error);
|
|
4438
|
+
if (isInternalRpcRejection(normalizedError))
|
|
4439
|
+
return internalRpcRejectionError;
|
|
4372
4440
|
if (isUserRejectionError(normalizedError)) {
|
|
4373
4441
|
// Return the specific rejection error if we can find it
|
|
4374
4442
|
if (normalizedError.code) {
|
|
@@ -4385,10 +4453,12 @@ const getTransactionError = (error) => {
|
|
|
4385
4453
|
}
|
|
4386
4454
|
if (normalizedError.code) {
|
|
4387
4455
|
return (transactionErrorCode[normalizedError.code.toString()] ||
|
|
4456
|
+
matchMessagePattern(normalizedError.message) ||
|
|
4388
4457
|
transactionErrorCode.UNKNOWN);
|
|
4389
4458
|
}
|
|
4390
4459
|
if (normalizedError.message) {
|
|
4391
4460
|
return (transactionErrorCode[normalizedError.message] ||
|
|
4461
|
+
matchMessagePattern(normalizedError.message) ||
|
|
4392
4462
|
transactionErrorCode.UNKNOWN);
|
|
4393
4463
|
}
|
|
4394
4464
|
return transactionErrorCode.UNKNOWN;
|
|
@@ -21667,14 +21737,71 @@ const isSolanaAddressValid = (address) => {
|
|
|
21667
21737
|
};
|
|
21668
21738
|
const deserializeSolanaTransaction = (transactionBuffer) => {
|
|
21669
21739
|
// Squid can return legacy Solana transactions (ITS) or versioned transactions
|
|
21670
|
-
// (Jupiter/Chainflip). Deserialize once to detect the payload type.
|
|
21671
|
-
// transactions need to be converted to Transaction because their blockhash is
|
|
21672
|
-
// mutable and must be refreshed before signing.
|
|
21740
|
+
// (Jupiter/Chainflip). Deserialize once to detect the payload type.
|
|
21673
21741
|
const versionedTransaction = web3_js.VersionedTransaction.deserialize(transactionBuffer);
|
|
21674
21742
|
return versionedTransaction.version === "legacy"
|
|
21675
21743
|
? web3_js.Transaction.from(transactionBuffer)
|
|
21676
21744
|
: versionedTransaction;
|
|
21677
21745
|
};
|
|
21746
|
+
const isSignedTransaction = (transaction) => transaction instanceof web3_js.Transaction
|
|
21747
|
+
? transaction.signatures.some(({ signature }) => signature !== null)
|
|
21748
|
+
: transaction.signatures.some((signature) => signature.some((byte) => byte !== 0));
|
|
21749
|
+
const getTransactionBlockhash = (transaction) => transaction instanceof web3_js.Transaction
|
|
21750
|
+
? transaction.recentBlockhash
|
|
21751
|
+
: transaction.message.recentBlockhash;
|
|
21752
|
+
const setTransactionBlockhash = (transaction, blockhash) => {
|
|
21753
|
+
if (transaction instanceof web3_js.Transaction) {
|
|
21754
|
+
transaction.recentBlockhash = blockhash;
|
|
21755
|
+
}
|
|
21756
|
+
else {
|
|
21757
|
+
transaction.message.recentBlockhash = blockhash;
|
|
21758
|
+
}
|
|
21759
|
+
};
|
|
21760
|
+
// Squid builds the transaction server-side, so its blockhash can expire before
|
|
21761
|
+
// the wallet approves it. Pre-signed transactions keep their blockhash: a new
|
|
21762
|
+
// one would invalidate their signatures.
|
|
21763
|
+
const resolveBlockhash = async (transaction, connection) => {
|
|
21764
|
+
const latestBlockhash = await connection.getLatestBlockhash();
|
|
21765
|
+
if (!isSignedTransaction(transaction)) {
|
|
21766
|
+
setTransactionBlockhash(transaction, latestBlockhash.blockhash);
|
|
21767
|
+
return latestBlockhash;
|
|
21768
|
+
}
|
|
21769
|
+
const blockhash = getTransactionBlockhash(transaction);
|
|
21770
|
+
if (!blockhash) {
|
|
21771
|
+
throw new Error("Signed transaction has no blockhash");
|
|
21772
|
+
}
|
|
21773
|
+
const { value: isValid } = await connection.isBlockhashValid(blockhash);
|
|
21774
|
+
if (!isValid) {
|
|
21775
|
+
throw new SolanaTransactionError(SOLANA_BLOCKHASH_EXPIRED_CODE, "Transaction blockhash expired; request a new route");
|
|
21776
|
+
}
|
|
21777
|
+
// The kept blockhash is older than the latest one, so the latest expiry
|
|
21778
|
+
// height is an upper bound: confirmation never gives up too early.
|
|
21779
|
+
return {
|
|
21780
|
+
blockhash,
|
|
21781
|
+
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
|
|
21782
|
+
};
|
|
21783
|
+
};
|
|
21784
|
+
const assertConfirmed = (signature, { err }) => {
|
|
21785
|
+
if (err) {
|
|
21786
|
+
throw new SolanaTransactionError(SOLANA_ON_CHAIN_ERROR_CODE, `Solana transaction failed on chain: ${JSON.stringify(err)}`, signature);
|
|
21787
|
+
}
|
|
21788
|
+
};
|
|
21789
|
+
const SWAP_SEND_OPTIONS = {
|
|
21790
|
+
skipPreflight: false,
|
|
21791
|
+
maxRetries: 2,
|
|
21792
|
+
preflightCommitment: "confirmed",
|
|
21793
|
+
};
|
|
21794
|
+
// Wallets that submit the transaction themselves (Phantom) run their own
|
|
21795
|
+
// preflight and hide its failure behind a generic error. Sign only and submit
|
|
21796
|
+
// through our connection so RPC errors stay visible.
|
|
21797
|
+
const sendSolanaTransaction = async (signer, connection, transaction) => {
|
|
21798
|
+
if (!signer.signTransaction) {
|
|
21799
|
+
return signer.sendTransaction(transaction, connection, SWAP_SEND_OPTIONS);
|
|
21800
|
+
}
|
|
21801
|
+
const signed = await signer.signTransaction(transaction);
|
|
21802
|
+
const raw = signed.serialize();
|
|
21803
|
+
return connection.sendRawTransaction(raw, SWAP_SEND_OPTIONS);
|
|
21804
|
+
};
|
|
21678
21805
|
/**
|
|
21679
21806
|
* Execute a Solana swap transaction
|
|
21680
21807
|
* This will be used for the swap flow - Using Jupiter Dex under the hood
|
|
@@ -21687,21 +21814,15 @@ const executeSolanaSwap = async ({ route, signer, connection, onSigned, }) => {
|
|
|
21687
21814
|
const swapTransactionBuf = Buffer.from(swapRequest, "base64");
|
|
21688
21815
|
const transaction = deserializeSolanaTransaction(swapTransactionBuf);
|
|
21689
21816
|
try {
|
|
21690
|
-
const
|
|
21691
|
-
|
|
21692
|
-
// ITS legacy transactions arrive with the placeholder blockhash
|
|
21693
|
-
// 11111111111111111111111111111111.
|
|
21694
|
-
// Refresh it right before signing so the submitted transaction
|
|
21695
|
-
// uses a valid blockhash. Versioned transactions are not mutable here.
|
|
21696
|
-
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
21697
|
-
}
|
|
21698
|
-
const signature = await signer.sendTransaction(transaction, connection);
|
|
21817
|
+
const { blockhash, lastValidBlockHeight } = await resolveBlockhash(transaction, connection);
|
|
21818
|
+
const signature = await sendSolanaTransaction(signer, connection, transaction);
|
|
21699
21819
|
onSigned?.(signature);
|
|
21700
|
-
await connection.confirmTransaction({
|
|
21820
|
+
const { value } = await connection.confirmTransaction({
|
|
21701
21821
|
signature,
|
|
21702
|
-
blockhash
|
|
21703
|
-
lastValidBlockHeight
|
|
21822
|
+
blockhash,
|
|
21823
|
+
lastValidBlockHeight,
|
|
21704
21824
|
});
|
|
21825
|
+
assertConfirmed(signature, value);
|
|
21705
21826
|
return signature;
|
|
21706
21827
|
}
|
|
21707
21828
|
catch (error) {
|
|
@@ -21766,11 +21887,12 @@ const executeSolanaTransfer = async ({ amount, target, signer, connection, sourc
|
|
|
21766
21887
|
// Trigger callback for UI purposes (show loading state)
|
|
21767
21888
|
onSigned?.(signature);
|
|
21768
21889
|
// Wait for transaction confirmation
|
|
21769
|
-
await connection.confirmTransaction({
|
|
21890
|
+
const { value } = await connection.confirmTransaction({
|
|
21770
21891
|
signature,
|
|
21771
21892
|
blockhash,
|
|
21772
21893
|
lastValidBlockHeight,
|
|
21773
21894
|
});
|
|
21895
|
+
assertConfirmed(signature, value);
|
|
21774
21896
|
return signature;
|
|
21775
21897
|
};
|
|
21776
21898
|
|
|
@@ -23699,7 +23821,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23699
23821
|
};
|
|
23700
23822
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
23701
23823
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
23702
|
-
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-
|
|
23824
|
+
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-BebOsCud.js'); });
|
|
23703
23825
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
23704
23826
|
};
|
|
23705
23827
|
function getTokenAssetsKey(token) {
|
|
@@ -23850,8 +23972,9 @@ async function addEthereumChain({ chain, provider, }) {
|
|
|
23850
23972
|
console.debug("Error adding chain:", error);
|
|
23851
23973
|
}
|
|
23852
23974
|
}
|
|
23975
|
+
const isEvmAddressValid = (address) => !!address && viem.isAddress(address);
|
|
23853
23976
|
const parseEvmAddress = (address) => {
|
|
23854
|
-
if (
|
|
23977
|
+
if (isEvmAddressValid(address)) {
|
|
23855
23978
|
return address;
|
|
23856
23979
|
}
|
|
23857
23980
|
};
|
|
@@ -28100,7 +28223,7 @@ function useSolana() {
|
|
|
28100
28223
|
};
|
|
28101
28224
|
}
|
|
28102
28225
|
const useSolanaConnection = () => {
|
|
28103
|
-
const connectionRef = React.useRef(new web3_js.Connection(SOLANA_RPC_URL));
|
|
28226
|
+
const connectionRef = React.useRef(new web3_js.Connection(SOLANA_RPC_URL, "confirmed"));
|
|
28104
28227
|
return connectionRef.current;
|
|
28105
28228
|
};
|
|
28106
28229
|
|
|
@@ -28126,7 +28249,7 @@ function useStellarWallets() {
|
|
|
28126
28249
|
try {
|
|
28127
28250
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
28128
28251
|
const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module.mjs');
|
|
28129
|
-
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-
|
|
28252
|
+
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-B6_2UV4u.js'); });
|
|
28130
28253
|
const modules = [...initializeAllModules(), new LedgerModule()];
|
|
28131
28254
|
const promises = modules.map(async (module) => {
|
|
28132
28255
|
const isAvailable = await module.isAvailable();
|
|
@@ -30840,18 +30963,24 @@ const DEFAULT_REFRESH_INTERVAL_MS$1 = 15000;
|
|
|
30840
30963
|
const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS$1, }) => {
|
|
30841
30964
|
const { isChainTypeConnected } = useWallet();
|
|
30842
30965
|
const isNativeToken = token?.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
|
|
30843
|
-
const
|
|
30966
|
+
const evmAddress = parseEvmAddress(userAddress);
|
|
30967
|
+
const tokenAddress = parseEvmAddress(token?.address);
|
|
30968
|
+
const isEvmChain = chain?.chainType === squidTypes.ChainType.EVM;
|
|
30969
|
+
const chainId = isEvmChain ? Number(chain.chainId) : undefined;
|
|
30970
|
+
const isEvmConnected = isChainTypeConnected(squidTypes.ChainType.EVM);
|
|
30971
|
+
const isNativeQueryEnabled = enabled && isEvmChain && isEvmConnected && !!evmAddress && isNativeToken;
|
|
30972
|
+
const isErc20QueryEnabled = enabled &&
|
|
30973
|
+
isEvmChain &&
|
|
30974
|
+
isEvmConnected &&
|
|
30975
|
+
!!evmAddress &&
|
|
30976
|
+
!!tokenAddress &&
|
|
30977
|
+
!isNativeToken;
|
|
30844
30978
|
// Only fetch using useBalance if it's a native token
|
|
30845
30979
|
const { data: nativeBalance, isLoading: isNativeTokenLoading } = wagmi.useBalance({
|
|
30846
|
-
address:
|
|
30847
|
-
chainId
|
|
30980
|
+
address: evmAddress,
|
|
30981
|
+
chainId,
|
|
30848
30982
|
query: {
|
|
30849
|
-
enabled:
|
|
30850
|
-
!!userAddress &&
|
|
30851
|
-
isNativeToken &&
|
|
30852
|
-
!!chain &&
|
|
30853
|
-
chain.chainType === squidTypes.ChainType.EVM &&
|
|
30854
|
-
isChainTypeConnected(chain.chainType),
|
|
30983
|
+
enabled: isNativeQueryEnabled,
|
|
30855
30984
|
refetchInterval: refreshIntervalMs,
|
|
30856
30985
|
retry: 2,
|
|
30857
30986
|
},
|
|
@@ -30859,23 +30988,20 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
|
|
|
30859
30988
|
// Only fetch using useReadContract if it's not a native token
|
|
30860
30989
|
// This is temporary, because of wagmi error: https://github.com/wevm/wagmi/issues/4353
|
|
30861
30990
|
const { data: erc20Balance, isLoading: isErc20Loading } = wagmi.useReadContract({
|
|
30862
|
-
address:
|
|
30991
|
+
address: tokenAddress,
|
|
30863
30992
|
abi: viem.erc20Abi,
|
|
30864
30993
|
functionName: "balanceOf",
|
|
30865
|
-
args: [
|
|
30866
|
-
chainId
|
|
30994
|
+
args: evmAddress ? [evmAddress] : undefined,
|
|
30995
|
+
chainId,
|
|
30867
30996
|
query: {
|
|
30868
|
-
enabled:
|
|
30869
|
-
enabled &&
|
|
30870
|
-
!!userAddress &&
|
|
30871
|
-
!isNativeToken,
|
|
30997
|
+
enabled: isErc20QueryEnabled,
|
|
30872
30998
|
refetchInterval: refreshIntervalMs,
|
|
30873
30999
|
retry: 2,
|
|
30874
31000
|
},
|
|
30875
31001
|
});
|
|
30876
31002
|
if (isNativeToken) {
|
|
30877
31003
|
return {
|
|
30878
|
-
isLoading: isNativeTokenLoading,
|
|
31004
|
+
isLoading: isNativeQueryEnabled && isNativeTokenLoading,
|
|
30879
31005
|
balance: nativeBalance
|
|
30880
31006
|
? formatBNToReadable(nativeBalance.value, nativeBalance.decimals)
|
|
30881
31007
|
: "0",
|
|
@@ -30885,11 +31011,16 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
|
|
|
30885
31011
|
balance: erc20Balance && token
|
|
30886
31012
|
? formatBNToReadable(erc20Balance, token.decimals)
|
|
30887
31013
|
: "0",
|
|
30888
|
-
isLoading: isErc20Loading,
|
|
31014
|
+
isLoading: isErc20QueryEnabled && isErc20Loading,
|
|
30889
31015
|
};
|
|
30890
31016
|
};
|
|
30891
31017
|
const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS$1, }) => {
|
|
30892
31018
|
const { isConnected } = useCosmosContext();
|
|
31019
|
+
const isQueryEnabled = !!isConnected &&
|
|
31020
|
+
enabled &&
|
|
31021
|
+
!!token &&
|
|
31022
|
+
chain?.chainType === squidTypes.ChainType.COSMOS &&
|
|
31023
|
+
isWalletAddressValid(chain, userAddress);
|
|
30893
31024
|
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
30894
31025
|
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
30895
31026
|
queryFn: async () => {
|
|
@@ -30902,17 +31033,17 @@ const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIn
|
|
|
30902
31033
|
const balanceBn = await getCosmosTokenBalance(chain, userAddress, token.address);
|
|
30903
31034
|
return formatBNToReadable(balanceBn, token.decimals);
|
|
30904
31035
|
},
|
|
30905
|
-
enabled:
|
|
30906
|
-
enabled &&
|
|
30907
|
-
!!userAddress &&
|
|
30908
|
-
!!token &&
|
|
30909
|
-
chain?.chainType === squidTypes.ChainType.COSMOS,
|
|
31036
|
+
enabled: isQueryEnabled,
|
|
30910
31037
|
refetchInterval: refreshIntervalMs,
|
|
30911
31038
|
retry: 2,
|
|
30912
31039
|
});
|
|
30913
|
-
return { balance, isLoading };
|
|
31040
|
+
return { balance, isLoading: isQueryEnabled && isLoading };
|
|
30914
31041
|
};
|
|
30915
31042
|
const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS$1, }) => {
|
|
31043
|
+
const isQueryEnabled = enabled &&
|
|
31044
|
+
!!token &&
|
|
31045
|
+
chain?.chainType === squidTypes.ChainType.SOLANA &&
|
|
31046
|
+
isWalletAddressValid(chain, userAddress);
|
|
30916
31047
|
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
30917
31048
|
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
30918
31049
|
queryFn: async () => {
|
|
@@ -30921,14 +31052,11 @@ const useSolanaBalance = ({ chain, token, userAddress, enabled = true, refreshIn
|
|
|
30921
31052
|
const balanceBn = await getSolanaTokenBalance(userAddress, token.address);
|
|
30922
31053
|
return formatBNToReadable(balanceBn, token.decimals);
|
|
30923
31054
|
},
|
|
30924
|
-
enabled:
|
|
30925
|
-
!!userAddress &&
|
|
30926
|
-
!!token &&
|
|
30927
|
-
chain?.chainType === squidTypes.ChainType.SOLANA,
|
|
31055
|
+
enabled: isQueryEnabled,
|
|
30928
31056
|
refetchInterval: refreshIntervalMs,
|
|
30929
31057
|
retry: 2,
|
|
30930
31058
|
});
|
|
30931
|
-
return { balance, isLoading };
|
|
31059
|
+
return { balance, isLoading: isQueryEnabled && isLoading };
|
|
30932
31060
|
};
|
|
30933
31061
|
// TODO: implement fetching balances for all bitcoin tokens
|
|
30934
31062
|
const useBitcoinBalance = ({ userAddress, chain, }) => {
|
|
@@ -31061,11 +31189,14 @@ function useNativeTokenForChain(chain) {
|
|
|
31061
31189
|
|
|
31062
31190
|
const useEvmNativeBalance = ({ address, chain, }) => {
|
|
31063
31191
|
const { isChainTypeConnected } = useWallet();
|
|
31192
|
+
const isEvmChain = chain?.chainType === squidTypes.ChainType.EVM;
|
|
31193
|
+
const evmAddress = parseEvmAddress(address);
|
|
31194
|
+
const isQueryEnabled = isEvmChain && !!evmAddress && isChainTypeConnected(squidTypes.ChainType.EVM);
|
|
31064
31195
|
const { data: nativeEvmBalance, isLoading } = wagmi.useBalance({
|
|
31065
|
-
address:
|
|
31066
|
-
chainId: Number(chain
|
|
31196
|
+
address: evmAddress,
|
|
31197
|
+
chainId: isEvmChain ? Number(chain.chainId) : undefined,
|
|
31067
31198
|
query: {
|
|
31068
|
-
enabled:
|
|
31199
|
+
enabled: isQueryEnabled,
|
|
31069
31200
|
refetchInterval: 10000,
|
|
31070
31201
|
staleTime: 5000,
|
|
31071
31202
|
refetchOnWindowFocus: true,
|
|
@@ -31089,7 +31220,7 @@ const useEvmNativeBalance = ({ address, chain, }) => {
|
|
|
31089
31220
|
}, [nativeEvmBalance?.decimals, nativeEvmBalance?.value, chain?.chainId]);
|
|
31090
31221
|
return {
|
|
31091
31222
|
balance,
|
|
31092
|
-
isLoading,
|
|
31223
|
+
isLoading: isQueryEnabled && isLoading,
|
|
31093
31224
|
};
|
|
31094
31225
|
};
|
|
31095
31226
|
const useCosmosNativeBalance = ({ address, chain, }) => {
|
|
@@ -31143,13 +31274,14 @@ const useBitcoinNativeBalance = ({ chain, address, }) => {
|
|
|
31143
31274
|
};
|
|
31144
31275
|
const useSolanaNativeBalance = ({ chain, address, }) => {
|
|
31145
31276
|
const { nativeToken } = useNativeTokenForChain(chain);
|
|
31277
|
+
const isQueryEnabled = nativeToken?.decimals != null &&
|
|
31278
|
+
chain?.chainType === squidTypes.ChainType.SOLANA &&
|
|
31279
|
+
isWalletAddressValid(chain, address);
|
|
31146
31280
|
const { data: rawBalance, isLoading } = reactQuery.useQuery(keys().balance(chain?.chainId, nativeToken?.address, address), async () => {
|
|
31147
31281
|
const balance = await getSolanaNativeBalance(address);
|
|
31148
31282
|
return formatBNToReadable(balance, nativeToken.decimals);
|
|
31149
31283
|
}, {
|
|
31150
|
-
enabled:
|
|
31151
|
-
nativeToken?.decimals != null &&
|
|
31152
|
-
chain?.chainType === squidTypes.ChainType.SOLANA,
|
|
31284
|
+
enabled: isQueryEnabled,
|
|
31153
31285
|
refetchInterval: 40000,
|
|
31154
31286
|
staleTime: 20000,
|
|
31155
31287
|
refetchOnWindowFocus: true,
|
|
@@ -31165,7 +31297,7 @@ const useSolanaNativeBalance = ({ chain, address, }) => {
|
|
|
31165
31297
|
}, [nativeToken?.decimals, rawBalance]);
|
|
31166
31298
|
return {
|
|
31167
31299
|
balance,
|
|
31168
|
-
isLoading,
|
|
31300
|
+
isLoading: isQueryEnabled && isLoading,
|
|
31169
31301
|
};
|
|
31170
31302
|
};
|
|
31171
31303
|
const useSuiNativeBalance = ({ address, chain, }) => {
|
|
@@ -31573,7 +31705,7 @@ function hederaWalletConnect(parameters) {
|
|
|
31573
31705
|
const optionalChains = config.chains.map((x) => x.id);
|
|
31574
31706
|
if (!optionalChains.length)
|
|
31575
31707
|
return;
|
|
31576
|
-
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-
|
|
31708
|
+
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-BQULJYpe.js'); });
|
|
31577
31709
|
const rawProvider = await EthereumProvider.init({
|
|
31578
31710
|
...restParameters,
|
|
31579
31711
|
disableProviderPing: true,
|
|
@@ -31917,7 +32049,10 @@ function useHederaTokenAssociations({ address, chain, token }) {
|
|
|
31917
32049
|
token,
|
|
31918
32050
|
});
|
|
31919
32051
|
},
|
|
31920
|
-
enabled:
|
|
32052
|
+
enabled: isEvmAddressValid(address) &&
|
|
32053
|
+
!!publicClient &&
|
|
32054
|
+
chain?.chainId === CHAIN_IDS.HEDERA &&
|
|
32055
|
+
token?.chainId === CHAIN_IDS.HEDERA,
|
|
31921
32056
|
});
|
|
31922
32057
|
return {
|
|
31923
32058
|
isTokenAssociated,
|
|
@@ -32030,7 +32165,9 @@ function useStellarAccountActivation({ address, chain, token, }) {
|
|
|
32030
32165
|
reserveBaseBn: accountReserveBase,
|
|
32031
32166
|
};
|
|
32032
32167
|
},
|
|
32033
|
-
enabled: !!address &&
|
|
32168
|
+
enabled: !!address &&
|
|
32169
|
+
chain?.chainType === squidTypes.ChainType.STELLAR &&
|
|
32170
|
+
isStellarAddressValid(address),
|
|
32034
32171
|
refetchInterval: DEFAULT_REFETCH_INTERVAL$2,
|
|
32035
32172
|
refetchOnWindowFocus: true,
|
|
32036
32173
|
});
|
|
@@ -39124,7 +39261,9 @@ function useXrplTrustLine({ address, chain, token, amount }) {
|
|
|
39124
39261
|
const xrplClient = await getClient(chain);
|
|
39125
39262
|
return xrplClient.accountActivatedInfo(address);
|
|
39126
39263
|
},
|
|
39127
|
-
enabled: !!address &&
|
|
39264
|
+
enabled: !!address &&
|
|
39265
|
+
chain?.chainType === squidTypes.ChainType.XRPL &&
|
|
39266
|
+
isXrplAddressValid(address),
|
|
39128
39267
|
refetchInterval: DEFAULT_REFETCH_INTERVAL,
|
|
39129
39268
|
refetchOnWindowFocus: true,
|
|
39130
39269
|
});
|
|
@@ -39386,6 +39525,7 @@ exports.isCoralBridgeAction = isCoralBridgeAction;
|
|
|
39386
39525
|
exports.isCosmosAddressValid = isCosmosAddressValid;
|
|
39387
39526
|
exports.isDepositAddressDirectTransferRoute = isDepositAddressDirectTransferRoute;
|
|
39388
39527
|
exports.isEmptyObject = isEmptyObject;
|
|
39528
|
+
exports.isEvmAddressValid = isEvmAddressValid;
|
|
39389
39529
|
exports.isEvmChainNotSupportedError = isEvmChainNotSupportedError;
|
|
39390
39530
|
exports.isEvmosChain = isEvmosChain;
|
|
39391
39531
|
exports.isFallbackAddressNeeded = isFallbackAddressNeeded;
|
|
@@ -39533,4 +39673,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
|
|
|
39533
39673
|
exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
|
|
39534
39674
|
exports.walletIconBaseUrl = walletIconBaseUrl;
|
|
39535
39675
|
exports.walletSupportsChainType = walletSupportsChainType;
|
|
39536
|
-
//# sourceMappingURL=index-
|
|
39676
|
+
//# sourceMappingURL=index-BjIX7utV.js.map
|