@0xsquid/react-hooks 8.0.6 → 8.0.7-hedera-beta.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/constants.d.ts +2 -0
- package/dist/core/queries/queries-keys.d.ts +5 -1
- package/dist/hooks/hedera/useHederaTokenAssociations.d.ts +11 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/{index-C23cJ6Ws.js → index-C0H64ktj.js} +310 -150
- package/dist/index-C0H64ktj.js.map +1 -0
- package/dist/{index-Bbnh4iOc.js → index-DFAgGls6.js} +311 -154
- package/dist/index-DFAgGls6.js.map +1 -0
- package/dist/index.esm.js +2 -2
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/{secretService-M8SCtgDG.js → secretService-D7gPw0fs.js} +3 -3
- package/dist/{secretService-M8SCtgDG.js.map → secretService-D7gPw0fs.js.map} +1 -1
- package/dist/{secretService-Bt57DxoX.js → secretService-DX3NE6Of.js} +3 -3
- package/dist/{secretService-Bt57DxoX.js.map → secretService-DX3NE6Of.js.map} +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/internal/hederaService.d.ts +2 -0
- package/dist/{stellarService.client-BHe6Jfr-.js → stellarService.client-Cr3lD8Iw.js} +3 -3
- package/dist/{stellarService.client-BHe6Jfr-.js.map → stellarService.client-Cr3lD8Iw.js.map} +1 -1
- package/dist/{stellarService.client-CNTH5mSh.js → stellarService.client-peMOjG49.js} +3 -3
- package/dist/{stellarService.client-CNTH5mSh.js.map → stellarService.client-peMOjG49.js.map} +1 -1
- package/package.json +1 -1
- package/dist/index-Bbnh4iOc.js.map +0 -1
- package/dist/index-C23cJ6Ws.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChainType, ActionType, SquidDataType, BridgeType, BridgeProvider, FeeType } from '@0xsquid/squid-types';
|
|
2
|
-
import { zeroAddress as zeroAddress$1, parseUnits, formatUnits, isAddress, SwitchChainError, UserRejectedRequestError,
|
|
2
|
+
import { zeroAddress as zeroAddress$1, parseUnits, formatUnits, isAddress, SwitchChainError, UserRejectedRequestError, defineChain, encodeFunctionData, erc20Abi } from 'viem';
|
|
3
3
|
import React, { useMemo, useCallback, useState, useEffect, createContext, useContext, useRef } from 'react';
|
|
4
4
|
import { useQuery, useMutation, useQueries, useQueryClient, QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
5
5
|
import { fromBech32 } from '@cosmjs/encoding';
|
|
@@ -15,22 +15,22 @@ import { StandardWalletAdapter } from '@solana/wallet-standard-wallet-adapter-ba
|
|
|
15
15
|
import { PublicKey, VersionedTransaction, Transaction, SystemProgram, Connection } from '@solana/web3.js';
|
|
16
16
|
import { Networks, StrKey, nativeToScVal, Address, rpc, TransactionBuilder, BASE_FEE, Contract, TimeoutInfinite, scValToNative, Operation, Transaction as Transaction$1, xdr } from '@stellar/stellar-sdk';
|
|
17
17
|
import { SUI_TESTNET_CHAIN, SUI_MAINNET_CHAIN } from '@mysten/wallet-standard';
|
|
18
|
-
import { CloudflareProvider, JsonRpcProvider, ethers, Interface, Contract as Contract$1,
|
|
18
|
+
import { CloudflareProvider, BrowserProvider, JsonRpcSigner, JsonRpcProvider, ethers, Interface, Contract as Contract$1, isError } from 'ethers';
|
|
19
19
|
import BigNumber$1, { BigNumber } from 'bignumber.js';
|
|
20
20
|
import { countries } from 'countries-list';
|
|
21
21
|
import getSymbolFromCurrency from 'currency-symbol-map';
|
|
22
22
|
import Fuse from 'fuse.js';
|
|
23
23
|
import { create } from 'zustand';
|
|
24
24
|
import { persist } from 'zustand/middleware';
|
|
25
|
-
import { useAccount, useConnectors, useConnect, useDisconnect, useSwitchChain,
|
|
25
|
+
import { useAccount, useConnectors, useConnect, useDisconnect, useSwitchChain, createConfig, http, useWalletClient, usePublicClient, useBalance, useReadContract, WagmiProvider } from 'wagmi';
|
|
26
26
|
import SafeAppsSDK, { TransactionStatus as TransactionStatus$1 } from '@safe-global/safe-apps-sdk';
|
|
27
27
|
import { getWallets } from '@wallet-standard/core';
|
|
28
28
|
import { SlushWallet } from '@mysten/slush-wallet';
|
|
29
|
+
import { injected, safe, metaMask, coinbaseWallet, walletConnect } from 'wagmi/connectors';
|
|
29
30
|
import { StargateClient, SigningStargateClient } from '@cosmjs/stargate';
|
|
30
31
|
import { SuiClient } from '@mysten/sui/client';
|
|
31
32
|
import { coin as coin$1 } from '@cosmjs/proto-signing';
|
|
32
33
|
import { Transaction as Transaction$2 } from '@mysten/sui/transactions';
|
|
33
|
-
import { injected, safe, metaMask, coinbaseWallet, walletConnect } from 'wagmi/connectors';
|
|
34
34
|
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
|
|
35
35
|
import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate/index.js';
|
|
36
36
|
import { Squid } from '@0xsquid/sdk';
|
|
@@ -119,8 +119,10 @@ const CHAIN_IDS = {
|
|
|
119
119
|
GNOSIS: "100",
|
|
120
120
|
SONIC: "146",
|
|
121
121
|
HYPER_EVM: "999",
|
|
122
|
+
DCHAIN: "2716446429837000",
|
|
122
123
|
SONEIUM: "1868",
|
|
123
124
|
PEAQ: "3338",
|
|
125
|
+
HEDERA: "295",
|
|
124
126
|
// others
|
|
125
127
|
BITCOIN: "bitcoin",
|
|
126
128
|
SOLANA: "solana-mainnet-beta",
|
|
@@ -22147,6 +22149,8 @@ var QueryKeys;
|
|
|
22147
22149
|
QueryKeys["FiatToCryptoPaymentMethods"] = "fiatToCryptoPaymentMethods";
|
|
22148
22150
|
QueryKeys["Stellar"] = "stellar";
|
|
22149
22151
|
QueryKeys["StellarAccountActivatedInfo"] = "stellarAccountActivatedInfo";
|
|
22152
|
+
QueryKeys["Hedera"] = "hedera";
|
|
22153
|
+
QueryKeys["IsHederaTokenAssociated"] = "isHederaTokenAssociated";
|
|
22150
22154
|
})(QueryKeys || (QueryKeys = {}));
|
|
22151
22155
|
const keys = () => ({
|
|
22152
22156
|
// ============
|
|
@@ -22160,6 +22164,7 @@ const keys = () => ({
|
|
|
22160
22164
|
transactions: () => [QueryKeys.All, QueryKeys.Transactions],
|
|
22161
22165
|
xrpl: () => [QueryKeys.All, QueryKeys.Xrpl],
|
|
22162
22166
|
stellar: () => [QueryKeys.All, QueryKeys.Stellar],
|
|
22167
|
+
hedera: () => [QueryKeys.All, QueryKeys.Hedera],
|
|
22163
22168
|
// ============
|
|
22164
22169
|
// Tokens
|
|
22165
22170
|
// ============
|
|
@@ -22336,6 +22341,17 @@ const keys = () => ({
|
|
|
22336
22341
|
chainId,
|
|
22337
22342
|
chainType,
|
|
22338
22343
|
],
|
|
22344
|
+
// ============
|
|
22345
|
+
// Hedera
|
|
22346
|
+
// ============
|
|
22347
|
+
isHederaTokenAssociated: (address, chainId, chainType, tokenAddress) => [
|
|
22348
|
+
...keys().hedera(),
|
|
22349
|
+
QueryKeys.IsHederaTokenAssociated,
|
|
22350
|
+
address,
|
|
22351
|
+
chainId,
|
|
22352
|
+
chainType,
|
|
22353
|
+
tokenAddress,
|
|
22354
|
+
],
|
|
22339
22355
|
});
|
|
22340
22356
|
const getPrefixKey = (key) => {
|
|
22341
22357
|
switch (key) {
|
|
@@ -22353,6 +22369,8 @@ const getPrefixKey = (key) => {
|
|
|
22353
22369
|
return [...keys().transactions(), key];
|
|
22354
22370
|
case QueryKeys.XrplTrustLine:
|
|
22355
22371
|
return [...keys().xrpl(), key];
|
|
22372
|
+
case QueryKeys.IsHederaTokenAssociated:
|
|
22373
|
+
return [...keys().hedera(), key];
|
|
22356
22374
|
default:
|
|
22357
22375
|
return [QueryKeys.All, key];
|
|
22358
22376
|
}
|
|
@@ -23046,6 +23064,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23046
23064
|
{ chainId: CHAIN_IDS.CELO, address: nativeEvmTokenAddress },
|
|
23047
23065
|
// SagaEVM is gasless, so the native token is not used
|
|
23048
23066
|
{ chainId: CHAIN_IDS.SAGA_EVM, address: nativeEvmTokenAddress },
|
|
23067
|
+
{ chainId: CHAIN_IDS.DCHAIN, address: nativeEvmTokenAddress },
|
|
23049
23068
|
];
|
|
23050
23069
|
return (tokens.filter((token) => {
|
|
23051
23070
|
if (direction) {
|
|
@@ -23063,7 +23082,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23063
23082
|
};
|
|
23064
23083
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
23065
23084
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
23066
|
-
const { fetchAllSecretBalances } = await import('./secretService-
|
|
23085
|
+
const { fetchAllSecretBalances } = await import('./secretService-DX3NE6Of.js');
|
|
23067
23086
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
23068
23087
|
};
|
|
23069
23088
|
function getTokenAssetsKey(token) {
|
|
@@ -24436,6 +24455,13 @@ function getSuggestedAmountsForCurrency(currencyCode) {
|
|
|
24436
24455
|
return amounts.map(adaptiveRound);
|
|
24437
24456
|
}
|
|
24438
24457
|
|
|
24458
|
+
function convertHederaAccountIdToEvmAddress(accId) {
|
|
24459
|
+
return "0x" + Number(accId.split(".").at(-1)).toString(16).padStart(40, "0");
|
|
24460
|
+
}
|
|
24461
|
+
function convertEvmAddressToHederaAccountId(address) {
|
|
24462
|
+
return "0.0." + Number(address);
|
|
24463
|
+
}
|
|
24464
|
+
|
|
24439
24465
|
/**
|
|
24440
24466
|
* Minimum length of a search query to search by address
|
|
24441
24467
|
* Some tokens can have very short addresses (e.g. "uosmo", "uixo", "satoshi", etc...)
|
|
@@ -26239,7 +26265,7 @@ function useStellarWallets() {
|
|
|
26239
26265
|
return;
|
|
26240
26266
|
try {
|
|
26241
26267
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
26242
|
-
const { formatStellarWallet } = await import('./stellarService.client-
|
|
26268
|
+
const { formatStellarWallet } = await import('./stellarService.client-Cr3lD8Iw.js');
|
|
26243
26269
|
const modules = initializeAllModules();
|
|
26244
26270
|
const promises = modules.map(async (module) => {
|
|
26245
26271
|
const isAvailable = await module.isAvailable();
|
|
@@ -27539,6 +27565,268 @@ function useTrackSearchEmpty({ searchQuery, resultsLength, context, debounceMs =
|
|
|
27539
27565
|
}, [context, debounceMs, resultsLength, searchQuery]);
|
|
27540
27566
|
}
|
|
27541
27567
|
|
|
27568
|
+
const createWagmiConfig = (squidChains) => {
|
|
27569
|
+
const filteredEvmChains = squidChains.filter((chain) => chain.chainType === ChainType.EVM);
|
|
27570
|
+
if (filteredEvmChains.length === 0) {
|
|
27571
|
+
throw new Error("At least one chain is required");
|
|
27572
|
+
}
|
|
27573
|
+
const wagmiChains = filteredEvmChains.map((chain) => {
|
|
27574
|
+
return defineChain({
|
|
27575
|
+
id: Number(chain.chainId),
|
|
27576
|
+
name: chain.networkName,
|
|
27577
|
+
nativeCurrency: {
|
|
27578
|
+
name: chain.nativeCurrency.name,
|
|
27579
|
+
symbol: chain.nativeCurrency.symbol,
|
|
27580
|
+
decimals: chain.nativeCurrency.decimals,
|
|
27581
|
+
},
|
|
27582
|
+
rpcUrls: {
|
|
27583
|
+
public: {
|
|
27584
|
+
http: [chain.rpc],
|
|
27585
|
+
},
|
|
27586
|
+
default: {
|
|
27587
|
+
http: [chain.rpc],
|
|
27588
|
+
},
|
|
27589
|
+
},
|
|
27590
|
+
});
|
|
27591
|
+
});
|
|
27592
|
+
return createConfig({
|
|
27593
|
+
chains: wagmiChains,
|
|
27594
|
+
transports: Object.fromEntries(wagmiChains.map((chain) => [
|
|
27595
|
+
chain.id,
|
|
27596
|
+
http(chain.rpcUrls.public.http[0] ?? ""),
|
|
27597
|
+
])),
|
|
27598
|
+
connectors: [
|
|
27599
|
+
injected(),
|
|
27600
|
+
safe({
|
|
27601
|
+
allowedDomains: [/app.safe.global$/],
|
|
27602
|
+
}),
|
|
27603
|
+
metaMask({
|
|
27604
|
+
dappMetadata: {
|
|
27605
|
+
name: SQUID_METADATA.name,
|
|
27606
|
+
url: SQUID_METADATA.url,
|
|
27607
|
+
iconUrl: SQUID_METADATA.icon,
|
|
27608
|
+
},
|
|
27609
|
+
}),
|
|
27610
|
+
coinbaseWallet({
|
|
27611
|
+
appName: SQUID_METADATA.name,
|
|
27612
|
+
appLogoUrl: SQUID_METADATA.icon,
|
|
27613
|
+
}),
|
|
27614
|
+
walletConnect({
|
|
27615
|
+
projectId: WALLETCONNECT_PROJECT_ID,
|
|
27616
|
+
metadata: {
|
|
27617
|
+
url: SQUID_METADATA.url,
|
|
27618
|
+
name: SQUID_METADATA.name,
|
|
27619
|
+
icons: [SQUID_METADATA.icon],
|
|
27620
|
+
description: SQUID_METADATA.description,
|
|
27621
|
+
},
|
|
27622
|
+
}),
|
|
27623
|
+
],
|
|
27624
|
+
});
|
|
27625
|
+
};
|
|
27626
|
+
// Taken from wagmi docs
|
|
27627
|
+
// https://wagmi.sh/react/guides/ethers
|
|
27628
|
+
function clientToSigner(client) {
|
|
27629
|
+
const { account, chain, transport } = client;
|
|
27630
|
+
if (!account || !chain || !transport) {
|
|
27631
|
+
return undefined;
|
|
27632
|
+
}
|
|
27633
|
+
const network = {
|
|
27634
|
+
chainId: chain.id,
|
|
27635
|
+
name: chain.name,
|
|
27636
|
+
ensAddress: chain.contracts?.ensRegistry?.address,
|
|
27637
|
+
};
|
|
27638
|
+
const provider = new BrowserProvider(transport, network);
|
|
27639
|
+
const signer = new JsonRpcSigner(provider, account.address);
|
|
27640
|
+
return signer;
|
|
27641
|
+
}
|
|
27642
|
+
|
|
27643
|
+
function useEvmSigner({ chainId }) {
|
|
27644
|
+
const { connector } = useAccount();
|
|
27645
|
+
const { data: client } = useWalletClient({ chainId, connector });
|
|
27646
|
+
const signer = useMemo(() => (client ? clientToSigner(client) : undefined), [client]);
|
|
27647
|
+
return { signer };
|
|
27648
|
+
}
|
|
27649
|
+
const useSigner = ({ chain }) => {
|
|
27650
|
+
const evmChainId = chain?.chainType === ChainType.EVM ? Number(chain.chainId) : undefined;
|
|
27651
|
+
// EVM and Cosmos need a different signer for each chain
|
|
27652
|
+
// This is not the case for Solana or Bitcoin as there's only one chain in those ecosystems
|
|
27653
|
+
const { signer: evmSigner } = useEvmSigner({ chainId: evmChainId });
|
|
27654
|
+
const { signer: cosmosSigner } = useCosmosSigner({ chain });
|
|
27655
|
+
const { signer: solanaSigner } = useSolanaContext();
|
|
27656
|
+
const { signer: bitcoinSigner } = useBitcoinContext();
|
|
27657
|
+
const { signer: suiSigner } = useSuiContext();
|
|
27658
|
+
const { signer: xrplSigner } = useXrplContext();
|
|
27659
|
+
const { signer: stellarSigner } = useStellarContext();
|
|
27660
|
+
const isEvmSignerReady = !!evmSigner;
|
|
27661
|
+
const isSolanaSignerReady = !!solanaSigner;
|
|
27662
|
+
const isCosmosSignerReady = !!cosmosSigner;
|
|
27663
|
+
const isBitcoinSignerReady = !!bitcoinSigner;
|
|
27664
|
+
const isSuiSignerReady = !!suiSigner;
|
|
27665
|
+
const isXrplSignerReady = !!xrplSigner;
|
|
27666
|
+
const isStellarSignerReady = !!stellarSigner;
|
|
27667
|
+
const isSignerReady = useMemo(() => {
|
|
27668
|
+
if (!chain?.chainType)
|
|
27669
|
+
return false;
|
|
27670
|
+
switch (chain.chainType) {
|
|
27671
|
+
case ChainType.EVM:
|
|
27672
|
+
return isEvmSignerReady;
|
|
27673
|
+
case ChainType.COSMOS:
|
|
27674
|
+
return isCosmosSignerReady;
|
|
27675
|
+
case ChainType.BTC:
|
|
27676
|
+
return isBitcoinSignerReady;
|
|
27677
|
+
case ChainType.SOLANA:
|
|
27678
|
+
return isSolanaSignerReady;
|
|
27679
|
+
case ChainType.SUI:
|
|
27680
|
+
return isSuiSignerReady;
|
|
27681
|
+
case ChainType.XRPL:
|
|
27682
|
+
return isXrplSignerReady;
|
|
27683
|
+
case ChainType.STELLAR:
|
|
27684
|
+
return isStellarSignerReady;
|
|
27685
|
+
}
|
|
27686
|
+
}, [
|
|
27687
|
+
chain?.chainType,
|
|
27688
|
+
isEvmSignerReady,
|
|
27689
|
+
isCosmosSignerReady,
|
|
27690
|
+
isBitcoinSignerReady,
|
|
27691
|
+
isSolanaSignerReady,
|
|
27692
|
+
isSuiSignerReady,
|
|
27693
|
+
isXrplSignerReady,
|
|
27694
|
+
isStellarSignerReady,
|
|
27695
|
+
]);
|
|
27696
|
+
return {
|
|
27697
|
+
isSignerReady,
|
|
27698
|
+
evmSigner,
|
|
27699
|
+
cosmosSigner,
|
|
27700
|
+
bitcoinSigner,
|
|
27701
|
+
solanaSigner,
|
|
27702
|
+
suiSigner,
|
|
27703
|
+
xrplSigner,
|
|
27704
|
+
stellarSigner,
|
|
27705
|
+
};
|
|
27706
|
+
};
|
|
27707
|
+
|
|
27708
|
+
function useHederaTokenAssociations({ address, chain, token }) {
|
|
27709
|
+
const publicClient = usePublicClient({
|
|
27710
|
+
chainId: Number(CHAIN_IDS.HEDERA),
|
|
27711
|
+
});
|
|
27712
|
+
const { evmSigner } = useSigner({ chain });
|
|
27713
|
+
const queryClient = useQueryClient();
|
|
27714
|
+
/**
|
|
27715
|
+
* Creates a token association transaction where the destination account authorizes to receive the given token
|
|
27716
|
+
*/
|
|
27717
|
+
const associateToken = useMutation({
|
|
27718
|
+
mutationFn: async () => {
|
|
27719
|
+
try {
|
|
27720
|
+
if (!evmSigner) {
|
|
27721
|
+
throw new Error("EVM signer not found");
|
|
27722
|
+
}
|
|
27723
|
+
if (chain?.chainId !== CHAIN_IDS.HEDERA ||
|
|
27724
|
+
token?.chainId !== CHAIN_IDS.HEDERA) {
|
|
27725
|
+
throw new Error("Chain and token to associate must be on Hedera");
|
|
27726
|
+
}
|
|
27727
|
+
const tokenAddress = parseEvmAddress(token.address);
|
|
27728
|
+
if (!tokenAddress) {
|
|
27729
|
+
throw new Error("Invalid token address");
|
|
27730
|
+
}
|
|
27731
|
+
const userAddress = parseEvmAddress(address);
|
|
27732
|
+
if (!userAddress) {
|
|
27733
|
+
throw new Error("Invalid user address");
|
|
27734
|
+
}
|
|
27735
|
+
const encodedData = encodeFunctionData({
|
|
27736
|
+
abi: [
|
|
27737
|
+
{
|
|
27738
|
+
inputs: [],
|
|
27739
|
+
name: "associate",
|
|
27740
|
+
outputs: [
|
|
27741
|
+
{
|
|
27742
|
+
internalType: "uint256",
|
|
27743
|
+
name: "responseCode",
|
|
27744
|
+
type: "uint256",
|
|
27745
|
+
},
|
|
27746
|
+
],
|
|
27747
|
+
stateMutability: "nonpayable",
|
|
27748
|
+
type: "function",
|
|
27749
|
+
},
|
|
27750
|
+
],
|
|
27751
|
+
functionName: "associate",
|
|
27752
|
+
args: [],
|
|
27753
|
+
});
|
|
27754
|
+
const txRes = await evmSigner.sendTransaction({
|
|
27755
|
+
data: encodedData,
|
|
27756
|
+
to: tokenAddress,
|
|
27757
|
+
chainId: chain.chainId,
|
|
27758
|
+
});
|
|
27759
|
+
const receipt = await txRes.wait();
|
|
27760
|
+
if (receipt?.status !== 1) {
|
|
27761
|
+
throw new Error(`Transaction failed with status: ${receipt?.status}`);
|
|
27762
|
+
}
|
|
27763
|
+
return true;
|
|
27764
|
+
}
|
|
27765
|
+
catch (error) {
|
|
27766
|
+
console.error("Error associating Hedera token:", error);
|
|
27767
|
+
return false;
|
|
27768
|
+
}
|
|
27769
|
+
},
|
|
27770
|
+
async onSuccess() {
|
|
27771
|
+
queryClient.refetchQueries({
|
|
27772
|
+
queryKey: getPrefixKey(QueryKeys.IsHederaTokenAssociated),
|
|
27773
|
+
});
|
|
27774
|
+
},
|
|
27775
|
+
});
|
|
27776
|
+
/**
|
|
27777
|
+
* Checks if the destination account has associated the given token.
|
|
27778
|
+
*
|
|
27779
|
+
* Hedera requires accounts to associate a token before being able to receive it.
|
|
27780
|
+
*
|
|
27781
|
+
* Accounts which have max. associations set to -1 can receive any token without previous association
|
|
27782
|
+
*/
|
|
27783
|
+
const isTokenAssociated = useQuery({
|
|
27784
|
+
queryKey: keys().isHederaTokenAssociated(address, token?.chainId, token?.type, token?.address),
|
|
27785
|
+
queryFn: async () => {
|
|
27786
|
+
if (token?.chainId !== CHAIN_IDS.HEDERA) {
|
|
27787
|
+
return true;
|
|
27788
|
+
}
|
|
27789
|
+
// The native HBAR token doesn't need an association
|
|
27790
|
+
if (token.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase()) {
|
|
27791
|
+
return true;
|
|
27792
|
+
}
|
|
27793
|
+
if (!publicClient) {
|
|
27794
|
+
throw new Error("Public client not found");
|
|
27795
|
+
}
|
|
27796
|
+
const url = `https://mainnet-public.mirrornode.hedera.com/api/v1/accounts/${address}`;
|
|
27797
|
+
const response = await fetch(url);
|
|
27798
|
+
const data = await response.json();
|
|
27799
|
+
switch (data.max_automatic_token_associations) {
|
|
27800
|
+
case -1: {
|
|
27801
|
+
// Unlimited auto associations
|
|
27802
|
+
return true;
|
|
27803
|
+
}
|
|
27804
|
+
case 0: {
|
|
27805
|
+
// No auto associations, token needs to be associated beforehand
|
|
27806
|
+
const tokenId = convertEvmAddressToHederaAccountId(token.address);
|
|
27807
|
+
return data.balance.tokens.some((t) => t.token_id === tokenId);
|
|
27808
|
+
}
|
|
27809
|
+
default: {
|
|
27810
|
+
// Limited auto associations, check if there is an available slot
|
|
27811
|
+
const url2 = `https://mainnet-public.mirrornode.hedera.com/api/v1/accounts/${address}/tokens`;
|
|
27812
|
+
const response2 = await fetch(url2);
|
|
27813
|
+
const data2 = await response2.json();
|
|
27814
|
+
if (!data2.tokens)
|
|
27815
|
+
return false;
|
|
27816
|
+
const autoAssociatedTokens = data2.tokens.filter((t) => t.automatic_association);
|
|
27817
|
+
const remainingAutoAssociations = data.max_automatic_token_associations - autoAssociatedTokens.length;
|
|
27818
|
+
return remainingAutoAssociations > 0;
|
|
27819
|
+
}
|
|
27820
|
+
}
|
|
27821
|
+
},
|
|
27822
|
+
enabled: !!address && !!publicClient && token?.chainId === CHAIN_IDS.HEDERA,
|
|
27823
|
+
});
|
|
27824
|
+
return {
|
|
27825
|
+
isTokenAssociated,
|
|
27826
|
+
associateToken,
|
|
27827
|
+
};
|
|
27828
|
+
}
|
|
27829
|
+
|
|
27542
27830
|
const useKeyboardNavigation = ({ onEscape }) => {
|
|
27543
27831
|
const onKeyDown = useCallback((event) => {
|
|
27544
27832
|
if (event.key === "Escape") {
|
|
@@ -27587,6 +27875,7 @@ const chainIdToMulticall3AddressMap = {
|
|
|
27587
27875
|
[CHAIN_IDS.SAGA_EVM]: "0x864DDc9B50B9A0dF676d826c9B9EDe9F8913a160",
|
|
27588
27876
|
[CHAIN_IDS.XRPL_EVM]: "0xaB3a12b26e72F4D6D9B579aCb5027a0918eF1114",
|
|
27589
27877
|
[CHAIN_IDS.XRPL_EVM_TESTNET]: "0x82Cc144D7d0AD4B1c27cb41420e82b82Ad6e9B31",
|
|
27878
|
+
[CHAIN_IDS.HEDERA]: "0xf21405c87d8538d22607eb9987cd3386121dd5dd",
|
|
27590
27879
|
};
|
|
27591
27880
|
/**
|
|
27592
27881
|
* Returns the multicall3 address for a given chain ID
|
|
@@ -29652,12 +29941,20 @@ const useEvmBalance = ({ chain, token, userAddress, enabled = true, refreshInter
|
|
|
29652
29941
|
retry: 2,
|
|
29653
29942
|
},
|
|
29654
29943
|
});
|
|
29655
|
-
|
|
29656
|
-
|
|
29657
|
-
|
|
29658
|
-
|
|
29659
|
-
|
|
29660
|
-
|
|
29944
|
+
if (isNativeToken) {
|
|
29945
|
+
return {
|
|
29946
|
+
isLoading: isNativeTokenLoading,
|
|
29947
|
+
balance: nativeBalance
|
|
29948
|
+
? formatBNToReadable(nativeBalance.value, nativeBalance.decimals)
|
|
29949
|
+
: "0",
|
|
29950
|
+
};
|
|
29951
|
+
}
|
|
29952
|
+
return {
|
|
29953
|
+
balance: erc20Balance && token
|
|
29954
|
+
? formatBNToReadable(erc20Balance, token.decimals)
|
|
29955
|
+
: "0",
|
|
29956
|
+
isLoading: isErc20Loading,
|
|
29957
|
+
};
|
|
29661
29958
|
};
|
|
29662
29959
|
const useCosmosBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS, }) => {
|
|
29663
29960
|
const { isConnected } = useCosmosContext();
|
|
@@ -30647,146 +30944,6 @@ async function sendTransactionStellar({ amount, signer, to, token, chain, }) {
|
|
|
30647
30944
|
};
|
|
30648
30945
|
}
|
|
30649
30946
|
|
|
30650
|
-
const createWagmiConfig = (squidChains) => {
|
|
30651
|
-
const filteredEvmChains = squidChains.filter((chain) => chain.chainType === ChainType.EVM);
|
|
30652
|
-
if (filteredEvmChains.length === 0) {
|
|
30653
|
-
throw new Error("At least one chain is required");
|
|
30654
|
-
}
|
|
30655
|
-
const wagmiChains = filteredEvmChains.map((chain) => {
|
|
30656
|
-
return defineChain({
|
|
30657
|
-
id: Number(chain.chainId),
|
|
30658
|
-
name: chain.networkName,
|
|
30659
|
-
nativeCurrency: {
|
|
30660
|
-
name: chain.nativeCurrency.name,
|
|
30661
|
-
symbol: chain.nativeCurrency.symbol,
|
|
30662
|
-
decimals: chain.nativeCurrency.decimals,
|
|
30663
|
-
},
|
|
30664
|
-
rpcUrls: {
|
|
30665
|
-
public: {
|
|
30666
|
-
http: [chain.rpc],
|
|
30667
|
-
},
|
|
30668
|
-
default: {
|
|
30669
|
-
http: [chain.rpc],
|
|
30670
|
-
},
|
|
30671
|
-
},
|
|
30672
|
-
});
|
|
30673
|
-
});
|
|
30674
|
-
return createConfig({
|
|
30675
|
-
chains: wagmiChains,
|
|
30676
|
-
transports: Object.fromEntries(wagmiChains.map((chain) => [
|
|
30677
|
-
chain.id,
|
|
30678
|
-
http(chain.rpcUrls.public.http[0] ?? ""),
|
|
30679
|
-
])),
|
|
30680
|
-
connectors: [
|
|
30681
|
-
injected(),
|
|
30682
|
-
safe({
|
|
30683
|
-
allowedDomains: [/app.safe.global$/],
|
|
30684
|
-
}),
|
|
30685
|
-
metaMask({
|
|
30686
|
-
dappMetadata: {
|
|
30687
|
-
name: SQUID_METADATA.name,
|
|
30688
|
-
url: SQUID_METADATA.url,
|
|
30689
|
-
iconUrl: SQUID_METADATA.icon,
|
|
30690
|
-
},
|
|
30691
|
-
}),
|
|
30692
|
-
coinbaseWallet({
|
|
30693
|
-
appName: SQUID_METADATA.name,
|
|
30694
|
-
appLogoUrl: SQUID_METADATA.icon,
|
|
30695
|
-
}),
|
|
30696
|
-
walletConnect({
|
|
30697
|
-
projectId: WALLETCONNECT_PROJECT_ID,
|
|
30698
|
-
metadata: {
|
|
30699
|
-
url: SQUID_METADATA.url,
|
|
30700
|
-
name: SQUID_METADATA.name,
|
|
30701
|
-
icons: [SQUID_METADATA.icon],
|
|
30702
|
-
description: SQUID_METADATA.description,
|
|
30703
|
-
},
|
|
30704
|
-
}),
|
|
30705
|
-
],
|
|
30706
|
-
});
|
|
30707
|
-
};
|
|
30708
|
-
// Taken from wagmi docs
|
|
30709
|
-
// https://wagmi.sh/react/guides/ethers
|
|
30710
|
-
function clientToSigner(client) {
|
|
30711
|
-
const { account, chain, transport } = client;
|
|
30712
|
-
if (!account || !chain || !transport) {
|
|
30713
|
-
return undefined;
|
|
30714
|
-
}
|
|
30715
|
-
const network = {
|
|
30716
|
-
chainId: chain.id,
|
|
30717
|
-
name: chain.name,
|
|
30718
|
-
ensAddress: chain.contracts?.ensRegistry?.address,
|
|
30719
|
-
};
|
|
30720
|
-
const provider = new BrowserProvider(transport, network);
|
|
30721
|
-
const signer = new JsonRpcSigner(provider, account.address);
|
|
30722
|
-
return signer;
|
|
30723
|
-
}
|
|
30724
|
-
|
|
30725
|
-
function useEvmSigner({ chainId }) {
|
|
30726
|
-
const { connector } = useAccount();
|
|
30727
|
-
const { data: client } = useWalletClient({ chainId, connector });
|
|
30728
|
-
const signer = useMemo(() => (client ? clientToSigner(client) : undefined), [client]);
|
|
30729
|
-
return { signer };
|
|
30730
|
-
}
|
|
30731
|
-
const useSigner = ({ chain }) => {
|
|
30732
|
-
const evmChainId = chain?.chainType === ChainType.EVM ? Number(chain.chainId) : undefined;
|
|
30733
|
-
// EVM and Cosmos need a different signer for each chain
|
|
30734
|
-
// This is not the case for Solana or Bitcoin as there's only one chain in those ecosystems
|
|
30735
|
-
const { signer: evmSigner } = useEvmSigner({ chainId: evmChainId });
|
|
30736
|
-
const { signer: cosmosSigner } = useCosmosSigner({ chain });
|
|
30737
|
-
const { signer: solanaSigner } = useSolanaContext();
|
|
30738
|
-
const { signer: bitcoinSigner } = useBitcoinContext();
|
|
30739
|
-
const { signer: suiSigner } = useSuiContext();
|
|
30740
|
-
const { signer: xrplSigner } = useXrplContext();
|
|
30741
|
-
const { signer: stellarSigner } = useStellarContext();
|
|
30742
|
-
const isEvmSignerReady = !!evmSigner;
|
|
30743
|
-
const isSolanaSignerReady = !!solanaSigner;
|
|
30744
|
-
const isCosmosSignerReady = !!cosmosSigner;
|
|
30745
|
-
const isBitcoinSignerReady = !!bitcoinSigner;
|
|
30746
|
-
const isSuiSignerReady = !!suiSigner;
|
|
30747
|
-
const isXrplSignerReady = !!xrplSigner;
|
|
30748
|
-
const isStellarSignerReady = !!stellarSigner;
|
|
30749
|
-
const isSignerReady = useMemo(() => {
|
|
30750
|
-
if (!chain?.chainType)
|
|
30751
|
-
return false;
|
|
30752
|
-
switch (chain.chainType) {
|
|
30753
|
-
case ChainType.EVM:
|
|
30754
|
-
return isEvmSignerReady;
|
|
30755
|
-
case ChainType.COSMOS:
|
|
30756
|
-
return isCosmosSignerReady;
|
|
30757
|
-
case ChainType.BTC:
|
|
30758
|
-
return isBitcoinSignerReady;
|
|
30759
|
-
case ChainType.SOLANA:
|
|
30760
|
-
return isSolanaSignerReady;
|
|
30761
|
-
case ChainType.SUI:
|
|
30762
|
-
return isSuiSignerReady;
|
|
30763
|
-
case ChainType.XRPL:
|
|
30764
|
-
return isXrplSignerReady;
|
|
30765
|
-
case ChainType.STELLAR:
|
|
30766
|
-
return isStellarSignerReady;
|
|
30767
|
-
}
|
|
30768
|
-
}, [
|
|
30769
|
-
chain?.chainType,
|
|
30770
|
-
isEvmSignerReady,
|
|
30771
|
-
isCosmosSignerReady,
|
|
30772
|
-
isBitcoinSignerReady,
|
|
30773
|
-
isSolanaSignerReady,
|
|
30774
|
-
isSuiSignerReady,
|
|
30775
|
-
isXrplSignerReady,
|
|
30776
|
-
isStellarSignerReady,
|
|
30777
|
-
]);
|
|
30778
|
-
return {
|
|
30779
|
-
isSignerReady,
|
|
30780
|
-
evmSigner,
|
|
30781
|
-
cosmosSigner,
|
|
30782
|
-
bitcoinSigner,
|
|
30783
|
-
solanaSigner,
|
|
30784
|
-
suiSigner,
|
|
30785
|
-
xrplSigner,
|
|
30786
|
-
stellarSigner,
|
|
30787
|
-
};
|
|
30788
|
-
};
|
|
30789
|
-
|
|
30790
30947
|
function useSendTransaction({ to, amount, token, chain, }) {
|
|
30791
30948
|
const { connectedWalletsByChainType } = useWallet();
|
|
30792
30949
|
const { connectedAddress } = useMultiChainWallet(chain);
|
|
@@ -36403,5 +36560,5 @@ const SquidProvider = ({ children, config, placeholder, }) => {
|
|
|
36403
36560
|
React.createElement(CosmosProvider, null, children)))))))))) : (placeholder);
|
|
36404
36561
|
};
|
|
36405
36562
|
|
|
36406
|
-
export {
|
|
36407
|
-
//# sourceMappingURL=index-
|
|
36563
|
+
export { useMultipleTokenPrices as $, AxelarStatusResponseType as A, useStellarAccountActivation as B, CHAIN_IDS as C, DEFAULT_LOCALE as D, useAddressBookStore as E, useAssetsColorsStore as F, useFavoriteTokensStore as G, HistoryTxType as H, useHistoryStore as I, useSendTransactionStore as J, useConfigStore as K, useSquidStore as L, useSwapRoutePersistStore as M, useTransactionStore as N, ConnectingWalletStatus as O, useWalletStore as P, useDepositAddress as Q, useSwap as R, SquidStatusErrorType as S, TransactionErrorType as T, useAllConnectedWalletBalances as U, useAllTokensWithBalanceForChainType as V, WindowWalletFlag as W, XamanXrplNetwork as X, useCosmosBalance as Y, useEvmBalance as Z, useMultiChainBalance as _, chainTypeToZeroAddressMap as a, sortAllTokens as a$, useNativeBalance as a0, useNativeTokenForChain as a1, useSingleTokenPrice as a2, useSquidTokens as a3, useHistoricalData as a4, useTokensData as a5, useEstimateSendTransaction as a6, useSendTransaction as a7, useSendTransactionGas as a8, useAllTransactionsStatus as a9, FINAL_TRANSACTION_STATUSES as aA, useGetFiatQuote as aB, useGetOnRampConfig as aC, useExecuteFiatQuote as aD, useFiatOnRampTxStatus as aE, useFiatTransactions as aF, useCurrencyDetails as aG, useCountryDetails as aH, useAvailableQuotes as aI, useRecommendedQuote as aJ, useGetOnrampPaymentTypes as aK, useSuggestedFiatAmounts as aL, SquidProvider as aM, EnsService as aN, getXummClient as aO, isXamanXAppContext as aP, getQueryHeaders as aQ, getStatusCode as aR, is404Error as aS, assetsBaseUrl as aT, shareSubgraphId as aU, sortTokensBySharedSubgraphIds as aV, getSupportedChainIdsForDirection as aW, filterChains as aX, filterTokens as aY, getTokenImage as aZ, getNewSwapParamsFromInput as a_, useApproval as aa, useEstimate as ab, useEstimatePriceImpact as ac, useExecuteTransaction as ad, useGetRoute as ae, useGetRouteWrapper as af, useRouteWarnings as ag, useSendTransactionStatus as ah, useSwapTransactionStatus as ai, useAvatar as aj, useHistory as ak, useUserParams as al, useDebouncedValue as am, useAddToken as an, useAutoConnect as ao, useEnsDataForAddress as ap, useEnsSearch as aq, useGnosisContext as ar, useIsSameAddressAndGnosisContext as as, useIntegratorContext as at, useMultiChainWallet as au, useSigner as av, useWallet as aw, useWallets as ax, useXrplTrustLine as ay, TX_STATUS_CONSTANTS as az, destinationAddressResetValue as b, convertUSDToTokenAmount as b$, findToken as b0, findNativeToken as b1, normalizeIbcAddress as b2, groupTokensBySymbol as b3, groupTokensByChainId as b4, filterViewableTokens as b5, getSecretNetworkBalances as b6, getTokenAssetsKey as b7, fetchAssetsColors as b8, initializeSquidWithAssetsColors as b9, handleTransactionErrorEvents as bA, isSwapRouteError as bB, isStatusError as bC, createQuoteRequestParamsHash as bD, WidgetEvents as bE, EvmNetworkNotSupportedErrorCode as bF, addEthereumChain as bG, parseEvmAddress as bH, formatEvmWallet as bI, filterWagmiConnector as bJ, waitForReceiptWithRetry as bK, getUserCountry as bL, getCountryData as bM, getCurrencyData as bN, adaptiveRound as bO, getSuggestedAmountsForCurrency as bP, convertHederaAccountIdToEvmAddress as bQ, convertEvmAddressToHederaAccountId as bR, parseToBigInt as bS, roundNumericValue as bT, formatUnitsRounded as bU, formatTokenAmount as bV, formatUsdAmount as bW, trimExtraDecimals as bX, getNumericValue as bY, cleanAmount as bZ, convertTokenAmountToUSD as b_, isEmptyObject as ba, normalizeTokenSymbol as bb, areTokenSymbolsCompatible as bc, isEvmosChain as bd, getConfigWithDefaults as be, randomIntFromInterval as bf, getTokensForChain as bg, getFirstAvailableChainId as bh, fetchHighestBalanceToken as bi, getInitialOrDefaultTokenAddressForChain as bj, getInitialTokenAddressForChain as bk, filterTokensForDestination as bl, getInitialChainIdFromConfig as bm, getCosmosKey as bn, getKeysSettled as bo, getAllKeysForSupportedCosmosChains as bp, isCosmosAddressValid as bq, getCosmosSigningClient as br, getCosmosChainInfosObject as bs, connectCosmosWallet as bt, isFallbackAddressNeeded as bu, suggestChainOrThrow as bv, normalizeError as bw, transactionErrorCode as bx, isUserRejectionError as by, getTransactionError as bz, chainTypeToNativeTokenAddressMap as c, calculateTotal24hChange as c0, searchTokens as c1, filterSolanaWallets as c2, isSolanaAddressValid as c3, executeSolanaSwap as c4, executeSolanaTransfer as c5, formatTransactionHistoryDate as c6, getAxelarExplorerTxUrl as c7, getSourceExplorerTxUrl as c8, getMainExplorerUrl as c9, redirectToExtensionsStore as cA, accessProperty as cB, populateWallets as cC, getDefaultChain as cD, sortWallets as cE, areSameAddress as cF, sortAddressBook as cG, calculateTotalUsdBalanceUSD as cH, addTokenToWallet as cI, isEvmChainNotSupportedError as cJ, getWalletSupportedChainTypes as cK, getConnectorForChainType as cL, walletSupportsChainType as cM, connectWallet as cN, cancelConnectWallet as cO, isProblematicConnector as cP, mergeWallets as cQ, isXionSmartContractAddress as cR, isXrplAddressValid as cS, buildXrplTrustSetTx as cT, getXrplNetwork as cU, parseXrplPaymentTx as cV, formatDistance as ca, formatSeconds as cb, formatSwapTxStatusResponseForStorage as cc, simplifyRouteAction as cd, fetchSwapTransactionStatus as ce, compareTransactionIds as cf, isCoralBridgeAction as cg, sleep as ch, isDepositRoute as ci, isChainflipBridgeTransaction as cj, getHistoryTransactionId as ck, getStepStatuses as cl, getHalfSuccessState as cm, getStepsInfos as cn, getSwapTxStatusRefetchInterval as co, getSendTxStatusRefetchInterval as cp, chainflipMultihopBridgeType as cq, getBridgeType as cr, getTransactionStatus as cs, getTransactionEndStatus as ct, isHistoryTransactionPending as cu, isHistoryTransactionFailed as cv, isHistoryTransactionWarning as cw, isHistoryTransactionEnded as cx, formatHash as cy, isWalletAddressValid as cz, definedInWindow as d, fallbackAddressResetValue as e, formatBNToReadable as f, nativeCosmosTokenAddress as g, nativeEvmTokenAddress as h, nativeSolanaTokenAddress as i, nativeStellarTokenAddress as j, nativeSuiTokenAddress as k, nativeXrplTokenAddress as l, CosmosProvider as m, nativeBitcoinTokenAddress as n, SendTransactionStatus as o, TransactionStatus as p, useTrackSearchEmpty as q, useSquidChains as r, useClient as s, useCosmosForChain as t, useCosmosContext as u, useHederaTokenAssociations as v, walletIconBaseUrl as w, useKeyboardNavigation as x, useSquidQueryClient as y, useSquid as z };
|
|
36564
|
+
//# sourceMappingURL=index-DFAgGls6.js.map
|