@0xsquid/react-hooks 1.0.4 → 1.0.6

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 (317) hide show
  1. package/dist/assets/images/icons/wallets/index.d.ts +22 -0
  2. package/{src/assets/images/icons/wallets/index.ts → dist/assets/images/icons/wallets/index.js} +21 -21
  3. package/dist/assets/images/icons/wallets/index.js.map +1 -0
  4. package/dist/connectors/ExodusConnector.d.ts +4 -0
  5. package/{src/connectors/ExodusConnector.ts → dist/connectors/ExodusConnector.js} +3 -3
  6. package/dist/connectors/ExodusConnector.js.map +1 -0
  7. package/dist/connectors/LedgerLiveConnector.d.ts +40 -0
  8. package/dist/connectors/LedgerLiveConnector.js +177 -0
  9. package/dist/connectors/LedgerLiveConnector.js.map +1 -0
  10. package/dist/contracts/typechain/factories/ERC20__factory.js +324 -0
  11. package/dist/contracts/typechain/factories/ERC20__factory.js.map +1 -0
  12. package/dist/core/constants.d.ts +37 -0
  13. package/dist/core/constants.js +487 -0
  14. package/dist/core/constants.js.map +1 -0
  15. package/dist/core/externalLinks.d.ts +18 -0
  16. package/{src/core/externalLinks.ts → dist/core/externalLinks.js} +5 -9
  17. package/dist/core/externalLinks.js.map +1 -0
  18. package/dist/core/index.js +2 -0
  19. package/dist/core/index.js.map +1 -0
  20. package/dist/core/multicall3.d.ts +16 -0
  21. package/dist/core/multicall3.js +23 -0
  22. package/dist/core/multicall3.js.map +1 -0
  23. package/dist/core/numbers.d.ts +3 -0
  24. package/dist/core/numbers.js +28 -0
  25. package/dist/core/numbers.js.map +1 -0
  26. package/dist/core/providers/CosmosProvider.d.ts +34 -0
  27. package/dist/core/providers/CosmosProvider.js +12 -0
  28. package/dist/core/providers/CosmosProvider.js.map +1 -0
  29. package/dist/core/queries/queries-keys.d.ts +34 -0
  30. package/dist/core/queries/queries-keys.js +120 -0
  31. package/dist/core/queries/queries-keys.js.map +1 -0
  32. package/dist/core/queries/react-query-config.d.ts +3 -0
  33. package/dist/core/queries/react-query-config.js +11 -0
  34. package/dist/core/queries/react-query-config.js.map +1 -0
  35. package/dist/core/types/components.d.ts +14 -0
  36. package/dist/core/types/components.js +2 -0
  37. package/dist/core/types/components.js.map +1 -0
  38. package/dist/core/types/config.d.ts +47 -0
  39. package/dist/core/types/config.js +2 -0
  40. package/dist/core/types/config.js.map +1 -0
  41. package/dist/core/types/dex.d.ts +28 -0
  42. package/dist/core/types/dex.js +33 -0
  43. package/dist/core/types/dex.js.map +1 -0
  44. package/dist/core/types/error.d.ts +44 -0
  45. package/dist/core/types/error.js +12 -0
  46. package/dist/core/types/error.js.map +1 -0
  47. package/dist/core/types/event.d.ts +17 -0
  48. package/dist/core/types/event.js +2 -0
  49. package/dist/core/types/event.js.map +1 -0
  50. package/dist/core/types/route.d.ts +9 -0
  51. package/dist/core/types/route.js +4 -0
  52. package/dist/core/types/route.js.map +1 -0
  53. package/dist/core/types/swap.d.ts +8 -0
  54. package/dist/core/types/swap.js +2 -0
  55. package/dist/core/types/swap.js.map +1 -0
  56. package/dist/core/types/tokens.d.ts +29 -0
  57. package/dist/core/types/tokens.js +2 -0
  58. package/dist/core/types/tokens.js.map +1 -0
  59. package/dist/core/types/transaction.d.ts +68 -0
  60. package/dist/core/types/transaction.js +38 -0
  61. package/dist/core/types/transaction.js.map +1 -0
  62. package/dist/core/types/types.d.ts +30 -0
  63. package/dist/core/types/types.js +7 -0
  64. package/dist/core/types/types.js.map +1 -0
  65. package/dist/core/types/wallet.d.ts +55 -0
  66. package/dist/core/types/wallet.js +26 -0
  67. package/dist/core/types/wallet.js.map +1 -0
  68. package/dist/hooks/chains/useSquidChains.d.ts +12 -0
  69. package/dist/hooks/chains/useSquidChains.js +45 -0
  70. package/dist/hooks/chains/useSquidChains.js.map +1 -0
  71. package/dist/hooks/cosmos/useCosmos.d.ts +33 -0
  72. package/dist/hooks/cosmos/useCosmos.js +194 -0
  73. package/dist/hooks/cosmos/useCosmos.js.map +1 -0
  74. package/dist/hooks/cosmos/useCosmosForChain.d.ts +4 -0
  75. package/dist/hooks/cosmos/useCosmosForChain.js +22 -0
  76. package/dist/hooks/cosmos/useCosmosForChain.js.map +1 -0
  77. package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -7
  78. package/dist/hooks/index.js +27 -0
  79. package/dist/hooks/index.js.map +1 -0
  80. package/dist/hooks/navigation/useKeyboardNavigation.d.ts +7 -0
  81. package/dist/hooks/navigation/useKeyboardNavigation.js +69 -0
  82. package/dist/hooks/navigation/useKeyboardNavigation.js.map +1 -0
  83. package/dist/hooks/store/useSquidStore.d.ts +105 -0
  84. package/dist/hooks/store/useSquidStore.js +35 -0
  85. package/dist/hooks/store/useSquidStore.js.map +1 -0
  86. package/dist/hooks/swap/useSwap.d.ts +25 -0
  87. package/dist/hooks/swap/useSwap.js +229 -0
  88. package/dist/hooks/swap/useSwap.js.map +1 -0
  89. package/dist/hooks/tokens/useAllTokensWithBalance.d.ts +11 -0
  90. package/dist/hooks/tokens/useAllTokensWithBalance.js +97 -0
  91. package/dist/hooks/tokens/useAllTokensWithBalance.js.map +1 -0
  92. package/dist/hooks/tokens/useBalance.d.ts +34 -0
  93. package/dist/hooks/tokens/useBalance.js +112 -0
  94. package/dist/hooks/tokens/useBalance.js.map +1 -0
  95. package/dist/hooks/tokens/useMultiChainBalance.d.ts +17 -0
  96. package/dist/hooks/tokens/useMultiChainBalance.js +36 -0
  97. package/dist/hooks/tokens/useMultiChainBalance.js.map +1 -0
  98. package/dist/hooks/tokens/usePrices.d.ts +6 -0
  99. package/dist/hooks/tokens/usePrices.js +42 -0
  100. package/dist/hooks/tokens/usePrices.js.map +1 -0
  101. package/dist/hooks/tokens/useSingleTokenPrice.d.ts +10 -0
  102. package/dist/hooks/tokens/useSingleTokenPrice.js +32 -0
  103. package/dist/hooks/tokens/useSingleTokenPrice.js.map +1 -0
  104. package/dist/hooks/tokens/useSquidTokens.d.ts +13 -0
  105. package/dist/hooks/tokens/useSquidTokens.js +35 -0
  106. package/dist/hooks/tokens/useSquidTokens.js.map +1 -0
  107. package/dist/hooks/tokens/useTokensWithBalance.d.ts +7 -0
  108. package/dist/hooks/tokens/useTokensWithBalance.js +111 -0
  109. package/dist/hooks/tokens/useTokensWithBalance.js.map +1 -0
  110. package/dist/hooks/transaction/useEstimate.d.ts +44 -0
  111. package/dist/hooks/transaction/useEstimate.js +274 -0
  112. package/dist/hooks/transaction/useEstimate.js.map +1 -0
  113. package/dist/hooks/transaction/useEstimatePriceImpact.d.ts +7 -0
  114. package/dist/hooks/transaction/useEstimatePriceImpact.js +26 -0
  115. package/dist/hooks/transaction/useEstimatePriceImpact.js.map +1 -0
  116. package/dist/hooks/transaction/useExecuteTransaction.d.ts +20 -0
  117. package/dist/hooks/transaction/useExecuteTransaction.js +310 -0
  118. package/dist/hooks/transaction/useExecuteTransaction.js.map +1 -0
  119. package/dist/hooks/transaction/useExpress.d.ts +5 -0
  120. package/dist/hooks/transaction/useExpress.js +31 -0
  121. package/dist/hooks/transaction/useExpress.js.map +1 -0
  122. package/dist/hooks/transaction/useGetRoute.d.ts +14 -0
  123. package/dist/hooks/transaction/useGetRoute.js +96 -0
  124. package/dist/hooks/transaction/useGetRoute.js.map +1 -0
  125. package/dist/hooks/transaction/useSingleTransaction.d.ts +8 -0
  126. package/dist/hooks/transaction/useSingleTransaction.js +99 -0
  127. package/dist/hooks/transaction/useSingleTransaction.js.map +1 -0
  128. package/dist/hooks/transaction/useTransaction.d.ts +25 -0
  129. package/dist/hooks/transaction/useTransaction.js +521 -0
  130. package/dist/hooks/transaction/useTransaction.js.map +1 -0
  131. package/dist/hooks/user/useUserParams.d.ts +6 -0
  132. package/dist/hooks/user/useUserParams.js +41 -0
  133. package/dist/hooks/user/useUserParams.js.map +1 -0
  134. package/dist/hooks/wallet/useAddToken.d.ts +4 -0
  135. package/dist/hooks/wallet/useAddToken.js +45 -0
  136. package/dist/hooks/wallet/useAddToken.js.map +1 -0
  137. package/dist/hooks/wallet/useAutoConnect.d.ts +6 -0
  138. package/dist/hooks/wallet/useAutoConnect.js +44 -0
  139. package/dist/hooks/wallet/useAutoConnect.js.map +1 -0
  140. package/dist/hooks/wallet/useGnosisContext.d.ts +7 -0
  141. package/dist/hooks/wallet/useGnosisContext.js +70 -0
  142. package/dist/hooks/wallet/useGnosisContext.js.map +1 -0
  143. package/dist/hooks/wallet/useIntegratorContext.d.ts +5 -0
  144. package/dist/hooks/wallet/useIntegratorContext.js +39 -0
  145. package/dist/hooks/wallet/useIntegratorContext.js.map +1 -0
  146. package/dist/hooks/wallet/useMultiChainWallet.d.ts +8 -0
  147. package/dist/hooks/wallet/useMultiChainWallet.js +113 -0
  148. package/dist/hooks/wallet/useMultiChainWallet.js.map +1 -0
  149. package/dist/hooks/wallet/useWallet.d.ts +6 -0
  150. package/dist/hooks/wallet/useWallet.js +65 -0
  151. package/dist/hooks/wallet/useWallet.js.map +1 -0
  152. package/dist/hooks/webapp-router/useSquidRouter.d.ts +11 -0
  153. package/dist/hooks/webapp-router/useSquidRouter.js +33 -0
  154. package/dist/hooks/webapp-router/useSquidRouter.js.map +1 -0
  155. package/{src/index.ts → dist/index.d.ts} +0 -1
  156. package/dist/index.js.map +1 -0
  157. package/dist/provider/index.d.ts +10 -0
  158. package/dist/provider/index.js +71 -0
  159. package/dist/provider/index.js.map +1 -0
  160. package/dist/services/external/analyticsService.d.ts +18 -0
  161. package/dist/services/external/analyticsService.js +30 -0
  162. package/dist/services/external/analyticsService.js.map +1 -0
  163. package/dist/services/external/coingeckoService.d.ts +8 -0
  164. package/dist/services/external/coingeckoService.js +20 -0
  165. package/dist/services/external/coingeckoService.js.map +1 -0
  166. package/dist/services/external/rpcService.d.ts +4 -0
  167. package/dist/services/external/rpcService.js +145 -0
  168. package/dist/services/external/rpcService.js.map +1 -0
  169. package/dist/services/external/secretService.d.ts +28 -0
  170. package/dist/services/external/secretService.js +129 -0
  171. package/dist/services/external/secretService.js.map +1 -0
  172. package/dist/services/index.js +2 -0
  173. package/dist/services/index.js.map +1 -0
  174. package/dist/services/internal/apiService.d.ts +4 -0
  175. package/dist/services/internal/apiService.js +7 -0
  176. package/dist/services/internal/apiService.js.map +1 -0
  177. package/dist/services/internal/assetsService.d.ts +28 -0
  178. package/dist/services/internal/assetsService.js +46 -0
  179. package/dist/services/internal/assetsService.js.map +1 -0
  180. package/dist/services/internal/configService.d.ts +40 -0
  181. package/dist/services/internal/configService.js +119 -0
  182. package/dist/services/internal/configService.js.map +1 -0
  183. package/dist/services/internal/errorService.d.ts +30 -0
  184. package/{src/services/internal/errorService.ts → dist/services/internal/errorService.js} +35 -54
  185. package/dist/services/internal/errorService.js.map +1 -0
  186. package/dist/services/internal/eventService.d.ts +52 -0
  187. package/dist/services/internal/eventService.js +66 -0
  188. package/dist/services/internal/eventService.js.map +1 -0
  189. package/dist/services/internal/priceService.d.ts +1 -0
  190. package/dist/services/internal/priceService.js +7 -0
  191. package/dist/services/internal/priceService.js.map +1 -0
  192. package/dist/services/internal/transactionService.d.ts +43 -0
  193. package/dist/services/internal/transactionService.js +172 -0
  194. package/dist/services/internal/transactionService.js.map +1 -0
  195. package/dist/services/internal/transactionStatusService.d.ts +28 -0
  196. package/dist/services/internal/transactionStatusService.js +225 -0
  197. package/dist/services/internal/transactionStatusService.js.map +1 -0
  198. package/dist/services/internal/walletService.d.ts +28 -0
  199. package/dist/services/internal/walletService.js +123 -0
  200. package/dist/services/internal/walletService.js.map +1 -0
  201. package/dist/tests/assetsService.test.d.ts +1 -0
  202. package/dist/tests/assetsService.test.js +130 -0
  203. package/dist/tests/assetsService.test.js.map +1 -0
  204. package/dist/tests/configService.test.d.ts +1 -0
  205. package/dist/tests/configService.test.js +295 -0
  206. package/dist/tests/configService.test.js.map +1 -0
  207. package/dist/tests/fetchSquidData.d.ts +6 -0
  208. package/dist/tests/fetchSquidData.js +27 -0
  209. package/dist/tests/fetchSquidData.js.map +1 -0
  210. package/{src/tests/jest-svg-transform.ts → dist/tests/jest-svg-transform.js} +11 -9
  211. package/dist/tests/jest-svg-transform.js.map +1 -0
  212. package/dist/tests/sample.json +0 -0
  213. package/dist/tests/walletService.test.d.ts +1 -0
  214. package/dist/tests/walletService.test.js +74 -0
  215. package/dist/tests/walletService.test.js.map +1 -0
  216. package/package.json +6 -1
  217. package/.babelrc +0 -7
  218. package/.eslintignore +0 -1
  219. package/.eslintrc.json +0 -44
  220. package/CHANGELOG.md +0 -9
  221. package/jest.config.ts +0 -28
  222. package/scripts/copyAssets.js +0 -27
  223. package/scripts/removeBuildTestFolder.js +0 -28
  224. package/scripts/replacePaths.js +0 -37
  225. package/src/connectors/LedgerLiveConnector.ts +0 -226
  226. package/src/contracts/typechain/ERC20.d.ts +0 -441
  227. package/src/contracts/typechain/factories/ERC20__factory.ts +0 -340
  228. package/src/core/constants.ts +0 -549
  229. package/src/core/multicall3.ts +0 -22
  230. package/src/core/numbers.ts +0 -44
  231. package/src/core/providers/CosmosProvider.tsx +0 -55
  232. package/src/core/queries/queries-keys.ts +0 -156
  233. package/src/core/queries/react-query-config.ts +0 -13
  234. package/src/core/types/components.ts +0 -16
  235. package/src/core/types/config.ts +0 -52
  236. package/src/core/types/dex.ts +0 -31
  237. package/src/core/types/error.ts +0 -52
  238. package/src/core/types/event.ts +0 -16
  239. package/src/core/types/route.ts +0 -21
  240. package/src/core/types/swap.ts +0 -8
  241. package/src/core/types/tokens.ts +0 -30
  242. package/src/core/types/transaction.ts +0 -84
  243. package/src/core/types/types.ts +0 -37
  244. package/src/core/types/wallet.ts +0 -83
  245. package/src/hooks/chains/useSquidChains.ts +0 -66
  246. package/src/hooks/cosmos/useCosmos.ts +0 -279
  247. package/src/hooks/cosmos/useCosmosForChain.ts +0 -33
  248. package/src/hooks/navigation/useKeyboardNavigation.ts +0 -88
  249. package/src/hooks/store/useSquidStore.ts +0 -80
  250. package/src/hooks/swap/useSwap.ts +0 -359
  251. package/src/hooks/tokens/useAllTokensWithBalance.ts +0 -157
  252. package/src/hooks/tokens/useBalance.ts +0 -180
  253. package/src/hooks/tokens/useMultiChainBalance.ts +0 -59
  254. package/src/hooks/tokens/usePrices.ts +0 -52
  255. package/src/hooks/tokens/useSingleTokenPrice.ts +0 -45
  256. package/src/hooks/tokens/useSquidTokens.ts +0 -48
  257. package/src/hooks/tokens/useTokensWithBalance.ts +0 -169
  258. package/src/hooks/transaction/useEstimate.ts +0 -397
  259. package/src/hooks/transaction/useEstimatePriceImpact.ts +0 -39
  260. package/src/hooks/transaction/useExecuteTransaction.ts +0 -440
  261. package/src/hooks/transaction/useExpress.ts +0 -46
  262. package/src/hooks/transaction/useGetRoute.ts +0 -145
  263. package/src/hooks/transaction/useSingleTransaction.ts +0 -155
  264. package/src/hooks/transaction/useTransaction.ts +0 -734
  265. package/src/hooks/user/useUserParams.ts +0 -63
  266. package/src/hooks/wallet/useAddToken.ts +0 -53
  267. package/src/hooks/wallet/useAutoConnect.ts +0 -56
  268. package/src/hooks/wallet/useGnosisContext.ts +0 -84
  269. package/src/hooks/wallet/useIntegratorContext.ts +0 -44
  270. package/src/hooks/wallet/useMultiChainWallet.ts +0 -146
  271. package/src/hooks/wallet/useWallet.ts +0 -86
  272. package/src/hooks/webapp-router/useSquidRouter.ts +0 -42
  273. package/src/provider/index.tsx +0 -105
  274. package/src/react-app-env.d.ts +0 -2
  275. package/src/services/external/analyticsService.ts +0 -46
  276. package/src/services/external/coingeckoService.ts +0 -35
  277. package/src/services/external/rpcService.ts +0 -196
  278. package/src/services/external/secretService.ts +0 -178
  279. package/src/services/internal/apiService.ts +0 -6
  280. package/src/services/internal/assetsService.ts +0 -84
  281. package/src/services/internal/configService.ts +0 -261
  282. package/src/services/internal/eventService.ts +0 -93
  283. package/src/services/internal/priceService.ts +0 -10
  284. package/src/services/internal/transactionService.ts +0 -255
  285. package/src/services/internal/transactionStatusService.ts +0 -293
  286. package/src/services/internal/walletService.ts +0 -158
  287. package/src/tests/assetsService.test.ts +0 -176
  288. package/src/tests/configService.test.ts +0 -486
  289. package/src/tests/fetchSquidData.ts +0 -43
  290. package/src/tests/walletService.test.ts +0 -178
  291. package/tsconfig.cjs.json +0 -8
  292. package/tsconfig.json +0 -31
  293. /package/{src → dist}/assets/images/icons/wallets/binance.svg +0 -0
  294. /package/{src → dist}/assets/images/icons/wallets/bitget.svg +0 -0
  295. /package/{src → dist}/assets/images/icons/wallets/bitkeep.svg +0 -0
  296. /package/{src → dist}/assets/images/icons/wallets/blockchaindotcom.svg +0 -0
  297. /package/{src → dist}/assets/images/icons/wallets/brave.svg +0 -0
  298. /package/{src → dist}/assets/images/icons/wallets/c98.svg +0 -0
  299. /package/{src → dist}/assets/images/icons/wallets/coinbase.svg +0 -0
  300. /package/{src → dist}/assets/images/icons/wallets/cosmostation.svg +0 -0
  301. /package/{src → dist}/assets/images/icons/wallets/defiConnect.svg +0 -0
  302. /package/{src → dist}/assets/images/icons/wallets/exodus.svg +0 -0
  303. /package/{src → dist}/assets/images/icons/wallets/fetchai.svg +0 -0
  304. /package/{src → dist}/assets/images/icons/wallets/keplr.svg +0 -0
  305. /package/{src → dist}/assets/images/icons/wallets/leap.svg +0 -0
  306. /package/{src → dist}/assets/images/icons/wallets/metamask.svg +0 -0
  307. /package/{src → dist}/assets/images/icons/wallets/okx.svg +0 -0
  308. /package/{src → dist}/assets/images/icons/wallets/rabby.svg +0 -0
  309. /package/{src → dist}/assets/images/icons/wallets/trustwallet.svg +0 -0
  310. /package/{src → dist}/assets/images/icons/wallets/walletConnect.svg +0 -0
  311. /package/{src → dist}/assets/images/icons/wallets/wallet_icon.svg +0 -0
  312. /package/{src → dist}/assets/images/icons/wallets/xdefi.svg +0 -0
  313. /package/{src → dist}/assets/images/icons/wallets/zerion.svg +0 -0
  314. /package/{src → dist}/contracts/typechain/factories/ERC20__factory.d.ts +0 -0
  315. /package/{src/core/index.ts → dist/core/index.d.ts} +0 -0
  316. /package/{src/services/index.ts → dist/services/index.d.ts} +0 -0
  317. /package/{src/tests/sample.json → dist/tests/jest-svg-transform.d.ts} +0 -0
@@ -1,261 +0,0 @@
1
- import { defaultValues } from "@/core/constants";
2
- import type { AppConfig } from "@/core/types/config";
3
- import type { ChainData, Token } from "@0xsquid/sdk/dist/types";
4
- import { ChainType } from "@0xsquid/sdk/dist/types";
5
- import get from "lodash/get";
6
- import { shareSubgraphId } from "./assetsService";
7
-
8
- export const getConfigWithDefaults = (
9
- config: AppConfig | undefined
10
- ): AppConfig => {
11
- return {
12
- integratorId: get(
13
- config,
14
- "integratorId",
15
- defaultValues.config.integratorId
16
- ),
17
- companyName: get(config, "companyName", defaultValues.config.companyName),
18
- slippage: get(config, "slippage", defaultValues.config.slippage),
19
- advanced: get(config, "advanced", defaultValues.config.advanced),
20
- internalSameChainSwapAllowed: get(
21
- config,
22
- "internalSameChainSwapAllowed",
23
- defaultValues.config.internalSameChainSwapAllowed
24
- ),
25
- hideAnimations: get(
26
- config,
27
- "hideAnimations",
28
- defaultValues.config.hideAnimations
29
- ),
30
- infiniteApproval: get(
31
- config,
32
- "infiniteApproval",
33
- defaultValues.config.infiniteApproval
34
- ),
35
- enableExpress: get(
36
- config,
37
- "enableExpress",
38
- defaultValues.config.enableExpress
39
- ),
40
- collectFees: get(config, "collectFees", defaultValues.config.collectFees),
41
- enableGetGasOnDestination: get(
42
- config,
43
- "enableGetGasOnDestination",
44
- defaultValues.config.enableGetGasOnDestination
45
- ),
46
- apiUrl: get(config, "apiUrl", defaultValues.config.apiUrl),
47
- showOnRampLink: get(
48
- config,
49
- "showOnRampLink",
50
- defaultValues.config.showOnRampLink
51
- ),
52
- priceImpactWarnings: get(
53
- config,
54
- "priceImpactWarnings",
55
- defaultValues.config.priceImpactWarnings
56
- ),
57
- initialAssets: get(
58
- config,
59
- "initialAssets",
60
- defaultValues.config.initialAssets
61
- ),
62
- defaultTokensPerChain: get(
63
- config,
64
- "defaultTokensPerChain",
65
- defaultValues.config.defaultTokensPerChain
66
- ),
67
- preferDex: get(config, "preferDex", defaultValues.config.preferDex),
68
- favTokens: get(config, "favTokens", defaultValues.config.favTokens),
69
- comingSoonChainIds: get(
70
- config,
71
- "comingSoonChainIds",
72
- defaultValues.config.comingSoonChainIds
73
- ),
74
- availableChains: get(
75
- config,
76
- "availableChains",
77
- defaultValues.config.availableChains
78
- ),
79
- onChainQuoting: get(
80
- config,
81
- "onChainQuoting",
82
- defaultValues.config.onChainQuoting
83
- ),
84
- disabledChains: get(
85
- config,
86
- "disabledChains",
87
- defaultValues.config.disabledChains
88
- ),
89
- };
90
- };
91
-
92
- export const randomIntFromInterval = (min: number, max: number) => {
93
- return Math.floor(Math.random() * (max - min + 1) + min);
94
- };
95
-
96
- export const getTokensForChain = (
97
- tokens: Token[],
98
- chainId: number | string | undefined
99
- ) => {
100
- return chainId ? tokens.filter((t) => t.chainId === chainId) : tokens;
101
- };
102
-
103
- export const getFirstAvailableChainId = (
104
- config: AppConfig,
105
- direction: "from" | "to",
106
- chains: ChainData[] | undefined = []
107
- ) => {
108
- // available chains are those that are not coming soon or disabled chains
109
- const availableChains = chains.filter(
110
- (c) =>
111
- !config.comingSoonChainIds?.find((id) => id === c.chainId) &&
112
- !config.disabledChains?.[
113
- direction === "from" ? "source" : "destination"
114
- ]?.some((id) => id === c.chainId)
115
- );
116
-
117
- if (
118
- direction === "from" &&
119
- config.initialAssets?.from &&
120
- availableChains.some(
121
- (c) => c.chainId === String(config.initialAssets?.from?.chainId)
122
- )
123
- ) {
124
- return config.initialAssets.from.chainId;
125
- }
126
-
127
- if (
128
- direction === "to" &&
129
- config.initialAssets?.to &&
130
- availableChains.some(
131
- (c) => c.chainId === String(config.initialAssets?.to?.chainId)
132
- )
133
- ) {
134
- return config.initialAssets.to.chainId;
135
- }
136
-
137
- return availableChains.length > 0 ? availableChains[0].chainId : undefined;
138
- };
139
-
140
- export const getDefaultTokenAddressForChain = (
141
- tokens: Token[],
142
- config: AppConfig,
143
- chainId: number | string | undefined,
144
- unavailableTokenAddress?: string
145
- ): string | undefined => {
146
- const chainIdDefaultToken = config.defaultTokensPerChain?.find(
147
- (token) => token.chainId == chainId
148
- );
149
-
150
- if (
151
- chainIdDefaultToken &&
152
- chainIdDefaultToken.address !== unavailableTokenAddress
153
- ) {
154
- return chainIdDefaultToken.address;
155
- }
156
-
157
- const filteredTokens = chainId
158
- ? tokens.filter(
159
- (t) => t.chainId === chainId && t.address !== unavailableTokenAddress
160
- )
161
- : tokens;
162
-
163
- return filteredTokens.length > 0 ? filteredTokens[0].address : undefined;
164
- };
165
-
166
- /**
167
- * Retrieves the initial token address for a specific chain and direction.
168
- * If no initial assets are set in config, returns the default token address for the chain.
169
- *
170
- * @param tokens - The list of tokens.
171
- * @param config - The application configuration.
172
- * @param chainId - The ID of the chain.
173
- * @param direction - The direction ("from" or "to").
174
- * @returns The initial token address if found; otherwise, the default token address.
175
- */
176
- export const getInitialOrDefaultTokenAddressForChain = ({
177
- chainId,
178
- config,
179
- direction,
180
- tokens,
181
- unavailableTokenAddress,
182
- }: {
183
- tokens: Token[];
184
- config: AppConfig;
185
- chainId: number | string | undefined;
186
- direction: "from" | "to";
187
- unavailableTokenAddress?: string;
188
- }): string | undefined => {
189
- if (
190
- direction === "from" &&
191
- config.initialAssets?.from &&
192
- config.initialAssets.from.chainId === chainId
193
- ) {
194
- return config.initialAssets.from.address;
195
- }
196
-
197
- if (
198
- direction === "to" &&
199
- config.initialAssets?.to &&
200
- config.initialAssets.to.chainId === chainId
201
- ) {
202
- return config.initialAssets.to.address;
203
- }
204
-
205
- return getDefaultTokenAddressForChain(
206
- tokens,
207
- config,
208
- chainId,
209
- unavailableTokenAddress
210
- );
211
- };
212
-
213
- /**
214
- * Filter tokens for destination chain
215
- *
216
- * Case 1: fromToken.bridgeOnly = true
217
- * Destination token list shows only tokens with the same commonKey as fromToken
218
- *
219
- * Case 2: fromToken.bridgeOnly = false
220
- * Destination token list shows all tokens with bridgeOnly = false
221
- * OR Destination token list shows all tokens with the same commonKey as fromToken
222
- * @param tokens
223
- * @param selectedDestinationChain
224
- * @param selectedSourceChainID
225
- * @param selectedSourceToken
226
- * @returns
227
- */
228
- export const filterTokensForDestination = <T extends Token>(
229
- tokens: T[],
230
- selectedDestinationChain: ChainData | undefined,
231
- selectedSourceToken: Token | undefined
232
- ): T[] => {
233
- let filteredTokens = [];
234
-
235
- if (selectedSourceToken?.subGraphOnly) {
236
- filteredTokens = tokens.filter(
237
- (t) =>
238
- shareSubgraphId(t, selectedSourceToken) &&
239
- t.chainId === selectedDestinationChain?.chainId
240
- );
241
- }
242
-
243
- filteredTokens = tokens.filter(
244
- (t) => !t.subGraphOnly || shareSubgraphId(t, selectedSourceToken as Token)
245
- );
246
-
247
- // We don't want to show the same source token & chain in the destination list
248
- // except for Cosmos swaps
249
- return filteredTokens.filter((t) => {
250
- const areSameToken =
251
- t.address === selectedSourceToken?.address &&
252
- t.chainId === selectedSourceToken.chainId;
253
-
254
- // only return tokens that are on the same chain as the destination chain
255
- const isValidChain = t.chainId === selectedDestinationChain?.chainId;
256
- const isCosmosSwap =
257
- selectedDestinationChain?.chainType === ChainType.COSMOS;
258
-
259
- return isValidChain && (isCosmosSwap || !areSameToken);
260
- });
261
- };
@@ -1,93 +0,0 @@
1
- import type { EventListenerFunction, WidgetEventMap } from "@/core/types/event";
2
- import type { RouteResponse } from "@0xsquid/sdk/dist/types";
3
-
4
- export class WidgetEvents extends EventTarget {
5
- private static instance: WidgetEvents;
6
-
7
- private constructor() {
8
- super();
9
- }
10
-
11
- // Singleton, because we need to access this service outside the widget
12
- public static getInstance(): WidgetEvents {
13
- if (!WidgetEvents.instance) {
14
- WidgetEvents.instance = new WidgetEvents();
15
- }
16
- return WidgetEvents.instance;
17
- }
18
-
19
- /**
20
- * Overriding the addEventListener method to make it easier to use with typescript
21
- * @param type
22
- * @param listener
23
- * @param options
24
- */
25
- listenToWidget<T extends keyof WidgetEventMap>(
26
- type: T,
27
- listener: EventListenerFunction<T>,
28
- options?: boolean | AddEventListenerOptions
29
- ) {
30
- super.addEventListener(type, listener as unknown as EventListener, options);
31
- }
32
-
33
- /**
34
- * Overriding the removeEventListener method to make it easier to use with typescript
35
- * @param type
36
- * @param listener
37
- * @param options
38
- */
39
- removeWidgetListener<T extends keyof WidgetEventMap>(
40
- type: T,
41
- listener: EventListenerFunction<T>,
42
- options?: boolean | EventListenerOptions
43
- ) {
44
- super.removeEventListener(
45
- type,
46
- listener as unknown as EventListener,
47
- options
48
- );
49
- }
50
-
51
- /**
52
- * Dispatch an event of the widget
53
- * To be listened from an integrator website
54
- * For example to display a success message when transaction is done
55
- * @param name
56
- * @param data
57
- */
58
- dispatch<T extends keyof WidgetEventMap>(name: T, data: WidgetEventMap[T]) {
59
- this.dispatchEvent(new CustomEvent(name, { detail: data }));
60
- }
61
-
62
- /**
63
- * Will dispatch the main axelar status of transaction
64
- * This will be called every time the status is received by backend
65
- * (Using interval to check status)
66
- * @param status
67
- */
68
- dispatchSwapStatus(status: string) {
69
- this.dispatch("swapStatus", { status });
70
- }
71
-
72
- /**
73
- * Dispatch event when user executes a swap
74
- * Only when we have the tx hash received
75
- * @param route
76
- */
77
- dispatchSwapExecuteCall(route: RouteResponse["route"], txHash: string) {
78
- this.dispatch("swap", { route, txHash });
79
- }
80
-
81
- /**
82
- * Dispatch event when user changes chain/token
83
- * @param swapParams
84
- */
85
- dispatchSwapParamsChanged(swapParams: {
86
- fromChainId?: string;
87
- toChainId?: string;
88
- fromTokenAddress?: string;
89
- toTokenAddress?: string;
90
- }) {
91
- this.dispatch("swapParamsChanged", { ...swapParams });
92
- }
93
- }
@@ -1,10 +0,0 @@
1
- import { BigNumber as BN } from "bignumber.js";
2
-
3
- export const convertTokenAmountToUSD = (
4
- tokenAmount: string,
5
- priceUSD?: string
6
- ) => {
7
- return BN(tokenAmount)
8
- .multipliedBy(priceUSD ?? "0")
9
- .toFixed();
10
- };
@@ -1,255 +0,0 @@
1
- import type {
2
- TransactionHistoryStore,
3
- TransactionParams,
4
- TransactionStatus,
5
- } from "@/core/types/transaction";
6
- import { TransactionType } from "@/core/types/transaction";
7
- import { usePersistStore } from "@/hooks/store/useSquidStore";
8
- import type { ChainData } from "@0xsquid/sdk/dist/types";
9
-
10
- /**
11
- * Helper to find the desired transaction history in array
12
- * @param transactionID
13
- * @returns
14
- */
15
- export const findHistoryItem = (
16
- transactionID: string | undefined
17
- ): TransactionHistoryStore | undefined => {
18
- // TODO: This works but could be improved, persistStore shouldnt be used directly
19
- // Or move this inside a callback hook
20
- return usePersistStore
21
- .getState()
22
- .transactionsHistory?.find((th) => th.transactionId === transactionID);
23
- };
24
-
25
- /**
26
- * Will return the same object but with the desired transaction history
27
- * Status changed
28
- * @param transactionID
29
- * @param status
30
- * @param transactionsHistory
31
- * @param statusResponse
32
- * @returns
33
- */
34
- export const updateTransactionHistoryStatus = (
35
- transactionID: string | undefined,
36
- status: TransactionStatus,
37
- transactionsHistory: TransactionHistoryStore[] | undefined,
38
- statusResponse: any | undefined
39
- ): TransactionHistoryStore[] => {
40
- return (
41
- transactionsHistory?.map((th) => {
42
- // Use the status response from the query if available, if not, use the one from the store
43
- statusResponse = statusResponse ?? th.statusResponse;
44
-
45
- // If the transaction is already in the store and had a different status, update status
46
- if (th.transactionId === transactionID && th.status !== status) {
47
- return {
48
- ...th,
49
- status,
50
- statusResponse,
51
- axelarUrl: statusResponse?.axelarTransactionUrl,
52
- sourceTxExplorerUrl: statusResponse?.fromChain?.transactionUrl,
53
- };
54
- }
55
- return {
56
- ...th,
57
- axelarUrl: statusResponse?.axelarTransactionUrl,
58
- sourceTxExplorerUrl: statusResponse?.fromChain?.transactionUrl,
59
- };
60
- }) ?? []
61
- );
62
- };
63
-
64
- export const replaceTransactionAtNonce = (
65
- nonce: number,
66
- fromAddress: string,
67
- transactionsHistory: TransactionHistoryStore[] | undefined,
68
- TransactionHistoryStore: TransactionHistoryStore
69
- ): TransactionHistoryStore[] => {
70
- const newTransactionsHistory: TransactionHistoryStore[] =
71
- transactionsHistory ?? [];
72
- // Find the transaction with the same nonce and from address
73
- const transactionIndex = transactionsHistory?.findIndex(
74
- (th) => th.nonce === nonce && th.fromAddress === fromAddress
75
- );
76
- // If found, replace it with the new transaction
77
- if (transactionIndex !== undefined && transactionIndex !== -1) {
78
- newTransactionsHistory[transactionIndex] = TransactionHistoryStore;
79
- }
80
-
81
- return newTransactionsHistory;
82
- };
83
-
84
- export const formatTransactionHistoryDate = (
85
- transaction: TransactionHistoryStore | undefined
86
- ): { month: string; day: string } | undefined => {
87
- if (!transaction?.timestamp) return undefined;
88
-
89
- try {
90
- const date = new Date(Number(transaction.timestamp));
91
-
92
- // Format date to: MMM DD. Examples:
93
- // Jan 01
94
- // May 12
95
- const month = new Intl.DateTimeFormat("en-US", { month: "short" }).format(
96
- date
97
- );
98
- const day = date.toLocaleString("en-US", { day: "2-digit" });
99
-
100
- return { month, day };
101
- } catch (error) {
102
- console.error("Error formatting date:", error);
103
- return undefined;
104
- }
105
- };
106
-
107
- export const getAxelarExplorerTxUrl = (
108
- urlPrefix: string | undefined,
109
- routeType: string | undefined,
110
- txID: string
111
- ): string | undefined => {
112
- if (!urlPrefix) {
113
- return undefined;
114
- }
115
- const txType = (routeType as TransactionType) ?? TransactionType.BRIDGE;
116
- if (
117
- txType === TransactionType.CALL_BRIDGE ||
118
- txType === TransactionType.BRIDGE
119
- ) {
120
- return `${urlPrefix}transfer/${txID}`;
121
- }
122
- return `${urlPrefix}gmp/${txID}`;
123
- };
124
-
125
- export const getSourceExplorerTxUrl = (
126
- chain: ChainData | undefined,
127
- txID: string
128
- ): string | undefined => {
129
- if (!chain || !chain.blockExplorerUrls[0]) {
130
- return undefined;
131
- }
132
-
133
- let txSuffix: string;
134
-
135
- switch (chain.chainId) {
136
- case "agoric-3":
137
- txSuffix = "/transactions/";
138
- break;
139
- default:
140
- txSuffix = "/tx/";
141
- }
142
-
143
- if (chain.blockExplorerUrls[0].endsWith("/")) {
144
- txSuffix = txSuffix.slice(1);
145
- }
146
-
147
- return `${chain.blockExplorerUrls[0]}${txSuffix}${txID}`;
148
- };
149
-
150
- export const getMainExplorerUrl = (transaction?: TransactionParams) => {
151
- // The most accurate one is coming from squid /status api
152
- if (transaction?.statusResponse?.axelarTransactionUrl) {
153
- return transaction?.statusResponse.axelarTransactionUrl;
154
- }
155
-
156
- // If not, we can try to get it from the source chain
157
- if (transaction?.sourceTxExplorerUrl) {
158
- return transaction?.sourceTxExplorerUrl;
159
- }
160
-
161
- // If not, we can try to guess it from the transaction type
162
- if (transaction && transaction?.transactionId) {
163
- return getAxelarExplorerTxUrl(
164
- transaction.statusResponse?.axelarTransactionUrl,
165
- transaction.routeType,
166
- transaction.transactionId
167
- );
168
- }
169
-
170
- return undefined;
171
- };
172
-
173
- /**
174
- * A CCTP Transaction is one that is not using Axelar, but using Circle Mint & Burn mechanism
175
- * Squid API is using a different status endpoint to track status of CCTP transactions
176
- * @param transaction
177
- * @returns
178
- */
179
- export const isCCTPBridge = (transaction: TransactionParams | undefined) => {
180
- return (
181
- transaction?.fromChain?.chainId.includes("noble") ||
182
- transaction?.toChain?.chainId.includes("noble")
183
- );
184
- };
185
-
186
- export const formatDistance = (
187
- date: number | Date,
188
- baseDate: number | Date,
189
- options?: {
190
- includeSeconds?: boolean | undefined;
191
- addSuffix?: boolean | undefined;
192
- locale?: Locale | undefined;
193
- }
194
- ): string => {
195
- const {
196
- includeSeconds = false,
197
- addSuffix = false,
198
- locale = { locale: "en-US" },
199
- } = options || {};
200
-
201
- const elapsedMilliseconds = Math.abs(
202
- new Date(date).getTime() - new Date(baseDate).getTime()
203
- );
204
-
205
- const seconds = Math.round(elapsedMilliseconds / 1000);
206
- const minutes = Math.round(seconds / 60);
207
- const hours = Math.round(minutes / 60);
208
- const days = Math.round(hours / 24);
209
- const months = Math.round(days / 30.44);
210
- const years = Math.round(days / 365.25);
211
-
212
- const rtf = new Intl.RelativeTimeFormat(locale.locale, { numeric: "auto" });
213
-
214
- let formatted = "";
215
-
216
- if (includeSeconds && seconds < 45) {
217
- const unit = addSuffix ? "second" : "seconds";
218
- formatted = rtf.format(-seconds, unit);
219
- } else if (minutes < 60) {
220
- formatted = rtf.format(-minutes, "minutes");
221
- } else if (hours < 24) {
222
- formatted = rtf.format(-hours, "hours");
223
- } else if (days < 30) {
224
- formatted = rtf.format(-days, "days");
225
- } else if (months < 12) {
226
- formatted = rtf.format(-months, "months");
227
- } else {
228
- formatted = rtf.format(-years, "years");
229
- }
230
-
231
- // remove "ago" from the string
232
- // before: "2 minutes ago"
233
- // after: "2 minutes"
234
- return addSuffix ? formatted : formatted.replace(/\b(?:ago)\b/, "").trim();
235
- };
236
-
237
- export const formatSeconds = (
238
- seconds: number,
239
- secondsTemplate: string = " seconds",
240
- minutesTemplate: string = " minutes"
241
- ) => {
242
- let duration = "";
243
- if (seconds < 60) {
244
- duration = `${seconds.toString()}${secondsTemplate}`;
245
- } else {
246
- duration = formatDistance(0, seconds * 1000, { includeSeconds: true });
247
- }
248
- return duration
249
- .replace(" minutes", minutesTemplate)
250
- .replace(" minute", minutesTemplate);
251
- };
252
-
253
- interface Locale {
254
- locale?: string;
255
- }