@rango-dev/widget-embedded 0.5.1-next.8 → 0.6.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 +23 -0
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/Wallets.d.ts +2 -1
- package/dist/Wallets.d.ts.map +1 -1
- package/dist/Widget.d.ts +0 -1
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/BottomLogo.d.ts.map +1 -1
- package/dist/components/ChangeSlippageButton.d.ts.map +1 -1
- package/dist/components/ConfirmSwapWarnings.d.ts +2 -2
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
- package/dist/components/HeaderButtons.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts +1 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts +2 -0
- package/dist/components/WidgetEvents.d.ts.map +1 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +4 -4
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/settings.d.ts +16 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +2 -2
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +23 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/swap.d.ts +1 -1
- package/dist/types/swap.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +1 -1
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +6 -4
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +10 -13
- package/src/QueueManager.tsx +0 -25
- package/src/Wallets.tsx +8 -2
- package/src/Widget.tsx +19 -22
- package/src/components/AppRouter.tsx +0 -2
- package/src/components/BottomLogo.tsx +2 -4
- package/src/components/ChangeSlippageButton.tsx +3 -3
- package/src/components/ConfirmSwapWarnings.tsx +10 -13
- package/src/components/HeaderButtons.tsx +7 -9
- package/src/components/Layout.tsx +21 -13
- package/src/components/SwapDetailsPlaceholder.tsx +10 -2
- package/src/components/TokenInfo.tsx +26 -23
- package/src/components/TokenPreview.tsx +12 -13
- package/src/components/WidgetEvents.tsx +45 -0
- package/src/components/warnings/BalanceErrors.tsx +3 -3
- package/src/components/warnings/HighSlippageWarning.tsx +9 -2
- package/src/components/warnings/MinRequiredSlippage.tsx +11 -4
- package/src/hooks/useConfirmSwap.ts +10 -3
- package/src/index.ts +56 -3
- package/src/pages/ConfirmSwapPage.tsx +5 -5
- package/src/pages/Home.tsx +2 -1
- package/src/pages/WalletsPage.tsx +2 -3
- package/src/store/bestRoute.ts +18 -8
- package/src/store/settings.ts +17 -0
- package/src/store/wallets.ts +39 -13
- package/src/types/config.ts +22 -4
- package/src/types/swap.ts +1 -1
- package/src/utils/routing.ts +1 -1
- package/src/utils/swap.ts +53 -26
- package/src/utils/wallets.ts +18 -4
- package/dist/hooks/useSelectLanguage.d.ts +0 -5
- package/dist/hooks/useSelectLanguage.d.ts.map +0 -1
- package/dist/i18n.d.ts +0 -3
- package/dist/i18n.d.ts.map +0 -1
- package/src/hooks/useSelectLanguage.ts +0 -17
- package/src/i18n.js +0 -30
|
@@ -18,7 +18,7 @@ import { useWallets } from '@rango-dev/wallets-core';
|
|
|
18
18
|
import { useUiStore } from '../store/ui';
|
|
19
19
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
20
20
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
21
|
-
import {
|
|
21
|
+
import { i18n } from '@lingui/core';
|
|
22
22
|
import { useMetaStore } from '../store/meta';
|
|
23
23
|
import { Spinner } from '@rango-dev/ui';
|
|
24
24
|
import { LoadingFailedAlert } from '@rango-dev/ui';
|
|
@@ -71,7 +71,6 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
|
|
|
71
71
|
const toggleConnectWalletsButton =
|
|
72
72
|
useUiStore.use.toggleConnectWalletsButton();
|
|
73
73
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
74
|
-
const { t } = useTranslation();
|
|
75
74
|
|
|
76
75
|
const onSelectWallet = async (type: WalletType) => {
|
|
77
76
|
const wallet = state(type);
|
|
@@ -115,7 +114,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
|
|
|
115
114
|
|
|
116
115
|
return (
|
|
117
116
|
<SecondaryPage
|
|
118
|
-
title={t('Select Wallet') || ''}
|
|
117
|
+
title={i18n.t('Select Wallet') || ''}
|
|
119
118
|
textField={false}
|
|
120
119
|
onBack={navigateBackFrom.bind(null, navigationRoutes.wallets)}>
|
|
121
120
|
<>
|
package/src/store/bestRoute.ts
CHANGED
|
@@ -24,16 +24,18 @@ import { PendingSwap } from '@rango-dev/queue-manager-rango-preset/dist/shared';
|
|
|
24
24
|
import { debounce } from '../utils/common';
|
|
25
25
|
import { isPositiveNumber } from '../utils/numbers';
|
|
26
26
|
|
|
27
|
-
const getUsdValue = (token: Token | null, amount: string) =>
|
|
28
|
-
|
|
27
|
+
const getUsdValue = (token: Token | null, amount: string): BigNumber | null =>
|
|
28
|
+
token?.usdPrice
|
|
29
|
+
? new BigNumber(amount || ZERO).multipliedBy(token?.usdPrice || 0)
|
|
30
|
+
: null;
|
|
29
31
|
|
|
30
32
|
export interface RouteState {
|
|
31
33
|
fromChain: BlockchainMeta | null;
|
|
32
34
|
toChain: BlockchainMeta | null;
|
|
33
35
|
inputAmount: string;
|
|
34
|
-
inputUsdValue: BigNumber;
|
|
36
|
+
inputUsdValue: BigNumber | null;
|
|
35
37
|
outputAmount: BigNumber | null;
|
|
36
|
-
outputUsdValue: BigNumber;
|
|
38
|
+
outputUsdValue: BigNumber | null;
|
|
37
39
|
fromToken: TokenWithBalance | null;
|
|
38
40
|
toToken: TokenWithBalance | null;
|
|
39
41
|
loading: boolean;
|
|
@@ -262,8 +264,14 @@ const bestRoute = (
|
|
|
262
264
|
const fetchBestRoute = () => {
|
|
263
265
|
const { fromToken, toToken, inputAmount, resetRoute } =
|
|
264
266
|
bestRouteStore.getState();
|
|
265
|
-
const {
|
|
266
|
-
|
|
267
|
+
const {
|
|
268
|
+
slippage,
|
|
269
|
+
customSlippage,
|
|
270
|
+
disabledLiquiditySources,
|
|
271
|
+
affiliateRef,
|
|
272
|
+
affiliatePercent,
|
|
273
|
+
affiliateWallets,
|
|
274
|
+
} = settingsStore.getState();
|
|
267
275
|
if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
|
|
268
276
|
abortController?.abort();
|
|
269
277
|
abortController = new AbortController();
|
|
@@ -276,7 +284,9 @@ const bestRoute = (
|
|
|
276
284
|
[],
|
|
277
285
|
disabledLiquiditySources,
|
|
278
286
|
userSlippage,
|
|
279
|
-
affiliateRef
|
|
287
|
+
affiliateRef,
|
|
288
|
+
affiliatePercent,
|
|
289
|
+
affiliateWallets
|
|
280
290
|
);
|
|
281
291
|
|
|
282
292
|
if (!bestRouteStore.getState().loading) {
|
|
@@ -306,7 +316,7 @@ const bestRoute = (
|
|
|
306
316
|
const bestRouteParamsListener = () => {
|
|
307
317
|
const { fromToken, toToken, inputAmount, inputUsdValue, resetRoute } =
|
|
308
318
|
useBestRouteStore.getState();
|
|
309
|
-
if (!isPositiveNumber(inputAmount) || inputUsdValue
|
|
319
|
+
if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0))
|
|
310
320
|
return bestRouteStore.setState({ loading: false });
|
|
311
321
|
|
|
312
322
|
if (tokensAreEqual(fromToken, toToken))
|
package/src/store/settings.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface SettingsState {
|
|
|
14
14
|
disabledLiquiditySources: string[];
|
|
15
15
|
theme: Theme;
|
|
16
16
|
affiliateRef: string | null;
|
|
17
|
+
affiliatePercent: number | null;
|
|
18
|
+
affiliateWallets: { [key: string]: string } | null;
|
|
17
19
|
setSlippage: (slippage: number) => void;
|
|
18
20
|
setCustomSlippage: (customSlippage: number | null) => void;
|
|
19
21
|
toggleInfiniteApprove: () => void;
|
|
@@ -21,6 +23,10 @@ export interface SettingsState {
|
|
|
21
23
|
setTheme: (theme: Theme) => void;
|
|
22
24
|
toggleAllLiquiditySources: () => void;
|
|
23
25
|
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
26
|
+
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
27
|
+
setAffiliateWallets: (
|
|
28
|
+
affiliateWallets: { [key: string]: string } | null
|
|
29
|
+
) => void;
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
export const useSettingsStore = createSelectors(
|
|
@@ -31,6 +37,8 @@ export const useSettingsStore = createSelectors(
|
|
|
31
37
|
customSlippage: null,
|
|
32
38
|
infiniteApprove: false,
|
|
33
39
|
affiliateRef: null,
|
|
40
|
+
affiliatePercent: null,
|
|
41
|
+
affiliateWallets: null,
|
|
34
42
|
disabledLiquiditySources: [],
|
|
35
43
|
theme: 'auto',
|
|
36
44
|
setSlippage: (slippage) =>
|
|
@@ -45,6 +53,15 @@ export const useSettingsStore = createSelectors(
|
|
|
45
53
|
set(() => ({
|
|
46
54
|
affiliateRef,
|
|
47
55
|
})),
|
|
56
|
+
setAffiliatePercent: (affiliatePercent) =>
|
|
57
|
+
set(() => ({
|
|
58
|
+
affiliatePercent,
|
|
59
|
+
})),
|
|
60
|
+
|
|
61
|
+
setAffiliateWallets: (affiliateWallets) =>
|
|
62
|
+
set(() => ({
|
|
63
|
+
affiliateWallets,
|
|
64
|
+
})),
|
|
48
65
|
toggleAllLiquiditySources: () =>
|
|
49
66
|
set((state) => {
|
|
50
67
|
const { swappers } = useMetaStore.getState().meta;
|
package/src/store/wallets.ts
CHANGED
|
@@ -45,7 +45,7 @@ interface WalletsStore {
|
|
|
45
45
|
initSelectedWallets: () => void;
|
|
46
46
|
setSelectedWallet: (wallet: SelectableWallet) => void;
|
|
47
47
|
clearConnectedWallet: () => void;
|
|
48
|
-
|
|
48
|
+
getWalletsDetails: (accounts: Wallet[], shouldRetry?: boolean) => void;
|
|
49
49
|
setCustomDestination: (customDestination: string) => void;
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -56,7 +56,7 @@ export const useWalletsStore = createSelectors(
|
|
|
56
56
|
selectedWallets: [],
|
|
57
57
|
customDestination: '',
|
|
58
58
|
connectWallet: (accounts) => {
|
|
59
|
-
const
|
|
59
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
60
60
|
set((state) => ({
|
|
61
61
|
connectedWallets: state.connectedWallets
|
|
62
62
|
.filter((wallet) => wallet.walletType !== accounts[0].walletType)
|
|
@@ -72,7 +72,7 @@ export const useWalletsStore = createSelectors(
|
|
|
72
72
|
}))
|
|
73
73
|
),
|
|
74
74
|
}));
|
|
75
|
-
accounts
|
|
75
|
+
getWalletsDetails(accounts);
|
|
76
76
|
},
|
|
77
77
|
disconnectWallet: (walletType) => {
|
|
78
78
|
set((state) => ({
|
|
@@ -131,26 +131,50 @@ export const useWalletsStore = createSelectors(
|
|
|
131
131
|
connectedWallets: [],
|
|
132
132
|
selectedWallets: [],
|
|
133
133
|
})),
|
|
134
|
-
|
|
135
|
-
const
|
|
134
|
+
getWalletsDetails: async (accounts, shouldRetry = true) => {
|
|
135
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
136
|
+
const { tokens } = useMetaStore.getState().meta;
|
|
136
137
|
set((state) => ({
|
|
137
138
|
connectedWallets: state.connectedWallets.map((wallet) => {
|
|
138
|
-
return
|
|
139
|
+
return accounts.find((account) =>
|
|
140
|
+
isAccountAndWalletMatched(account, wallet)
|
|
141
|
+
)
|
|
139
142
|
? { ...wallet, loading: true }
|
|
140
143
|
: wallet;
|
|
141
144
|
}),
|
|
142
145
|
}));
|
|
143
146
|
try {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
const data = accounts.map(({ address, chain }) => ({
|
|
148
|
+
address,
|
|
149
|
+
blockchain: chain,
|
|
150
|
+
}));
|
|
151
|
+
const response = await httpService().getWalletsDetails(data);
|
|
152
|
+
const retrivedBalance = response.wallets;
|
|
148
153
|
if (retrivedBalance) {
|
|
149
154
|
set((state) => ({
|
|
150
155
|
connectedWallets: state.connectedWallets.map(
|
|
151
156
|
(connectedWallet) => {
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
const matchedAccount = accounts.find((account) =>
|
|
158
|
+
isAccountAndWalletMatched(account, connectedWallet)
|
|
159
|
+
);
|
|
160
|
+
const retrivedBalanceAccount = retrivedBalance.find(
|
|
161
|
+
(balance) =>
|
|
162
|
+
balance.address === connectedWallet.address &&
|
|
163
|
+
balance.blockChain === connectedWallet.chain
|
|
164
|
+
);
|
|
165
|
+
if (
|
|
166
|
+
retrivedBalanceAccount?.failed &&
|
|
167
|
+
matchedAccount &&
|
|
168
|
+
shouldRetry
|
|
169
|
+
) {
|
|
170
|
+
getWalletsDetails([matchedAccount], false);
|
|
171
|
+
}
|
|
172
|
+
return matchedAccount && retrivedBalanceAccount
|
|
173
|
+
? makeBalanceFor(
|
|
174
|
+
matchedAccount,
|
|
175
|
+
retrivedBalanceAccount,
|
|
176
|
+
tokens
|
|
177
|
+
)
|
|
154
178
|
: connectedWallet;
|
|
155
179
|
}
|
|
156
180
|
),
|
|
@@ -159,7 +183,9 @@ export const useWalletsStore = createSelectors(
|
|
|
159
183
|
} catch (error) {
|
|
160
184
|
set((state) => ({
|
|
161
185
|
connectedWallets: state.connectedWallets.map((balance) => {
|
|
162
|
-
return
|
|
186
|
+
return accounts.find((account) =>
|
|
187
|
+
isAccountAndWalletMatched(account, balance)
|
|
188
|
+
)
|
|
163
189
|
? resetConnectedWalletState(balance)
|
|
164
190
|
: balance;
|
|
165
191
|
}),
|
package/src/types/config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Asset } from 'rango-sdk';
|
|
2
2
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
3
|
import { ProviderInterface } from '@rango-dev/wallets-core';
|
|
4
|
+
import { Language } from '@rango-dev/ui';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The above type defines a set of optional color properties for a widget.
|
|
@@ -51,6 +52,23 @@ export type WidgetTheme = {
|
|
|
51
52
|
singleTheme?: boolean;
|
|
52
53
|
};
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* If you want to charge users fee per transaction, you should
|
|
57
|
+
* pass `WidgetAffiliate` including affiliateRef, affiliatePercent, and affiliateWallets.
|
|
58
|
+
* @property {string | null} ref - To enable dApps to charge affiliate fees and generate income from
|
|
59
|
+
* users' transactions, the affiliate referral code should be provided. You can create this code by
|
|
60
|
+
* visiting the following link: https://app.rango.exchange/affiliate.
|
|
61
|
+
* @property {number | null} percent - If you want to change the default affiliate fee percentage,
|
|
62
|
+
* you can provide a new value here.
|
|
63
|
+
* @property {{ [key: string]: string }} wallets - If you want to change the default affiliate wallet
|
|
64
|
+
* addresses, you can provide new values here. (Map of route blockchains to affiliate address)
|
|
65
|
+
*/
|
|
66
|
+
export type WidgeAffiliate = {
|
|
67
|
+
ref?: string;
|
|
68
|
+
percent?: number;
|
|
69
|
+
wallets?: { [key: string]: string };
|
|
70
|
+
};
|
|
71
|
+
|
|
54
72
|
/**
|
|
55
73
|
* `BlockchainAndTokenConfig`
|
|
56
74
|
*
|
|
@@ -75,8 +93,8 @@ export type BlockchainAndTokenConfig = {
|
|
|
75
93
|
* and theme.
|
|
76
94
|
*
|
|
77
95
|
* @property {string} apiKey - The API key used to communicate with Rango API
|
|
78
|
-
* @property {
|
|
79
|
-
*
|
|
96
|
+
* @property {WidgeAffiliate} affiliate - If you want to charge users fee per transaction, you should
|
|
97
|
+
* pass `WidgetAffiliate` including affiliateRef, affiliatePercent, and affiliateWallets.
|
|
80
98
|
* @property {number} amount - The default input amount.
|
|
81
99
|
* @property {BlockchainAndTokenConfig} from - The `from` property is an optional property of type
|
|
82
100
|
* `BlockchainAndTokenConfig` that specifies the default blockchain and token from which the user wants to
|
|
@@ -107,7 +125,7 @@ export type BlockchainAndTokenConfig = {
|
|
|
107
125
|
*/
|
|
108
126
|
export type WidgetConfig = {
|
|
109
127
|
apiKey: string;
|
|
110
|
-
|
|
128
|
+
affiliate?: WidgeAffiliate;
|
|
111
129
|
amount?: number;
|
|
112
130
|
from?: BlockchainAndTokenConfig;
|
|
113
131
|
to?: BlockchainAndTokenConfig;
|
|
@@ -115,7 +133,7 @@ export type WidgetConfig = {
|
|
|
115
133
|
wallets?: (WalletType | ProviderInterface)[];
|
|
116
134
|
multiWallets?: boolean;
|
|
117
135
|
customDestination?: boolean;
|
|
118
|
-
language?:
|
|
136
|
+
language?: Language;
|
|
119
137
|
theme?: WidgetTheme;
|
|
120
138
|
externalWallets?: boolean;
|
|
121
139
|
};
|
package/src/types/swap.ts
CHANGED
package/src/utils/routing.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SimulationAssetAndAmount,
|
|
3
3
|
SimulationValidationStatus,
|
|
4
|
-
} from '@rango-dev/ui/dist/types/swaps';
|
|
4
|
+
} from '@rango-dev/ui/dist/widget/ui/src/types/swaps';
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
6
|
import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
7
7
|
import { areEqual } from './common';
|
package/src/utils/swap.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
SwapResult,
|
|
7
7
|
Token,
|
|
8
8
|
} from 'rango-sdk';
|
|
9
|
+
import { i18n } from '@lingui/core';
|
|
9
10
|
import { ConnectedWallet } from '../store/wallets';
|
|
10
11
|
import { ZERO } from '../constants/numbers';
|
|
11
12
|
import { numberToString } from './numbers';
|
|
@@ -22,22 +23,29 @@ import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
|
22
23
|
import { removeDuplicateFrom } from './common';
|
|
23
24
|
|
|
24
25
|
export function getOutputRatio(
|
|
25
|
-
inputUsdValue: BigNumber,
|
|
26
|
-
outputUsdValue: BigNumber
|
|
26
|
+
inputUsdValue: BigNumber | null,
|
|
27
|
+
outputUsdValue: BigNumber | null
|
|
27
28
|
) {
|
|
28
|
-
if (
|
|
29
|
+
if (
|
|
30
|
+
!inputUsdValue ||
|
|
31
|
+
!outputUsdValue ||
|
|
32
|
+
inputUsdValue.lte(ZERO) ||
|
|
33
|
+
outputUsdValue.lte(ZERO)
|
|
34
|
+
)
|
|
35
|
+
return 0;
|
|
29
36
|
return outputUsdValue.div(inputUsdValue).minus(1).multipliedBy(100);
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
export function outputRatioHasWarning(
|
|
33
|
-
inputUsdValue: BigNumber,
|
|
40
|
+
inputUsdValue: BigNumber | null,
|
|
34
41
|
outputRatio: BigNumber | 0
|
|
35
|
-
) {
|
|
42
|
+
): boolean {
|
|
36
43
|
return (
|
|
37
|
-
(parseInt(outputRatio.toFixed(2) || '0') <= -10 &&
|
|
38
|
-
inputUsdValue
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
((parseInt(outputRatio.toFixed(2) || '0') <= -10 &&
|
|
45
|
+
inputUsdValue?.gte(new BigNumber(400))) ||
|
|
46
|
+
(parseInt(outputRatio.toFixed(2) || '0') <= -5 &&
|
|
47
|
+
inputUsdValue?.gte(new BigNumber(1000)))) ??
|
|
48
|
+
false
|
|
41
49
|
);
|
|
42
50
|
}
|
|
43
51
|
|
|
@@ -132,40 +140,45 @@ export function getSwapButtonState(
|
|
|
132
140
|
inputAmount: string
|
|
133
141
|
): SwapButtonState {
|
|
134
142
|
if (loadingMetaStatus !== 'success')
|
|
135
|
-
return { title: 'Connect Wallet'
|
|
143
|
+
return { title: `${i18n.t('Connect Wallet')}`, disabled: true };
|
|
136
144
|
if (connectedWallets.length == 0)
|
|
137
|
-
return { title: 'Connect Wallet'
|
|
138
|
-
if (loading)
|
|
145
|
+
return { title: `${i18n.t('Connect Wallet')}`, disabled: false };
|
|
146
|
+
if (loading)
|
|
147
|
+
return { title: `${i18n.t('Finding Best Route...')}`, disabled: true };
|
|
139
148
|
else if (!inputAmount || inputAmount === '0')
|
|
140
|
-
return { title: 'Enter an amount'
|
|
149
|
+
return { title: `${i18n.t('Enter an amount')}`, disabled: true };
|
|
141
150
|
else if (!bestRoute || !bestRoute.result)
|
|
142
|
-
return { title: 'Swap'
|
|
143
|
-
else if (hasLimitError)
|
|
151
|
+
return { title: `${i18n.t('Swap')}`, disabled: true };
|
|
152
|
+
else if (hasLimitError)
|
|
153
|
+
return { title: `${i18n.t('Limit Error')}`, disabled: true };
|
|
144
154
|
else if (highValueLoss)
|
|
145
|
-
return { title: 'Price impact is too high!'
|
|
155
|
+
return { title: `${i18n.t('Price impact is too high!')}`, disabled: true };
|
|
146
156
|
else if (priceImpactCanNotBeComputed)
|
|
147
157
|
return {
|
|
148
|
-
title: 'USD price is unknown, price impact might be high!'
|
|
158
|
+
title: `${i18n.t('USD price is unknown, price impact might be high!')}`,
|
|
149
159
|
disabled: false,
|
|
150
160
|
hasWarning: true,
|
|
151
161
|
};
|
|
152
162
|
else if (needsToWarnEthOnPath)
|
|
153
163
|
return {
|
|
154
|
-
title: 'The route goes through Ethereum. Continue?'
|
|
164
|
+
title: `${i18n.t('The route goes through Ethereum. Continue?')}`,
|
|
155
165
|
disabled: false,
|
|
156
166
|
hasWarning: true,
|
|
157
167
|
};
|
|
158
|
-
else return { title: 'Swap'
|
|
168
|
+
else return { title: `${i18n.t('Swap')}`, disabled: false };
|
|
159
169
|
}
|
|
160
170
|
|
|
161
171
|
export function canComputePriceImpact(
|
|
162
172
|
bestRoute: BestRouteResponse | null,
|
|
163
173
|
inputAmount: string,
|
|
164
|
-
inputUsdValue: BigNumber,
|
|
165
|
-
outputUsdValue: BigNumber
|
|
174
|
+
inputUsdValue: BigNumber | null,
|
|
175
|
+
outputUsdValue: BigNumber | null
|
|
166
176
|
) {
|
|
167
177
|
return !(
|
|
168
|
-
(inputUsdValue
|
|
178
|
+
(!inputUsdValue ||
|
|
179
|
+
!outputUsdValue ||
|
|
180
|
+
inputUsdValue.lte(ZERO) ||
|
|
181
|
+
outputUsdValue.lte(ZERO)) &&
|
|
169
182
|
!!bestRoute?.result &&
|
|
170
183
|
!!inputAmount &&
|
|
171
184
|
inputAmount !== '0' &&
|
|
@@ -317,6 +330,8 @@ export function createBestRouteRequestBody(
|
|
|
317
330
|
disabledLiquiditySources: string[],
|
|
318
331
|
slippage: number,
|
|
319
332
|
affiliateRef: string | null,
|
|
333
|
+
affiliatePercent: number | null,
|
|
334
|
+
affiliateWallets: { [key: string]: string } | null,
|
|
320
335
|
initialRoute?: BestRouteResponse,
|
|
321
336
|
destination?: string
|
|
322
337
|
): BestRouteRequest {
|
|
@@ -349,16 +364,28 @@ export function createBestRouteRequestBody(
|
|
|
349
364
|
|
|
350
365
|
const filteredBlockchains = removeDuplicateFrom(
|
|
351
366
|
(initialRoute?.result?.swaps || []).reduce(
|
|
352
|
-
(blockchains: string[], swap) =>
|
|
353
|
-
blockchains.push(swap.from.blockchain, swap.to.blockchain)
|
|
354
|
-
|
|
367
|
+
(blockchains: string[], swap) => {
|
|
368
|
+
blockchains.push(swap.from.blockchain, swap.to.blockchain);
|
|
369
|
+
// Check if internalSwaps array exists
|
|
370
|
+
if (swap.internalSwaps && Array.isArray(swap.internalSwaps)) {
|
|
371
|
+
swap.internalSwaps.map((internalSwap) => {
|
|
372
|
+
blockchains.push(
|
|
373
|
+
internalSwap.from.blockchain,
|
|
374
|
+
internalSwap.to.blockchain
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return blockchains;
|
|
379
|
+
},
|
|
355
380
|
[]
|
|
356
381
|
)
|
|
357
382
|
);
|
|
358
383
|
|
|
359
384
|
const requestBody: BestRouteRequest = {
|
|
360
385
|
amount: inputAmount.toString(),
|
|
361
|
-
affiliateRef,
|
|
386
|
+
affiliateRef: affiliateRef ?? undefined,
|
|
387
|
+
affiliatePercent: affiliatePercent ?? undefined,
|
|
388
|
+
affiliateWallets: affiliateWallets ?? undefined,
|
|
362
389
|
checkPrerequisites,
|
|
363
390
|
from: {
|
|
364
391
|
address: fromToken.address,
|
package/src/utils/wallets.ts
CHANGED
|
@@ -159,12 +159,26 @@ export function getRequiredChains(route: BestRouteResponse | null) {
|
|
|
159
159
|
route?.result?.swaps.forEach((swap) => {
|
|
160
160
|
const currentStepFromBlockchain = swap.from.blockchain;
|
|
161
161
|
const currentStepToBlockchain = swap.to.blockchain;
|
|
162
|
-
|
|
163
|
-
if (currentStepFromBlockchain != lastAddedWallet)
|
|
162
|
+
if (!wallets.includes(currentStepFromBlockchain)) {
|
|
164
163
|
wallets.push(currentStepFromBlockchain);
|
|
165
|
-
|
|
166
|
-
if (currentStepToBlockchain
|
|
164
|
+
}
|
|
165
|
+
if (!wallets.includes(currentStepToBlockchain)) {
|
|
167
166
|
wallets.push(currentStepToBlockchain);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Check if internalSwaps array exists
|
|
170
|
+
if (swap.internalSwaps && Array.isArray(swap.internalSwaps)) {
|
|
171
|
+
swap.internalSwaps.forEach((internalSwap) => {
|
|
172
|
+
const internalStepFromBlockchain = internalSwap.from.blockchain;
|
|
173
|
+
const internalStepToBlockchain = internalSwap.to.blockchain;
|
|
174
|
+
if (!wallets.includes(internalStepFromBlockchain)) {
|
|
175
|
+
wallets.push(internalStepFromBlockchain);
|
|
176
|
+
}
|
|
177
|
+
if (!wallets.includes(internalStepToBlockchain)) {
|
|
178
|
+
wallets.push(internalStepToBlockchain);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
168
182
|
});
|
|
169
183
|
return wallets;
|
|
170
184
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectLanguage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSelectLanguage.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,iBAAiB;4BAKR,MAAM;;EAStC"}
|
package/dist/i18n.d.ts
DELETED
package/dist/i18n.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.js"],"names":[],"mappings":""}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useTranslation } from 'react-i18next';
|
|
2
|
-
|
|
3
|
-
export default function useSelectLanguage() {
|
|
4
|
-
const { i18n } = useTranslation();
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
const currentLanguage = i18n?.language || 'en';
|
|
8
|
-
const changeLanguage = (value: string) => {
|
|
9
|
-
if (currentLanguage !== value) {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
i18n.changeLanguage(value);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return { changeLanguage, currentLanguage };
|
|
17
|
-
}
|
package/src/i18n.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import i18n from 'i18next';
|
|
2
|
-
import { initReactI18next } from 'react-i18next';
|
|
3
|
-
import en from './languages/en.json';
|
|
4
|
-
import tr from './languages/tr.json';
|
|
5
|
-
import Backend from 'i18next-http-backend';
|
|
6
|
-
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
7
|
-
|
|
8
|
-
const languages = ['en', 'tr'];
|
|
9
|
-
|
|
10
|
-
i18n
|
|
11
|
-
.use(Backend)
|
|
12
|
-
// detect user language
|
|
13
|
-
.use(LanguageDetector)
|
|
14
|
-
// pass the i18n instance to react-i18next.
|
|
15
|
-
.use(initReactI18next)
|
|
16
|
-
.init({
|
|
17
|
-
resources: {
|
|
18
|
-
en: {
|
|
19
|
-
translation: en,
|
|
20
|
-
},
|
|
21
|
-
tr: {
|
|
22
|
-
translation: tr,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
fallbackLng: 'en',
|
|
26
|
-
debug: true,
|
|
27
|
-
whitelist: languages,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export default i18n;
|