@rango-dev/widget-embedded 0.12.1-next.9 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +5 -2
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.helpers.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +14 -4
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +6 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +94 -17
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +18 -3
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +25 -284
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts +1 -0
- package/dist/components/HeaderButtons/HeaderButtons.types.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HomeButtons.d.ts.map +1 -1
- package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts.map +1 -1
- package/dist/components/HeaderButtons/WalletButton.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +18 -3
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +6 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetailStep.d.ts +4 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetailStep.d.ts.map +1 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.d.ts +3 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.d.ts.map +1 -0
- package/dist/components/{SelectableCategoryList/SelectableCategoryList.styles.d.ts → LoadingSwapDetails/LoadingSwapDetails.styles.d.ts} +21 -6
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.types.d.ts +4 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.types.d.ts.map +1 -0
- package/dist/components/LoadingSwapDetails/index.d.ts +2 -0
- package/dist/components/LoadingSwapDetails/index.d.ts.map +1 -0
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts +18 -3
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +24 -4
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts +24 -4
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.types.d.ts +3 -1
- package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +6 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +23 -151
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/SettingsContainer/index.d.ts +1 -1
- package/dist/components/SettingsContainer/index.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +24 -4
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.Placeholder.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts +2 -9
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +35 -153
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.types.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +6 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +2 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +6 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +2 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +24 -4
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
- package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.helpers.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +207 -9
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.types.d.ts +1 -1
- package/dist/components/TokenList/TokenList.types.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts +6 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +24 -4
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +2 -2
- package/dist/constants/routing.d.ts +12 -2
- package/dist/constants/routing.d.ts.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/globalStyles.d.ts +1 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useNavigateBack.d.ts.map +1 -1
- package/dist/hooks/usePrepareBlockchainList.d.ts +18 -0
- package/dist/hooks/usePrepareBlockchainList.d.ts.map +1 -0
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts +3 -0
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts +3 -6
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders.d.ts +3 -3
- package/dist/hooks/useWalletProviders.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectBlockchainPage.d.ts +1 -2
- package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts +1 -5
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/services/httpService.d.ts +0 -1
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/store/app.d.ts +26 -0
- package/dist/store/app.d.ts.map +1 -0
- package/dist/store/bestRoute.d.ts +4 -8
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/meta.d.ts +0 -2
- package/dist/store/meta.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +8 -0
- package/dist/store/slices/config.d.ts.map +1 -0
- package/dist/store/slices/data.d.ts +26 -0
- package/dist/store/slices/data.d.ts.map +1 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +5 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/meta.d.ts +1 -0
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +3 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +6 -3
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +1 -0
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts +2 -2
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +8 -8
- package/readme.md +3 -1
- package/src/Widget.tsx +22 -3
- package/src/components/AppRouter.tsx +38 -7
- package/src/components/AppRoutes.tsx +4 -28
- package/src/components/BlockchainList/BlockchainList.helpers.ts +1 -1
- package/src/components/BlockchainList/BlockchainList.styles.ts +6 -5
- package/src/components/BlockchainList/BlockchainList.tsx +6 -9
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +29 -42
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +33 -7
- package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +48 -7
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +59 -16
- package/src/components/ConfirmWalletsModal/WalletList.tsx +66 -22
- package/src/components/HeaderButtons/HeaderButtons.styles.ts +2 -2
- package/src/components/HeaderButtons/HeaderButtons.types.ts +1 -0
- package/src/components/HeaderButtons/HomeButtons.tsx +18 -5
- package/src/components/HeaderButtons/UnreadNotificationsBadge.tsx +1 -2
- package/src/components/HeaderButtons/WalletButton.tsx +4 -1
- package/src/components/Layout/Layout.styles.ts +5 -3
- package/src/components/Layout/Layout.tsx +5 -20
- package/src/components/LoadingSwapDetails/LoadingSwapDetailStep.tsx +41 -0
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +78 -0
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +53 -0
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.types.ts +3 -0
- package/src/components/LoadingSwapDetails/index.ts +1 -0
- package/src/components/NoRoutes/NoRoutes.helper.ts +4 -2
- package/src/components/NotificationContent/NotificationContent.tsx +3 -7
- package/src/components/RouteErrors/RouteErrors.styles.ts +2 -1
- package/src/components/RouteErrors/RouteErrors.tsx +37 -26
- package/src/components/RouteErrors/RouteErrors.types.ts +3 -1
- package/src/components/RouteErrors/RouteErrorsModal.tsx +42 -14
- package/src/components/SettingsContainer/SettingsContainer.style.ts +2 -7
- package/src/components/SettingsContainer/index.ts +0 -1
- package/src/components/Slippage/Slippage.tsx +6 -2
- package/src/components/Slippage/SlippageTooltipContent.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +52 -16
- package/src/components/SwapDetails/SwapDetails.helpers.tsx +19 -33
- package/src/components/SwapDetails/SwapDetails.styles.ts +10 -14
- package/src/components/SwapDetails/SwapDetails.tsx +143 -101
- package/src/components/SwapDetails/SwapDetails.types.ts +1 -1
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +5 -4
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +6 -7
- package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +2 -1
- package/src/components/SwapsGroup/SwapsGroup.tsx +3 -2
- package/src/components/SwitchFromAndTo.tsx +1 -35
- package/src/components/TokenList/TokenList.helpers.ts +6 -8
- package/src/components/TokenList/TokenList.styles.ts +7 -1
- package/src/components/TokenList/TokenList.tsx +29 -23
- package/src/components/TokenList/TokenList.types.ts +1 -1
- package/src/components/UpdateUrl.tsx +7 -1
- package/src/components/WidgetEvents.tsx +9 -3
- package/src/constants/errors.ts +2 -2
- package/src/constants/routing.ts +17 -2
- package/src/constants.ts +1 -0
- package/src/globalStyles.ts +1 -4
- package/src/hooks/useFetchBestRoute.ts +2 -2
- package/src/hooks/useNavigateBack.ts +10 -0
- package/src/hooks/usePrepareBlockchainList.ts +125 -0
- package/src/hooks/useSwapInput.ts +17 -3
- package/src/hooks/useSyncStoresWithConfig.ts +102 -0
- package/src/hooks/useTheme.ts +37 -75
- package/src/hooks/useWalletProviders.ts +7 -7
- package/src/pages/ConfirmSwapPage.tsx +65 -36
- package/src/pages/HistoryPage.tsx +2 -2
- package/src/pages/Home.tsx +114 -50
- package/src/pages/LanguagePage.tsx +1 -1
- package/src/pages/LiquiditySourcePage.tsx +22 -18
- package/src/pages/SelectBlockchainPage.tsx +19 -20
- package/src/pages/SelectSwapItemsPage.tsx +66 -88
- package/src/pages/SettingsPage.tsx +42 -15
- package/src/pages/SwapDetailsPage.tsx +9 -2
- package/src/pages/ThemePage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +11 -5
- package/src/services/httpService.ts +4 -5
- package/src/store/app.ts +15 -0
- package/src/store/bestRoute.ts +45 -71
- package/src/store/meta.ts +11 -29
- package/src/store/slices/config.ts +26 -0
- package/src/store/slices/data.ts +203 -0
- package/src/store/wallets.ts +0 -27
- package/src/types/config.ts +3 -0
- package/src/utils/common.ts +3 -0
- package/src/utils/configs.ts +8 -2
- package/src/utils/meta.ts +7 -0
- package/src/utils/numbers.ts +3 -2
- package/src/utils/routing.ts +76 -14
- package/src/utils/settings.ts +15 -0
- package/src/utils/swap.ts +82 -26
- package/src/utils/time.ts +69 -36
- package/src/utils/wallets.ts +49 -29
- package/dist/components/BlockchainsChip/BlockchainsChip.d.ts +0 -5
- package/dist/components/BlockchainsChip/BlockchainsChip.d.ts.map +0 -1
- package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts +0 -151
- package/dist/components/BlockchainsChip/BlockchainsChip.styles.d.ts.map +0 -1
- package/dist/components/BlockchainsChip/BlockchainsChip.types.d.ts +0 -6
- package/dist/components/BlockchainsChip/BlockchainsChip.types.d.ts.map +0 -1
- package/dist/components/BlockchainsChip/index.d.ts +0 -2
- package/dist/components/BlockchainsChip/index.d.ts.map +0 -1
- package/dist/components/BlockchainsSection/BlockchainSection.helpers.d.ts +0 -3
- package/dist/components/BlockchainsSection/BlockchainSection.helpers.d.ts.map +0 -1
- package/dist/components/SelectableCategoryList/SelectableCategoryList.d.ts +0 -4
- package/dist/components/SelectableCategoryList/SelectableCategoryList.d.ts.map +0 -1
- package/dist/components/SelectableCategoryList/SelectableCategoryList.helpers.d.ts +0 -4
- package/dist/components/SelectableCategoryList/SelectableCategoryList.helpers.d.ts.map +0 -1
- package/dist/components/SelectableCategoryList/SelectableCategoryList.styles.d.ts.map +0 -1
- package/dist/components/SelectableCategoryList/SelectableCategoryList.types.d.ts +0 -12
- package/dist/components/SelectableCategoryList/SelectableCategoryList.types.d.ts.map +0 -1
- package/dist/components/SelectableCategoryList/index.d.ts +0 -2
- package/dist/components/SelectableCategoryList/index.d.ts.map +0 -1
- package/src/components/BlockchainsChip/BlockchainsChip.styles.ts +0 -30
- package/src/components/BlockchainsChip/BlockchainsChip.tsx +0 -15
- package/src/components/BlockchainsChip/BlockchainsChip.types.ts +0 -4
- package/src/components/BlockchainsChip/index.ts +0 -1
- package/src/components/BlockchainsSection/BlockchainSection.helpers.ts +0 -20
- package/src/components/SelectableCategoryList/SelectableCategoryList.helpers.ts +0 -20
- package/src/components/SelectableCategoryList/SelectableCategoryList.styles.ts +0 -21
- package/src/components/SelectableCategoryList/SelectableCategoryList.tsx +0 -79
- package/src/components/SelectableCategoryList/SelectableCategoryList.types.ts +0 -12
- package/src/components/SelectableCategoryList/index.ts +0 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// We keep all the received data from server in this slice
|
|
2
|
+
|
|
3
|
+
import type { ConfigSlice } from './config';
|
|
4
|
+
import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
|
|
5
|
+
import type { StateCreator } from 'zustand';
|
|
6
|
+
|
|
7
|
+
import { httpService as sdk } from '../../services/httpService';
|
|
8
|
+
import { containsText } from '../../utils/common';
|
|
9
|
+
import { tokensAreEqual } from '../../utils/wallets';
|
|
10
|
+
|
|
11
|
+
type BlockchainOptions = {
|
|
12
|
+
type?: 'source' | 'destination';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type TokenOptions = {
|
|
16
|
+
type?: 'source' | 'destination';
|
|
17
|
+
// filter by an specific blockchain
|
|
18
|
+
blockchain?: string;
|
|
19
|
+
searchFor?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface DataSlice {
|
|
23
|
+
_blockchains: BlockchainMeta[];
|
|
24
|
+
_tokens: Token[];
|
|
25
|
+
_popularTokens: Token[];
|
|
26
|
+
_swappers: SwapperMeta[];
|
|
27
|
+
|
|
28
|
+
blockchains: (options?: BlockchainOptions) => BlockchainMeta[];
|
|
29
|
+
tokens: (options?: TokenOptions) => Token[];
|
|
30
|
+
isTokenPinned: (token: Token) => boolean;
|
|
31
|
+
|
|
32
|
+
fetch: () => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const createDataSlice: StateCreator<
|
|
36
|
+
DataSlice & ConfigSlice,
|
|
37
|
+
[],
|
|
38
|
+
[],
|
|
39
|
+
DataSlice
|
|
40
|
+
> = (set, get) => ({
|
|
41
|
+
// State
|
|
42
|
+
_blockchains: [],
|
|
43
|
+
_tokens: [],
|
|
44
|
+
_popularTokens: [],
|
|
45
|
+
_swappers: [],
|
|
46
|
+
|
|
47
|
+
// Selectors
|
|
48
|
+
blockchains: (options) => {
|
|
49
|
+
const blockchainsFromState = get()._blockchains;
|
|
50
|
+
|
|
51
|
+
if (!options || !options?.type) {
|
|
52
|
+
return blockchainsFromState;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const config = get().config;
|
|
56
|
+
const supportedBlockchainsFromConfig =
|
|
57
|
+
(options.type === 'source'
|
|
58
|
+
? config.from?.blockchains
|
|
59
|
+
: config.to?.blockchains) ?? [];
|
|
60
|
+
|
|
61
|
+
const list = blockchainsFromState.filter((blockchain) => {
|
|
62
|
+
if (
|
|
63
|
+
supportedBlockchainsFromConfig.length > 0 &&
|
|
64
|
+
!supportedBlockchainsFromConfig.includes(blockchain.name)
|
|
65
|
+
) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return list;
|
|
73
|
+
},
|
|
74
|
+
tokens: (options) => {
|
|
75
|
+
const tokensFromState = get()._tokens;
|
|
76
|
+
|
|
77
|
+
if (!options || !options?.type) {
|
|
78
|
+
return tokensFromState;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const config = get().config;
|
|
82
|
+
const supportedTokensFromConfig =
|
|
83
|
+
(options.type === 'source' ? config.from?.tokens : config.to?.tokens) ??
|
|
84
|
+
[];
|
|
85
|
+
const blockchains = get().blockchains({
|
|
86
|
+
type: options.type,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const list = tokensFromState
|
|
90
|
+
.filter((token) => {
|
|
91
|
+
// If there is a list of tokens in config, we only keep them.
|
|
92
|
+
if (
|
|
93
|
+
supportedTokensFromConfig.length > 0 &&
|
|
94
|
+
!supportedTokensFromConfig.some((asset) => {
|
|
95
|
+
return tokensAreEqual(asset, token);
|
|
96
|
+
})
|
|
97
|
+
) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// If a specific blockchain has passed, we only keep that blockchain's tokens.
|
|
102
|
+
if (!!options.blockchain && token.blockchain !== options.blockchain) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Check only available blockchains
|
|
107
|
+
if (
|
|
108
|
+
!blockchains.some((blockchain) => {
|
|
109
|
+
return blockchain.name === token.blockchain;
|
|
110
|
+
})
|
|
111
|
+
) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Search functionality
|
|
116
|
+
if (options.searchFor) {
|
|
117
|
+
if (
|
|
118
|
+
containsText(token.symbol, options.searchFor) ||
|
|
119
|
+
containsText(token.address || '', options.searchFor) ||
|
|
120
|
+
containsText(token.name || '', options.searchFor)
|
|
121
|
+
) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return true;
|
|
129
|
+
})
|
|
130
|
+
.sort((a, b) => {
|
|
131
|
+
// Check pinned tokens
|
|
132
|
+
if (get().isTokenPinned(a)) {
|
|
133
|
+
return -1;
|
|
134
|
+
}
|
|
135
|
+
if (get().isTokenPinned(b)) {
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Check secondary coins
|
|
140
|
+
if (a.isSecondaryCoin) {
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
if (b.isSecondaryCoin) {
|
|
144
|
+
return -1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Check it has an address or not.
|
|
148
|
+
if (!a.address && b.address) {
|
|
149
|
+
return -1;
|
|
150
|
+
}
|
|
151
|
+
if (a.address && !b.address) {
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return 0;
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return list;
|
|
159
|
+
},
|
|
160
|
+
isTokenPinned: (token) => {
|
|
161
|
+
const pinned = !!get().config.pinnedTokens?.some((pinnedToken) =>
|
|
162
|
+
tokensAreEqual(pinnedToken, token)
|
|
163
|
+
);
|
|
164
|
+
return pinned;
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
// Actions
|
|
168
|
+
fetch: async () => {
|
|
169
|
+
const response = await sdk().getAllMetadata();
|
|
170
|
+
|
|
171
|
+
const blockchains: BlockchainMeta[] = [];
|
|
172
|
+
const tokens: Token[] = [];
|
|
173
|
+
const popularTokens: Token[] = response.popularTokens;
|
|
174
|
+
const swappers: SwapperMeta[] = response.swappers;
|
|
175
|
+
|
|
176
|
+
const blockchainsWithAtLeastOneToken = new Set();
|
|
177
|
+
|
|
178
|
+
response.tokens.forEach((token) => {
|
|
179
|
+
blockchainsWithAtLeastOneToken.add(token.blockchain);
|
|
180
|
+
|
|
181
|
+
tokens.push(token);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
response.blockchains.forEach((blockchain) => {
|
|
185
|
+
if (
|
|
186
|
+
blockchain.enabled &&
|
|
187
|
+
blockchainsWithAtLeastOneToken.has(blockchain.name)
|
|
188
|
+
) {
|
|
189
|
+
blockchains.push(blockchain);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Sort
|
|
194
|
+
blockchains.sort((a, b) => a.sort - b.sort);
|
|
195
|
+
|
|
196
|
+
set({
|
|
197
|
+
_blockchains: blockchains,
|
|
198
|
+
_tokens: tokens,
|
|
199
|
+
_popularTokens: popularTokens,
|
|
200
|
+
_swappers: swappers,
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
});
|
package/src/store/wallets.ts
CHANGED
|
@@ -3,18 +3,14 @@ import type { WalletType } from '@rango-dev/wallets-shared';
|
|
|
3
3
|
|
|
4
4
|
import { create } from 'zustand';
|
|
5
5
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
6
|
-
import { shallow } from 'zustand/shallow';
|
|
7
6
|
|
|
8
7
|
import { httpService } from '../services/httpService';
|
|
9
8
|
import {
|
|
10
|
-
getTokensWithBalance,
|
|
11
9
|
isAccountAndWalletMatched,
|
|
12
10
|
makeBalanceFor,
|
|
13
11
|
resetConnectedWalletState,
|
|
14
|
-
sortTokens,
|
|
15
12
|
} from '../utils/wallets';
|
|
16
13
|
|
|
17
|
-
import { useBestRouteStore } from './bestRoute';
|
|
18
14
|
import { useMetaStore } from './meta';
|
|
19
15
|
import createSelectors from './selectors';
|
|
20
16
|
|
|
@@ -212,28 +208,5 @@ export const useWalletsStore = createSelectors(
|
|
|
212
208
|
)
|
|
213
209
|
);
|
|
214
210
|
|
|
215
|
-
useWalletsStore.subscribe(
|
|
216
|
-
(state) => state.connectedWallets,
|
|
217
|
-
(connectedWallets) => {
|
|
218
|
-
useBestRouteStore.setState(({ sourceTokens, destinationTokens }) => {
|
|
219
|
-
const sourceTokensWithBalance = getTokensWithBalance(
|
|
220
|
-
sourceTokens,
|
|
221
|
-
connectedWallets
|
|
222
|
-
);
|
|
223
|
-
const destinationTokensWithBalance = getTokensWithBalance(
|
|
224
|
-
destinationTokens,
|
|
225
|
-
connectedWallets
|
|
226
|
-
);
|
|
227
|
-
return {
|
|
228
|
-
sourceTokens: sortTokens(sourceTokensWithBalance),
|
|
229
|
-
destinationTokens: sortTokens(destinationTokensWithBalance),
|
|
230
|
-
};
|
|
231
|
-
});
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
equalityFn: shallow,
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
|
|
238
211
|
export const fetchingBalanceSelector = (state: WalletsStore) =>
|
|
239
212
|
!!state.connectedWallets.find((wallet) => wallet.loading);
|
package/src/types/config.ts
CHANGED
|
@@ -38,6 +38,8 @@ export type WidgetColors = {
|
|
|
38
38
|
* border color
|
|
39
39
|
* @property {number} borderRadius - `borderRadius` is a property of the `WidgetTheme` type that
|
|
40
40
|
* specifies the radius of the corners of a widget.
|
|
41
|
+
* @property {number} secondaryBorderRadius - `secondaryBorderRadius` is a property of the `WidgetTheme` type that
|
|
42
|
+
* specifies the radius of the buttons of a widget.
|
|
41
43
|
* @property {number} width - The `width` property is a number that represents the width of the widget.
|
|
42
44
|
* @property {number} height - The `height` property is a number that specifies the height of the widget.
|
|
43
45
|
* @property {boolean} singleTheme - The `singleTheme` property is a boolean that specifies the theme is support dark and light or only light.
|
|
@@ -47,6 +49,7 @@ export type WidgetTheme = {
|
|
|
47
49
|
fontFamily?: string;
|
|
48
50
|
colors?: { light: WidgetColors; dark: WidgetColors };
|
|
49
51
|
borderRadius?: number;
|
|
52
|
+
secondaryBorderRadius?: number;
|
|
50
53
|
width?: number;
|
|
51
54
|
height?: number;
|
|
52
55
|
singleTheme?: boolean;
|
package/src/utils/common.ts
CHANGED
package/src/utils/configs.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { RANGO_PUBLIC_API_KEY } from '../constants';
|
|
2
|
+
|
|
1
3
|
export interface Configs {
|
|
2
4
|
API_KEY: string;
|
|
3
5
|
}
|
|
4
6
|
|
|
5
|
-
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
6
|
-
|
|
7
7
|
let configs: Configs = {
|
|
8
8
|
API_KEY: RANGO_PUBLIC_API_KEY,
|
|
9
9
|
};
|
|
@@ -18,6 +18,9 @@ export function setConfig(name: keyof Configs, value: any) {
|
|
|
18
18
|
return value;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Getting new configs from params and reset the value of global `configs` with provided param.
|
|
23
|
+
*/
|
|
21
24
|
export function initConfig(nextConfigs: Configs) {
|
|
22
25
|
let clonedConfigs;
|
|
23
26
|
if (typeof structuredClone === 'function') {
|
|
@@ -28,3 +31,6 @@ export function initConfig(nextConfigs: Configs) {
|
|
|
28
31
|
configs = clonedConfigs;
|
|
29
32
|
return configs;
|
|
30
33
|
}
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_PRIMARY_RADIUS = 20;
|
|
36
|
+
export const DEFAULT_SECONDARY_RADIUS = 25;
|
package/src/utils/meta.ts
CHANGED
|
@@ -7,3 +7,10 @@ export function getBlockchainDisplayNameFor(
|
|
|
7
7
|
return blockchains.find((blockchain) => blockchain.name === blockchainName)
|
|
8
8
|
?.displayName;
|
|
9
9
|
}
|
|
10
|
+
export function getBlockchainShortNameFor(
|
|
11
|
+
blockchainName: string,
|
|
12
|
+
blockchains: BlockchainMeta[]
|
|
13
|
+
): string | undefined {
|
|
14
|
+
return blockchains.find((blockchain) => blockchain.name === blockchainName)
|
|
15
|
+
?.shortName;
|
|
16
|
+
}
|
package/src/utils/numbers.ts
CHANGED
|
@@ -147,8 +147,9 @@ export function removeExtraDecimals(num: string, maxDecimals: number): string {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
export const totalArrivalTime = (
|
|
151
|
-
data
|
|
150
|
+
export const totalArrivalTime = (
|
|
151
|
+
data: { estimatedTimeInSeconds: number | null }[] | undefined
|
|
152
|
+
) => data?.reduce((a, b) => a + (b.estimatedTimeInSeconds ?? 0), 0) || 0;
|
|
152
153
|
|
|
153
154
|
export const rawFees = (data: BestRouteResponse): string =>
|
|
154
155
|
(
|
package/src/utils/routing.ts
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
2
|
import type { BestRouteEqualityParams, Wallet } from '../types';
|
|
3
3
|
import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
4
|
+
import type { PriceImpactWarningLevel } from '@rango-dev/ui';
|
|
4
5
|
import type {
|
|
5
6
|
SimulationAssetAndAmount,
|
|
6
7
|
SimulationValidationStatus,
|
|
7
8
|
} from '@rango-dev/ui/dist/widget/ui/src/types/swaps';
|
|
8
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
Asset,
|
|
11
|
+
BestRouteResponse,
|
|
12
|
+
BlockchainMeta,
|
|
13
|
+
Token,
|
|
14
|
+
} from 'rango-sdk';
|
|
9
15
|
|
|
10
16
|
import BigNumber from 'bignumber.js';
|
|
11
17
|
|
|
18
|
+
import {
|
|
19
|
+
GAS_FEE_MAX_DECIMALS,
|
|
20
|
+
GAS_FEE_MIN_DECIMALS,
|
|
21
|
+
HIGHT_PRICE_IMPACT,
|
|
22
|
+
LOW_PRICE_IMPACT,
|
|
23
|
+
TOKEN_AMOUNT_MAX_DECIMALS,
|
|
24
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
25
|
+
} from '../constants/routing';
|
|
26
|
+
|
|
12
27
|
import { areEqual } from './common';
|
|
13
28
|
import { numberToString } from './numbers';
|
|
14
29
|
|
|
@@ -149,43 +164,63 @@ export function isRouteParametersChanged(params: BestRouteEqualityParams) {
|
|
|
149
164
|
return false;
|
|
150
165
|
}
|
|
151
166
|
|
|
152
|
-
export function
|
|
167
|
+
export function getFormattedBestRoute(
|
|
153
168
|
bestRoute: BestRouteResponse | null
|
|
154
169
|
): BestRouteResponse | null {
|
|
155
170
|
if (!bestRoute) {
|
|
156
171
|
return null;
|
|
157
172
|
}
|
|
158
173
|
|
|
159
|
-
const
|
|
174
|
+
const formattedSwaps = (bestRoute.result?.swaps || []).map((swap) => ({
|
|
160
175
|
...swap,
|
|
161
|
-
fromAmount: numberToString(
|
|
162
|
-
|
|
176
|
+
fromAmount: numberToString(
|
|
177
|
+
swap.fromAmount,
|
|
178
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
179
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
180
|
+
),
|
|
181
|
+
toAmount: numberToString(
|
|
182
|
+
swap.toAmount,
|
|
183
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
184
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
185
|
+
),
|
|
163
186
|
}));
|
|
164
187
|
|
|
165
188
|
return {
|
|
166
189
|
...bestRoute,
|
|
167
190
|
...(bestRoute.result && {
|
|
168
|
-
result: { ...bestRoute.result, swaps:
|
|
191
|
+
result: { ...bestRoute.result, swaps: formattedSwaps },
|
|
169
192
|
}),
|
|
170
193
|
};
|
|
171
194
|
}
|
|
172
195
|
|
|
173
|
-
export function
|
|
174
|
-
const
|
|
196
|
+
export function getFormattedPendingSwap(pendingSwap: PendingSwap): PendingSwap {
|
|
197
|
+
const formattedSteps = pendingSwap.steps.map((step) => ({
|
|
175
198
|
...step,
|
|
176
|
-
feeInUsd: numberToString(
|
|
177
|
-
|
|
199
|
+
feeInUsd: numberToString(
|
|
200
|
+
step.feeInUsd,
|
|
201
|
+
GAS_FEE_MIN_DECIMALS,
|
|
202
|
+
GAS_FEE_MAX_DECIMALS
|
|
203
|
+
),
|
|
204
|
+
outputAmount: numberToString(
|
|
205
|
+
step.outputAmount,
|
|
206
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
207
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
208
|
+
),
|
|
178
209
|
expectedOutputAmountHumanReadable: numberToString(
|
|
179
210
|
step.expectedOutputAmountHumanReadable,
|
|
180
|
-
|
|
181
|
-
|
|
211
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
212
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
182
213
|
),
|
|
183
214
|
}));
|
|
184
215
|
|
|
185
216
|
return {
|
|
186
217
|
...pendingSwap,
|
|
187
|
-
inputAmount: numberToString(
|
|
188
|
-
|
|
218
|
+
inputAmount: numberToString(
|
|
219
|
+
pendingSwap.inputAmount,
|
|
220
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
221
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
222
|
+
),
|
|
223
|
+
steps: formattedSteps,
|
|
189
224
|
};
|
|
190
225
|
}
|
|
191
226
|
|
|
@@ -199,3 +234,30 @@ export const getBestRouteStatus = (loading: boolean, error: boolean) => {
|
|
|
199
234
|
}
|
|
200
235
|
return 'success';
|
|
201
236
|
};
|
|
237
|
+
|
|
238
|
+
export function getPriceImpactLevel(
|
|
239
|
+
priceImpact: number
|
|
240
|
+
): PriceImpactWarningLevel {
|
|
241
|
+
let warningLevel: PriceImpactWarningLevel = undefined;
|
|
242
|
+
if (priceImpact <= LOW_PRICE_IMPACT && priceImpact > HIGHT_PRICE_IMPACT) {
|
|
243
|
+
warningLevel = 'low';
|
|
244
|
+
} else if (priceImpact <= HIGHT_PRICE_IMPACT) {
|
|
245
|
+
warningLevel = 'high';
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return warningLevel;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function findCommonTokens<T extends Asset[], R extends Asset[]>(
|
|
252
|
+
listA: T,
|
|
253
|
+
listB: R
|
|
254
|
+
) {
|
|
255
|
+
const tokenToString = (token: Asset): string =>
|
|
256
|
+
`${token.symbol}-${token.blockchain}-${token.address ?? ''}`;
|
|
257
|
+
|
|
258
|
+
const set = new Set();
|
|
259
|
+
|
|
260
|
+
listA.forEach((token) => set.add(tokenToString(token)));
|
|
261
|
+
|
|
262
|
+
return listB.filter((token) => set.has(tokenToString(token))) as R;
|
|
263
|
+
}
|
package/src/utils/settings.ts
CHANGED
|
@@ -55,3 +55,18 @@ export function getUniqueSwappersGroups(
|
|
|
55
55
|
|
|
56
56
|
return uniqueSupportedSwappersGroups;
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
export function sortLiquiditySourcesByGroupTitle(
|
|
60
|
+
a: UniqueSwappersGroupType,
|
|
61
|
+
b: UniqueSwappersGroupType
|
|
62
|
+
) {
|
|
63
|
+
if (a.groupTitle < b.groupTitle) {
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (a.groupTitle > b.groupTitle) {
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
package/src/utils/swap.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
Token,
|
|
17
17
|
} from 'rango-sdk';
|
|
18
18
|
|
|
19
|
+
import { i18n } from '@lingui/core';
|
|
19
20
|
import { PendingSwapNetworkStatus } from '@rango-dev/queue-manager-rango-preset';
|
|
20
21
|
import BigNumber from 'bignumber.js';
|
|
21
22
|
|
|
@@ -23,6 +24,12 @@ import { isValidAddress } from '../components/ConfirmWalletsModal/ConfirmWallets
|
|
|
23
24
|
import { errorMessages } from '../constants/errors';
|
|
24
25
|
import { swapButtonTitles } from '../constants/messages';
|
|
25
26
|
import { ZERO } from '../constants/numbers';
|
|
27
|
+
import {
|
|
28
|
+
BALANCE_MAX_DECIMALS,
|
|
29
|
+
BALANCE_MIN_DECIMALS,
|
|
30
|
+
TOKEN_AMOUNT_MAX_DECIMALS,
|
|
31
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
32
|
+
} from '../constants/routing';
|
|
26
33
|
import { useMetaStore } from '../store/meta';
|
|
27
34
|
import { ButtonState } from '../types';
|
|
28
35
|
|
|
@@ -112,26 +119,62 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
112
119
|
let fromAmountRangeError = '';
|
|
113
120
|
let recommendation = '';
|
|
114
121
|
if (!isExclusive && !!minimum && minimum.gt(swap.fromAmount)) {
|
|
115
|
-
fromAmountRangeError =
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
fromAmountRangeError = i18n.t({
|
|
123
|
+
id: 'requiredEqualMin',
|
|
124
|
+
message: 'Required: >= {min} {symbol}',
|
|
125
|
+
values: {
|
|
126
|
+
min: numberToString(
|
|
127
|
+
minimum,
|
|
128
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
129
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
130
|
+
),
|
|
131
|
+
symbol: swap.from.symbol,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
118
134
|
recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
|
|
119
135
|
} else if (isExclusive && !!minimum && minimum.gte(swap.fromAmount)) {
|
|
120
|
-
fromAmountRangeError =
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
fromAmountRangeError = i18n.t({
|
|
137
|
+
id: 'requiredMin',
|
|
138
|
+
message: 'Required: > {min} {symbol}',
|
|
139
|
+
values: {
|
|
140
|
+
min: numberToString(
|
|
141
|
+
minimum,
|
|
142
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
143
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
144
|
+
),
|
|
145
|
+
symbol: swap.from.symbol,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
123
148
|
recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
|
|
124
149
|
}
|
|
125
150
|
|
|
126
151
|
if (!isExclusive && !!maximum && maximum.lt(swap.fromAmount)) {
|
|
127
|
-
fromAmountRangeError =
|
|
128
|
-
|
|
129
|
-
|
|
152
|
+
fromAmountRangeError = i18n.t({
|
|
153
|
+
id: 'requiredEqualMax',
|
|
154
|
+
message: 'Required: <= {max} {symbol}',
|
|
155
|
+
values: {
|
|
156
|
+
max: numberToString(
|
|
157
|
+
maximum,
|
|
158
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
159
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
160
|
+
),
|
|
161
|
+
symbol: swap.from.symbol,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
130
164
|
recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
|
|
131
165
|
} else if (isExclusive && !!maximum && maximum.lte(swap.fromAmount)) {
|
|
132
|
-
fromAmountRangeError =
|
|
133
|
-
|
|
134
|
-
|
|
166
|
+
fromAmountRangeError = i18n.t({
|
|
167
|
+
id: 'requiredMax',
|
|
168
|
+
message: 'Required: < {max} {symbol}',
|
|
169
|
+
values: {
|
|
170
|
+
max: numberToString(
|
|
171
|
+
maximum,
|
|
172
|
+
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
173
|
+
TOKEN_AMOUNT_MAX_DECIMALS
|
|
174
|
+
),
|
|
175
|
+
symbol: swap.from.symbol,
|
|
176
|
+
},
|
|
177
|
+
});
|
|
135
178
|
recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
|
|
136
179
|
}
|
|
137
180
|
|
|
@@ -492,14 +535,14 @@ export function getRouteOutputAmount(route: BestRouteResponse | null) {
|
|
|
492
535
|
}
|
|
493
536
|
|
|
494
537
|
export function getPercentageChange(
|
|
495
|
-
|
|
496
|
-
|
|
538
|
+
inputUsdValue: string | number | null,
|
|
539
|
+
outputUsdValue: string | number | null
|
|
497
540
|
) {
|
|
498
|
-
if (!
|
|
541
|
+
if (!inputUsdValue || !outputUsdValue) {
|
|
499
542
|
return null;
|
|
500
543
|
}
|
|
501
|
-
return new BigNumber(
|
|
502
|
-
.div(new BigNumber(
|
|
544
|
+
return new BigNumber(outputUsdValue)
|
|
545
|
+
.div(new BigNumber(inputUsdValue))
|
|
503
546
|
.minus(1)
|
|
504
547
|
.multipliedBy(100);
|
|
505
548
|
}
|
|
@@ -544,25 +587,37 @@ export function getBalanceWarnings(
|
|
|
544
587
|
new BigNumber(asset.currentAmount.amount).shiftedBy(
|
|
545
588
|
-asset.currentAmount.decimals
|
|
546
589
|
),
|
|
547
|
-
|
|
590
|
+
BALANCE_MIN_DECIMALS,
|
|
591
|
+
BALANCE_MAX_DECIMALS
|
|
548
592
|
);
|
|
549
593
|
const requiredAmount = numberToString(
|
|
550
594
|
new BigNumber(asset.requiredAmount.amount).shiftedBy(
|
|
551
595
|
-asset.requiredAmount.decimals
|
|
552
596
|
),
|
|
553
|
-
|
|
597
|
+
BALANCE_MIN_DECIMALS,
|
|
598
|
+
BALANCE_MAX_DECIMALS
|
|
554
599
|
);
|
|
555
600
|
let reason = '';
|
|
556
601
|
if (asset.reason === 'FEE') {
|
|
557
|
-
reason = ' for network fee';
|
|
602
|
+
reason = i18n.t(' for network fee');
|
|
558
603
|
}
|
|
559
604
|
if (asset.reason === 'INPUT_ASSET') {
|
|
560
|
-
reason = ' for swap';
|
|
605
|
+
reason = i18n.t(' for swap');
|
|
561
606
|
}
|
|
562
607
|
if (asset.reason === 'FEE_AND_INPUT_ASSET') {
|
|
563
|
-
reason = ' for input and network fee';
|
|
608
|
+
reason = i18n.t(' for input and network fee');
|
|
564
609
|
}
|
|
565
|
-
const warningMessage =
|
|
610
|
+
const warningMessage = i18n.t({
|
|
611
|
+
id: 'balanceWarningMessage',
|
|
612
|
+
message: `Needs ≈ {requiredAmount} {symbol}{reason}, but you have {currentAmount} {symbol} in your {blockchain} wallet.`,
|
|
613
|
+
values: {
|
|
614
|
+
requiredAmount,
|
|
615
|
+
symbol,
|
|
616
|
+
reason,
|
|
617
|
+
currentAmount,
|
|
618
|
+
blockchain: asset.asset.blockchain,
|
|
619
|
+
},
|
|
620
|
+
});
|
|
566
621
|
return warningMessage;
|
|
567
622
|
});
|
|
568
623
|
}
|
|
@@ -610,13 +665,14 @@ export function getSwapMessages(
|
|
|
610
665
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
611
666
|
switch (currentStep?.networkStatus) {
|
|
612
667
|
case PendingSwapNetworkStatus.WaitingForConnectingWallet:
|
|
613
|
-
message = message || 'Waiting for connecting wallet';
|
|
668
|
+
message = message || i18n.t('Waiting for connecting wallet');
|
|
614
669
|
break;
|
|
615
670
|
case PendingSwapNetworkStatus.WaitingForQueue:
|
|
616
|
-
message =
|
|
671
|
+
message =
|
|
672
|
+
message || i18n.t('Waiting for other running tasks to be finished');
|
|
617
673
|
break;
|
|
618
674
|
case PendingSwapNetworkStatus.WaitingForNetworkChange:
|
|
619
|
-
message = message || 'Waiting for changing wallet network';
|
|
675
|
+
message = message || i18n.t('Waiting for changing wallet network');
|
|
620
676
|
break;
|
|
621
677
|
default:
|
|
622
678
|
message = message || '';
|