@rango-dev/widget-embedded 0.14.1-next.8 → 0.15.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 +29 -0
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +2 -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 +1 -0
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +15 -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 +3 -0
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +4 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +3 -0
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -0
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +3 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts +3 -0
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +4 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts +4 -0
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +1 -0
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +4 -0
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +4 -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 +6 -0
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +1 -0
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +4 -0
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +10 -0
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +4 -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/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 +1 -1
- package/dist/hooks/useTheme.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/settings.d.ts +15 -6
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +7 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/colors.d.ts +1 -1
- package/dist/utils/colors.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/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 +8 -8
- package/src/Widget.tsx +14 -2
- 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 +1 -1
- package/src/constants/configs.ts +1 -0
- package/src/constants/errors.ts +44 -41
- 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 +34 -56
- 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/settings.ts +46 -4
- package/src/types/config.ts +6 -2
- package/src/utils/colors.ts +16 -0
- package/src/utils/configs.ts +3 -0
- package/src/utils/hash.ts +27 -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/hooks/usePrepareBlockchainList.d.ts.map +0 -1
- package/src/hooks/usePrepareBlockchainList.ts +0 -125
|
@@ -6,57 +6,34 @@ import {
|
|
|
6
6
|
RadioRoot,
|
|
7
7
|
Typography,
|
|
8
8
|
} from '@rango-dev/ui';
|
|
9
|
-
import React
|
|
9
|
+
import React from 'react';
|
|
10
10
|
|
|
11
11
|
import { Layout } from '../components/Layout';
|
|
12
12
|
import { SettingsContainer } from '../components/SettingsContainer';
|
|
13
13
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
14
|
+
import { useLanguage } from '../hooks/useLanguage';
|
|
14
15
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
15
16
|
|
|
16
|
-
enum Languages {
|
|
17
|
-
ENGLISH = 'english',
|
|
18
|
-
FRENCH = 'french',
|
|
19
|
-
SPANISH = 'spanish',
|
|
20
|
-
}
|
|
21
17
|
export function LanguagePage() {
|
|
22
18
|
const { navigateBackFrom } = useNavigateBack();
|
|
23
|
-
const [language, setLanguage] = useState(Languages.ENGLISH);
|
|
24
19
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
</Typography>
|
|
33
|
-
),
|
|
34
|
-
onClick: () => setLanguage(Languages.ENGLISH),
|
|
35
|
-
end: <Radio value={Languages.ENGLISH} />,
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: Languages.FRENCH,
|
|
39
|
-
value: Languages.FRENCH,
|
|
40
|
-
title: (
|
|
41
|
-
<Typography variant="title" size="xmedium">
|
|
42
|
-
{i18n.t('French')}
|
|
43
|
-
</Typography>
|
|
44
|
-
),
|
|
45
|
-
onClick: () => setLanguage(Languages.FRENCH),
|
|
46
|
-
end: <Radio value={Languages.FRENCH} />,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: Languages.SPANISH,
|
|
50
|
-
value: Languages.SPANISH,
|
|
20
|
+
const { activeLanguage, changeLanguage, languages } = useLanguage();
|
|
21
|
+
|
|
22
|
+
const languageList = languages.map((languageItem) => {
|
|
23
|
+
const { local, label, SVGFlag } = languageItem;
|
|
24
|
+
return {
|
|
25
|
+
id: local,
|
|
26
|
+
value: local,
|
|
51
27
|
title: (
|
|
52
28
|
<Typography variant="title" size="xmedium">
|
|
53
|
-
{
|
|
29
|
+
{label}
|
|
54
30
|
</Typography>
|
|
55
31
|
),
|
|
56
|
-
onClick: () =>
|
|
57
|
-
end: <Radio value={
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
onClick: () => changeLanguage(languageItem.local),
|
|
33
|
+
end: <Radio value={local} />,
|
|
34
|
+
start: <SVGFlag />,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
60
37
|
|
|
61
38
|
return (
|
|
62
39
|
<Layout
|
|
@@ -65,7 +42,7 @@ export function LanguagePage() {
|
|
|
65
42
|
title: i18n.t('Language'),
|
|
66
43
|
}}>
|
|
67
44
|
<SettingsContainer>
|
|
68
|
-
<RadioRoot value={
|
|
45
|
+
<RadioRoot value={activeLanguage}>
|
|
69
46
|
<List
|
|
70
47
|
type={
|
|
71
48
|
<ListItemButton
|
|
@@ -147,7 +147,7 @@ export function SettingsPage({ supportedSwappers, singleTheme }: PropTypes) {
|
|
|
147
147
|
container={getContainer()}
|
|
148
148
|
content={
|
|
149
149
|
<TooltipContainer>
|
|
150
|
-
<Typography variant="label" size="medium" color="
|
|
150
|
+
<Typography variant="label" size="medium" color="neutral700">
|
|
151
151
|
{i18n.t(
|
|
152
152
|
"Enabling the 'Infinite Approval' mode grants unrestricted access to smart contracts of DEXes/Bridges, allowing them to utilize the approved token amount without limitations."
|
|
153
153
|
)}
|
package/src/store/settings.ts
CHANGED
|
@@ -1,40 +1,50 @@
|
|
|
1
|
+
import { type Language } from '@rango-dev/ui';
|
|
1
2
|
import { create } from 'zustand';
|
|
2
3
|
import { persist, subscribeWithSelector } from 'zustand/middleware';
|
|
3
4
|
|
|
5
|
+
import { BLOCKCHAIN_LIST_SIZE } from '../constants/configs';
|
|
6
|
+
import { DEFAULT_LANGUAGE } from '../constants/languages';
|
|
4
7
|
import { DEFAULT_SLIPPAGE } from '../constants/swapSettings';
|
|
5
8
|
import { removeDuplicateFrom } from '../utils/common';
|
|
6
9
|
|
|
7
10
|
import { useMetaStore } from './meta';
|
|
8
11
|
import createSelectors from './selectors';
|
|
9
12
|
|
|
10
|
-
type
|
|
13
|
+
export type ThemeMode = 'auto' | 'dark' | 'light';
|
|
11
14
|
|
|
12
15
|
export interface SettingsState {
|
|
16
|
+
/** Keeping a history of blockchains that user has selected (in Swap process) */
|
|
17
|
+
preferredBlockchains: string[];
|
|
13
18
|
slippage: number;
|
|
14
19
|
customSlippage: number | null;
|
|
15
20
|
infiniteApprove: boolean;
|
|
16
21
|
disabledLiquiditySources: string[];
|
|
17
|
-
theme:
|
|
22
|
+
theme: ThemeMode;
|
|
23
|
+
language: Language;
|
|
18
24
|
affiliateRef: string | null;
|
|
19
25
|
affiliatePercent: number | null;
|
|
20
26
|
affiliateWallets: { [key: string]: string } | null;
|
|
27
|
+
|
|
21
28
|
setSlippage: (slippage: number) => void;
|
|
22
29
|
setCustomSlippage: (customSlippage: number | null) => void;
|
|
23
30
|
toggleInfiniteApprove: () => void;
|
|
24
31
|
toggleLiquiditySource: (name: string) => void;
|
|
25
|
-
setTheme: (theme:
|
|
32
|
+
setTheme: (theme: ThemeMode) => void;
|
|
33
|
+
setLanguage: (language: Language) => void;
|
|
26
34
|
toggleAllLiquiditySources: (shouldReset?: boolean) => void;
|
|
27
35
|
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
28
36
|
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
29
37
|
setAffiliateWallets: (
|
|
30
38
|
affiliateWallets: { [key: string]: string } | null
|
|
31
39
|
) => void;
|
|
40
|
+
addPreferredBlockchain: (blockchain: string) => void;
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
export const useSettingsStore = createSelectors(
|
|
35
44
|
create<SettingsState>()(
|
|
36
45
|
persist(
|
|
37
|
-
subscribeWithSelector((set) => ({
|
|
46
|
+
subscribeWithSelector((set, get) => ({
|
|
47
|
+
preferredBlockchains: [],
|
|
38
48
|
slippage: DEFAULT_SLIPPAGE,
|
|
39
49
|
customSlippage: null,
|
|
40
50
|
infiniteApprove: false,
|
|
@@ -43,6 +53,34 @@ export const useSettingsStore = createSelectors(
|
|
|
43
53
|
affiliateWallets: null,
|
|
44
54
|
disabledLiquiditySources: [],
|
|
45
55
|
theme: 'auto',
|
|
56
|
+
language: DEFAULT_LANGUAGE,
|
|
57
|
+
addPreferredBlockchain: (blockchain) => {
|
|
58
|
+
const currentPreferredBlockchains = get().preferredBlockchains;
|
|
59
|
+
|
|
60
|
+
const noNeedToDoAnything = currentPreferredBlockchains.find(
|
|
61
|
+
(preferredBlockchain, index) => {
|
|
62
|
+
const isSameBlockchain = preferredBlockchain === blockchain;
|
|
63
|
+
const isInVisibleList = index <= BLOCKCHAIN_LIST_SIZE - 1;
|
|
64
|
+
|
|
65
|
+
return isSameBlockchain && isInVisibleList;
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (noNeedToDoAnything) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const nextPreferredBlockchains: string[] =
|
|
74
|
+
currentPreferredBlockchains.filter((preferredBlockchain) => {
|
|
75
|
+
const isSameBlockchain = preferredBlockchain === blockchain;
|
|
76
|
+
|
|
77
|
+
return !isSameBlockchain;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
set(() => ({
|
|
81
|
+
preferredBlockchains: [blockchain, ...nextPreferredBlockchains],
|
|
82
|
+
}));
|
|
83
|
+
},
|
|
46
84
|
setSlippage: (slippage) =>
|
|
47
85
|
set(() => ({
|
|
48
86
|
slippage: slippage,
|
|
@@ -106,6 +144,10 @@ export const useSettingsStore = createSelectors(
|
|
|
106
144
|
set(() => ({
|
|
107
145
|
theme,
|
|
108
146
|
})),
|
|
147
|
+
setLanguage: (language) =>
|
|
148
|
+
set(() => ({
|
|
149
|
+
language,
|
|
150
|
+
})),
|
|
109
151
|
})),
|
|
110
152
|
{
|
|
111
153
|
name: 'user-settings',
|
package/src/types/config.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type WidgetColors = {
|
|
|
18
18
|
neutral?: string;
|
|
19
19
|
primary?: string;
|
|
20
20
|
secondary?: string;
|
|
21
|
+
info?: string;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -26,7 +27,7 @@ export type WidgetColors = {
|
|
|
26
27
|
* @property {'auto' | 'light' | 'dark'} mode - The mode property is used to specify the default theme for
|
|
27
28
|
* the widget.
|
|
28
29
|
* @property {string} fontFamily - The font family to be used in the widget.
|
|
29
|
-
* @property {
|
|
30
|
+
* @property {{ light?: WidgetColors; dark?: WidgetColors }} colors - The `colors` property is a sub-property of the `WidgetTheme` object that
|
|
30
31
|
* defines the color scheme for the widget. It is of type `Colors`, which is likely another object that
|
|
31
32
|
* contains specific color values for various parts of the widget (e.g. background color, text color,
|
|
32
33
|
* border color
|
|
@@ -41,7 +42,7 @@ export type WidgetColors = {
|
|
|
41
42
|
export type WidgetTheme = {
|
|
42
43
|
mode?: 'auto' | 'light' | 'dark';
|
|
43
44
|
fontFamily?: string;
|
|
44
|
-
colors?: { light
|
|
45
|
+
colors?: { light?: WidgetColors; dark?: WidgetColors };
|
|
45
46
|
borderRadius?: number;
|
|
46
47
|
secondaryBorderRadius?: number;
|
|
47
48
|
width?: number;
|
|
@@ -120,6 +121,8 @@ export type BlockchainAndTokenConfig = {
|
|
|
120
121
|
* If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
|
|
121
122
|
* @property {Asset} pinnedTokens - The `pinnedTokens` property is an optional array of `Asset` objects that
|
|
122
123
|
* you could use to pin tokens of your choice to the top of the token list.
|
|
124
|
+
* @property {boolean} includeNewLiquiditySources - The `includeNewLiquiditySources` property is a boolean value that when you
|
|
125
|
+
* set it to true, whenever a new liquidity source is added, it will be added to your list as well.
|
|
123
126
|
*/
|
|
124
127
|
export type WidgetConfig = {
|
|
125
128
|
apiKey: string;
|
|
@@ -136,4 +139,5 @@ export type WidgetConfig = {
|
|
|
136
139
|
theme?: WidgetTheme;
|
|
137
140
|
externalWallets?: boolean;
|
|
138
141
|
pinnedTokens?: Asset[];
|
|
142
|
+
includeNewLiquiditySources?: boolean;
|
|
139
143
|
};
|
package/src/utils/colors.ts
CHANGED
|
@@ -64,6 +64,7 @@ export const generateRangeColors = (name: string, color: string) => {
|
|
|
64
64
|
};
|
|
65
65
|
export const generateColors = (
|
|
66
66
|
mainColors: { [x: string]: string },
|
|
67
|
+
reverseNeutralRange: boolean,
|
|
67
68
|
colors?: WidgetColors
|
|
68
69
|
) => {
|
|
69
70
|
if (!colors || !Object.entries(colors).length) {
|
|
@@ -81,6 +82,21 @@ export const generateColors = (
|
|
|
81
82
|
...listOfColors,
|
|
82
83
|
[colorKey]: color,
|
|
83
84
|
};
|
|
85
|
+
} else if (colorKey === 'neutral' && reverseNeutralRange) {
|
|
86
|
+
const range = generateRangeColors(colorKey, color);
|
|
87
|
+
listOfColors = {
|
|
88
|
+
...listOfColors,
|
|
89
|
+
// Reverse the neutral shade
|
|
90
|
+
[`${colorKey}100`]: range[`${colorKey}900`],
|
|
91
|
+
[`${colorKey}200`]: range[`${colorKey}800`],
|
|
92
|
+
[`${colorKey}300`]: range[`${colorKey}700`],
|
|
93
|
+
[`${colorKey}400`]: range[`${colorKey}600`],
|
|
94
|
+
[`${colorKey}500`]: range[`${colorKey}500`],
|
|
95
|
+
[`${colorKey}600`]: range[`${colorKey}400`],
|
|
96
|
+
[`${colorKey}700`]: range[`${colorKey}300`],
|
|
97
|
+
[`${colorKey}800`]: range[`${colorKey}200`],
|
|
98
|
+
[`${colorKey}900`]: range[`${colorKey}100`],
|
|
99
|
+
};
|
|
84
100
|
} else {
|
|
85
101
|
listOfColors = {
|
|
86
102
|
...listOfColors,
|
package/src/utils/configs.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
// Original Code: https://github.com/stitchesjs/stitches/blob/canary/packages/core/src/convert/toHash.js
|
|
3
|
+
|
|
4
|
+
const toAlphabeticChar = (code: number) =>
|
|
5
|
+
String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
6
|
+
|
|
7
|
+
const toAlphabeticName = (code: number) => {
|
|
8
|
+
let name = '';
|
|
9
|
+
let x;
|
|
10
|
+
|
|
11
|
+
for (x = Math.abs(code); x > 52; x = (x / 52) | 0) {
|
|
12
|
+
name = toAlphabeticChar(x % 52) + name;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return toAlphabeticChar(x % 52) + name;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const toPhash = (h: number, x: string) => {
|
|
19
|
+
let i = x.length;
|
|
20
|
+
while (i) {
|
|
21
|
+
h = (h * 33) ^ x.charCodeAt(--i);
|
|
22
|
+
}
|
|
23
|
+
return h;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const toHash = (value: object) =>
|
|
27
|
+
toAlphabeticName(toPhash(5381, JSON.stringify(value)) >>> 0);
|
package/src/utils/settings.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function getUniqueSwappersGroups(
|
|
|
33
33
|
let isSupportedSwapper = true;
|
|
34
34
|
if (supportedSwappers) {
|
|
35
35
|
isSupportedSwapper = supportedSwappers.some(
|
|
36
|
-
(supportedItem) => supportedItem === swapperItem.
|
|
36
|
+
(supportedItem) => supportedItem === swapperItem.swapperGroup
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
package/src/utils/swap.ts
CHANGED
|
@@ -120,8 +120,7 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
120
120
|
let recommendation = '';
|
|
121
121
|
if (!isExclusive && !!minimum && minimum.gt(swap.fromAmount)) {
|
|
122
122
|
fromAmountRangeError = i18n.t({
|
|
123
|
-
id: '
|
|
124
|
-
message: 'Required: >= {min} {symbol}',
|
|
123
|
+
id: 'Required: >= {min} {symbol}',
|
|
125
124
|
values: {
|
|
126
125
|
min: numberToString(
|
|
127
126
|
minimum,
|
|
@@ -131,11 +130,10 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
131
130
|
symbol: swap.from.symbol,
|
|
132
131
|
},
|
|
133
132
|
});
|
|
134
|
-
recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
|
|
133
|
+
recommendation = errorMessages().bridgeLimitErrors.increaseAmount;
|
|
135
134
|
} else if (isExclusive && !!minimum && minimum.gte(swap.fromAmount)) {
|
|
136
135
|
fromAmountRangeError = i18n.t({
|
|
137
|
-
id: '
|
|
138
|
-
message: 'Required: > {min} {symbol}',
|
|
136
|
+
id: 'Required: > {min} {symbol}',
|
|
139
137
|
values: {
|
|
140
138
|
min: numberToString(
|
|
141
139
|
minimum,
|
|
@@ -145,13 +143,12 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
145
143
|
symbol: swap.from.symbol,
|
|
146
144
|
},
|
|
147
145
|
});
|
|
148
|
-
recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
|
|
146
|
+
recommendation = errorMessages().bridgeLimitErrors.increaseAmount;
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
if (!isExclusive && !!maximum && maximum.lt(swap.fromAmount)) {
|
|
152
150
|
fromAmountRangeError = i18n.t({
|
|
153
|
-
id: '
|
|
154
|
-
message: 'Required: <= {max} {symbol}',
|
|
151
|
+
id: 'Required: <= {max} {symbol}',
|
|
155
152
|
values: {
|
|
156
153
|
max: numberToString(
|
|
157
154
|
maximum,
|
|
@@ -161,11 +158,10 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
161
158
|
symbol: swap.from.symbol,
|
|
162
159
|
},
|
|
163
160
|
});
|
|
164
|
-
recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
|
|
161
|
+
recommendation = errorMessages().bridgeLimitErrors.decreaseAmount;
|
|
165
162
|
} else if (isExclusive && !!maximum && maximum.lte(swap.fromAmount)) {
|
|
166
163
|
fromAmountRangeError = i18n.t({
|
|
167
|
-
id: '
|
|
168
|
-
message: 'Required: < {max} {symbol}',
|
|
164
|
+
id: 'Required: < {max} {symbol}',
|
|
169
165
|
values: {
|
|
170
166
|
max: numberToString(
|
|
171
167
|
maximum,
|
|
@@ -175,7 +171,7 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
175
171
|
symbol: swap.from.symbol,
|
|
176
172
|
},
|
|
177
173
|
});
|
|
178
|
-
recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
|
|
174
|
+
recommendation = errorMessages().bridgeLimitErrors.decreaseAmount;
|
|
179
175
|
}
|
|
180
176
|
|
|
181
177
|
return { swap, fromAmountRangeError, recommendation };
|
|
@@ -194,14 +190,14 @@ export function getSwapButtonState(
|
|
|
194
190
|
): SwapButtonState {
|
|
195
191
|
if (loadingMetaStatus !== 'success') {
|
|
196
192
|
return {
|
|
197
|
-
title: swapButtonTitles.connectWallet,
|
|
193
|
+
title: swapButtonTitles().connectWallet,
|
|
198
194
|
state: ButtonState.WAITFORCONNECTING,
|
|
199
195
|
disabled: true,
|
|
200
196
|
};
|
|
201
197
|
}
|
|
202
198
|
if (connectedWallets.length == 0) {
|
|
203
199
|
return {
|
|
204
|
-
title: swapButtonTitles.connectWallet,
|
|
200
|
+
title: swapButtonTitles().connectWallet,
|
|
205
201
|
state: ButtonState.WAITFORCONNECTING,
|
|
206
202
|
disabled: false,
|
|
207
203
|
};
|
|
@@ -215,27 +211,27 @@ export function getSwapButtonState(
|
|
|
215
211
|
inputAmount === '0'
|
|
216
212
|
) {
|
|
217
213
|
return {
|
|
218
|
-
title: swapButtonTitles.swap,
|
|
214
|
+
title: swapButtonTitles().swap,
|
|
219
215
|
disabled: true,
|
|
220
216
|
state: ButtonState.SWAP,
|
|
221
217
|
};
|
|
222
218
|
} else if (highValueLoss || priceImpactCanNotBeComputed) {
|
|
223
219
|
return {
|
|
224
|
-
title: swapButtonTitles.swapAnyway,
|
|
220
|
+
title: swapButtonTitles().swapAnyway,
|
|
225
221
|
disabled: false,
|
|
226
222
|
hasWarning: true,
|
|
227
223
|
state: ButtonState.NEEDTOCONFIRM,
|
|
228
224
|
};
|
|
229
225
|
} else if (needsToWarnEthOnPath) {
|
|
230
226
|
return {
|
|
231
|
-
title: swapButtonTitles.ethRouteWarning,
|
|
227
|
+
title: swapButtonTitles().ethRouteWarning,
|
|
232
228
|
disabled: false,
|
|
233
229
|
hasWarning: true,
|
|
234
230
|
state: ButtonState.WARNING,
|
|
235
231
|
};
|
|
236
232
|
}
|
|
237
233
|
return {
|
|
238
|
-
title: swapButtonTitles.swap,
|
|
234
|
+
title: swapButtonTitles().swap,
|
|
239
235
|
disabled: false,
|
|
240
236
|
state: ButtonState.SWAP,
|
|
241
237
|
};
|
|
@@ -608,8 +604,7 @@ export function getBalanceWarnings(
|
|
|
608
604
|
reason = i18n.t(' for input and network fee');
|
|
609
605
|
}
|
|
610
606
|
const warningMessage = i18n.t({
|
|
611
|
-
id:
|
|
612
|
-
message: `Needs ≈ {requiredAmount} {symbol}{reason}, but you have {currentAmount} {symbol} in your {blockchain} wallet.`,
|
|
607
|
+
id: `Needs ≈ {requiredAmount} {symbol}{reason}, but you have {currentAmount} {symbol} in your {blockchain} wallet.`,
|
|
613
608
|
values: {
|
|
614
609
|
requiredAmount,
|
|
615
610
|
symbol,
|
package/src/utils/time.ts
CHANGED
|
@@ -67,13 +67,11 @@ export function timeSince(millisecond: number): string {
|
|
|
67
67
|
export function getSwapDate(pendingSwap: PendingSwap) {
|
|
68
68
|
return pendingSwap.finishTime
|
|
69
69
|
? i18n.t({
|
|
70
|
-
id: '
|
|
71
|
-
message: '{time} ago',
|
|
70
|
+
id: '{time} ago',
|
|
72
71
|
values: { time: timeSince(parseInt(pendingSwap.finishTime)) },
|
|
73
72
|
})
|
|
74
73
|
: i18n.t({
|
|
75
|
-
id: '
|
|
76
|
-
message: '{time} ago',
|
|
74
|
+
id: '{time} ago',
|
|
77
75
|
values: { time: timeSince(parseInt(pendingSwap.creationTime)) },
|
|
78
76
|
});
|
|
79
77
|
}
|
package/src/utils/ui.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import type { WidgetTheme } from '../types';
|
|
3
|
+
import type { createTheme } from '@rango-dev/ui';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
theme as baseThemeTokens,
|
|
7
|
+
darkColors as defaultDarkColors,
|
|
8
|
+
} from '@rango-dev/ui';
|
|
9
|
+
|
|
10
|
+
import { generateColors } from '../utils/colors';
|
|
11
|
+
import { toHash } from '../utils/hash';
|
|
12
|
+
|
|
13
|
+
import { THEME_CLASS_NAME_PREFIX } from './configs';
|
|
14
|
+
|
|
15
|
+
interface CustomizedThemeValues {
|
|
16
|
+
id: string;
|
|
17
|
+
tokens: Parameters<typeof createTheme>[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface CustomizedTheme {
|
|
21
|
+
light: undefined | CustomizedThemeValues;
|
|
22
|
+
dark: undefined | CustomizedThemeValues;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function customizedThemeTokens(
|
|
26
|
+
colors: WidgetTheme['colors']
|
|
27
|
+
): CustomizedTheme {
|
|
28
|
+
const baseColors = baseThemeTokens.colors;
|
|
29
|
+
|
|
30
|
+
const darkColorsWithDefaults = generateColors(
|
|
31
|
+
{
|
|
32
|
+
...baseColors,
|
|
33
|
+
...defaultDarkColors,
|
|
34
|
+
},
|
|
35
|
+
true,
|
|
36
|
+
colors?.dark
|
|
37
|
+
);
|
|
38
|
+
const lightColorsWithDefaults = generateColors(
|
|
39
|
+
baseColors,
|
|
40
|
+
false,
|
|
41
|
+
colors?.light
|
|
42
|
+
);
|
|
43
|
+
const hasDefaultDarkColors = Object.keys(darkColorsWithDefaults).length > 0;
|
|
44
|
+
const hasDefaultLightColors = Object.keys(lightColorsWithDefaults).length > 0;
|
|
45
|
+
|
|
46
|
+
let light: CustomizedTheme['light'] = undefined;
|
|
47
|
+
let dark: CustomizedTheme['dark'] = undefined;
|
|
48
|
+
|
|
49
|
+
if (hasDefaultLightColors) {
|
|
50
|
+
const tokens = { colors: lightColorsWithDefaults };
|
|
51
|
+
const id = `${THEME_CLASS_NAME_PREFIX}-light-${toHash(tokens)}`;
|
|
52
|
+
light = {
|
|
53
|
+
id,
|
|
54
|
+
tokens,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (hasDefaultDarkColors) {
|
|
58
|
+
const tokens = {
|
|
59
|
+
colors: darkColorsWithDefaults,
|
|
60
|
+
};
|
|
61
|
+
const id = `${THEME_CLASS_NAME_PREFIX}-dark-${toHash(tokens)}`;
|
|
62
|
+
dark = {
|
|
63
|
+
id,
|
|
64
|
+
tokens,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
light,
|
|
70
|
+
dark,
|
|
71
|
+
};
|
|
72
|
+
}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -55,8 +55,11 @@ export function mapWalletTypesToWalletInfo(
|
|
|
55
55
|
return list
|
|
56
56
|
.filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
|
|
57
57
|
.filter((wallet) => {
|
|
58
|
+
const { supportedChains, hideWhenNotInstalled } = getWalletInfo(wallet);
|
|
59
|
+
if (hideWhenNotInstalled && !getState(wallet).installed) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
58
62
|
if (chain) {
|
|
59
|
-
const { supportedChains } = getWalletInfo(wallet);
|
|
60
63
|
return !!supportedChains.find(
|
|
61
64
|
(supportedChain) => supportedChain.name === chain
|
|
62
65
|
);
|
|
@@ -203,30 +206,6 @@ export function getRequiredChains(route: BestRouteResponse | null) {
|
|
|
203
206
|
|
|
204
207
|
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
205
208
|
|
|
206
|
-
export function getSelectableWallets(
|
|
207
|
-
connectedWallets: ConnectedWallet[],
|
|
208
|
-
getWalletInfo: (type: WalletType) => WalletInfo,
|
|
209
|
-
destinationChain?: string
|
|
210
|
-
): Wallet[] {
|
|
211
|
-
const selectableWallets = connectedWallets.map(
|
|
212
|
-
(connectedWallet: ConnectedWallet) => {
|
|
213
|
-
return {
|
|
214
|
-
address: connectedWallet.address,
|
|
215
|
-
walletType: connectedWallet.walletType,
|
|
216
|
-
chain: connectedWallet.chain,
|
|
217
|
-
image: getWalletInfo(connectedWallet.walletType).img,
|
|
218
|
-
name: getWalletInfo(connectedWallet.walletType).name,
|
|
219
|
-
selected:
|
|
220
|
-
destinationChain === connectedWallet.chain
|
|
221
|
-
? false
|
|
222
|
-
: connectedWallet.selected,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
return selectableWallets;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
209
|
export function getBalanceFromWallet(
|
|
231
210
|
connectedWallets: ConnectedWallet[],
|
|
232
211
|
chain: string,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePrepareBlockchainList.d.ts","sourceRoot":"","sources":["../../src/hooks/usePrepareBlockchainList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIhD,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,iBAAiB;IACzB,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,IAAI,EAAE,cAAc,EAAE,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,cAAc,EAAE,EAC7B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,iBAAiB,CAgEnB"}
|