@rango-dev/widget-embedded 0.14.1-next.2 → 0.14.1-next.21
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/Widget.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +8 -0
- 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 +4 -0
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +60 -0
- 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 +12 -0
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +16 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +12 -0
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +4 -0
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +12 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts +12 -0
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +16 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts +16 -0
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +4 -0
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +16 -0
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +16 -0
- 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.styles.d.ts +24 -0
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +4 -0
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +4 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +16 -0
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +40 -0
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +16 -0
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/constants/configs.d.ts +2 -0
- package/dist/constants/configs.d.ts.map +1 -0
- package/dist/constants/errors.d.ts +1 -1
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/constants/fonts.d.ts +2 -0
- package/dist/constants/fonts.d.ts.map +1 -0
- package/dist/{constants.d.ts → constants/index.d.ts} +1 -1
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/languages.d.ts +11 -0
- package/dist/constants/languages.d.ts.map +1 -0
- package/dist/constants/messages.d.ts +1 -1
- package/dist/constants/messages.d.ts.map +1 -1
- package/dist/hooks/useLanguage.d.ts +11 -0
- package/dist/hooks/useLanguage.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/index.d.ts +2 -0
- package/dist/hooks/usePrepareBlockchainList/index.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts +2 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts.map +1 -0
- package/dist/hooks/{usePrepareBlockchainList.d.ts → usePrepareBlockchainList/usePrepareBlockchainList.d.ts} +1 -9
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +10 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts +3 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts +2 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts +11 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts.map +1 -0
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -2
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.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/LanguagePage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/settings.d.ts +15 -6
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +11 -13
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/colors.d.ts +11 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/common.d.ts +0 -4
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +2 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/meta.d.ts +3 -1
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +8 -1
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/utils/ui.d.ts +13 -0
- package/dist/utils/ui.d.ts.map +1 -0
- package/dist/utils/wallets.d.ts +0 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/Widget.tsx +15 -3
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +21 -6
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -11
- package/src/components/ConfirmWalletsModal/WalletList.tsx +35 -24
- package/src/components/Layout/Layout.styles.ts +7 -2
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +1 -1
- package/src/components/NoRoutes/NoRoutes.helper.ts +4 -4
- package/src/components/NoRoutes/NoRoutes.tsx +2 -2
- package/src/components/NotificationContent/NotificationContent.tsx +1 -1
- package/src/components/NotificationContent/NotificationNotFound.tsx +1 -1
- package/src/components/RouteErrors/RouteErrors.tsx +2 -2
- package/src/components/RouteErrors/RouteErrorsModal.tsx +6 -6
- package/src/components/RouteErrors/RouteErrorsModalItem.tsx +1 -1
- package/src/components/Slippage/SlippageTooltipContent.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +5 -6
- package/src/components/SwapDetails/SwapDetails.tsx +6 -10
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +1 -1
- package/src/components/SwapsGroup/SwapsGroup.tsx +2 -2
- package/src/components/TokenList/TokenList.styles.ts +1 -1
- package/src/components/TokenList/TokenList.tsx +2 -2
- package/src/constants/configs.ts +1 -0
- package/src/constants/errors.ts +44 -41
- package/src/constants/fonts.ts +1 -0
- package/src/constants/languages.ts +19 -0
- package/src/constants/messages.ts +7 -5
- package/src/hooks/useConfirmSwap.ts +1 -1
- package/src/hooks/useLanguage.ts +27 -0
- package/src/hooks/usePrepareBlockchainList/index.ts +1 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.ts +1 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.ts +108 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.ts +3101 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.ts +273 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.ts +38 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.ts +12 -0
- package/src/hooks/useSyncStoresWithConfig.ts +49 -1
- package/src/hooks/useTheme.ts +44 -26
- package/src/index.ts +33 -26
- package/src/pages/ConfirmSwapPage.tsx +9 -18
- package/src/pages/Home.tsx +6 -7
- package/src/pages/LanguagePage.tsx +16 -39
- package/src/pages/SettingsPage.tsx +1 -1
- package/src/store/bestRoute.ts +12 -38
- package/src/store/settings.ts +46 -4
- package/src/types/config.ts +10 -12
- package/src/utils/colors.ts +109 -0
- package/src/utils/common.ts +0 -49
- package/src/utils/configs.ts +3 -0
- package/src/utils/hash.ts +27 -0
- package/src/utils/meta.ts +11 -1
- package/src/utils/routing.ts +58 -0
- package/src/utils/settings.ts +1 -1
- package/src/utils/swap.ts +15 -20
- package/src/utils/time.ts +2 -4
- package/src/utils/ui.ts +72 -0
- package/src/utils/wallets.ts +4 -25
- package/dist/constants.d.ts.map +0 -1
- package/dist/hooks/usePrepareBlockchainList.d.ts.map +0 -1
- package/src/hooks/usePrepareBlockchainList.ts +0 -125
- /package/src/{constants.ts → constants/index.ts} +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { PrepareListOptions } from './usePrepareBlockchainList.types';
|
|
2
|
+
import type { BlockchainMeta } from 'rango-sdk';
|
|
3
|
+
|
|
4
|
+
import { MOST_USED_BLOCKChAINS } from './usePrepareBlockchainList.constants';
|
|
5
|
+
|
|
6
|
+
export function prepare(
|
|
7
|
+
blockchains: BlockchainMeta[],
|
|
8
|
+
preferredBlockchains: string[],
|
|
9
|
+
options?: PrepareListOptions
|
|
10
|
+
) {
|
|
11
|
+
/*
|
|
12
|
+
* TODO:
|
|
13
|
+
* We copying the `blockchains` which can causes performance penalties but we should because we are mutating the original object.
|
|
14
|
+
* A better way to solve the problem maybe is using new JS features like Use toSpliced() but
|
|
15
|
+
* we can not use it right now because we need to upgrade our toolings first.
|
|
16
|
+
*/
|
|
17
|
+
const list: BlockchainMeta[] = JSON.parse(JSON.stringify(blockchains));
|
|
18
|
+
let more: BlockchainMeta[] = [];
|
|
19
|
+
|
|
20
|
+
list.sort(sortByMostUsedBlockchains);
|
|
21
|
+
|
|
22
|
+
// Checking `limit` has set and it should be more than of the list items.
|
|
23
|
+
if (!!options?.limit && blockchains.length > options.limit) {
|
|
24
|
+
const start = options.limit;
|
|
25
|
+
let preferredBlockchainsWithoutMainList = preferredBlockchains;
|
|
26
|
+
|
|
27
|
+
if (preferredBlockchains.length <= options.limit) {
|
|
28
|
+
/*
|
|
29
|
+
* For first X (limit) numbers, we need to remove them from preferred if exists.
|
|
30
|
+
*/
|
|
31
|
+
for (let i = 0; i < options.limit; i++) {
|
|
32
|
+
const blockchain = list[i];
|
|
33
|
+
preferredBlockchainsWithoutMainList =
|
|
34
|
+
preferredBlockchainsWithoutMainList.filter((preferredBlockchain) => {
|
|
35
|
+
return blockchain.name !== preferredBlockchain;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
list.sort(
|
|
40
|
+
generateSortByPreferredBlockchainsFor(preferredBlockchainsWithoutMainList)
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Splice will modify the original list and returns the deleted items
|
|
45
|
+
* We use the deleted items as `more`
|
|
46
|
+
*/
|
|
47
|
+
more = list.splice(start);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
list,
|
|
51
|
+
more,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** There is a hardcoded list of blockchains that we want to show them first in the list. */
|
|
56
|
+
export function sortByMostUsedBlockchains(
|
|
57
|
+
a: BlockchainMeta,
|
|
58
|
+
b: BlockchainMeta
|
|
59
|
+
) {
|
|
60
|
+
const mostUsed = MOST_USED_BLOCKChAINS;
|
|
61
|
+
const aIndexInMostUsed = mostUsed.findIndex((token) => token === a.name);
|
|
62
|
+
const bIndexInMostUsed = mostUsed.findIndex((token) => token === b.name);
|
|
63
|
+
const aIsMostUsed = aIndexInMostUsed > -1;
|
|
64
|
+
const bIsMostUsed = bIndexInMostUsed > -1;
|
|
65
|
+
|
|
66
|
+
if (aIsMostUsed && bIsMostUsed) {
|
|
67
|
+
return aIndexInMostUsed > bIndexInMostUsed ? 1 : -1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (aIsMostUsed) {
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (bIsMostUsed) {
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function generateSortByPreferredBlockchainsFor(
|
|
82
|
+
preferredBlockchains: string[]
|
|
83
|
+
) {
|
|
84
|
+
return function sortByPreferred(a: BlockchainMeta, b: BlockchainMeta) {
|
|
85
|
+
const aIndexInPreferred = preferredBlockchains.findIndex(
|
|
86
|
+
(blockchain) => blockchain === a.name
|
|
87
|
+
);
|
|
88
|
+
const bIndexInPreferred = preferredBlockchains.findIndex(
|
|
89
|
+
(blockchain) => blockchain === b.name
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const aIsPreferred = aIndexInPreferred > -1;
|
|
93
|
+
const bIsPreferred = bIndexInPreferred > -1;
|
|
94
|
+
|
|
95
|
+
if (aIsPreferred && bIsPreferred) {
|
|
96
|
+
return aIndexInPreferred > bIndexInPreferred ? 1 : -1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (preferredBlockchains.includes(a.name)) {
|
|
100
|
+
return -1;
|
|
101
|
+
}
|
|
102
|
+
if (preferredBlockchains.includes(b.name)) {
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return 0;
|
|
107
|
+
};
|
|
108
|
+
}
|