@rango-dev/widget-embedded 0.17.1-next.25 → 0.17.1-next.27
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/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +3 -3
- package/dist/components/HeaderButtons/HomeButtons.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/Slippage/Slippage.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.helpers.d.ts +2 -2
- package/dist/components/TokenList/TokenList.helpers.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.types.d.ts +3 -9
- package/dist/components/TokenList/TokenList.types.d.ts.map +1 -1
- package/dist/components/TokenList/index.d.ts +0 -1
- package/dist/components/TokenList/index.d.ts.map +1 -1
- package/dist/containers/App/App.d.ts.map +1 -1
- package/dist/hooks/useLanguage.d.ts.map +1 -1
- 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/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/ThemePage.d.ts.map +1 -1
- package/dist/store/AppStore.d.ts +37 -1
- package/dist/store/AppStore.d.ts.map +1 -1
- package/dist/store/app.d.ts +39 -2
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/quote.d.ts +4 -5
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/settings.d.ts +39 -0
- package/dist/store/slices/settings.d.ts.map +1 -0
- package/dist/store/wallets.d.ts +5 -2
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +28 -9
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +15 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +4 -1
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +6 -8
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/HeaderButtons/HomeButtons.tsx +28 -18
- package/src/components/Layout/Layout.tsx +11 -1
- package/src/components/NoResult/NoResult.tsx +2 -5
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +2 -2
- package/src/components/Slippage/Slippage.tsx +3 -5
- package/src/components/TokenList/TokenList.helpers.ts +2 -2
- package/src/components/TokenList/TokenList.tsx +10 -12
- package/src/components/TokenList/TokenList.types.ts +3 -10
- package/src/components/TokenList/index.ts +0 -1
- package/src/containers/App/App.tsx +0 -2
- package/src/containers/Wallets/Wallets.tsx +3 -3
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +4 -4
- package/src/hooks/useLanguage.ts +2 -3
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.ts +2 -2
- package/src/hooks/useSwapInput.ts +4 -4
- package/src/hooks/useSyncStoresWithConfig.ts +1 -2
- package/src/hooks/useTheme.ts +4 -5
- package/src/pages/ConfirmSwapPage.tsx +2 -3
- package/src/pages/Home.tsx +9 -33
- package/src/pages/LiquiditySourcePage.tsx +3 -3
- package/src/pages/SelectSwapItemsPage.tsx +3 -6
- package/src/pages/SettingsPage.tsx +22 -11
- package/src/pages/ThemePage.tsx +2 -3
- package/src/store/AppStore.tsx +7 -1
- package/src/store/app.ts +31 -5
- package/src/store/quote.ts +2 -3
- package/src/store/slices/settings.ts +168 -0
- package/src/store/wallets.ts +56 -29
- package/src/types/config.ts +38 -8
- package/src/types/wallets.ts +18 -1
- package/src/utils/settings.ts +11 -5
- package/src/utils/wallets.ts +80 -134
- package/dist/store/settings.d.ts +0 -83
- package/dist/store/settings.d.ts.map +0 -1
- package/src/store/settings.ts +0 -161
package/src/utils/wallets.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { TokenWithBalance } from '../components/TokenList';
|
|
2
1
|
import type { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
3
|
-
import type { Wallet } from '../types';
|
|
2
|
+
import type { Balance, TokenHash, TokensBalance, Wallet } from '../types';
|
|
4
3
|
import type { WalletInfo as ModalWalletInfo } from '@rango-dev/ui';
|
|
5
4
|
import type {
|
|
5
|
+
Asset,
|
|
6
6
|
Network,
|
|
7
7
|
WalletInfo,
|
|
8
8
|
WalletState,
|
|
@@ -29,6 +29,12 @@ import BigNumber from 'bignumber.js';
|
|
|
29
29
|
import { isCosmosBlockchain } from 'rango-types';
|
|
30
30
|
|
|
31
31
|
import { ZERO } from '../constants/numbers';
|
|
32
|
+
import {
|
|
33
|
+
BALANCE_MAX_DECIMALS,
|
|
34
|
+
BALANCE_MIN_DECIMALS,
|
|
35
|
+
USD_VALUE_MAX_DECIMALS,
|
|
36
|
+
USD_VALUE_MIN_DECIMALS,
|
|
37
|
+
} from '../constants/routing';
|
|
32
38
|
import { EXCLUDED_WALLETS } from '../constants/wallets';
|
|
33
39
|
|
|
34
40
|
import { numberToString } from './numbers';
|
|
@@ -218,43 +224,6 @@ export function getRequiredChains(quote: BestRouteResponse | null) {
|
|
|
218
224
|
|
|
219
225
|
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
220
226
|
|
|
221
|
-
export function getBalanceFromWallet(
|
|
222
|
-
connectedWallets: ConnectedWallet[],
|
|
223
|
-
chain: string,
|
|
224
|
-
symbol: string,
|
|
225
|
-
address: string | null
|
|
226
|
-
): TokenBalance | null {
|
|
227
|
-
if (connectedWallets.length === 0) {
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const selectedChainWallets = connectedWallets.filter(
|
|
232
|
-
(wallet) => wallet.chain === chain
|
|
233
|
-
);
|
|
234
|
-
if (selectedChainWallets.length === 0) {
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return (
|
|
239
|
-
selectedChainWallets
|
|
240
|
-
.map(
|
|
241
|
-
(wallet) =>
|
|
242
|
-
wallet.balances?.find(
|
|
243
|
-
(balance) =>
|
|
244
|
-
(address !== null && balance.address === address) ||
|
|
245
|
-
(address === null &&
|
|
246
|
-
balance.address === address &&
|
|
247
|
-
balance.symbol === symbol)
|
|
248
|
-
) || null
|
|
249
|
-
)
|
|
250
|
-
.filter((balance) => balance !== null)
|
|
251
|
-
.sort(
|
|
252
|
-
(a, b) => parseFloat(b?.amount || '0') - parseFloat(a?.amount || '1')
|
|
253
|
-
)
|
|
254
|
-
.find(() => true) || null
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
227
|
export function isAccountAndWalletMatched(
|
|
259
228
|
account: Wallet,
|
|
260
229
|
connectedWallet: ConnectedWallet
|
|
@@ -348,30 +317,6 @@ function numberWithThousandSeparator(number: string | number): string {
|
|
|
348
317
|
return parts.join('.');
|
|
349
318
|
}
|
|
350
319
|
|
|
351
|
-
export const sortTokens = (tokens: TokenWithBalance[]): TokenWithBalance[] => {
|
|
352
|
-
const walletConnected = !!tokens.some((token) => token.balance);
|
|
353
|
-
if (!walletConnected) {
|
|
354
|
-
return tokens
|
|
355
|
-
.filter((token) => !token.address)
|
|
356
|
-
.concat(
|
|
357
|
-
tokens.filter((token) => token.address && !token.isSecondaryCoin),
|
|
358
|
-
tokens.filter((token) => token.isSecondaryCoin)
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return tokens
|
|
363
|
-
.filter((token) => !!token.balance)
|
|
364
|
-
.sort(
|
|
365
|
-
(tokenA, tokenB) =>
|
|
366
|
-
parseFloat(tokenB.balance?.usdValue || '0') -
|
|
367
|
-
parseFloat(tokenA.balance?.usdValue || '0')
|
|
368
|
-
)
|
|
369
|
-
.concat(
|
|
370
|
-
tokens.filter((token) => !token.balance && !token.isSecondaryCoin),
|
|
371
|
-
tokens.filter((token) => !token.balance && token.isSecondaryCoin)
|
|
372
|
-
);
|
|
373
|
-
};
|
|
374
|
-
|
|
375
320
|
export const getUsdPrice = (
|
|
376
321
|
blockchain: string,
|
|
377
322
|
symbol: string,
|
|
@@ -415,98 +360,58 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
415
360
|
);
|
|
416
361
|
};
|
|
417
362
|
|
|
418
|
-
export function
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
let tokenUsdValue = '';
|
|
435
|
-
if (otherProps.usdPrice) {
|
|
436
|
-
tokenUsdValue = numberToString(
|
|
437
|
-
new BigNumber(
|
|
438
|
-
getBalanceFromWallet(
|
|
439
|
-
connectedWallets,
|
|
440
|
-
otherProps.blockchain,
|
|
441
|
-
otherProps.symbol,
|
|
442
|
-
otherProps.address
|
|
443
|
-
)?.amount || ZERO
|
|
444
|
-
).multipliedBy(otherProps.usdPrice)
|
|
445
|
-
);
|
|
446
|
-
}
|
|
363
|
+
export function formatBalance(balance: Balance | null): Balance | null {
|
|
364
|
+
const formattedBalance: Balance | null = balance
|
|
365
|
+
? {
|
|
366
|
+
...balance,
|
|
367
|
+
amount: numberToString(
|
|
368
|
+
balance.amount,
|
|
369
|
+
BALANCE_MIN_DECIMALS,
|
|
370
|
+
BALANCE_MAX_DECIMALS
|
|
371
|
+
),
|
|
372
|
+
usdValue: numberToString(
|
|
373
|
+
balance.usdValue,
|
|
374
|
+
USD_VALUE_MIN_DECIMALS,
|
|
375
|
+
USD_VALUE_MAX_DECIMALS
|
|
376
|
+
),
|
|
377
|
+
}
|
|
378
|
+
: null;
|
|
447
379
|
|
|
448
|
-
|
|
449
|
-
...otherProps,
|
|
450
|
-
...(tokenAmount !== '0' && {
|
|
451
|
-
balance: { amount: tokenAmount, usdValue: tokenUsdValue },
|
|
452
|
-
}),
|
|
453
|
-
};
|
|
454
|
-
});
|
|
380
|
+
return formattedBalance;
|
|
455
381
|
}
|
|
456
382
|
|
|
457
|
-
export function
|
|
458
|
-
tokens:
|
|
459
|
-
|
|
383
|
+
export function sortTokensByBalance(
|
|
384
|
+
tokens: Token[],
|
|
385
|
+
getBalanceFor: (token: Token) => Balance | null
|
|
460
386
|
) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
list.sort((tokenA, tokenB) => {
|
|
466
|
-
if (tokenA.balance?.usdValue && tokenB.balance?.usdValue) {
|
|
387
|
+
tokens.sort((token1, token2) => {
|
|
388
|
+
const token1Balance = getBalanceFor(token1);
|
|
389
|
+
const token2Balance = getBalanceFor(token2);
|
|
390
|
+
if (token1Balance?.usdValue && token2Balance?.usdValue) {
|
|
467
391
|
return (
|
|
468
|
-
parseFloat(
|
|
469
|
-
parseFloat(tokenA.balance.usdValue)
|
|
392
|
+
parseFloat(token2Balance.usdValue) - parseFloat(token1Balance.usdValue)
|
|
470
393
|
);
|
|
471
394
|
}
|
|
472
395
|
|
|
473
|
-
if (!
|
|
396
|
+
if (!token1Balance?.usdValue && token2Balance?.usdValue) {
|
|
474
397
|
return 1;
|
|
475
398
|
}
|
|
476
399
|
|
|
477
|
-
if (
|
|
400
|
+
if (token1Balance?.usdValue && !token2Balance?.usdValue) {
|
|
478
401
|
return -1;
|
|
479
402
|
}
|
|
480
403
|
|
|
481
|
-
if (!
|
|
404
|
+
if (!token1Balance?.usdValue && !token2Balance?.usdValue) {
|
|
482
405
|
return (
|
|
483
|
-
parseFloat(
|
|
484
|
-
parseFloat(
|
|
406
|
+
parseFloat(token2Balance?.amount || '0') -
|
|
407
|
+
parseFloat(token1Balance?.amount || '0')
|
|
485
408
|
);
|
|
486
409
|
}
|
|
487
410
|
|
|
488
411
|
return 0;
|
|
489
412
|
});
|
|
490
413
|
|
|
491
|
-
return
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
export function getSortedTokens(
|
|
495
|
-
chain: BlockchainMeta | null,
|
|
496
|
-
tokens: Token[],
|
|
497
|
-
connectedWallets: ConnectedWallet[],
|
|
498
|
-
otherChainTokens: TokenWithBalance[]
|
|
499
|
-
): TokenWithBalance[] {
|
|
500
|
-
const fromChainEqualsToToBlockchain =
|
|
501
|
-
chain?.name === otherChainTokens[0]?.name;
|
|
502
|
-
if (fromChainEqualsToToBlockchain) {
|
|
503
|
-
return otherChainTokens;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
const filteredTokens = tokens.filter(
|
|
507
|
-
(token) => token.blockchain === chain?.name
|
|
508
|
-
);
|
|
509
|
-
return sortTokens(getTokensWithBalance(filteredTokens, connectedWallets));
|
|
414
|
+
return tokens;
|
|
510
415
|
}
|
|
511
416
|
|
|
512
417
|
export function tokensAreEqual(
|
|
@@ -568,3 +473,44 @@ export function getAddress({
|
|
|
568
473
|
connectedWallet.chain === chain
|
|
569
474
|
)?.address;
|
|
570
475
|
}
|
|
476
|
+
|
|
477
|
+
export function createTokenHash(token: Asset): TokenHash {
|
|
478
|
+
return `${token.blockchain}-${token.symbol}-${token.address ?? ''}`;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export function makeTokensBalance(connectedWallets: ConnectedWallet[]) {
|
|
482
|
+
return connectedWallets
|
|
483
|
+
.flatMap((wallet) => wallet.balances)
|
|
484
|
+
.reduce((balances: TokensBalance, balance) => {
|
|
485
|
+
const currentBalance = {
|
|
486
|
+
amount: balance?.amount ?? '',
|
|
487
|
+
decimals: balance?.decimal ?? 0,
|
|
488
|
+
usdValue: balance?.usdPrice
|
|
489
|
+
? new BigNumber(balance?.usdPrice ?? ZERO)
|
|
490
|
+
.multipliedBy(balance?.amount)
|
|
491
|
+
.toString()
|
|
492
|
+
: '',
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const tokenHash = balance
|
|
496
|
+
? createTokenHash({
|
|
497
|
+
symbol: balance.symbol,
|
|
498
|
+
blockchain: balance.chain,
|
|
499
|
+
address: balance.address,
|
|
500
|
+
})
|
|
501
|
+
: null;
|
|
502
|
+
|
|
503
|
+
const prevBalance = tokenHash ? balances[tokenHash] : null;
|
|
504
|
+
|
|
505
|
+
const shouldUpdateBalance =
|
|
506
|
+
tokenHash &&
|
|
507
|
+
(!prevBalance ||
|
|
508
|
+
(prevBalance && prevBalance.amount < currentBalance.amount));
|
|
509
|
+
|
|
510
|
+
if (shouldUpdateBalance) {
|
|
511
|
+
balances[tokenHash] = currentBalance;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return balances;
|
|
515
|
+
}, {});
|
|
516
|
+
}
|
package/dist/store/settings.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { SwapperMeta } from 'rango-sdk';
|
|
2
|
-
import { type Language } from '@rango-dev/ui';
|
|
3
|
-
export type ThemeMode = 'auto' | 'dark' | 'light';
|
|
4
|
-
export interface SettingsState {
|
|
5
|
-
/** Keeping a history of blockchains that user has selected (in Swap process) */
|
|
6
|
-
preferredBlockchains: string[];
|
|
7
|
-
slippage: number;
|
|
8
|
-
customSlippage: number | null;
|
|
9
|
-
infiniteApprove: boolean;
|
|
10
|
-
disabledLiquiditySources: string[];
|
|
11
|
-
theme: ThemeMode;
|
|
12
|
-
language: Language;
|
|
13
|
-
affiliateRef: string | null;
|
|
14
|
-
affiliatePercent: number | null;
|
|
15
|
-
affiliateWallets: {
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
} | null;
|
|
18
|
-
setSlippage: (slippage: number) => void;
|
|
19
|
-
setCustomSlippage: (customSlippage: number | null) => void;
|
|
20
|
-
toggleInfiniteApprove: () => void;
|
|
21
|
-
toggleLiquiditySource: (name: string) => void;
|
|
22
|
-
setTheme: (theme: ThemeMode) => void;
|
|
23
|
-
setLanguage: (language: Language) => void;
|
|
24
|
-
toggleAllLiquiditySources: (swappers: SwapperMeta[], shouldReset?: boolean) => void;
|
|
25
|
-
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
26
|
-
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
27
|
-
setAffiliateWallets: (affiliateWallets: {
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
} | null) => void;
|
|
30
|
-
addPreferredBlockchain: (blockchain: string) => void;
|
|
31
|
-
}
|
|
32
|
-
export declare const useSettingsStore: {
|
|
33
|
-
(): SettingsState;
|
|
34
|
-
<U>(selector: (state: SettingsState) => U): U;
|
|
35
|
-
<U_1>(selector: (state: SettingsState) => U_1, equalityFn: (a: U_1, b: U_1) => boolean): U_1;
|
|
36
|
-
} & Omit<Omit<import("zustand").StoreApi<SettingsState>, "persist"> & {
|
|
37
|
-
persist: {
|
|
38
|
-
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsState, SettingsState>>) => void;
|
|
39
|
-
clearStorage: () => void;
|
|
40
|
-
rehydrate: () => void | Promise<void>;
|
|
41
|
-
hasHydrated: () => boolean;
|
|
42
|
-
onHydrate: (fn: (state: SettingsState) => void) => () => void;
|
|
43
|
-
onFinishHydration: (fn: (state: SettingsState) => void) => () => void;
|
|
44
|
-
getOptions: () => Partial<import("zustand/middleware").PersistOptions<SettingsState, SettingsState>>;
|
|
45
|
-
};
|
|
46
|
-
}, "subscribe"> & {
|
|
47
|
-
subscribe: {
|
|
48
|
-
(listener: (selectedState: SettingsState, previousSelectedState: SettingsState) => void): () => void;
|
|
49
|
-
<U_2>(selector: (state: SettingsState) => U_2, listener: (selectedState: U_2, previousSelectedState: U_2) => void, options?: {
|
|
50
|
-
equalityFn?: ((a: U_2, b: U_2) => boolean) | undefined;
|
|
51
|
-
fireImmediately?: boolean | undefined;
|
|
52
|
-
} | undefined): () => void;
|
|
53
|
-
};
|
|
54
|
-
} & {
|
|
55
|
-
use: {
|
|
56
|
-
preferredBlockchains: () => string[];
|
|
57
|
-
slippage: () => number;
|
|
58
|
-
customSlippage: () => number | null;
|
|
59
|
-
infiniteApprove: () => boolean;
|
|
60
|
-
disabledLiquiditySources: () => string[];
|
|
61
|
-
theme: () => ThemeMode;
|
|
62
|
-
language: () => "en" | "es" | "ja" | "fr";
|
|
63
|
-
affiliateRef: () => string | null;
|
|
64
|
-
affiliatePercent: () => number | null;
|
|
65
|
-
affiliateWallets: () => {
|
|
66
|
-
[key: string]: string;
|
|
67
|
-
} | null;
|
|
68
|
-
setSlippage: () => (slippage: number) => void;
|
|
69
|
-
setCustomSlippage: () => (customSlippage: number | null) => void;
|
|
70
|
-
toggleInfiniteApprove: () => () => void;
|
|
71
|
-
toggleLiquiditySource: () => (name: string) => void;
|
|
72
|
-
setTheme: () => (theme: ThemeMode) => void;
|
|
73
|
-
setLanguage: () => (language: Language) => void;
|
|
74
|
-
toggleAllLiquiditySources: () => (swappers: SwapperMeta[], shouldReset?: boolean) => void;
|
|
75
|
-
setAffiliateRef: () => (affiliateRef: string | null) => void;
|
|
76
|
-
setAffiliatePercent: () => (affiliatePercent: number | null) => void;
|
|
77
|
-
setAffiliateWallets: () => (affiliateWallets: {
|
|
78
|
-
[key: string]: string;
|
|
79
|
-
} | null) => void;
|
|
80
|
-
addPreferredBlockchain: () => (blockchain: string) => void;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/store/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAW9C,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,CACzB,QAAQ,EAAE,WAAW,EAAE,EACvB,WAAW,CAAC,EAAE,OAAO,KAClB,IAAI,CAAC;IACV,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sCAlBH,MAAM,KAAK,IAAI;kDACH,MAAM,GAAG,IAAI,KAAK,IAAI;2CAC7B,IAAI;4CACH,MAAM,KAAK,IAAI;gCAC3B,SAAS,KAAK,IAAI;sCACZ,QAAQ,KAAK,IAAI;oDAE7B,WAAW,EAAE,gBACT,OAAO,KAClB,IAAI;8CACuB,MAAM,GAAG,IAAI,KAAK,IAAI;sDACd,MAAM,GAAG,IAAI,KAAK,IAAI;;;qBAGzD,IAAI;mDAC4B,MAAM,KAAK,IAAI;;CAqHrD,CAAC"}
|
package/src/store/settings.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import type { SwapperMeta } from 'rango-sdk';
|
|
2
|
-
|
|
3
|
-
import { type Language } from '@rango-dev/ui';
|
|
4
|
-
import { create } from 'zustand';
|
|
5
|
-
import { persist, subscribeWithSelector } from 'zustand/middleware';
|
|
6
|
-
|
|
7
|
-
import { BLOCKCHAIN_LIST_SIZE } from '../constants/configs';
|
|
8
|
-
import { DEFAULT_LANGUAGE } from '../constants/languages';
|
|
9
|
-
import { DEFAULT_SLIPPAGE } from '../constants/swapSettings';
|
|
10
|
-
import { removeDuplicateFrom } from '../utils/common';
|
|
11
|
-
|
|
12
|
-
import createSelectors from './selectors';
|
|
13
|
-
|
|
14
|
-
export type ThemeMode = 'auto' | 'dark' | 'light';
|
|
15
|
-
|
|
16
|
-
export interface SettingsState {
|
|
17
|
-
/** Keeping a history of blockchains that user has selected (in Swap process) */
|
|
18
|
-
preferredBlockchains: string[];
|
|
19
|
-
slippage: number;
|
|
20
|
-
customSlippage: number | null;
|
|
21
|
-
infiniteApprove: boolean;
|
|
22
|
-
disabledLiquiditySources: string[];
|
|
23
|
-
theme: ThemeMode;
|
|
24
|
-
language: Language;
|
|
25
|
-
affiliateRef: string | null;
|
|
26
|
-
affiliatePercent: number | null;
|
|
27
|
-
affiliateWallets: { [key: string]: string } | null;
|
|
28
|
-
|
|
29
|
-
setSlippage: (slippage: number) => void;
|
|
30
|
-
setCustomSlippage: (customSlippage: number | null) => void;
|
|
31
|
-
toggleInfiniteApprove: () => void;
|
|
32
|
-
toggleLiquiditySource: (name: string) => void;
|
|
33
|
-
setTheme: (theme: ThemeMode) => void;
|
|
34
|
-
setLanguage: (language: Language) => void;
|
|
35
|
-
toggleAllLiquiditySources: (
|
|
36
|
-
swappers: SwapperMeta[],
|
|
37
|
-
shouldReset?: boolean
|
|
38
|
-
) => void;
|
|
39
|
-
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
40
|
-
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
41
|
-
setAffiliateWallets: (
|
|
42
|
-
affiliateWallets: { [key: string]: string } | null
|
|
43
|
-
) => void;
|
|
44
|
-
addPreferredBlockchain: (blockchain: string) => void;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const useSettingsStore = createSelectors(
|
|
48
|
-
create<SettingsState>()(
|
|
49
|
-
persist(
|
|
50
|
-
subscribeWithSelector((set, get) => ({
|
|
51
|
-
preferredBlockchains: [],
|
|
52
|
-
slippage: DEFAULT_SLIPPAGE,
|
|
53
|
-
customSlippage: null,
|
|
54
|
-
infiniteApprove: false,
|
|
55
|
-
affiliateRef: null,
|
|
56
|
-
affiliatePercent: null,
|
|
57
|
-
affiliateWallets: null,
|
|
58
|
-
disabledLiquiditySources: [],
|
|
59
|
-
theme: 'auto',
|
|
60
|
-
language: DEFAULT_LANGUAGE,
|
|
61
|
-
addPreferredBlockchain: (blockchain) => {
|
|
62
|
-
const currentPreferredBlockchains = get().preferredBlockchains;
|
|
63
|
-
|
|
64
|
-
const noNeedToDoAnything = currentPreferredBlockchains.find(
|
|
65
|
-
(preferredBlockchain, index) => {
|
|
66
|
-
const isSameBlockchain = preferredBlockchain === blockchain;
|
|
67
|
-
const isInVisibleList = index <= BLOCKCHAIN_LIST_SIZE - 1;
|
|
68
|
-
|
|
69
|
-
return isSameBlockchain && isInVisibleList;
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
if (noNeedToDoAnything) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const nextPreferredBlockchains: string[] =
|
|
78
|
-
currentPreferredBlockchains.filter((preferredBlockchain) => {
|
|
79
|
-
const isSameBlockchain = preferredBlockchain === blockchain;
|
|
80
|
-
|
|
81
|
-
return !isSameBlockchain;
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
set(() => ({
|
|
85
|
-
preferredBlockchains: [blockchain, ...nextPreferredBlockchains],
|
|
86
|
-
}));
|
|
87
|
-
},
|
|
88
|
-
setSlippage: (slippage) =>
|
|
89
|
-
set(() => ({
|
|
90
|
-
slippage: slippage,
|
|
91
|
-
})),
|
|
92
|
-
setCustomSlippage: (customSlippage) =>
|
|
93
|
-
set(() => ({
|
|
94
|
-
customSlippage: customSlippage,
|
|
95
|
-
})),
|
|
96
|
-
setAffiliateRef: (affiliateRef) =>
|
|
97
|
-
set(() => ({
|
|
98
|
-
affiliateRef,
|
|
99
|
-
})),
|
|
100
|
-
setAffiliatePercent: (affiliatePercent) =>
|
|
101
|
-
set(() => ({
|
|
102
|
-
affiliatePercent,
|
|
103
|
-
})),
|
|
104
|
-
|
|
105
|
-
setAffiliateWallets: (affiliateWallets) =>
|
|
106
|
-
set(() => ({
|
|
107
|
-
affiliateWallets,
|
|
108
|
-
})),
|
|
109
|
-
toggleAllLiquiditySources: (swappers, shouldReset) =>
|
|
110
|
-
set((state) => {
|
|
111
|
-
if (shouldReset) {
|
|
112
|
-
return { disabledLiquiditySources: [] };
|
|
113
|
-
}
|
|
114
|
-
const swappersGroup = removeDuplicateFrom(
|
|
115
|
-
swappers.map((swapper) => swapper.swapperGroup)
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
swappersGroup.length === state.disabledLiquiditySources.length
|
|
120
|
-
) {
|
|
121
|
-
return { disabledLiquiditySources: [] };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
disabledLiquiditySources: swappersGroup,
|
|
126
|
-
};
|
|
127
|
-
}),
|
|
128
|
-
toggleInfiniteApprove: () =>
|
|
129
|
-
set((state) => ({
|
|
130
|
-
infiniteApprove: !state.infiniteApprove,
|
|
131
|
-
})),
|
|
132
|
-
toggleLiquiditySource: (name) =>
|
|
133
|
-
set((state) => {
|
|
134
|
-
if (state.disabledLiquiditySources.includes(name)) {
|
|
135
|
-
return {
|
|
136
|
-
disabledLiquiditySources: state.disabledLiquiditySources.filter(
|
|
137
|
-
(liquiditySource) => liquiditySource != name
|
|
138
|
-
),
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
disabledLiquiditySources:
|
|
143
|
-
state.disabledLiquiditySources.concat(name),
|
|
144
|
-
};
|
|
145
|
-
}),
|
|
146
|
-
setTheme: (theme) =>
|
|
147
|
-
set(() => ({
|
|
148
|
-
theme,
|
|
149
|
-
})),
|
|
150
|
-
setLanguage: (language) =>
|
|
151
|
-
set(() => ({
|
|
152
|
-
language,
|
|
153
|
-
})),
|
|
154
|
-
})),
|
|
155
|
-
{
|
|
156
|
-
name: 'user-settings',
|
|
157
|
-
skipHydration: true,
|
|
158
|
-
}
|
|
159
|
-
)
|
|
160
|
-
)
|
|
161
|
-
);
|