@rango-dev/widget-embedded 0.14.1-next.14 → 0.14.1-next.16
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/BlockchainsSection/BlockchainsSection.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/index.js +1 -1
- package/dist/index.js.map +4 -4
- 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/package.json +2 -2
- package/src/Widget.tsx +10 -1
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +21 -6
- package/src/components/NoRoutes/NoRoutes.helper.ts +4 -4
- package/src/components/NoRoutes/NoRoutes.tsx +1 -1
- package/src/components/RouteErrors/RouteErrors.tsx +2 -2
- package/src/components/RouteErrors/RouteErrorsModal.tsx +6 -6
- package/src/constants/configs.ts +1 -0
- package/src/constants/errors.ts +43 -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/pages/Home.tsx +2 -2
- package/src/pages/LanguagePage.tsx +16 -39
- package/src/store/settings.ts +46 -4
- package/src/utils/swap.ts +10 -10
- package/dist/hooks/usePrepareBlockchainList.d.ts.map +0 -1
- package/src/hooks/usePrepareBlockchainList.ts +0 -125
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LanguagePage.d.ts","sourceRoot":"","sources":["../../src/pages/LanguagePage.tsx"],"names":[],"mappings":"AAQA,OAAO,
|
|
1
|
+
{"version":3,"file":"LanguagePage.d.ts","sourceRoot":"","sources":["../../src/pages/LanguagePage.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,wBAAgB,YAAY,sBA2C3B"}
|
package/dist/store/settings.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Language } from '@rango-dev/ui';
|
|
2
|
+
export type ThemeMode = 'auto' | 'dark' | 'light';
|
|
2
3
|
export interface SettingsState {
|
|
4
|
+
/** Keeping a history of blockchains that user has selected (in Swap process) */
|
|
5
|
+
preferredBlockchains: string[];
|
|
3
6
|
slippage: number;
|
|
4
7
|
customSlippage: number | null;
|
|
5
8
|
infiniteApprove: boolean;
|
|
6
9
|
disabledLiquiditySources: string[];
|
|
7
|
-
theme:
|
|
10
|
+
theme: ThemeMode;
|
|
11
|
+
language: Language;
|
|
8
12
|
affiliateRef: string | null;
|
|
9
13
|
affiliatePercent: number | null;
|
|
10
14
|
affiliateWallets: {
|
|
@@ -14,13 +18,15 @@ export interface SettingsState {
|
|
|
14
18
|
setCustomSlippage: (customSlippage: number | null) => void;
|
|
15
19
|
toggleInfiniteApprove: () => void;
|
|
16
20
|
toggleLiquiditySource: (name: string) => void;
|
|
17
|
-
setTheme: (theme:
|
|
21
|
+
setTheme: (theme: ThemeMode) => void;
|
|
22
|
+
setLanguage: (language: Language) => void;
|
|
18
23
|
toggleAllLiquiditySources: (shouldReset?: boolean) => void;
|
|
19
24
|
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
20
25
|
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
21
26
|
setAffiliateWallets: (affiliateWallets: {
|
|
22
27
|
[key: string]: string;
|
|
23
28
|
} | null) => void;
|
|
29
|
+
addPreferredBlockchain: (blockchain: string) => void;
|
|
24
30
|
}
|
|
25
31
|
export declare const useSettingsStore: {
|
|
26
32
|
(): SettingsState;
|
|
@@ -45,11 +51,13 @@ export declare const useSettingsStore: {
|
|
|
45
51
|
};
|
|
46
52
|
} & {
|
|
47
53
|
use: {
|
|
54
|
+
preferredBlockchains: () => string[];
|
|
48
55
|
slippage: () => number;
|
|
49
56
|
customSlippage: () => number | null;
|
|
50
57
|
infiniteApprove: () => boolean;
|
|
51
58
|
disabledLiquiditySources: () => string[];
|
|
52
|
-
theme: () =>
|
|
59
|
+
theme: () => ThemeMode;
|
|
60
|
+
language: () => "en" | "es" | "jp" | "fr";
|
|
53
61
|
affiliateRef: () => string | null;
|
|
54
62
|
affiliatePercent: () => number | null;
|
|
55
63
|
affiliateWallets: () => {
|
|
@@ -59,14 +67,15 @@ export declare const useSettingsStore: {
|
|
|
59
67
|
setCustomSlippage: () => (customSlippage: number | null) => void;
|
|
60
68
|
toggleInfiniteApprove: () => () => void;
|
|
61
69
|
toggleLiquiditySource: () => (name: string) => void;
|
|
62
|
-
setTheme: () => (theme:
|
|
70
|
+
setTheme: () => (theme: ThemeMode) => void;
|
|
71
|
+
setLanguage: () => (language: Language) => void;
|
|
63
72
|
toggleAllLiquiditySources: () => (shouldReset?: boolean) => void;
|
|
64
73
|
setAffiliateRef: () => (affiliateRef: string | null) => void;
|
|
65
74
|
setAffiliatePercent: () => (affiliatePercent: number | null) => void;
|
|
66
75
|
setAffiliateWallets: () => (affiliateWallets: {
|
|
67
76
|
[key: string]: string;
|
|
68
77
|
} | null) => void;
|
|
78
|
+
addPreferredBlockchain: () => (blockchain: string) => void;
|
|
69
79
|
};
|
|
70
80
|
};
|
|
71
|
-
export {};
|
|
72
81
|
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/store/settings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/store/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAY9C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAEnD,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,iBAAiB,EAAE,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3D,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC1C,yBAAyB,EAAE,CAAC,WAAW,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D,eAAe,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,mBAAmB,EAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/D,mBAAmB,EAAE,CACnB,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI,KAC/C,IAAI,CAAC;IACV,sBAAsB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACtD;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sCAfH,MAAM,KAAK,IAAI;kDACH,MAAM,GAAG,IAAI,KAAK,IAAI;2CAC7B,IAAI;4CACH,MAAM,KAAK,IAAI;gCAC3B,SAAS,KAAK,IAAI;sCACZ,QAAQ,KAAK,IAAI;wDACC,OAAO,KAAK,IAAI;8CAC1B,MAAM,GAAG,IAAI,KAAK,IAAI;sDACd,MAAM,GAAG,IAAI,KAAK,IAAI;;;qBAGzD,IAAI;mDAC4B,MAAM,KAAK,IAAI;;CAsHrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.14.1-next.
|
|
3
|
+
"version": "0.14.1-next.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@rango-dev/queue-manager-core": "^0.17.0",
|
|
24
24
|
"@rango-dev/queue-manager-rango-preset": "^0.17.1-next.2",
|
|
25
25
|
"@rango-dev/queue-manager-react": "^0.17.0",
|
|
26
|
-
"@rango-dev/ui": "^0.17.1-next.
|
|
26
|
+
"@rango-dev/ui": "^0.17.1-next.10",
|
|
27
27
|
"@rango-dev/wallets-react": "^0.3.1-next.1",
|
|
28
28
|
"@rango-dev/wallets-shared": "^0.17.1-next.0",
|
|
29
29
|
"bignumber.js": "^9.1.1",
|
package/src/Widget.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { AppRouter } from './components/AppRouter';
|
|
|
9
9
|
import { AppRoutes } from './components/AppRoutes';
|
|
10
10
|
import { WidgetEvents } from './components/WidgetEvents';
|
|
11
11
|
import { globalFont } from './globalStyles';
|
|
12
|
+
import { useLanguage } from './hooks/useLanguage';
|
|
12
13
|
import { useTheme } from './hooks/useTheme';
|
|
13
14
|
import QueueManager from './QueueManager';
|
|
14
15
|
import { useAppStore } from './store/app';
|
|
@@ -44,6 +45,8 @@ export function Main(props: PropsWithChildren<WidgetProps>) {
|
|
|
44
45
|
globalFont();
|
|
45
46
|
|
|
46
47
|
const { activeTheme } = useTheme(config?.theme || {});
|
|
48
|
+
const { activeLanguage, changeLanguage } = useLanguage();
|
|
49
|
+
|
|
47
50
|
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
48
51
|
useState<string>('');
|
|
49
52
|
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
@@ -65,8 +68,14 @@ export function Main(props: PropsWithChildren<WidgetProps>) {
|
|
|
65
68
|
widgetContext.onConnectWallet(setLastConnectedWalletWithNetwork);
|
|
66
69
|
}, []);
|
|
67
70
|
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (config?.language) {
|
|
73
|
+
changeLanguage(config.language);
|
|
74
|
+
}
|
|
75
|
+
}, [config?.language]);
|
|
76
|
+
|
|
68
77
|
return (
|
|
69
|
-
<I18nManager language={
|
|
78
|
+
<I18nManager language={activeLanguage}>
|
|
70
79
|
<MainContainer id="swap-container" className={activeTheme()}>
|
|
71
80
|
<QueueManager>
|
|
72
81
|
<WidgetEvents />
|
|
@@ -11,28 +11,31 @@ import {
|
|
|
11
11
|
} from '@rango-dev/ui';
|
|
12
12
|
import React from 'react';
|
|
13
13
|
|
|
14
|
+
import { BLOCKCHAIN_LIST_SIZE } from '../../constants/configs';
|
|
14
15
|
import { usePrepareBlockchainList } from '../../hooks/usePrepareBlockchainList';
|
|
15
16
|
import { useBestRouteStore } from '../../store/bestRoute';
|
|
16
17
|
import { useMetaStore } from '../../store/meta';
|
|
17
18
|
|
|
18
19
|
import { Container } from './BlockchainsSection.styles';
|
|
19
20
|
|
|
20
|
-
const LIST_SIZE = 10;
|
|
21
|
-
const MAX_ITEMS = LIST_SIZE + 1;
|
|
22
21
|
const NUMBER_OF_LOADING = 12;
|
|
23
22
|
|
|
24
23
|
export function BlockchainsSection(props: PropTypes) {
|
|
25
24
|
const { blockchains, type, blockchain, onChange, onMoreClick } = props;
|
|
26
25
|
const blockchainsList = usePrepareBlockchainList(blockchains, {
|
|
27
|
-
limit:
|
|
26
|
+
limit: BLOCKCHAIN_LIST_SIZE,
|
|
28
27
|
selected: blockchain?.name,
|
|
29
28
|
});
|
|
30
29
|
|
|
31
30
|
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
32
31
|
const resetToBlockchain = useBestRouteStore.use.resetToBlockchain();
|
|
33
32
|
const resetFromBlockchain = useBestRouteStore.use.resetFromBlockchain();
|
|
34
|
-
const
|
|
35
|
-
|
|
33
|
+
const hasMoreItemsInList = blockchainsList.more.length > 0;
|
|
34
|
+
/**
|
|
35
|
+
* When only one item is left on list, we will not show the `More` button and will show the item itself instead.
|
|
36
|
+
*/
|
|
37
|
+
const onlyOneItemInList = blockchainsList.more.length === 1;
|
|
38
|
+
const showMoreButton = !onlyOneItemInList && hasMoreItemsInList;
|
|
36
39
|
|
|
37
40
|
return (
|
|
38
41
|
<div>
|
|
@@ -70,8 +73,20 @@ export function BlockchainsSection(props: PropTypes) {
|
|
|
70
73
|
</BlockchainsChip>
|
|
71
74
|
))}
|
|
72
75
|
|
|
76
|
+
{onlyOneItemInList ? (
|
|
77
|
+
<BlockchainsChip
|
|
78
|
+
key={blockchainsList.more[0].name}
|
|
79
|
+
selected={
|
|
80
|
+
!!blockchain &&
|
|
81
|
+
blockchain.name === blockchainsList.more[0].name
|
|
82
|
+
}
|
|
83
|
+
onClick={() => onChange(blockchainsList.more[0])}>
|
|
84
|
+
<Image src={blockchainsList.more[0].logo} size={30} />
|
|
85
|
+
</BlockchainsChip>
|
|
86
|
+
) : null}
|
|
87
|
+
|
|
73
88
|
{showMoreButton ? (
|
|
74
|
-
<BlockchainsChip onClick={onMoreClick}>
|
|
89
|
+
<BlockchainsChip onClick={onMoreClick} key="more-blockchains">
|
|
75
90
|
<Typography variant="body" size="xsmall" color="secondary500">
|
|
76
91
|
{i18n._('More +{count}', {
|
|
77
92
|
count: blockchainsList.more.length,
|
|
@@ -15,7 +15,7 @@ export function makeInfo(
|
|
|
15
15
|
return {
|
|
16
16
|
alert: {
|
|
17
17
|
type: 'warning',
|
|
18
|
-
text: errorMessages.genericServerError,
|
|
18
|
+
text: errorMessages().genericServerError,
|
|
19
19
|
action: {
|
|
20
20
|
onClick: refetchBestRoute,
|
|
21
21
|
title: i18n.t('Retry'),
|
|
@@ -36,17 +36,17 @@ export function makeInfo(
|
|
|
36
36
|
return {
|
|
37
37
|
alert: {
|
|
38
38
|
type: 'warning',
|
|
39
|
-
text: errorMessages.liquiditySourcesError.title,
|
|
39
|
+
text: errorMessages().liquiditySourcesError.title,
|
|
40
40
|
action: {
|
|
41
41
|
onClick: () => toggleAllLiquiditySources(true),
|
|
42
42
|
title: i18n.t('Reset'),
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
-
description: errorMessages.liquiditySourcesError.description,
|
|
45
|
+
description: errorMessages().liquiditySourcesError.description,
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
return {
|
|
49
49
|
alert: null,
|
|
50
|
-
description: errorMessages.noRoutesError.description,
|
|
50
|
+
description: errorMessages().noRoutesError.description,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
@@ -40,7 +40,7 @@ export function NoRoutes(props: PropTypes) {
|
|
|
40
40
|
<NoRouteIcon size={24} color="gray" />
|
|
41
41
|
<Divider size={4} />
|
|
42
42
|
<Typography variant="title" size="small">
|
|
43
|
-
{errorMessages.noRoutesError.title}
|
|
43
|
+
{errorMessages().noRoutesError.title}
|
|
44
44
|
</Typography>
|
|
45
45
|
{!!info.description && (
|
|
46
46
|
<Typography
|
|
@@ -42,8 +42,8 @@ export function RouteErrors(props: PropTypes) {
|
|
|
42
42
|
<Alert
|
|
43
43
|
title={
|
|
44
44
|
highValueLoss
|
|
45
|
-
? errorMessages.highValueLossError.title
|
|
46
|
-
: errorMessages.unknownPriceError.title
|
|
45
|
+
? errorMessages().highValueLossError.title
|
|
46
|
+
: errorMessages().unknownPriceError.title
|
|
47
47
|
}
|
|
48
48
|
type={
|
|
49
49
|
highValueLoss && !!percentageChange?.lt(WARNING_LEVEL_LIMIT)
|
|
@@ -87,14 +87,14 @@ export function RouteErrorsModal(props: ModalPropTypes) {
|
|
|
87
87
|
{highValueLoss ? (
|
|
88
88
|
<MessageBox
|
|
89
89
|
type={type}
|
|
90
|
-
title={errorMessages.highValueLossError.impactTitle}
|
|
91
|
-
description={errorMessages.highValueLossError.description}
|
|
90
|
+
title={errorMessages().highValueLossError.impactTitle}
|
|
91
|
+
description={errorMessages().highValueLossError.description}
|
|
92
92
|
/>
|
|
93
93
|
) : (
|
|
94
94
|
<MessageBox
|
|
95
95
|
type={type}
|
|
96
|
-
title={errorMessages.unknownPriceError.impactTitle}
|
|
97
|
-
description={errorMessages.unknownPriceError.description}
|
|
96
|
+
title={errorMessages().unknownPriceError.impactTitle}
|
|
97
|
+
description={errorMessages().unknownPriceError.description}
|
|
98
98
|
/>
|
|
99
99
|
)}
|
|
100
100
|
{highValueLoss && (
|
|
@@ -121,8 +121,8 @@ export function RouteErrorsModal(props: ModalPropTypes) {
|
|
|
121
121
|
navigate(navigationRoutes.confirmSwap);
|
|
122
122
|
}}>
|
|
123
123
|
{highValueLoss
|
|
124
|
-
? errorMessages.highValueLossError.confirmMessage
|
|
125
|
-
: errorMessages.unknownPriceError.confirmMessage}
|
|
124
|
+
? errorMessages().highValueLossError.confirmMessage
|
|
125
|
+
: errorMessages().unknownPriceError.confirmMessage}
|
|
126
126
|
</Button>
|
|
127
127
|
</Modal>
|
|
128
128
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BLOCKCHAIN_LIST_SIZE = 10;
|
package/src/constants/errors.ts
CHANGED
|
@@ -4,54 +4,56 @@ import { i18n } from '@lingui/core';
|
|
|
4
4
|
|
|
5
5
|
import { ConfirmSwapErrorTypes } from '../types';
|
|
6
6
|
|
|
7
|
-
export const errorMessages = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
7
|
+
export const errorMessages = () => {
|
|
8
|
+
return {
|
|
9
|
+
genericServerError: i18n.t('Failed Network, Please retry your swap.'),
|
|
10
|
+
liquiditySourcesError: {
|
|
11
|
+
title: i18n.t('Please reset your liquidity sources.'),
|
|
12
|
+
description: i18n.t(
|
|
13
|
+
'You have limited the liquidity sources and this might result in Rango finding no routes. Please consider resetting your liquidity sources'
|
|
14
|
+
),
|
|
15
|
+
},
|
|
16
|
+
noRoutesError: {
|
|
17
|
+
title: i18n.t('No Routes Found'),
|
|
18
|
+
description:
|
|
19
|
+
"Reasons why Rango couldn't find a route: low liquidity on token, very low input amount or no routes available for the selected input/output token combination.",
|
|
20
|
+
},
|
|
21
|
+
bridgeLimitErrors: {
|
|
22
|
+
increaseAmount: i18n.t('Bridge Limit Error: Please increase your amount'),
|
|
23
|
+
decreaseAmount: i18n.t('Bridge Limit Error: Please decrease your amount'),
|
|
24
|
+
},
|
|
25
|
+
highValueLossError: {
|
|
26
|
+
impactTitle: i18n.t('High Price Impact'),
|
|
27
|
+
title: i18n.t('Price impact is too high!'),
|
|
28
|
+
description: i18n.t(
|
|
29
|
+
'The price impact is significantly higher than the allowed amount. If you are sure, continue, otherwise, change the swap.'
|
|
30
|
+
),
|
|
31
|
+
confirmMessage: i18n.t('Confirm High price impact'),
|
|
32
|
+
},
|
|
33
|
+
routeUpdatedWithHighValueLoss: {
|
|
34
|
+
title: i18n.t(
|
|
35
|
+
'Route updated and price impact is too high, try again later!'
|
|
36
|
+
),
|
|
37
|
+
},
|
|
38
|
+
unknownPriceError: {
|
|
39
|
+
impactTitle: i18n.t('USD Price Unknown'),
|
|
40
|
+
title: i18n.t('USD Price Unknown, Cannot calculate Price Impact.'),
|
|
41
|
+
description: i18n.t(
|
|
42
|
+
'USD Price Unknown, Cannot calculate Price Impact. The price impact may be higher than usual. Are you sure to continue the Swap?'
|
|
43
|
+
),
|
|
44
|
+
confirmMessage: i18n.t('Confirm USD Price Unknown'),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
45
47
|
};
|
|
46
48
|
|
|
47
49
|
export function getConfirmSwapErrorMessage(error: ConfirmSwapError) {
|
|
48
50
|
switch (error.type) {
|
|
49
51
|
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
50
|
-
return error.diagnosisMessage ?? errorMessages.noRoutesError.title;
|
|
52
|
+
return error.diagnosisMessage ?? errorMessages().noRoutesError.title;
|
|
51
53
|
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
52
|
-
return errorMessages.genericServerError;
|
|
54
|
+
return errorMessages().genericServerError;
|
|
53
55
|
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
54
|
-
return errorMessages.routeUpdatedWithHighValueLoss.title;
|
|
56
|
+
return errorMessages().routeUpdatedWithHighValueLoss.title;
|
|
55
57
|
default:
|
|
56
58
|
return '';
|
|
57
59
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FlagPropTypes, Language } from '@rango-dev/ui';
|
|
2
|
+
|
|
3
|
+
import { English, French, Japanese, Spanish } from '@rango-dev/ui';
|
|
4
|
+
|
|
5
|
+
export type LanguageItem = {
|
|
6
|
+
title: string;
|
|
7
|
+
label: string;
|
|
8
|
+
local: Language;
|
|
9
|
+
SVGFlag: React.ComponentType<FlagPropTypes>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const LANGUAGES: LanguageItem[] = [
|
|
13
|
+
{ title: 'English', label: 'English', local: 'en', SVGFlag: English },
|
|
14
|
+
{ title: 'Spanish', label: 'Español', local: 'es', SVGFlag: Spanish },
|
|
15
|
+
{ title: 'French', label: 'Français', local: 'fr', SVGFlag: French },
|
|
16
|
+
{ title: 'Japanese', label: '日本語', local: 'jp', SVGFlag: Japanese },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_LANGUAGE = 'en';
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { i18n } from '@lingui/core';
|
|
2
2
|
|
|
3
|
-
export const swapButtonTitles = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export const swapButtonTitles = () => {
|
|
4
|
+
return {
|
|
5
|
+
connectWallet: i18n.t('Connect Wallet'),
|
|
6
|
+
swap: i18n.t('Swap'),
|
|
7
|
+
swapAnyway: i18n.t('Swap anyway'),
|
|
8
|
+
ethRouteWarning: i18n.t('The route goes through Ethereum. Continue?'),
|
|
9
|
+
};
|
|
8
10
|
};
|
|
@@ -70,7 +70,7 @@ function throwErrorIfResponseIsNotValid(
|
|
|
70
70
|
params: { inputUsdValue: BigNumber | null; outputUsdValue: number | null }
|
|
71
71
|
) {
|
|
72
72
|
if (!response.result) {
|
|
73
|
-
throw new Error(errorMessages.noRoutesError.title, {
|
|
73
|
+
throw new Error(errorMessages().noRoutesError.title, {
|
|
74
74
|
cause: {
|
|
75
75
|
type: ConfirmSwapErrorTypes.NO_ROUTE,
|
|
76
76
|
diagnosisMessage: response.diagnosisMessages?.[0],
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LanguageItem } from '../constants/languages';
|
|
2
|
+
|
|
3
|
+
import { type Language } from '@rango-dev/ui';
|
|
4
|
+
|
|
5
|
+
import { DEFAULT_LANGUAGE, LANGUAGES } from '../constants/languages';
|
|
6
|
+
import { useSettingsStore } from '../store/settings';
|
|
7
|
+
|
|
8
|
+
interface UseLanguage {
|
|
9
|
+
languages: LanguageItem[];
|
|
10
|
+
defaultLanguage: Language;
|
|
11
|
+
activeLanguage: Language;
|
|
12
|
+
changeLanguage: (language: Language) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useLanguage(): UseLanguage {
|
|
16
|
+
const language = useSettingsStore.use.language();
|
|
17
|
+
const setLanguage = useSettingsStore.use.setLanguage();
|
|
18
|
+
const languages = LANGUAGES;
|
|
19
|
+
const defaultLanguage = DEFAULT_LANGUAGE;
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
activeLanguage: language,
|
|
23
|
+
languages,
|
|
24
|
+
defaultLanguage,
|
|
25
|
+
changeLanguage: setLanguage,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { usePrepareBlockchainList } from './usePrepareBlockchainList';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MOST_USED_BLOCKChAINS = ['ETH', 'COSMOS', 'OSMOSIS'];
|
|
@@ -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
|
+
}
|