@0xsquid/react-hooks 1.0.4 → 1.0.5
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/assets/images/icons/wallets/index.d.ts +22 -0
- package/{src/assets/images/icons/wallets/index.ts → dist/assets/images/icons/wallets/index.js} +21 -21
- package/dist/assets/images/icons/wallets/index.js.map +1 -0
- package/dist/connectors/ExodusConnector.d.ts +4 -0
- package/{src/connectors/ExodusConnector.ts → dist/connectors/ExodusConnector.js} +3 -3
- package/dist/connectors/ExodusConnector.js.map +1 -0
- package/dist/connectors/LedgerLiveConnector.d.ts +40 -0
- package/dist/connectors/LedgerLiveConnector.js +177 -0
- package/dist/connectors/LedgerLiveConnector.js.map +1 -0
- package/dist/contracts/typechain/factories/ERC20__factory.js +324 -0
- package/dist/contracts/typechain/factories/ERC20__factory.js.map +1 -0
- package/dist/core/constants.d.ts +37 -0
- package/dist/core/constants.js +487 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/externalLinks.d.ts +18 -0
- package/{src/core/externalLinks.ts → dist/core/externalLinks.js} +5 -9
- package/dist/core/externalLinks.js.map +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/multicall3.d.ts +16 -0
- package/dist/core/multicall3.js +23 -0
- package/dist/core/multicall3.js.map +1 -0
- package/dist/core/numbers.d.ts +3 -0
- package/dist/core/numbers.js +28 -0
- package/dist/core/numbers.js.map +1 -0
- package/dist/core/providers/CosmosProvider.d.ts +34 -0
- package/dist/core/providers/CosmosProvider.js +12 -0
- package/dist/core/providers/CosmosProvider.js.map +1 -0
- package/dist/core/queries/queries-keys.d.ts +34 -0
- package/dist/core/queries/queries-keys.js +120 -0
- package/dist/core/queries/queries-keys.js.map +1 -0
- package/dist/core/queries/react-query-config.d.ts +3 -0
- package/dist/core/queries/react-query-config.js +11 -0
- package/dist/core/queries/react-query-config.js.map +1 -0
- package/dist/core/types/components.d.ts +14 -0
- package/dist/core/types/components.js +2 -0
- package/dist/core/types/components.js.map +1 -0
- package/dist/core/types/config.d.ts +47 -0
- package/dist/core/types/config.js +2 -0
- package/dist/core/types/config.js.map +1 -0
- package/dist/core/types/dex.d.ts +28 -0
- package/dist/core/types/dex.js +33 -0
- package/dist/core/types/dex.js.map +1 -0
- package/dist/core/types/error.d.ts +44 -0
- package/dist/core/types/error.js +12 -0
- package/dist/core/types/error.js.map +1 -0
- package/dist/core/types/event.d.ts +17 -0
- package/dist/core/types/event.js +2 -0
- package/dist/core/types/event.js.map +1 -0
- package/dist/core/types/route.d.ts +9 -0
- package/dist/core/types/route.js +4 -0
- package/dist/core/types/route.js.map +1 -0
- package/dist/core/types/swap.d.ts +8 -0
- package/dist/core/types/swap.js +2 -0
- package/dist/core/types/swap.js.map +1 -0
- package/dist/core/types/tokens.d.ts +29 -0
- package/dist/core/types/tokens.js +2 -0
- package/dist/core/types/tokens.js.map +1 -0
- package/dist/core/types/transaction.d.ts +68 -0
- package/dist/core/types/transaction.js +38 -0
- package/dist/core/types/transaction.js.map +1 -0
- package/dist/core/types/types.d.ts +30 -0
- package/dist/core/types/types.js +7 -0
- package/dist/core/types/types.js.map +1 -0
- package/dist/core/types/wallet.d.ts +55 -0
- package/dist/core/types/wallet.js +26 -0
- package/dist/core/types/wallet.js.map +1 -0
- package/dist/hooks/chains/useSquidChains.d.ts +12 -0
- package/dist/hooks/chains/useSquidChains.js +45 -0
- package/dist/hooks/chains/useSquidChains.js.map +1 -0
- package/dist/hooks/cosmos/useCosmos.d.ts +33 -0
- package/dist/hooks/cosmos/useCosmos.js +194 -0
- package/dist/hooks/cosmos/useCosmos.js.map +1 -0
- package/dist/hooks/cosmos/useCosmosForChain.d.ts +4 -0
- package/dist/hooks/cosmos/useCosmosForChain.js +22 -0
- package/dist/hooks/cosmos/useCosmosForChain.js.map +1 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -7
- package/dist/hooks/index.js +27 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/navigation/useKeyboardNavigation.d.ts +7 -0
- package/dist/hooks/navigation/useKeyboardNavigation.js +69 -0
- package/dist/hooks/navigation/useKeyboardNavigation.js.map +1 -0
- package/dist/hooks/store/useSquidStore.d.ts +105 -0
- package/dist/hooks/store/useSquidStore.js +35 -0
- package/dist/hooks/store/useSquidStore.js.map +1 -0
- package/dist/hooks/swap/useSwap.d.ts +25 -0
- package/dist/hooks/swap/useSwap.js +229 -0
- package/dist/hooks/swap/useSwap.js.map +1 -0
- package/dist/hooks/tokens/useAllTokensWithBalance.d.ts +11 -0
- package/dist/hooks/tokens/useAllTokensWithBalance.js +97 -0
- package/dist/hooks/tokens/useAllTokensWithBalance.js.map +1 -0
- package/dist/hooks/tokens/useBalance.d.ts +34 -0
- package/dist/hooks/tokens/useBalance.js +112 -0
- package/dist/hooks/tokens/useBalance.js.map +1 -0
- package/dist/hooks/tokens/useMultiChainBalance.d.ts +17 -0
- package/dist/hooks/tokens/useMultiChainBalance.js +36 -0
- package/dist/hooks/tokens/useMultiChainBalance.js.map +1 -0
- package/dist/hooks/tokens/usePrices.d.ts +6 -0
- package/dist/hooks/tokens/usePrices.js +42 -0
- package/dist/hooks/tokens/usePrices.js.map +1 -0
- package/dist/hooks/tokens/useSingleTokenPrice.d.ts +10 -0
- package/dist/hooks/tokens/useSingleTokenPrice.js +32 -0
- package/dist/hooks/tokens/useSingleTokenPrice.js.map +1 -0
- package/dist/hooks/tokens/useSquidTokens.d.ts +13 -0
- package/dist/hooks/tokens/useSquidTokens.js +35 -0
- package/dist/hooks/tokens/useSquidTokens.js.map +1 -0
- package/dist/hooks/tokens/useTokensWithBalance.d.ts +7 -0
- package/dist/hooks/tokens/useTokensWithBalance.js +111 -0
- package/dist/hooks/tokens/useTokensWithBalance.js.map +1 -0
- package/dist/hooks/transaction/useEstimate.d.ts +44 -0
- package/dist/hooks/transaction/useEstimate.js +274 -0
- package/dist/hooks/transaction/useEstimate.js.map +1 -0
- package/dist/hooks/transaction/useEstimatePriceImpact.d.ts +7 -0
- package/dist/hooks/transaction/useEstimatePriceImpact.js +26 -0
- package/dist/hooks/transaction/useEstimatePriceImpact.js.map +1 -0
- package/dist/hooks/transaction/useExecuteTransaction.d.ts +20 -0
- package/dist/hooks/transaction/useExecuteTransaction.js +310 -0
- package/dist/hooks/transaction/useExecuteTransaction.js.map +1 -0
- package/dist/hooks/transaction/useExpress.d.ts +5 -0
- package/dist/hooks/transaction/useExpress.js +31 -0
- package/dist/hooks/transaction/useExpress.js.map +1 -0
- package/dist/hooks/transaction/useGetRoute.d.ts +14 -0
- package/dist/hooks/transaction/useGetRoute.js +96 -0
- package/dist/hooks/transaction/useGetRoute.js.map +1 -0
- package/dist/hooks/transaction/useSingleTransaction.d.ts +8 -0
- package/dist/hooks/transaction/useSingleTransaction.js +99 -0
- package/dist/hooks/transaction/useSingleTransaction.js.map +1 -0
- package/dist/hooks/transaction/useTransaction.d.ts +25 -0
- package/dist/hooks/transaction/useTransaction.js +521 -0
- package/dist/hooks/transaction/useTransaction.js.map +1 -0
- package/dist/hooks/user/useUserParams.d.ts +6 -0
- package/dist/hooks/user/useUserParams.js +41 -0
- package/dist/hooks/user/useUserParams.js.map +1 -0
- package/dist/hooks/wallet/useAddToken.d.ts +4 -0
- package/dist/hooks/wallet/useAddToken.js +45 -0
- package/dist/hooks/wallet/useAddToken.js.map +1 -0
- package/dist/hooks/wallet/useAutoConnect.d.ts +6 -0
- package/dist/hooks/wallet/useAutoConnect.js +44 -0
- package/dist/hooks/wallet/useAutoConnect.js.map +1 -0
- package/dist/hooks/wallet/useGnosisContext.d.ts +7 -0
- package/dist/hooks/wallet/useGnosisContext.js +70 -0
- package/dist/hooks/wallet/useGnosisContext.js.map +1 -0
- package/dist/hooks/wallet/useIntegratorContext.d.ts +5 -0
- package/dist/hooks/wallet/useIntegratorContext.js +39 -0
- package/dist/hooks/wallet/useIntegratorContext.js.map +1 -0
- package/dist/hooks/wallet/useMultiChainWallet.d.ts +8 -0
- package/dist/hooks/wallet/useMultiChainWallet.js +113 -0
- package/dist/hooks/wallet/useMultiChainWallet.js.map +1 -0
- package/dist/hooks/wallet/useWallet.d.ts +6 -0
- package/dist/hooks/wallet/useWallet.js +65 -0
- package/dist/hooks/wallet/useWallet.js.map +1 -0
- package/dist/hooks/webapp-router/useSquidRouter.d.ts +11 -0
- package/dist/hooks/webapp-router/useSquidRouter.js +33 -0
- package/dist/hooks/webapp-router/useSquidRouter.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +0 -1
- package/dist/index.js.map +1 -0
- package/dist/provider/index.d.ts +10 -0
- package/dist/provider/index.js +71 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/services/external/analyticsService.d.ts +18 -0
- package/dist/services/external/analyticsService.js +30 -0
- package/dist/services/external/analyticsService.js.map +1 -0
- package/dist/services/external/coingeckoService.d.ts +8 -0
- package/dist/services/external/coingeckoService.js +20 -0
- package/dist/services/external/coingeckoService.js.map +1 -0
- package/dist/services/external/rpcService.d.ts +4 -0
- package/dist/services/external/rpcService.js +145 -0
- package/dist/services/external/rpcService.js.map +1 -0
- package/dist/services/external/secretService.d.ts +28 -0
- package/dist/services/external/secretService.js +129 -0
- package/dist/services/external/secretService.js.map +1 -0
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/internal/apiService.d.ts +4 -0
- package/dist/services/internal/apiService.js +7 -0
- package/dist/services/internal/apiService.js.map +1 -0
- package/dist/services/internal/assetsService.d.ts +28 -0
- package/dist/services/internal/assetsService.js +46 -0
- package/dist/services/internal/assetsService.js.map +1 -0
- package/dist/services/internal/configService.d.ts +40 -0
- package/dist/services/internal/configService.js +119 -0
- package/dist/services/internal/configService.js.map +1 -0
- package/dist/services/internal/errorService.d.ts +30 -0
- package/{src/services/internal/errorService.ts → dist/services/internal/errorService.js} +35 -54
- package/dist/services/internal/errorService.js.map +1 -0
- package/dist/services/internal/eventService.d.ts +52 -0
- package/dist/services/internal/eventService.js +66 -0
- package/dist/services/internal/eventService.js.map +1 -0
- package/dist/services/internal/priceService.d.ts +1 -0
- package/dist/services/internal/priceService.js +7 -0
- package/dist/services/internal/priceService.js.map +1 -0
- package/dist/services/internal/transactionService.d.ts +43 -0
- package/dist/services/internal/transactionService.js +172 -0
- package/dist/services/internal/transactionService.js.map +1 -0
- package/dist/services/internal/transactionStatusService.d.ts +28 -0
- package/dist/services/internal/transactionStatusService.js +225 -0
- package/dist/services/internal/transactionStatusService.js.map +1 -0
- package/dist/services/internal/walletService.d.ts +28 -0
- package/dist/services/internal/walletService.js +123 -0
- package/dist/services/internal/walletService.js.map +1 -0
- package/dist/tests/assetsService.test.d.ts +1 -0
- package/dist/tests/assetsService.test.js +130 -0
- package/dist/tests/assetsService.test.js.map +1 -0
- package/dist/tests/configService.test.d.ts +1 -0
- package/dist/tests/configService.test.js +295 -0
- package/dist/tests/configService.test.js.map +1 -0
- package/dist/tests/fetchSquidData.d.ts +6 -0
- package/dist/tests/fetchSquidData.js +27 -0
- package/dist/tests/fetchSquidData.js.map +1 -0
- package/{src/tests/jest-svg-transform.ts → dist/tests/jest-svg-transform.js} +11 -9
- package/dist/tests/jest-svg-transform.js.map +1 -0
- package/dist/tests/sample.json +0 -0
- package/dist/tests/walletService.test.d.ts +1 -0
- package/dist/tests/walletService.test.js +74 -0
- package/dist/tests/walletService.test.js.map +1 -0
- package/package.json +5 -1
- package/.babelrc +0 -7
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -44
- package/CHANGELOG.md +0 -9
- package/jest.config.ts +0 -28
- package/scripts/copyAssets.js +0 -27
- package/scripts/removeBuildTestFolder.js +0 -28
- package/scripts/replacePaths.js +0 -37
- package/src/connectors/LedgerLiveConnector.ts +0 -226
- package/src/contracts/typechain/ERC20.d.ts +0 -441
- package/src/contracts/typechain/factories/ERC20__factory.ts +0 -340
- package/src/core/constants.ts +0 -549
- package/src/core/multicall3.ts +0 -22
- package/src/core/numbers.ts +0 -44
- package/src/core/providers/CosmosProvider.tsx +0 -55
- package/src/core/queries/queries-keys.ts +0 -156
- package/src/core/queries/react-query-config.ts +0 -13
- package/src/core/types/components.ts +0 -16
- package/src/core/types/config.ts +0 -52
- package/src/core/types/dex.ts +0 -31
- package/src/core/types/error.ts +0 -52
- package/src/core/types/event.ts +0 -16
- package/src/core/types/route.ts +0 -21
- package/src/core/types/swap.ts +0 -8
- package/src/core/types/tokens.ts +0 -30
- package/src/core/types/transaction.ts +0 -84
- package/src/core/types/types.ts +0 -37
- package/src/core/types/wallet.ts +0 -83
- package/src/hooks/chains/useSquidChains.ts +0 -66
- package/src/hooks/cosmos/useCosmos.ts +0 -279
- package/src/hooks/cosmos/useCosmosForChain.ts +0 -33
- package/src/hooks/navigation/useKeyboardNavigation.ts +0 -88
- package/src/hooks/store/useSquidStore.ts +0 -80
- package/src/hooks/swap/useSwap.ts +0 -359
- package/src/hooks/tokens/useAllTokensWithBalance.ts +0 -157
- package/src/hooks/tokens/useBalance.ts +0 -180
- package/src/hooks/tokens/useMultiChainBalance.ts +0 -59
- package/src/hooks/tokens/usePrices.ts +0 -52
- package/src/hooks/tokens/useSingleTokenPrice.ts +0 -45
- package/src/hooks/tokens/useSquidTokens.ts +0 -48
- package/src/hooks/tokens/useTokensWithBalance.ts +0 -169
- package/src/hooks/transaction/useEstimate.ts +0 -397
- package/src/hooks/transaction/useEstimatePriceImpact.ts +0 -39
- package/src/hooks/transaction/useExecuteTransaction.ts +0 -440
- package/src/hooks/transaction/useExpress.ts +0 -46
- package/src/hooks/transaction/useGetRoute.ts +0 -145
- package/src/hooks/transaction/useSingleTransaction.ts +0 -155
- package/src/hooks/transaction/useTransaction.ts +0 -734
- package/src/hooks/user/useUserParams.ts +0 -63
- package/src/hooks/wallet/useAddToken.ts +0 -53
- package/src/hooks/wallet/useAutoConnect.ts +0 -56
- package/src/hooks/wallet/useGnosisContext.ts +0 -84
- package/src/hooks/wallet/useIntegratorContext.ts +0 -44
- package/src/hooks/wallet/useMultiChainWallet.ts +0 -146
- package/src/hooks/wallet/useWallet.ts +0 -86
- package/src/hooks/webapp-router/useSquidRouter.ts +0 -42
- package/src/provider/index.tsx +0 -105
- package/src/react-app-env.d.ts +0 -2
- package/src/services/external/analyticsService.ts +0 -46
- package/src/services/external/coingeckoService.ts +0 -35
- package/src/services/external/rpcService.ts +0 -196
- package/src/services/external/secretService.ts +0 -178
- package/src/services/internal/apiService.ts +0 -6
- package/src/services/internal/assetsService.ts +0 -84
- package/src/services/internal/configService.ts +0 -261
- package/src/services/internal/eventService.ts +0 -93
- package/src/services/internal/priceService.ts +0 -10
- package/src/services/internal/transactionService.ts +0 -255
- package/src/services/internal/transactionStatusService.ts +0 -293
- package/src/services/internal/walletService.ts +0 -158
- package/src/tests/assetsService.test.ts +0 -176
- package/src/tests/configService.test.ts +0 -486
- package/src/tests/fetchSquidData.ts +0 -43
- package/src/tests/walletService.test.ts +0 -178
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.json +0 -31
- /package/{src → dist}/assets/images/icons/wallets/binance.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/bitget.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/bitkeep.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/blockchaindotcom.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/brave.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/c98.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/coinbase.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/cosmostation.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/defiConnect.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/exodus.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/fetchai.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/keplr.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/leap.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/metamask.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/okx.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/rabby.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/trustwallet.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/walletConnect.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/wallet_icon.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/xdefi.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/zerion.svg +0 -0
- /package/{src → dist}/contracts/typechain/factories/ERC20__factory.d.ts +0 -0
- /package/{src/core/index.ts → dist/core/index.d.ts} +0 -0
- /package/{src/services/index.ts → dist/services/index.d.ts} +0 -0
- /package/{src/tests/sample.json → dist/tests/jest-svg-transform.d.ts} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SquidRouteError, SquidStatusError, TransactionError, TransactionErrorWithMessage } from "@/core/types/error";
|
|
2
|
+
export declare const transactionErrorCode: Record<string, TransactionErrorWithMessage>;
|
|
3
|
+
/**
|
|
4
|
+
* Check if the error is an EVM transaction error
|
|
5
|
+
* Because Typescript supports casting but that's only for compilation time,
|
|
6
|
+
* We need it at runtime since we're getting the error object from the wallet
|
|
7
|
+
* @param error
|
|
8
|
+
* @returns boolean
|
|
9
|
+
*/
|
|
10
|
+
export declare const isTransactionError: (error: any) => error is TransactionError;
|
|
11
|
+
/**
|
|
12
|
+
* Return the error from enum entry
|
|
13
|
+
* @param error
|
|
14
|
+
* @returns boolean
|
|
15
|
+
*/
|
|
16
|
+
export declare const getTransactionError: (error: any) => TransactionErrorWithMessage;
|
|
17
|
+
/**
|
|
18
|
+
* Check if the error is an Squid route error
|
|
19
|
+
* Because Typescript supports casting but that's only for compilation time,
|
|
20
|
+
* We need it at runtime since we're getting the error object from the wallet
|
|
21
|
+
* @param error
|
|
22
|
+
* @returns boolean
|
|
23
|
+
*/
|
|
24
|
+
export declare const isSwapRouteError: (error: any) => error is SquidRouteError;
|
|
25
|
+
export declare const isStatusError: (error: any) => error is SquidStatusError;
|
|
26
|
+
/**
|
|
27
|
+
* Tries to parse as SquidRouteError Type & Return the error from Record entries
|
|
28
|
+
* @param error
|
|
29
|
+
* @returns string error message
|
|
30
|
+
*/
|
|
@@ -1,39 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
SquidStatusError,
|
|
4
|
-
TransactionError,
|
|
5
|
-
TransactionErrorWithMessage,
|
|
6
|
-
} from "@/core/types/error";
|
|
7
|
-
import { TransactionErrorType } from "@/core/types/error";
|
|
8
|
-
|
|
9
|
-
export const transactionErrorCode: Record<string, TransactionErrorWithMessage> =
|
|
10
|
-
{
|
|
1
|
+
import { TransactionErrorType } from "./../../core/types/error";
|
|
2
|
+
export const transactionErrorCode = {
|
|
11
3
|
// Metamask
|
|
12
4
|
ACTION_REJECTED: {
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
type: TransactionErrorType.REJECTED_BY_USER,
|
|
6
|
+
message: "Return to the swap page and try again.",
|
|
15
7
|
},
|
|
16
8
|
// Keplr
|
|
17
9
|
"Request rejected": {
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
type: TransactionErrorType.REJECTED_BY_USER,
|
|
11
|
+
message: "Return to the swap page and try again.",
|
|
20
12
|
},
|
|
21
13
|
// Metamask
|
|
22
14
|
4001: {
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
type: TransactionErrorType.REJECTED_BY_USER,
|
|
16
|
+
message: "Return to the swap page and try again.",
|
|
25
17
|
},
|
|
26
18
|
CALL_EXCEPTION: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"Swap failed on the source chain. Please let us know by submitting a ticket here.",
|
|
19
|
+
type: TransactionErrorType.CALL_EXCEPTION,
|
|
20
|
+
message: "Swap failed on the source chain. Please let us know by submitting a ticket here.",
|
|
30
21
|
},
|
|
31
22
|
UNKNOWN: {
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
type: TransactionErrorType.UNKNOWN,
|
|
24
|
+
message: "The transaction could not be initiated.",
|
|
34
25
|
},
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
};
|
|
37
27
|
/**
|
|
38
28
|
* Check if the error is an EVM transaction error
|
|
39
29
|
* Because Typescript supports casting but that's only for compilation time,
|
|
@@ -41,34 +31,30 @@ export const transactionErrorCode: Record<string, TransactionErrorWithMessage> =
|
|
|
41
31
|
* @param error
|
|
42
32
|
* @returns boolean
|
|
43
33
|
*/
|
|
44
|
-
export const isTransactionError = (error
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
typeof error.action === "string")
|
|
52
|
-
);
|
|
34
|
+
export const isTransactionError = (error) => {
|
|
35
|
+
return (error &&
|
|
36
|
+
(typeof error.code === "string" ||
|
|
37
|
+
typeof error.code === "number" ||
|
|
38
|
+
typeof error.message === "string" ||
|
|
39
|
+
typeof error.reason === "string" ||
|
|
40
|
+
typeof error.action === "string"));
|
|
53
41
|
};
|
|
54
|
-
|
|
55
42
|
/**
|
|
56
43
|
* Return the error from enum entry
|
|
57
44
|
* @param error
|
|
58
45
|
* @returns boolean
|
|
59
46
|
*/
|
|
60
|
-
export const getTransactionError = (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
47
|
+
export const getTransactionError = (error) => {
|
|
48
|
+
if (isTransactionError(error)) {
|
|
49
|
+
const castError = error;
|
|
50
|
+
if (castError.code)
|
|
51
|
+
return transactionErrorCode[castError.code];
|
|
52
|
+
if (castError.message)
|
|
53
|
+
return transactionErrorCode[castError.message];
|
|
54
|
+
return transactionErrorCode.UNKNOWN;
|
|
55
|
+
}
|
|
67
56
|
return transactionErrorCode.UNKNOWN;
|
|
68
|
-
}
|
|
69
|
-
return transactionErrorCode.UNKNOWN;
|
|
70
57
|
};
|
|
71
|
-
|
|
72
58
|
// --------------------
|
|
73
59
|
// SQUID ROUTE ERRORS
|
|
74
60
|
// --------------------
|
|
@@ -81,7 +67,6 @@ export const getTransactionError = (
|
|
|
81
67
|
// UnknownError: RouteDefaultErrorMsg(),
|
|
82
68
|
// SquidServiceError: RouteDefaultErrorMsg(),
|
|
83
69
|
// };
|
|
84
|
-
|
|
85
70
|
/**
|
|
86
71
|
* Check if the error is an Squid route error
|
|
87
72
|
* Because Typescript supports casting but that's only for compilation time,
|
|
@@ -89,17 +74,13 @@ export const getTransactionError = (
|
|
|
89
74
|
* @param error
|
|
90
75
|
* @returns boolean
|
|
91
76
|
*/
|
|
92
|
-
export const isSwapRouteError = (error
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
(typeof error.code === "string" || typeof error.errorType === "string")
|
|
96
|
-
);
|
|
77
|
+
export const isSwapRouteError = (error) => {
|
|
78
|
+
return (error &&
|
|
79
|
+
(typeof error.code === "string" || typeof error.errorType === "string"));
|
|
97
80
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return error && typeof error.errorType === "string";
|
|
81
|
+
export const isStatusError = (error) => {
|
|
82
|
+
return error && typeof error.errorType === "string";
|
|
101
83
|
};
|
|
102
|
-
|
|
103
84
|
/**
|
|
104
85
|
* Tries to parse as SquidRouteError Type & Return the error from Record entries
|
|
105
86
|
* @param error
|
|
@@ -115,10 +96,10 @@ export const isStatusError = (error: any): error is SquidStatusError => {
|
|
|
115
96
|
// (error.code ?? error.errorType) as SquidRouteErrorType
|
|
116
97
|
// ]
|
|
117
98
|
// : undefined;
|
|
118
|
-
|
|
119
99
|
// if (codeMsg) return codeMsg;
|
|
120
100
|
// // If there is no error code, try to get the error message from backend
|
|
121
101
|
// if (error.message) return error.message;
|
|
122
102
|
// }
|
|
123
103
|
// return squidRouteErrorMapping.Unknown;
|
|
124
104
|
// };
|
|
105
|
+
//# sourceMappingURL=errorService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorService.js","sourceRoot":"","sources":["../../../src/services/internal/errorService.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,o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AC,OAAO,CAAC,CAAC;QACtE,OAAO,oBAAoB,CAAC,OAAO,CAAC;IACtC,CAAC;IACD,OAAO,oBAAoB,CAAC,OAAO,CAAC;AACtC,CAAC,CAAC;AAEF,uBAAuB;AACvB,qBAAqB;AACrB,uBAAuB;AACvB,qDAAqD;AACrD,wCAAwC;AACxC,yBAAyB;AACzB,yBAAyB;AACzB,QAAQ;AACR,qCAAqC;AACrC,0CAA0C;AAC1C,+CAA+C;AAC/C,KAAK;AAEL;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAU,EAA4B,EAAE;IACvE,OAAO,CACL,KAAK;QACL,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,CAAC,CACxE,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAU,EAA6B,EAAE;IACrE,OAAO,KAAK,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,CAAC;AACtD,CAAC,CAAC;AAEF;;;;GAIG;AACH,gCAAgC;AAChC,mFAAmF;AACnF,mCAAmC;AACnC,0DAA0D;AAC1D,sBAAsB;AACtB,sCAAsC;AACtC,oCAAoC;AACpC,qEAAqE;AACrE,cAAc;AACd,uBAAuB;AAEvB,mCAAmC;AACnC,8EAA8E;AAC9E,+CAA+C;AAC/C,MAAM;AACN,2CAA2C;AAC3C,KAAK"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { EventListenerFunction, WidgetEventMap } from "@/core/types/event";
|
|
2
|
+
import type { RouteResponse } from "@0xsquid/sdk/dist/types";
|
|
3
|
+
export declare class WidgetEvents extends EventTarget {
|
|
4
|
+
private static instance;
|
|
5
|
+
private constructor();
|
|
6
|
+
static getInstance(): WidgetEvents;
|
|
7
|
+
/**
|
|
8
|
+
* Overriding the addEventListener method to make it easier to use with typescript
|
|
9
|
+
* @param type
|
|
10
|
+
* @param listener
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
listenToWidget<T extends keyof WidgetEventMap>(type: T, listener: EventListenerFunction<T>, options?: boolean | AddEventListenerOptions): void;
|
|
14
|
+
/**
|
|
15
|
+
* Overriding the removeEventListener method to make it easier to use with typescript
|
|
16
|
+
* @param type
|
|
17
|
+
* @param listener
|
|
18
|
+
* @param options
|
|
19
|
+
*/
|
|
20
|
+
removeWidgetListener<T extends keyof WidgetEventMap>(type: T, listener: EventListenerFunction<T>, options?: boolean | EventListenerOptions): void;
|
|
21
|
+
/**
|
|
22
|
+
* Dispatch an event of the widget
|
|
23
|
+
* To be listened from an integrator website
|
|
24
|
+
* For example to display a success message when transaction is done
|
|
25
|
+
* @param name
|
|
26
|
+
* @param data
|
|
27
|
+
*/
|
|
28
|
+
dispatch<T extends keyof WidgetEventMap>(name: T, data: WidgetEventMap[T]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Will dispatch the main axelar status of transaction
|
|
31
|
+
* This will be called every time the status is received by backend
|
|
32
|
+
* (Using interval to check status)
|
|
33
|
+
* @param status
|
|
34
|
+
*/
|
|
35
|
+
dispatchSwapStatus(status: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Dispatch event when user executes a swap
|
|
38
|
+
* Only when we have the tx hash received
|
|
39
|
+
* @param route
|
|
40
|
+
*/
|
|
41
|
+
dispatchSwapExecuteCall(route: RouteResponse["route"], txHash: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Dispatch event when user changes chain/token
|
|
44
|
+
* @param swapParams
|
|
45
|
+
*/
|
|
46
|
+
dispatchSwapParamsChanged(swapParams: {
|
|
47
|
+
fromChainId?: string;
|
|
48
|
+
toChainId?: string;
|
|
49
|
+
fromTokenAddress?: string;
|
|
50
|
+
toTokenAddress?: string;
|
|
51
|
+
}): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export class WidgetEvents extends EventTarget {
|
|
2
|
+
static instance;
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
}
|
|
6
|
+
// Singleton, because we need to access this service outside the widget
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!WidgetEvents.instance) {
|
|
9
|
+
WidgetEvents.instance = new WidgetEvents();
|
|
10
|
+
}
|
|
11
|
+
return WidgetEvents.instance;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Overriding the addEventListener method to make it easier to use with typescript
|
|
15
|
+
* @param type
|
|
16
|
+
* @param listener
|
|
17
|
+
* @param options
|
|
18
|
+
*/
|
|
19
|
+
listenToWidget(type, listener, options) {
|
|
20
|
+
super.addEventListener(type, listener, options);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Overriding the removeEventListener method to make it easier to use with typescript
|
|
24
|
+
* @param type
|
|
25
|
+
* @param listener
|
|
26
|
+
* @param options
|
|
27
|
+
*/
|
|
28
|
+
removeWidgetListener(type, listener, options) {
|
|
29
|
+
super.removeEventListener(type, listener, options);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Dispatch an event of the widget
|
|
33
|
+
* To be listened from an integrator website
|
|
34
|
+
* For example to display a success message when transaction is done
|
|
35
|
+
* @param name
|
|
36
|
+
* @param data
|
|
37
|
+
*/
|
|
38
|
+
dispatch(name, data) {
|
|
39
|
+
this.dispatchEvent(new CustomEvent(name, { detail: data }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Will dispatch the main axelar status of transaction
|
|
43
|
+
* This will be called every time the status is received by backend
|
|
44
|
+
* (Using interval to check status)
|
|
45
|
+
* @param status
|
|
46
|
+
*/
|
|
47
|
+
dispatchSwapStatus(status) {
|
|
48
|
+
this.dispatch("swapStatus", { status });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Dispatch event when user executes a swap
|
|
52
|
+
* Only when we have the tx hash received
|
|
53
|
+
* @param route
|
|
54
|
+
*/
|
|
55
|
+
dispatchSwapExecuteCall(route, txHash) {
|
|
56
|
+
this.dispatch("swap", { route, txHash });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Dispatch event when user changes chain/token
|
|
60
|
+
* @param swapParams
|
|
61
|
+
*/
|
|
62
|
+
dispatchSwapParamsChanged(swapParams) {
|
|
63
|
+
this.dispatch("swapParamsChanged", { ...swapParams });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=eventService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventService.js","sourceRoot":"","sources":["../../../src/services/internal/eventService.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,YAAa,SAAQ,WAAW;IACnC,MAAM,CAAC,QAAQ,CAAe;IAEtC;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,uEAAuE;IAChE,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC3B,YAAY,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;QAC7C,CAAC;QACD,OAAO,YAAY,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,cAAc,CACZ,IAAO,EACP,QAAkC,EAClC,OAA2C;QAE3C,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAoC,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAClB,IAAO,EACP,QAAkC,EAClC,OAAwC;QAExC,KAAK,CAAC,mBAAmB,CACvB,IAAI,EACJ,QAAoC,EACpC,OAAO,CACR,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAiC,IAAO,EAAE,IAAuB;QACvE,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,MAAc;QAC/B,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,uBAAuB,CAAC,KAA6B,EAAE,MAAc;QACnE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,yBAAyB,CAAC,UAKzB;QACC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC;IACxD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertTokenAmountToUSD: (tokenAmount: string, priceUSD?: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priceService.js","sourceRoot":"","sources":["../../../src/services/internal/priceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,EAAE,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,WAAmB,EACnB,QAAiB,EACjB,EAAE;IACF,OAAO,EAAE,CAAC,WAAW,CAAC;SACnB,YAAY,CAAC,QAAQ,IAAI,GAAG,CAAC;SAC7B,OAAO,EAAE,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { TransactionHistoryStore, TransactionParams, TransactionStatus } from "@/core/types/transaction";
|
|
2
|
+
import type { ChainData } from "@0xsquid/sdk/dist/types";
|
|
3
|
+
/**
|
|
4
|
+
* Helper to find the desired transaction history in array
|
|
5
|
+
* @param transactionID
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const findHistoryItem: (transactionID: string | undefined) => TransactionHistoryStore | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Will return the same object but with the desired transaction history
|
|
11
|
+
* Status changed
|
|
12
|
+
* @param transactionID
|
|
13
|
+
* @param status
|
|
14
|
+
* @param transactionsHistory
|
|
15
|
+
* @param statusResponse
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare const updateTransactionHistoryStatus: (transactionID: string | undefined, status: TransactionStatus, transactionsHistory: TransactionHistoryStore[] | undefined, statusResponse: any | undefined) => TransactionHistoryStore[];
|
|
19
|
+
export declare const replaceTransactionAtNonce: (nonce: number, fromAddress: string, transactionsHistory: TransactionHistoryStore[] | undefined, TransactionHistoryStore: TransactionHistoryStore) => TransactionHistoryStore[];
|
|
20
|
+
export declare const formatTransactionHistoryDate: (transaction: TransactionHistoryStore | undefined) => {
|
|
21
|
+
month: string;
|
|
22
|
+
day: string;
|
|
23
|
+
} | undefined;
|
|
24
|
+
export declare const getAxelarExplorerTxUrl: (urlPrefix: string | undefined, routeType: string | undefined, txID: string) => string | undefined;
|
|
25
|
+
export declare const getSourceExplorerTxUrl: (chain: ChainData | undefined, txID: string) => string | undefined;
|
|
26
|
+
export declare const getMainExplorerUrl: (transaction?: TransactionParams) => any;
|
|
27
|
+
/**
|
|
28
|
+
* A CCTP Transaction is one that is not using Axelar, but using Circle Mint & Burn mechanism
|
|
29
|
+
* Squid API is using a different status endpoint to track status of CCTP transactions
|
|
30
|
+
* @param transaction
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export declare const isCCTPBridge: (transaction: TransactionParams | undefined) => boolean | undefined;
|
|
34
|
+
export declare const formatDistance: (date: number | Date, baseDate: number | Date, options?: {
|
|
35
|
+
includeSeconds?: boolean | undefined;
|
|
36
|
+
addSuffix?: boolean | undefined;
|
|
37
|
+
locale?: Locale | undefined;
|
|
38
|
+
}) => string;
|
|
39
|
+
export declare const formatSeconds: (seconds: number, secondsTemplate?: string, minutesTemplate?: string) => string;
|
|
40
|
+
interface Locale {
|
|
41
|
+
locale?: string;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { TransactionType } from "./../../core/types/transaction";
|
|
2
|
+
import { usePersistStore } from "./../../hooks/store/useSquidStore";
|
|
3
|
+
/**
|
|
4
|
+
* Helper to find the desired transaction history in array
|
|
5
|
+
* @param transactionID
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const findHistoryItem = (transactionID) => {
|
|
9
|
+
// TODO: This works but could be improved, persistStore shouldnt be used directly
|
|
10
|
+
// Or move this inside a callback hook
|
|
11
|
+
return usePersistStore
|
|
12
|
+
.getState()
|
|
13
|
+
.transactionsHistory?.find((th) => th.transactionId === transactionID);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Will return the same object but with the desired transaction history
|
|
17
|
+
* Status changed
|
|
18
|
+
* @param transactionID
|
|
19
|
+
* @param status
|
|
20
|
+
* @param transactionsHistory
|
|
21
|
+
* @param statusResponse
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export const updateTransactionHistoryStatus = (transactionID, status, transactionsHistory, statusResponse) => {
|
|
25
|
+
return (transactionsHistory?.map((th) => {
|
|
26
|
+
// Use the status response from the query if available, if not, use the one from the store
|
|
27
|
+
statusResponse = statusResponse ?? th.statusResponse;
|
|
28
|
+
// If the transaction is already in the store and had a different status, update status
|
|
29
|
+
if (th.transactionId === transactionID && th.status !== status) {
|
|
30
|
+
return {
|
|
31
|
+
...th,
|
|
32
|
+
status,
|
|
33
|
+
statusResponse,
|
|
34
|
+
axelarUrl: statusResponse?.axelarTransactionUrl,
|
|
35
|
+
sourceTxExplorerUrl: statusResponse?.fromChain?.transactionUrl,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
...th,
|
|
40
|
+
axelarUrl: statusResponse?.axelarTransactionUrl,
|
|
41
|
+
sourceTxExplorerUrl: statusResponse?.fromChain?.transactionUrl,
|
|
42
|
+
};
|
|
43
|
+
}) ?? []);
|
|
44
|
+
};
|
|
45
|
+
export const replaceTransactionAtNonce = (nonce, fromAddress, transactionsHistory, TransactionHistoryStore) => {
|
|
46
|
+
const newTransactionsHistory = transactionsHistory ?? [];
|
|
47
|
+
// Find the transaction with the same nonce and from address
|
|
48
|
+
const transactionIndex = transactionsHistory?.findIndex((th) => th.nonce === nonce && th.fromAddress === fromAddress);
|
|
49
|
+
// If found, replace it with the new transaction
|
|
50
|
+
if (transactionIndex !== undefined && transactionIndex !== -1) {
|
|
51
|
+
newTransactionsHistory[transactionIndex] = TransactionHistoryStore;
|
|
52
|
+
}
|
|
53
|
+
return newTransactionsHistory;
|
|
54
|
+
};
|
|
55
|
+
export const formatTransactionHistoryDate = (transaction) => {
|
|
56
|
+
if (!transaction?.timestamp)
|
|
57
|
+
return undefined;
|
|
58
|
+
try {
|
|
59
|
+
const date = new Date(Number(transaction.timestamp));
|
|
60
|
+
// Format date to: MMM DD. Examples:
|
|
61
|
+
// Jan 01
|
|
62
|
+
// May 12
|
|
63
|
+
const month = new Intl.DateTimeFormat("en-US", { month: "short" }).format(date);
|
|
64
|
+
const day = date.toLocaleString("en-US", { day: "2-digit" });
|
|
65
|
+
return { month, day };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error("Error formatting date:", error);
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const getAxelarExplorerTxUrl = (urlPrefix, routeType, txID) => {
|
|
73
|
+
if (!urlPrefix) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const txType = routeType ?? TransactionType.BRIDGE;
|
|
77
|
+
if (txType === TransactionType.CALL_BRIDGE ||
|
|
78
|
+
txType === TransactionType.BRIDGE) {
|
|
79
|
+
return `${urlPrefix}transfer/${txID}`;
|
|
80
|
+
}
|
|
81
|
+
return `${urlPrefix}gmp/${txID}`;
|
|
82
|
+
};
|
|
83
|
+
export const getSourceExplorerTxUrl = (chain, txID) => {
|
|
84
|
+
if (!chain || !chain.blockExplorerUrls[0]) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
let txSuffix;
|
|
88
|
+
switch (chain.chainId) {
|
|
89
|
+
case "agoric-3":
|
|
90
|
+
txSuffix = "/transactions/";
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
txSuffix = "/tx/";
|
|
94
|
+
}
|
|
95
|
+
if (chain.blockExplorerUrls[0].endsWith("/")) {
|
|
96
|
+
txSuffix = txSuffix.slice(1);
|
|
97
|
+
}
|
|
98
|
+
return `${chain.blockExplorerUrls[0]}${txSuffix}${txID}`;
|
|
99
|
+
};
|
|
100
|
+
export const getMainExplorerUrl = (transaction) => {
|
|
101
|
+
// The most accurate one is coming from squid /status api
|
|
102
|
+
if (transaction?.statusResponse?.axelarTransactionUrl) {
|
|
103
|
+
return transaction?.statusResponse.axelarTransactionUrl;
|
|
104
|
+
}
|
|
105
|
+
// If not, we can try to get it from the source chain
|
|
106
|
+
if (transaction?.sourceTxExplorerUrl) {
|
|
107
|
+
return transaction?.sourceTxExplorerUrl;
|
|
108
|
+
}
|
|
109
|
+
// If not, we can try to guess it from the transaction type
|
|
110
|
+
if (transaction && transaction?.transactionId) {
|
|
111
|
+
return getAxelarExplorerTxUrl(transaction.statusResponse?.axelarTransactionUrl, transaction.routeType, transaction.transactionId);
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* A CCTP Transaction is one that is not using Axelar, but using Circle Mint & Burn mechanism
|
|
117
|
+
* Squid API is using a different status endpoint to track status of CCTP transactions
|
|
118
|
+
* @param transaction
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
export const isCCTPBridge = (transaction) => {
|
|
122
|
+
return (transaction?.fromChain?.chainId.includes("noble") ||
|
|
123
|
+
transaction?.toChain?.chainId.includes("noble"));
|
|
124
|
+
};
|
|
125
|
+
export const formatDistance = (date, baseDate, options) => {
|
|
126
|
+
const { includeSeconds = false, addSuffix = false, locale = { locale: "en-US" }, } = options || {};
|
|
127
|
+
const elapsedMilliseconds = Math.abs(new Date(date).getTime() - new Date(baseDate).getTime());
|
|
128
|
+
const seconds = Math.round(elapsedMilliseconds / 1000);
|
|
129
|
+
const minutes = Math.round(seconds / 60);
|
|
130
|
+
const hours = Math.round(minutes / 60);
|
|
131
|
+
const days = Math.round(hours / 24);
|
|
132
|
+
const months = Math.round(days / 30.44);
|
|
133
|
+
const years = Math.round(days / 365.25);
|
|
134
|
+
const rtf = new Intl.RelativeTimeFormat(locale.locale, { numeric: "auto" });
|
|
135
|
+
let formatted = "";
|
|
136
|
+
if (includeSeconds && seconds < 45) {
|
|
137
|
+
const unit = addSuffix ? "second" : "seconds";
|
|
138
|
+
formatted = rtf.format(-seconds, unit);
|
|
139
|
+
}
|
|
140
|
+
else if (minutes < 60) {
|
|
141
|
+
formatted = rtf.format(-minutes, "minutes");
|
|
142
|
+
}
|
|
143
|
+
else if (hours < 24) {
|
|
144
|
+
formatted = rtf.format(-hours, "hours");
|
|
145
|
+
}
|
|
146
|
+
else if (days < 30) {
|
|
147
|
+
formatted = rtf.format(-days, "days");
|
|
148
|
+
}
|
|
149
|
+
else if (months < 12) {
|
|
150
|
+
formatted = rtf.format(-months, "months");
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
formatted = rtf.format(-years, "years");
|
|
154
|
+
}
|
|
155
|
+
// remove "ago" from the string
|
|
156
|
+
// before: "2 minutes ago"
|
|
157
|
+
// after: "2 minutes"
|
|
158
|
+
return addSuffix ? formatted : formatted.replace(/\b(?:ago)\b/, "").trim();
|
|
159
|
+
};
|
|
160
|
+
export const formatSeconds = (seconds, secondsTemplate = " seconds", minutesTemplate = " minutes") => {
|
|
161
|
+
let duration = "";
|
|
162
|
+
if (seconds < 60) {
|
|
163
|
+
duration = `${seconds.toString()}${secondsTemplate}`;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
duration = formatDistance(0, seconds * 1000, { includeSeconds: true });
|
|
167
|
+
}
|
|
168
|
+
return duration
|
|
169
|
+
.replace(" minutes", minutesTemplate)
|
|
170
|
+
.replace(" minute", minutesTemplate);
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=transactionService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionService.js","sourceRoot":"","sources":["../../../src/services/internal/transactionService.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,aAAiC,EACI,EAAE;IACvC,iFAAiF;IACjF,sCAAsC;IACtC,OAAO,eAAe;SACnB,QAAQ,EAAE;SACV,mBAAmB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,aAAa,KAAK,aAAa,CAAC,CAAC;AAC3E,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,aAAiC,EACjC,MAAyB,EACzB,mBAA0D,EAC1D,cAA+B,EACJ,EAAE;IAC7B,OAAO,CACL,mBAAmB,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QAC9B,0FAA0F;QAC1F,cAAc,GAAG,cAAc,IAAI,EAAE,CAAC,cAAc,CAAC;QAErD,uFAAuF;QACvF,IAAI,EAAE,CAAC,aAAa,KAAK,aAAa,IAAI,EAAE,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC/D,OAAO;gBACL,GAAG,EAAE;gBACL,MAAM;gBACN,cAAc;gBACd,SAAS,EAAE,cAAc,EAAE,oBAAoB;gBAC/C,mBAAmB,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc;aAC/D,CAAC;QACJ,CAAC;QACD,OAAO;YACL,GAAG,EAAE;YACL,SAAS,EAAE,cAAc,EAAE,oBAAoB;YAC/C,mBAAmB,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc;SA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C;QACvB,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC5C,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,+BAA+B;IAC/B,0BAA0B;IAC1B,qBAAqB;IACrB,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAe,EACf,kBAA0B,UAAU,EACpC,kBAA0B,UAAU,EACpC,EAAE;IACF,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,OAAO,GAAG,EAAE,EAAE,CAAC;QACjB,QAAQ,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,eAAe,EAAE,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,QAAQ;SACZ,OAAO,CAAC,UAAU,EAAE,eAAe,CAAC;SACpC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StepStatusGetterProps, TransactionParams } from "@/core/types/transaction";
|
|
2
|
+
import { TransactionStatus, TransactionType } from "@/core/types/transaction";
|
|
3
|
+
import type { ChainData, StatusResponse, Token } from "@0xsquid/sdk/dist/types";
|
|
4
|
+
import type { UseQueryResult } from "@tanstack/react-query";
|
|
5
|
+
/**
|
|
6
|
+
* Get the steps for a transaction
|
|
7
|
+
* First step and second step are always the same
|
|
8
|
+
* @param transaction
|
|
9
|
+
* @param statusResponse
|
|
10
|
+
* @returns {TransactionStepStatus[]}
|
|
11
|
+
*/
|
|
12
|
+
export declare const getStepStatuses: ({ transaction, statusResponse, onlyFullStatusStep, }: StepStatusGetterProps) => TransactionStatus[];
|
|
13
|
+
export declare const getHalfSuccessState: (status?: TransactionStatus) => TransactionStatus | undefined;
|
|
14
|
+
export declare const getStepsInfos: ({ fromChain, toChain, fromToken, toToken, amount, txType, transaction, statusResponse, }: {
|
|
15
|
+
txType: TransactionType;
|
|
16
|
+
amount: string;
|
|
17
|
+
fromChain?: ChainData;
|
|
18
|
+
toChain?: ChainData;
|
|
19
|
+
fromToken?: Token;
|
|
20
|
+
toToken?: Token;
|
|
21
|
+
transaction?: TransactionParams;
|
|
22
|
+
statusResponse?: UseQueryResult<StatusResponse, unknown>;
|
|
23
|
+
}) => {
|
|
24
|
+
label: string;
|
|
25
|
+
status: TransactionStatus;
|
|
26
|
+
subTitle?: string;
|
|
27
|
+
link?: string;
|
|
28
|
+
}[];
|