@0xsquid/react-hooks 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/.babelrc +7 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.json +44 -0
  4. package/dist/index.js +6 -0
  5. package/jest.config.ts +28 -0
  6. package/package.json +124 -0
  7. package/scripts/copyAssets.js +27 -0
  8. package/scripts/removeBuildTestFolder.js +28 -0
  9. package/scripts/replacePaths.js +37 -0
  10. package/src/assets/images/icons/wallets/binance.svg +4 -0
  11. package/src/assets/images/icons/wallets/bitget.svg +43 -0
  12. package/src/assets/images/icons/wallets/bitkeep.svg +9 -0
  13. package/src/assets/images/icons/wallets/blockchaindotcom.svg +11 -0
  14. package/src/assets/images/icons/wallets/brave.svg +18 -0
  15. package/src/assets/images/icons/wallets/c98.svg +3 -0
  16. package/src/assets/images/icons/wallets/coinbase.svg +5 -0
  17. package/src/assets/images/icons/wallets/cosmostation.svg +9 -0
  18. package/src/assets/images/icons/wallets/defiConnect.svg +25 -0
  19. package/src/assets/images/icons/wallets/exodus.svg +33 -0
  20. package/src/assets/images/icons/wallets/fetchai.svg +1 -0
  21. package/src/assets/images/icons/wallets/index.ts +43 -0
  22. package/src/assets/images/icons/wallets/keplr.svg +9 -0
  23. package/src/assets/images/icons/wallets/leap.svg +35 -0
  24. package/src/assets/images/icons/wallets/metamask.svg +48 -0
  25. package/src/assets/images/icons/wallets/okx.svg +1 -0
  26. package/src/assets/images/icons/wallets/rabby.svg +1 -0
  27. package/src/assets/images/icons/wallets/trustwallet.svg +11 -0
  28. package/src/assets/images/icons/wallets/walletConnect.svg +11 -0
  29. package/src/assets/images/icons/wallets/wallet_icon.svg +1 -0
  30. package/src/assets/images/icons/wallets/xdefi.svg +9 -0
  31. package/src/assets/images/icons/wallets/zerion.svg +11 -0
  32. package/src/connectors/ExodusConnector.ts +6 -0
  33. package/src/connectors/LedgerLiveConnector.ts +226 -0
  34. package/src/contracts/typechain/ERC20.d.ts +441 -0
  35. package/src/contracts/typechain/factories/ERC20__factory.d.ts +56 -0
  36. package/src/contracts/typechain/factories/ERC20__factory.ts +340 -0
  37. package/src/core/constants.ts +549 -0
  38. package/src/core/externalLinks.ts +26 -0
  39. package/src/core/index.ts +1 -0
  40. package/src/core/multicall3.ts +22 -0
  41. package/src/core/numbers.ts +44 -0
  42. package/src/core/providers/CosmosProvider.tsx +55 -0
  43. package/src/core/queries/queries-keys.ts +156 -0
  44. package/src/core/queries/react-query-config.ts +13 -0
  45. package/src/core/types/components.ts +16 -0
  46. package/src/core/types/config.ts +52 -0
  47. package/src/core/types/dex.ts +31 -0
  48. package/src/core/types/error.ts +52 -0
  49. package/src/core/types/event.ts +16 -0
  50. package/src/core/types/route.ts +21 -0
  51. package/src/core/types/swap.ts +8 -0
  52. package/src/core/types/tokens.ts +30 -0
  53. package/src/core/types/transaction.ts +84 -0
  54. package/src/core/types/types.ts +37 -0
  55. package/src/core/types/wallet.ts +83 -0
  56. package/src/hooks/chains/useSquidChains.ts +66 -0
  57. package/src/hooks/cosmos/useCosmos.ts +279 -0
  58. package/src/hooks/cosmos/useCosmosForChain.ts +33 -0
  59. package/src/hooks/index.ts +32 -0
  60. package/src/hooks/navigation/useKeyboardNavigation.ts +88 -0
  61. package/src/hooks/store/useSquidStore.ts +80 -0
  62. package/src/hooks/swap/useSwap.ts +359 -0
  63. package/src/hooks/tokens/useAllTokensWithBalance.ts +157 -0
  64. package/src/hooks/tokens/useBalance.ts +180 -0
  65. package/src/hooks/tokens/useMultiChainBalance.ts +59 -0
  66. package/src/hooks/tokens/usePrices.ts +52 -0
  67. package/src/hooks/tokens/useSingleTokenPrice.ts +45 -0
  68. package/src/hooks/tokens/useSquidTokens.ts +48 -0
  69. package/src/hooks/tokens/useTokensWithBalance.ts +169 -0
  70. package/src/hooks/transaction/useEstimate.ts +397 -0
  71. package/src/hooks/transaction/useEstimatePriceImpact.ts +39 -0
  72. package/src/hooks/transaction/useExecuteTransaction.ts +440 -0
  73. package/src/hooks/transaction/useExpress.ts +46 -0
  74. package/src/hooks/transaction/useGetRoute.ts +145 -0
  75. package/src/hooks/transaction/useSingleTransaction.ts +155 -0
  76. package/src/hooks/transaction/useTransaction.ts +734 -0
  77. package/src/hooks/user/useUserParams.ts +63 -0
  78. package/src/hooks/wallet/useAddToken.ts +53 -0
  79. package/src/hooks/wallet/useAutoConnect.ts +56 -0
  80. package/src/hooks/wallet/useGnosisContext.ts +84 -0
  81. package/src/hooks/wallet/useIntegratorContext.ts +44 -0
  82. package/src/hooks/wallet/useMultiChainWallet.ts +146 -0
  83. package/src/hooks/wallet/useWallet.ts +86 -0
  84. package/src/hooks/webapp-router/useSquidRouter.ts +42 -0
  85. package/src/index.ts +5 -0
  86. package/src/provider/index.tsx +105 -0
  87. package/src/react-app-env.d.ts +2 -0
  88. package/src/services/external/analyticsService.ts +46 -0
  89. package/src/services/external/coingeckoService.ts +35 -0
  90. package/src/services/external/rpcService.ts +196 -0
  91. package/src/services/external/secretService.ts +178 -0
  92. package/src/services/index.ts +1 -0
  93. package/src/services/internal/apiService.ts +6 -0
  94. package/src/services/internal/assetsService.ts +84 -0
  95. package/src/services/internal/configService.ts +261 -0
  96. package/src/services/internal/errorService.ts +124 -0
  97. package/src/services/internal/eventService.ts +93 -0
  98. package/src/services/internal/priceService.ts +10 -0
  99. package/src/services/internal/transactionService.ts +255 -0
  100. package/src/services/internal/transactionStatusService.ts +293 -0
  101. package/src/services/internal/walletService.ts +158 -0
  102. package/src/tests/assetsService.test.ts +176 -0
  103. package/src/tests/configService.test.ts +486 -0
  104. package/src/tests/fetchSquidData.ts +43 -0
  105. package/src/tests/jest-svg-transform.ts +19 -0
  106. package/src/tests/sample.json +0 -0
  107. package/src/tests/walletService.test.ts +178 -0
  108. package/tsconfig.json +30 -0
@@ -0,0 +1,156 @@
1
+ import type { SlippageOption } from "@/core/types/config";
2
+ import type { SwapRoute } from "@/core/types/swap";
3
+ import type { TransactionParams } from "@/core/types/transaction";
4
+ import type { RouteResponse } from "@0xsquid/sdk/dist/types";
5
+ import { ChainType } from "@0xsquid/sdk/dist/types";
6
+
7
+ /**
8
+ * Cache keys implementation for react-query caching / invalidating
9
+ * For example if you invalidate a top level query, all its child will be invalidated, e.g "all" key
10
+ * @returns Query Keys array
11
+ */
12
+ export const keys = ({
13
+ address,
14
+ apiUrl,
15
+ }: {
16
+ address?: string;
17
+ apiUrl?: string;
18
+ }) => ({
19
+ all: [address, apiUrl, "all"],
20
+ // Chains
21
+ chains: () => [...keys({ apiUrl, address }).all, apiUrl, "chains"],
22
+
23
+ // Tokens
24
+ tokens: () => [...keys({ apiUrl, address }).all, apiUrl, "tokens"],
25
+ tokensForChain: (chainId?: number | string) => [
26
+ ...keys({ apiUrl, address }).tokens(),
27
+ chainId,
28
+ "tokensForChain",
29
+ ],
30
+ tokensPrice: (swapRoute: SwapRoute | undefined) => [
31
+ ...keys({ apiUrl, address }).tokens(),
32
+ swapRoute?.fromChainId,
33
+ swapRoute?.toChainId,
34
+ swapRoute?.toTokenAddress,
35
+ swapRoute?.fromTokenAddress,
36
+ "tokensPrice",
37
+ ],
38
+ singleTokenPrice: (tokenAddress?: string, chainId?: number | string) => [
39
+ ...keys({ apiUrl, address }).tokens(),
40
+ tokenAddress,
41
+ chainId,
42
+ "singleTokenPrice",
43
+ ],
44
+ axelarTokens: () => [...keys({ apiUrl }).tokens(), "axelarTokens"],
45
+
46
+ // Balances
47
+ balances: () => [...keys({ apiUrl, address }).all, "balances"],
48
+ balance: (
49
+ chainId?: number | string,
50
+ tokenAddress?: string,
51
+ userAddress?: string,
52
+ chainType: ChainType = ChainType.EVM
53
+ ) => [
54
+ ...keys({ apiUrl, address }).balances(),
55
+ address,
56
+ chainId,
57
+ tokenAddress,
58
+ chainType,
59
+ userAddress,
60
+ "balance",
61
+ ],
62
+ nativeBalanceBigNumber: (
63
+ chainId?: number | string,
64
+ tokenAddress?: string,
65
+ chainType: ChainType = ChainType.EVM
66
+ ) => [
67
+ ...keys({ apiUrl, address }).balances(),
68
+ address,
69
+ chainId,
70
+ tokenAddress,
71
+ chainType,
72
+ "nativeBalance",
73
+ ],
74
+ tokensBalanceForChain: (chainType?: ChainType, chainId?: number | string) => [
75
+ ...keys({ apiUrl, address }).balances(),
76
+ address,
77
+ chainId,
78
+ chainType,
79
+ "tokensBalanceForChain",
80
+ ],
81
+
82
+ allTokensBalance: (direction: "from" | "to") => [
83
+ ...keys({ apiUrl, address }).balances(),
84
+ address,
85
+ direction,
86
+ "allTokensBalance",
87
+ ],
88
+
89
+ allTokensPriceUSDAndBalance: () => [
90
+ ...keys({ apiUrl, address }).balances(),
91
+ address,
92
+ "allTokensPriceUSDAndBalance",
93
+ ],
94
+
95
+ // Transactions
96
+ transactions: () => [...keys({ apiUrl, address }).all, "transactions"],
97
+ transaction: (
98
+ swapDirection: SwapRoute | undefined,
99
+ price: string | undefined,
100
+ slippage: SlippageOption | undefined,
101
+ infiniteApproval: boolean | undefined,
102
+ getGasOnDestination: boolean | undefined,
103
+ expressEnabled: boolean | undefined,
104
+ sourceUserAddress: string | undefined
105
+ ) => [
106
+ ...keys({ apiUrl, address }).transactions(),
107
+ swapDirection?.fromChainId,
108
+ swapDirection?.toChainId,
109
+ swapDirection?.toTokenAddress,
110
+ swapDirection?.fromTokenAddress,
111
+ price,
112
+ slippage,
113
+ infiniteApproval,
114
+ getGasOnDestination,
115
+ expressEnabled,
116
+ sourceUserAddress,
117
+ "transaction",
118
+ ],
119
+ transactionStatus: (currentTransaction?: TransactionParams) => [
120
+ ...keys({ apiUrl, address }).transactions(),
121
+ currentTransaction?.routeType,
122
+ currentTransaction?.transactionId,
123
+ currentTransaction?.status,
124
+ currentTransaction?.fromChain?.chainId,
125
+ currentTransaction?.toChain?.chainId,
126
+ "transactionStatus",
127
+ ],
128
+ transactionStatusRefetcher: (currentTransaction?: TransactionParams) => [
129
+ ...keys({ apiUrl, address }).transactions(),
130
+ currentTransaction?.routeType,
131
+ currentTransaction?.transactionId,
132
+ currentTransaction?.status,
133
+ "transactionStatusRefetcher",
134
+ ],
135
+ routeApproved: (
136
+ swapDirection: SwapRoute | undefined,
137
+ sender: string | undefined,
138
+ routeData: RouteResponse["route"] | undefined
139
+ ) => [
140
+ ...keys({ apiUrl, address }).transactions(),
141
+ swapDirection?.fromChainId,
142
+ swapDirection?.toChainId,
143
+ swapDirection?.toTokenAddress,
144
+ swapDirection?.fromTokenAddress,
145
+ swapDirection?.destinationAddress,
146
+ sender,
147
+ routeData?.estimate?.fromAmount,
148
+ "routeApproved",
149
+ ],
150
+ aproveRoute: (tokenAddress?: string, amount?: string) => [
151
+ ...keys({ apiUrl, address }).transactions(),
152
+ tokenAddress,
153
+ amount,
154
+ "aproveRoute",
155
+ ],
156
+ });
@@ -0,0 +1,13 @@
1
+ import type { DefaultOptions } from "@tanstack/react-query";
2
+
3
+ // Prevent fetching too soon after the first successful request.
4
+ export const DEFAULT_STALE_TIME = 8000;
5
+
6
+ export const defaultOptions: DefaultOptions = {
7
+ queries: {
8
+ staleTime: DEFAULT_STALE_TIME,
9
+ refetchOnWindowFocus: false,
10
+ retry: false, // Prevent refetching everytime a query fails, will do manually when needed
11
+ retryOnMount: false,
12
+ },
13
+ };
@@ -0,0 +1,16 @@
1
+ export type ComponentSize = "xs" | "sm" | "md" | "lg";
2
+
3
+ export interface SkeletonConfig {
4
+ hasRandomWidth?: boolean;
5
+ backgroundColor?: string;
6
+ foregroundColor?: string;
7
+ animate?: boolean;
8
+ title?: string;
9
+ speed?: number;
10
+ width?: number;
11
+ height?: number;
12
+ }
13
+
14
+ export interface LoadingComponentProps {
15
+ isLoading?: boolean;
16
+ }
@@ -0,0 +1,52 @@
1
+ import type { DexName } from "./dex";
2
+
3
+ export type SlippageOption = 0.5 | 1 | 1.5 | 3;
4
+
5
+ export type TokenConfig = {
6
+ address: string;
7
+ chainId: number | string;
8
+ };
9
+
10
+ export interface AppConfig {
11
+ integratorId: string; // The integrator ID, this way we'll be able to provide data about volume to integrators
12
+ companyName?: string;
13
+ slippage?: SlippageOption;
14
+ enableExpress?: boolean;
15
+ enableGetGasOnDestination?: boolean;
16
+ infiniteApproval?: boolean;
17
+ apiUrl?: string;
18
+ internalSameChainSwapAllowed?: boolean; // Will display a message indicating that the swap is possible on the website
19
+ hideAnimations?: boolean;
20
+ preferDex?: DexName[] | string[]; // Can select a preferred dex to route transactions, will be sent to the sdk when executing route
21
+ advanced?: {
22
+ shareOnTwitter?: boolean;
23
+ disableTradeLimit?: boolean; // Will probably disappear in the future, when we remove the trade limit by default
24
+ };
25
+ priceImpactWarnings?: {
26
+ warning: number;
27
+ critical: number;
28
+ };
29
+ favTokens?: TokenConfig[];
30
+ comingSoonChainIds?: any[]; // number | string chain ids. If set to [], will show all chains
31
+ // The initial from and to assets when widget loads
32
+ initialAssets?: {
33
+ from?: TokenConfig;
34
+ to?: TokenConfig;
35
+ };
36
+ defaultTokensPerChain?: TokenConfig[]; // When chain is changed, this allow to chose the first token that will be selected
37
+ availableChains?: {
38
+ source?: (number | string)[];
39
+ destination?: (number | string)[];
40
+ }; // If set to [] or undefined, will show all chains
41
+ collectFees?: {
42
+ integratorAddress: string; // The EVM address of the integrator that will receive the fee
43
+ fee: number; // The amount in "basis points" for the fee. 50 = 0.05%. there is currently soft limit of 1% fee allowed for each tx.
44
+ };
45
+ showOnRampLink?: boolean; // If set to true, will show the default onramp link in the widget
46
+ onChainQuoting?: boolean; // Will pass this param to API when doing a quote. if true, then rpc calls for quoting instead of off chain calls
47
+ // Allows to disable chains for a specific direction (source or destination)
48
+ disabledChains?: {
49
+ source?: string[];
50
+ destination?: string[];
51
+ };
52
+ }
@@ -0,0 +1,31 @@
1
+ // This is a temporary list to help integrator
2
+ // Selecting the right name, this enum will evolve in api side
3
+ // This enum was not available in the sdk
4
+ export enum DexName {
5
+ UNISWAP_V2 = "UniswapV2",
6
+ UNISWAP_V3 = "UniswapV3",
7
+ UBESWAP = "Ubeswap",
8
+ SPOOKYSWAP = "Spookyswap",
9
+ SUSHISWAP = "Sushiswap",
10
+ STELLASWAP = "Stellaswap",
11
+ PANGOLIN = "Pangolin",
12
+ CURVE_V2 = "Curve_v2",
13
+ CURVE_V2_CELO = "Curve_v2_celo",
14
+ ELLIPSIS = "Ellipsis",
15
+ QUICKSWAP = "Quickswap",
16
+ STELLASWAP_SADDLE = "Stellaswap_Saddle",
17
+ QUICKSWAP_V3 = "Quickswap_v3",
18
+ PANCAKESWAP = "Pancakeswap",
19
+ PANCAKESWAP_V3 = "Pancakeswap_v3",
20
+ PANCAKESWAP_STABLE = "Pancakeswap_stable",
21
+ TRADERJOE = "TraderJoe",
22
+ TRIDENT = "Trident",
23
+ PLATYPUS = "Platypus",
24
+ WOMBAT = "Wombat",
25
+ ZYBERSWAP = "Zyberswap",
26
+ KYBERSWAP = "KyberSwap",
27
+ KYBERSWAP_AGGREGATOR = "KyberSwap_Aggregator",
28
+ GMX = "GMX",
29
+ APESWAP = "Apeswap",
30
+ OPENOCEAN = "OpenOcean",
31
+ }
@@ -0,0 +1,52 @@
1
+ import type { TransactionResponse } from "@ethersproject/providers";
2
+ import type { BigNumber } from "ethers";
3
+
4
+ export enum TransactionErrorType {
5
+ REJECTED_BY_USER,
6
+ CALL_EXCEPTION,
7
+ UNKNOWN,
8
+ WARNING,
9
+ }
10
+
11
+ export type TransactionErrorWithMessage = {
12
+ type: TransactionErrorType;
13
+ message: string;
14
+ };
15
+
16
+ export interface TransactionReplacedError extends Error {
17
+ code: string;
18
+ replacement: TransactionResponse;
19
+ }
20
+
21
+ export interface TransactionError {
22
+ reason: string;
23
+ code: string;
24
+ action: string;
25
+ message: string;
26
+ transaction: {
27
+ to: string;
28
+ data: string;
29
+ gasLimit: number;
30
+ value: { type: BigNumber; hex: string };
31
+ from: string;
32
+ };
33
+ }
34
+
35
+ export interface SquidRouteError {
36
+ code?: string;
37
+ errorType?: string;
38
+ message?: string;
39
+ }
40
+
41
+ export interface SquidStatusError {
42
+ errorType?: string;
43
+ }
44
+
45
+ export type SquidRouteErrorType =
46
+ | "Unknown"
47
+ | "UnknownError"
48
+ | "SquidServiceError";
49
+
50
+ export enum SquidStatusErrorType {
51
+ NotFoundError = "NotFoundError",
52
+ }
@@ -0,0 +1,16 @@
1
+ import type { RouteResponse } from "@0xsquid/sdk/dist/types";
2
+
3
+ export interface WidgetEventMap {
4
+ swapStatus: { status: string };
5
+ swap: { route: RouteResponse["route"]; txHash: string };
6
+ swapParamsChanged: {
7
+ fromChainId?: string;
8
+ toChainId?: string;
9
+ fromTokenAddress?: string;
10
+ toTokenAddress?: string;
11
+ };
12
+ }
13
+
14
+ export type EventListenerFunction<T extends keyof WidgetEventMap> = (
15
+ event: CustomEvent<WidgetEventMap[T]>
16
+ ) => void;
@@ -0,0 +1,21 @@
1
+ // TODO: Might not be needed in this file
2
+ // Could be on widget code only
3
+
4
+ export type Routes =
5
+ | "swap"
6
+ | "settings"
7
+ | "wallets"
8
+ | "tokens"
9
+ | "chains"
10
+ | "history"
11
+ | "transaction"
12
+ | "allTokens"
13
+ | "destination";
14
+
15
+ type HeaderButton = "back" | "settings" | "history";
16
+ export interface WidgetRoute {
17
+ id: Routes;
18
+ path: string;
19
+ title: string;
20
+ headerButtons?: HeaderButton[];
21
+ }
@@ -0,0 +1,8 @@
1
+ export interface SwapRoute {
2
+ fromChainId?: number | string;
3
+ toChainId?: number | string;
4
+ fromTokenAddress?: string;
5
+ toTokenAddress?: string;
6
+ destinationAddress?: string;
7
+ fallbackAddress?: string;
8
+ }
@@ -0,0 +1,30 @@
1
+ import type { Token } from "@0xsquid/sdk/dist/types";
2
+
3
+ export type TokenWithBalance = Token & {
4
+ balance: string;
5
+ priceUSD?: string;
6
+ isFavorite?: boolean;
7
+ };
8
+
9
+ export type AxelarTokenData = {
10
+ id: string;
11
+ common_key: object;
12
+ native_chain: string;
13
+ fully_supported: boolean;
14
+ decimals: number;
15
+ chain_aliases: {
16
+ [key: string]: {
17
+ assetSymbol: string;
18
+ assetName: string;
19
+ minDepositAmt: number;
20
+ ibcDenom: string;
21
+ fullDenomPath: string;
22
+ tokenAddress: string;
23
+ mintLimit: number;
24
+ };
25
+ };
26
+ };
27
+
28
+ export type AxelarTokensData = {
29
+ assets: { [key: string]: AxelarTokenData };
30
+ };
@@ -0,0 +1,84 @@
1
+ import type {
2
+ ChainData,
3
+ RouteResponse,
4
+ // StatusResponse,
5
+ Token,
6
+ } from "@0xsquid/sdk/dist/types";
7
+ import type { UseQueryResult } from "@tanstack/react-query";
8
+ import type { TransactionErrorWithMessage } from "./error";
9
+
10
+ export enum TransactionType {
11
+ BRIDGE = "BRIDGE",
12
+ BRIDGE_CALL = "BRIDGE_CALL",
13
+ CALL_BRIDGE = "CALL_BRIDGE",
14
+ CALL_BRIDGE_CALL = "CALL_BRIDGE_CALL",
15
+ }
16
+
17
+ export enum AxelarStatusResponseType {
18
+ GAS_PAID_NOT_ENOUGH_GAS = "gas_paid_not_enough_gas",
19
+ DESTINATION_EXECUTED = "destination_executed",
20
+ EXPRESS_EXECUTED = "express_executed",
21
+ CROSS_MULTICALL_EXECUTED = "CrossMulticallExecuted",
22
+ CROSS_MULTICALL_FAILED = "CrossMulticallFailed",
23
+ SRC_GATEWAY_CALLED = "source_gateway_called",
24
+ DEST_GATEWAY_APPROVED = "destination_gateway_approved",
25
+ DESTINATION_EXECUTE_ERROR = "destination_execute_error",
26
+ DESTINATION_EXECUTING = "executing",
27
+ UNKNOWN_ERROR = "unknown_error",
28
+ CANNOT_FETCH_STATUS = "cannot_fetch_status",
29
+ ERROR = "error",
30
+ }
31
+
32
+ export enum TransactionStatus {
33
+ // Submitted transaction, returned by squid axelar
34
+ SUCCESS = "success",
35
+ NEEDS_GAS = "needs_gas",
36
+ ONGOING = "ongoing",
37
+ PARTIAL_SUCCESS = "partial_success",
38
+ NOT_FOUND = "not_found",
39
+ // Unsubmitted Transaction, can be status from wallet
40
+ INITIAL_LOADING = "initialLoading",
41
+ ERROR = "error",
42
+ WARNING = "warning",
43
+ PENDING = "pending",
44
+ REJECTED = "rejected",
45
+ }
46
+
47
+ export interface TransactionParams {
48
+ routeType: string;
49
+ fromChain?: ChainData;
50
+ toChain?: ChainData;
51
+ nonce?: number;
52
+ transactionId: string | undefined;
53
+ timestamp?: number;
54
+ sourceStatus?: TransactionStatus; // The source / wallet transaction status
55
+ status: TransactionStatus; // Cross chain Transaction Status
56
+ error?: TransactionErrorWithMessage;
57
+ fromAddress?: string;
58
+ statusResponse?: any;
59
+ axelarUrl?: string;
60
+ sourceTxExplorerUrl?: string;
61
+ sourceExplorerImgUrl?: string;
62
+ }
63
+
64
+ export type TransactionHistoryStore = TransactionParams &
65
+ Pick<RouteResponse["route"], "params" | "estimate">;
66
+
67
+ export interface TransactionStepsProps {
68
+ currentTransaction?: TransactionParams;
69
+ sourceExplorerUrl?: string;
70
+ fromToken?: Token;
71
+ toToken?: Token;
72
+ toChain?: ChainData;
73
+ fromChain?: ChainData;
74
+ }
75
+
76
+ export type TransactionStepProps = TransactionStepsProps & {
77
+ statusResponse?: UseQueryResult<any, unknown>;
78
+ };
79
+
80
+ export interface StepStatusGetterProps {
81
+ transaction?: TransactionParams;
82
+ statusResponse?: UseQueryResult<any, unknown>;
83
+ onlyFullStatusStep?: boolean;
84
+ }
@@ -0,0 +1,37 @@
1
+ import type { Token } from "@0xsquid/sdk/dist/types";
2
+
3
+ export type SwapDirection = "from" | "to";
4
+
5
+ export type NextJsImg = {
6
+ src: string;
7
+ }; // On nextjs the image will be of type {src: "/_next/static/media/metamask.8a0fd576.svg", width: number, height: number}
8
+ export type ImgType = string | NextJsImg;
9
+
10
+ // TODO: BELOW Are temporary types taken from api for development because SDK wasn't up to date
11
+ export enum FeeType {
12
+ AXELAR_FEE = "Axelar Fee",
13
+ GAS_RECEIVER_FEE = "Cross-chain gas fees",
14
+ }
15
+
16
+ export type FeeCost = {
17
+ name: FeeType;
18
+ description: string;
19
+ percentage: string;
20
+ token: Token;
21
+ amount: string;
22
+ amountUSD: string;
23
+ };
24
+
25
+ export type ApiBasicResponse = {
26
+ error?: string;
27
+ errorType?: any;
28
+ };
29
+
30
+ export type TimeSpent = {
31
+ send_vote?: number;
32
+ type?: string;
33
+ destination_chain_type?: string;
34
+ source_chain_type?: string;
35
+ total?: number;
36
+ vote_ibc?: number;
37
+ };
@@ -0,0 +1,83 @@
1
+ /* eslint-disable @typescript-eslint/no-duplicate-enum-values */
2
+ import type { ChainType } from "@0xsquid/sdk/dist/types";
3
+ import type { Chain } from "wagmi";
4
+
5
+ export type TypedWindow = Window &
6
+ typeof globalThis & {
7
+ [key in WindowWalletFlag]?: any;
8
+ };
9
+
10
+ export enum WindowWalletFlag {
11
+ Binance = "bbcSignTx",
12
+ Coinbase = "isCoinbaseWallet",
13
+ MetaMask = "isMetaMask",
14
+ WalletConnect = "walletConnect",
15
+ CosmostationEVM = "cosmostation",
16
+ BlockchainDotCom = "blockchaindotcom",
17
+ CosmostationCosmos = "cosmostation.providers.keplr",
18
+ Keplr = "keplr",
19
+ Leap = "leap",
20
+ Xdefi = "xfi",
21
+ XdefiCosmos = "xfi.keplr",
22
+ BitGet = "bitkeep",
23
+ TrustWallet = "trustwallet",
24
+ FetchAi = "keplr", // Sadly the same as the real Keplr wallet
25
+ Coin98 = "coin98",
26
+ Rabby = "isRabby",
27
+ OKX = "okxwallet",
28
+ Injected = "injected",
29
+ DefiConnect = "deficonnectProvider", // From crypto.com: https://github.com/crypto-com/deficonnect-monorepo/wiki/Chrome-Extension-Wallet-Integration
30
+ Zerion = "isZerion",
31
+ Snapper = "cosmos",
32
+ Exodus = "exodus",
33
+ }
34
+
35
+ export type ConnectorID =
36
+ | "metaMask"
37
+ | "walletConnect"
38
+ | "blockchaindotcom"
39
+ | "coinbaseWallet"
40
+ | "keplr"
41
+ | "cosmostation"
42
+ | "cosmostationCosmos"
43
+ | "leap"
44
+ | "xdefi"
45
+ | "xdeficosmos"
46
+ | "bitget"
47
+ | "fetchai"
48
+ | "coin98"
49
+ | "rabby"
50
+ | "okx"
51
+ | "injected"
52
+ | "zerion"
53
+ | "deficonnect"
54
+ | "snapper"
55
+ | "trustwallet"
56
+ | "exodus";
57
+
58
+ export interface Wallet {
59
+ name: string;
60
+ type: ChainType;
61
+ connectorId: ConnectorID;
62
+ connectorName: string;
63
+ connector?: (chains?: Chain[]) => any; // For evm chains only
64
+ icon: string | undefined;
65
+ windowFlag: string; // Wallet identitiy attached to window object
66
+ canSwitchWallets: boolean;
67
+ direction?: "from" | "to";
68
+ connectedAddress?: string;
69
+ }
70
+
71
+ export interface AddEthereumChainParameter {
72
+ chainId: string; // A 0x-prefixed hexadecimal string
73
+ chainName: string;
74
+ nativeCurrency: {
75
+ name: string;
76
+ symbol: string; // 2-6 characters long
77
+ decimals: number;
78
+ icon: string;
79
+ };
80
+ rpcUrls: string[];
81
+ blockExplorerUrls?: string[];
82
+ iconUrls?: string[]; // Currently ignored.
83
+ }
@@ -0,0 +1,66 @@
1
+ import { keys } from "@/core/queries/queries-keys";
2
+ import { useSquidStore } from "@/hooks/store/useSquidStore";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { useMemo } from "react";
5
+
6
+ export const useSquidChains = () => {
7
+ const { squid, config } = useSquidStore();
8
+
9
+ const fuseSearchOptions = {
10
+ isCaseSensitive: false,
11
+ includeScore: false,
12
+ minMatchCharLength: 1,
13
+ threshold: 0.1,
14
+ keys: ["networkName", "chainName", "nativeCurrency.symbol"],
15
+ };
16
+
17
+ const supportedChains = useQuery(
18
+ keys({ apiUrl: config.apiUrl }).chains(),
19
+ () => {
20
+ return squid?.chains ?? [];
21
+ },
22
+ {
23
+ enabled: squid !== undefined,
24
+ // cacheTime: 1000 * 60 * 60 * 24,
25
+ // staleTime: 1000 * 60 * 60 * 24,
26
+ }
27
+ );
28
+
29
+ const chains = useMemo(
30
+ () => supportedChains.data ?? [],
31
+ [supportedChains.data]
32
+ );
33
+
34
+ const supportedSourceChains = useMemo(() => {
35
+ if (
36
+ config.availableChains &&
37
+ config.availableChains?.source &&
38
+ config.availableChains.source.length > 0
39
+ ) {
40
+ return chains.filter((c) =>
41
+ config.availableChains?.source?.includes(c.chainId)
42
+ );
43
+ }
44
+ return chains;
45
+ }, [chains, config.availableChains]);
46
+
47
+ const supportedDestinationChains = useMemo(() => {
48
+ if (
49
+ config.availableChains &&
50
+ config.availableChains?.destination &&
51
+ config.availableChains.destination.length > 0
52
+ ) {
53
+ return chains.filter((c) =>
54
+ config.availableChains?.destination?.includes(c.chainId)
55
+ );
56
+ }
57
+ return chains;
58
+ }, [chains, config.availableChains]);
59
+
60
+ return {
61
+ supportedSourceChains,
62
+ supportedDestinationChains,
63
+ chains,
64
+ fuseSearchOptions,
65
+ };
66
+ };