@rango-dev/widget-embedded 0.23.1-next.8 → 0.24.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/dist/components/AppRouter.d.ts +1 -6
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -283
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +489 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts +4 -0
- package/dist/components/HeaderButtons/InProgressTransactionBadge.d.ts.map +1 -0
- package/dist/components/HeaderButtons/RefreshButton.d.ts.map +1 -1
- package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts.map +1 -1
- package/dist/components/HeaderButtons/WalletButton.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.helpers.d.ts +8 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.styles.d.ts +167 -1
- package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.types.d.ts +1 -0
- package/dist/components/NoResult/NoResult.types.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +165 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.types.d.ts +1 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteTrigger.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +1 -0
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +3 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.types.d.ts +1 -0
- package/dist/components/Quotes/Quotes.types.d.ts.map +1 -1
- package/dist/components/Quotes/SelectStrategy.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/languages.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +1 -5
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/constants/searchFor.d.ts +7 -0
- package/dist/constants/searchFor.d.ts.map +1 -0
- package/dist/containers/App/App.d.ts.map +1 -1
- package/dist/containers/App/App.styles.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts +3 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.types.d.ts +1 -0
- package/dist/containers/Inputs/Inputs.types.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
- package/dist/containers/Settings/Lists.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.types.d.ts +13 -2
- package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
- package/dist/containers/Widget/Widget.d.ts.map +1 -1
- package/dist/hooks/useBootstrap/index.d.ts +2 -0
- package/dist/hooks/useBootstrap/index.d.ts.map +1 -0
- package/dist/hooks/useBootstrap/useBootstrap.d.ts +2 -0
- package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -0
- package/dist/hooks/useScreenDetect.d.ts +9 -0
- package/dist/hooks/useScreenDetect.d.ts.map +1 -0
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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/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/store/AppStore.d.ts +2 -2
- package/dist/store/app.d.ts +2 -2
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts +3 -1
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/slices/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +9 -5
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/colors.d.ts +5 -3
- package/dist/utils/colors.d.ts.map +1 -1
- package/dist/utils/common.d.ts +4 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +2 -1
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/meta.d.ts +1 -0
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -0
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/ui.d.ts +5 -2
- package/dist/utils/ui.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/components/AppRouter.tsx +1 -29
- package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +6 -12
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +7 -11
- package/src/components/ConfirmWalletsModal/WalletList.tsx +2 -2
- package/src/components/HeaderButtons/HeaderButtons.styles.ts +43 -2
- package/src/components/HeaderButtons/HeaderButtons.tsx +2 -0
- package/src/components/HeaderButtons/InProgressTransactionBadge.tsx +26 -0
- package/src/components/HeaderButtons/RefreshButton.tsx +2 -1
- package/src/components/HeaderButtons/UnreadNotificationsBadge.tsx +10 -2
- package/src/components/HeaderButtons/WalletButton.tsx +26 -6
- package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.ts +1 -1
- package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.tsx +4 -4
- package/src/components/NoResult/NoResult.helpers.ts +13 -0
- package/src/components/NoResult/NoResult.styles.ts +19 -1
- package/src/components/NoResult/NoResult.tsx +27 -16
- package/src/components/NoResult/NoResult.types.ts +1 -0
- package/src/components/NotificationContent/NotificationContent.styles.ts +14 -1
- package/src/components/NotificationContent/NotificationContent.tsx +49 -39
- package/src/components/Quote/Quote.styles.ts +13 -14
- package/src/components/Quote/Quote.tsx +166 -145
- package/src/components/Quote/Quote.types.ts +1 -0
- package/src/components/Quote/QuoteTrigger.tsx +19 -14
- package/src/components/QuoteSkeleton/QuoteSkeleton.styles.ts +10 -2
- package/src/components/QuoteSkeleton/QuoteSkeleton.tsx +2 -2
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.styles.ts +2 -2
- package/src/components/QuoteSkeleton/QuoteSummarySkeleton.tsx +5 -4
- package/src/components/QuoteSkeleton/StepSkeleton.styles.ts +7 -0
- package/src/components/QuoteSkeleton/StepSkeleton.tsx +1 -1
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +1 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +3 -3
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts +1 -1
- package/src/components/Quotes/Quotes.tsx +33 -21
- package/src/components/Quotes/Quotes.types.ts +1 -0
- package/src/components/Quotes/SelectStrategy.tsx +27 -10
- package/src/components/Slippage/Slippage.tsx +11 -13
- package/src/components/SwapDetails/SwapDetails.tsx +3 -1
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +5 -1
- package/src/components/TokenList/TokenList.tsx +9 -8
- package/src/constants/errors.ts +1 -1
- package/src/constants/index.ts +1 -1
- package/src/constants/languages.ts +27 -1
- package/src/constants/quote.ts +1 -24
- package/src/constants/searchFor.ts +6 -0
- package/src/containers/App/App.styles.ts +0 -4
- package/src/containers/App/App.tsx +4 -28
- package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +13 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +5 -0
- package/src/containers/Inputs/Inputs.tsx +2 -3
- package/src/containers/Inputs/Inputs.types.ts +1 -0
- package/src/containers/QuoteInfo/QuoteInfo.tsx +2 -0
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +1 -0
- package/src/containers/Settings/Lists.tsx +28 -13
- package/src/containers/Wallets/Wallets.tsx +27 -10
- package/src/containers/Wallets/Wallets.types.ts +13 -2
- package/src/containers/Widget/Widget.tsx +13 -13
- package/src/hooks/useBootstrap/index.ts +1 -0
- package/src/hooks/useBootstrap/useBootstrap.ts +72 -0
- package/src/hooks/useScreenDetect.ts +49 -0
- package/src/hooks/useSwapInput.ts +7 -2
- package/src/hooks/useTheme.ts +1 -8
- package/src/hooks/useWalletList.ts +12 -0
- package/src/pages/ConfirmSwapPage.tsx +14 -5
- package/src/pages/Home.tsx +29 -7
- package/src/pages/LanguagePage.tsx +14 -1
- package/src/pages/LiquiditySourcePage.tsx +4 -3
- package/src/pages/SelectSwapItemsPage.tsx +2 -7
- package/src/pages/SettingsPage.tsx +0 -1
- package/src/store/slices/config.ts +3 -2
- package/src/store/slices/data.ts +82 -34
- package/src/store/slices/settings.ts +10 -4
- package/src/types/config.ts +9 -5
- package/src/utils/colors.ts +106 -75
- package/src/utils/common.ts +181 -0
- package/src/utils/configs.ts +12 -1
- package/src/utils/meta.ts +21 -0
- package/src/utils/swap.ts +12 -5
- package/src/utils/ui.ts +7 -5
- package/src/utils/wallets.ts +5 -47
- package/dist/hooks/useMobileDetect.d.ts +0 -3
- package/dist/hooks/useMobileDetect.d.ts.map +0 -1
- package/src/hooks/useMobileDetect.ts +0 -21
|
@@ -14,7 +14,6 @@ import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
|
14
14
|
import { useAppStore } from '../store/AppStore';
|
|
15
15
|
import { useQuoteStore } from '../store/quote';
|
|
16
16
|
import { useWalletsStore } from '../store/wallets';
|
|
17
|
-
import { sortTokens } from '../utils/wallets';
|
|
18
17
|
|
|
19
18
|
interface PropTypes {
|
|
20
19
|
type: 'source' | 'destination';
|
|
@@ -34,7 +33,6 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
34
33
|
} = useQuoteStore();
|
|
35
34
|
const getBalanceFor = useWalletsStore.use.getBalanceFor();
|
|
36
35
|
const [searchedFor, setSearchedFor] = useState<string>('');
|
|
37
|
-
const { isTokenPinned } = useAppStore();
|
|
38
36
|
|
|
39
37
|
const selectedBlockchain = type === 'source' ? fromBlockchain : toBlockchain;
|
|
40
38
|
const selectedBlockchainName = selectedBlockchain?.name ?? '';
|
|
@@ -47,12 +45,9 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
47
45
|
type,
|
|
48
46
|
blockchain: selectedBlockchainName,
|
|
49
47
|
searchFor: searchedFor,
|
|
48
|
+
getBalanceFor: getBalanceFor,
|
|
50
49
|
});
|
|
51
50
|
|
|
52
|
-
const checkIsTokenPinned = (token: Token) => isTokenPinned(token, type);
|
|
53
|
-
|
|
54
|
-
const tokensList = sortTokens(tokens, getBalanceFor, checkIsTokenPinned);
|
|
55
|
-
|
|
56
51
|
const updateBlockchain = (blockchain: BlockchainMeta) => {
|
|
57
52
|
if (type === 'source') {
|
|
58
53
|
setFromBlockchain(blockchain);
|
|
@@ -101,7 +96,7 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
101
96
|
/>
|
|
102
97
|
<Divider size={16} />
|
|
103
98
|
<TokenList
|
|
104
|
-
list={
|
|
99
|
+
list={tokens}
|
|
105
100
|
selectedBlockchain={selectedBlockchainName}
|
|
106
101
|
searchedFor={searchedFor}
|
|
107
102
|
type={type}
|
|
@@ -6,8 +6,9 @@ export const DEFAULT_CONFIG: WidgetConfig = {
|
|
|
6
6
|
apiKey: '',
|
|
7
7
|
title: undefined,
|
|
8
8
|
multiWallets: true,
|
|
9
|
-
|
|
9
|
+
excludeLiquiditySources: true,
|
|
10
10
|
customDestination: true,
|
|
11
|
+
variant: 'default',
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
interface IframeConfigs {
|
|
@@ -72,7 +73,7 @@ export const createConfigSlice: StateCreatorWithInitialData<
|
|
|
72
73
|
const { config, campaignMode } = get();
|
|
73
74
|
return campaignMode.liquiditySources?.length
|
|
74
75
|
? false
|
|
75
|
-
: !!config.
|
|
76
|
+
: !!config.excludeLiquiditySources;
|
|
76
77
|
},
|
|
77
78
|
isInCampaignMode: () => {
|
|
78
79
|
const { campaignMode } = get();
|
package/src/store/slices/data.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// We keep all the received data from server in this slice
|
|
2
2
|
|
|
3
3
|
import type { ConfigSlice } from './config';
|
|
4
|
+
import type { Balance } from '../../types';
|
|
4
5
|
import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
|
|
5
6
|
import type { StateCreator } from 'zustand';
|
|
6
7
|
|
|
7
8
|
import { httpService as sdk } from '../../services/httpService';
|
|
8
|
-
import { containsText } from '../../utils/common';
|
|
9
|
+
import { compareWithSearchFor, containsText } from '../../utils/common';
|
|
9
10
|
import { isTokenExcludedInConfig } from '../../utils/configs';
|
|
11
|
+
import { isTokenNative } from '../../utils/meta';
|
|
10
12
|
import { sortLiquiditySourcesByGroupTitle } from '../../utils/settings';
|
|
11
|
-
import { areTokensEqual } from '../../utils/wallets';
|
|
13
|
+
import { areTokensEqual, compareTokenBalance } from '../../utils/wallets';
|
|
12
14
|
|
|
13
15
|
type BlockchainOptions = {
|
|
14
16
|
type?: 'source' | 'destination';
|
|
@@ -19,10 +21,12 @@ type TokenOptions = {
|
|
|
19
21
|
// filter by an specific blockchain
|
|
20
22
|
blockchain?: string;
|
|
21
23
|
searchFor?: string;
|
|
24
|
+
getBalanceFor?: (token: Token) => Balance | null;
|
|
22
25
|
};
|
|
26
|
+
|
|
23
27
|
export type FetchStatus = 'loading' | 'success' | 'failed';
|
|
24
28
|
export interface DataSlice {
|
|
25
|
-
|
|
29
|
+
_blockchainsMapByName: Map<string, BlockchainMeta>;
|
|
26
30
|
_tokens: Token[];
|
|
27
31
|
_popularTokens: Token[];
|
|
28
32
|
_swappers: SwapperMeta[];
|
|
@@ -31,7 +35,6 @@ export interface DataSlice {
|
|
|
31
35
|
tokens: (options?: TokenOptions) => Token[];
|
|
32
36
|
swappers: () => SwapperMeta[];
|
|
33
37
|
isTokenPinned: (token: Token, type: 'source' | 'destination') => boolean;
|
|
34
|
-
|
|
35
38
|
fetch: () => Promise<void>;
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -42,14 +45,17 @@ export const createDataSlice: StateCreator<
|
|
|
42
45
|
DataSlice
|
|
43
46
|
> = (set, get) => ({
|
|
44
47
|
// State
|
|
45
|
-
|
|
48
|
+
_blockchainsMapByName: new Map<string, BlockchainMeta>(),
|
|
46
49
|
_tokens: [],
|
|
47
50
|
_popularTokens: [],
|
|
48
51
|
_swappers: [],
|
|
49
52
|
fetchStatus: 'loading',
|
|
50
53
|
// Selectors
|
|
51
54
|
blockchains: (options) => {
|
|
52
|
-
const
|
|
55
|
+
const blockchainsMapByName = get()._blockchainsMapByName;
|
|
56
|
+
const blockchainsFromState = Array.from(
|
|
57
|
+
blockchainsMapByName?.values() || []
|
|
58
|
+
);
|
|
53
59
|
|
|
54
60
|
if (!options || !options?.type) {
|
|
55
61
|
return blockchainsFromState;
|
|
@@ -76,6 +82,7 @@ export const createDataSlice: StateCreator<
|
|
|
76
82
|
},
|
|
77
83
|
tokens: (options) => {
|
|
78
84
|
const tokensFromState = get()._tokens;
|
|
85
|
+
const blockchainsMapByName = get()._blockchainsMapByName;
|
|
79
86
|
|
|
80
87
|
if (!options || !options?.type) {
|
|
81
88
|
return tokensFromState;
|
|
@@ -127,29 +134,62 @@ export const createDataSlice: StateCreator<
|
|
|
127
134
|
|
|
128
135
|
return true;
|
|
129
136
|
})
|
|
130
|
-
.sort((
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
.sort((tokenA, tokenB) => {
|
|
138
|
+
//1. sort by pinned tokens
|
|
139
|
+
const isToken1Pinned = get().isTokenPinned(tokenA, options.type);
|
|
140
|
+
const isToken2Pinned = get().isTokenPinned(tokenB, options.type);
|
|
141
|
+
if (isToken1Pinned !== isToken2Pinned) {
|
|
142
|
+
return isToken1Pinned ? -1 : 1;
|
|
134
143
|
}
|
|
135
|
-
|
|
136
|
-
|
|
144
|
+
|
|
145
|
+
//2. sort by balance
|
|
146
|
+
if (options.getBalanceFor) {
|
|
147
|
+
const token1Balance = options.getBalanceFor(tokenA);
|
|
148
|
+
const token2Balance = options.getBalanceFor(tokenB);
|
|
149
|
+
const balanceCompare = compareTokenBalance(
|
|
150
|
+
token1Balance,
|
|
151
|
+
token2Balance
|
|
152
|
+
);
|
|
153
|
+
if (balanceCompare !== 0) {
|
|
154
|
+
return balanceCompare;
|
|
155
|
+
}
|
|
137
156
|
}
|
|
138
157
|
|
|
139
|
-
//
|
|
140
|
-
if (
|
|
141
|
-
return 1;
|
|
158
|
+
//3. sort by token popularity
|
|
159
|
+
if (tokenA.isPopular !== tokenB.isPopular) {
|
|
160
|
+
return tokenA.isPopular ? -1 : 1;
|
|
142
161
|
}
|
|
143
|
-
|
|
144
|
-
|
|
162
|
+
|
|
163
|
+
//4. sort by search phrase
|
|
164
|
+
if (options.searchFor) {
|
|
165
|
+
const symbolSearchForCompare = compareWithSearchFor(
|
|
166
|
+
tokenA,
|
|
167
|
+
tokenB,
|
|
168
|
+
options.searchFor
|
|
169
|
+
);
|
|
170
|
+
if (symbolSearchForCompare) {
|
|
171
|
+
return symbolSearchForCompare;
|
|
172
|
+
}
|
|
145
173
|
}
|
|
146
174
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
175
|
+
const blockChainA = blockchainsMapByName.get(tokenA.blockchain);
|
|
176
|
+
const blockChainB = blockchainsMapByName.get(tokenB.blockchain);
|
|
177
|
+
|
|
178
|
+
//5. sort by native token
|
|
179
|
+
const isNativeTokenA = isTokenNative(tokenA, blockChainA);
|
|
180
|
+
const isNativeTokenB = isTokenNative(tokenB, blockChainB);
|
|
181
|
+
if (isNativeTokenA !== isNativeTokenB) {
|
|
182
|
+
return isNativeTokenA ? -1 : 1;
|
|
150
183
|
}
|
|
151
|
-
|
|
152
|
-
|
|
184
|
+
|
|
185
|
+
//6. sort by token isSecondary
|
|
186
|
+
if (tokenA.isSecondaryCoin !== tokenB.isSecondaryCoin) {
|
|
187
|
+
return tokenA.isSecondaryCoin ? 1 : -1;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
//7. sort by blockchain order
|
|
191
|
+
if (!!blockChainA && !!blockChainB) {
|
|
192
|
+
return blockChainA.sort - blockChainB.sort;
|
|
153
193
|
}
|
|
154
194
|
|
|
155
195
|
return 0;
|
|
@@ -177,12 +217,12 @@ export const createDataSlice: StateCreator<
|
|
|
177
217
|
const liquiditySources =
|
|
178
218
|
campaignModeLiquiditySource ?? config.liquiditySources;
|
|
179
219
|
|
|
180
|
-
const
|
|
220
|
+
const excludeLiquiditySources = campaignModeLiquiditySource
|
|
181
221
|
? false
|
|
182
|
-
: config.
|
|
222
|
+
: config.excludeLiquiditySources;
|
|
183
223
|
|
|
184
224
|
/*
|
|
185
|
-
* If the
|
|
225
|
+
* If the excludeLiquiditySources flag is set to true, we return all swappers that are not included in the config.
|
|
186
226
|
* Otherwise, we return all swappers that are included in the config.
|
|
187
227
|
*/
|
|
188
228
|
const swappers = get()._swappers.filter((swapper) => {
|
|
@@ -191,7 +231,7 @@ export const createDataSlice: StateCreator<
|
|
|
191
231
|
);
|
|
192
232
|
|
|
193
233
|
const shouldExcludeLiquiditySources =
|
|
194
|
-
|
|
234
|
+
excludeLiquiditySources ||
|
|
195
235
|
!liquiditySources ||
|
|
196
236
|
liquiditySources.length === 0;
|
|
197
237
|
|
|
@@ -207,10 +247,17 @@ export const createDataSlice: StateCreator<
|
|
|
207
247
|
// Actions
|
|
208
248
|
fetch: async () => {
|
|
209
249
|
try {
|
|
210
|
-
const
|
|
250
|
+
const { enableCentralizedSwappers } = get().config;
|
|
251
|
+
const response = await sdk().getAllMetadata({
|
|
252
|
+
enableCentralizedSwappers,
|
|
253
|
+
});
|
|
211
254
|
|
|
212
255
|
set({ fetchStatus: 'success' });
|
|
213
|
-
const
|
|
256
|
+
const blockchainsMapByName: Map<string, BlockchainMeta> = new Map<
|
|
257
|
+
string,
|
|
258
|
+
BlockchainMeta
|
|
259
|
+
>();
|
|
260
|
+
|
|
214
261
|
const tokens: Token[] = [];
|
|
215
262
|
const popularTokens: Token[] = response.popularTokens;
|
|
216
263
|
const swappers: SwapperMeta[] = response.swappers;
|
|
@@ -223,20 +270,21 @@ export const createDataSlice: StateCreator<
|
|
|
223
270
|
tokens.push(token);
|
|
224
271
|
});
|
|
225
272
|
|
|
226
|
-
response.blockchains.
|
|
273
|
+
const sortedBlockchain = response.blockchains.sort(
|
|
274
|
+
(a, b) => a.sort - b.sort
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
sortedBlockchain.forEach((blockchain) => {
|
|
227
278
|
if (
|
|
228
279
|
blockchain.enabled &&
|
|
229
280
|
blockchainsWithAtLeastOneToken.has(blockchain.name)
|
|
230
281
|
) {
|
|
231
|
-
|
|
282
|
+
blockchainsMapByName.set(blockchain.name, blockchain);
|
|
232
283
|
}
|
|
233
284
|
});
|
|
234
285
|
|
|
235
|
-
// Sort
|
|
236
|
-
blockchains.sort((a, b) => a.sort - b.sort);
|
|
237
|
-
|
|
238
286
|
set({
|
|
239
|
-
|
|
287
|
+
_blockchainsMapByName: blockchainsMapByName,
|
|
240
288
|
_tokens: tokens,
|
|
241
289
|
_popularTokens: popularTokens,
|
|
242
290
|
_swappers: swappers,
|
|
@@ -153,16 +153,22 @@ export const createSettingsSlice: StateCreator<
|
|
|
153
153
|
language,
|
|
154
154
|
})),
|
|
155
155
|
updateSettings: (nextConfig: WidgetConfig) => {
|
|
156
|
-
const { features } = nextConfig;
|
|
156
|
+
const { features, theme } = nextConfig;
|
|
157
157
|
|
|
158
158
|
const isThemeHidden = isFeatureHidden('theme', features);
|
|
159
159
|
const isLanguageHidden = isFeatureHidden('language', features);
|
|
160
160
|
const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
|
|
161
|
+
const singleTheme = theme?.singleTheme;
|
|
161
162
|
|
|
162
163
|
set({
|
|
163
|
-
...(isThemeHidden && { theme: 'auto' }),
|
|
164
|
-
...(
|
|
165
|
-
...(
|
|
164
|
+
...(isThemeHidden && { theme: nextConfig.theme?.mode || 'auto' }),
|
|
165
|
+
...(singleTheme && { theme: nextConfig.theme?.mode || 'light' }),
|
|
166
|
+
...(isLanguageHidden && {
|
|
167
|
+
language: nextConfig.language || DEFAULT_LANGUAGE,
|
|
168
|
+
}),
|
|
169
|
+
...(isLiquidityHidden && {
|
|
170
|
+
disabledLiquiditySources: nextConfig.liquiditySources || [],
|
|
171
|
+
}),
|
|
166
172
|
});
|
|
167
173
|
},
|
|
168
174
|
});
|
package/src/types/config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
|
3
3
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
4
|
import type { Asset } from 'rango-sdk';
|
|
5
5
|
|
|
6
|
-
export type WidgetVariant = 'default' | '
|
|
6
|
+
export type WidgetVariant = 'default' | 'expanded' | 'full-expanded';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The above type defines a set of optional color properties for a widget.
|
|
@@ -171,8 +171,8 @@ export type Features = Partial<
|
|
|
171
171
|
* that defines the various properties of the theme, such as colors, fonts, and others.
|
|
172
172
|
* @property {boolean} externalWallets
|
|
173
173
|
* If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
|
|
174
|
-
* @property {boolean}
|
|
175
|
-
* set it to true,
|
|
174
|
+
* @property {boolean} excludeLiquiditySources - The `excludeLiquiditySources` property is a boolean value that when you
|
|
175
|
+
* set it to true, the list of liquidity sources provided in `liquiditySources` will be excluded; otherwise, they will be included.
|
|
176
176
|
* @property {Features} features - An optional object for configuring the visibility or enablement of various features.
|
|
177
177
|
* Keys include:
|
|
178
178
|
* - 'notification': Visibility state for the notification icon.
|
|
@@ -182,8 +182,11 @@ export type Features = Partial<
|
|
|
182
182
|
* - 'language': Visibility state for the language.
|
|
183
183
|
* - 'experimentalRoute': Enablement state for the experimental route.
|
|
184
184
|
* @property {WidgetVariant} variant
|
|
185
|
-
* If it is
|
|
185
|
+
* If it is expanded, multiple routes will show up on the home page;
|
|
186
|
+
* If it is full-expanded, multiple routes will show up on the home page with full routes;
|
|
186
187
|
* if not, you will need to go to a different page to see the suggested routes.
|
|
188
|
+
* @property {boolean} enableCentralizedSwappers
|
|
189
|
+
* If you want to enable routing from the centralized protocols like XO Swap, you could set this parameter to true.
|
|
187
190
|
*/
|
|
188
191
|
|
|
189
192
|
export type WidgetConfig = {
|
|
@@ -202,7 +205,8 @@ export type WidgetConfig = {
|
|
|
202
205
|
language?: Language;
|
|
203
206
|
theme?: WidgetTheme;
|
|
204
207
|
externalWallets?: boolean;
|
|
205
|
-
|
|
208
|
+
excludeLiquiditySources?: boolean;
|
|
206
209
|
features?: Features;
|
|
207
210
|
variant?: WidgetVariant;
|
|
211
|
+
enableCentralizedSwappers?: boolean;
|
|
208
212
|
};
|
package/src/utils/colors.ts
CHANGED
|
@@ -1,68 +1,113 @@
|
|
|
1
1
|
import type { WidgetColors, WidgetColorsKeys } from '../types';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let [r, g, b]: any = col.match(/.{2}/g);
|
|
13
|
-
[r, g, b] = [
|
|
14
|
-
parseInt(r, RADIX) + amt,
|
|
15
|
-
parseInt(g, RADIX) + amt,
|
|
16
|
-
parseInt(b, RADIX) + amt,
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
r = Math.max(Math.min(RANGE, r), 0).toString(RADIX);
|
|
20
|
-
g = Math.max(Math.min(RANGE, g), 0).toString(RADIX);
|
|
21
|
-
b = Math.max(Math.min(RANGE, b), 0).toString(RADIX);
|
|
22
|
-
|
|
23
|
-
const rr = (r.length < 2 ? '0' : '') + r;
|
|
24
|
-
const gg = (g.length < 2 ? '0' : '') + g;
|
|
25
|
-
const bb = (b.length < 2 ? '0' : '') + b;
|
|
26
|
-
|
|
27
|
-
return `#${rr}${gg}${bb}`;
|
|
28
|
-
};
|
|
3
|
+
export function generateShades(
|
|
4
|
+
baseColor: string,
|
|
5
|
+
prefix: string,
|
|
6
|
+
reverse?: boolean
|
|
7
|
+
): { [key: string]: string } {
|
|
8
|
+
const BASE_SHADE_INDEX = 100;
|
|
9
|
+
const NUMBER_OF_COLORS = 9;
|
|
10
|
+
const SHADING_INCREMENT_MAX = 10; // For bright colors
|
|
11
|
+
const SHADING_INCREMENT_MIN = 6; // For dark colors
|
|
29
12
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(HALF_NUMBER_OF_COLORS - i) * AMT
|
|
44
|
-
),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (i === HALF_NUMBER_OF_COLORS) {
|
|
48
|
-
colors = {
|
|
49
|
-
...colors,
|
|
50
|
-
[name + i * COLOR_SUFFIX]: color,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
if (i > HALF_NUMBER_OF_COLORS) {
|
|
54
|
-
colors = {
|
|
55
|
-
...colors,
|
|
56
|
-
[name + i * COLOR_SUFFIX]: colorShade(
|
|
57
|
-
color,
|
|
58
|
-
-((i - HALF_NUMBER_OF_COLORS) * AMT)
|
|
59
|
-
),
|
|
60
|
-
};
|
|
13
|
+
const HALF_NUMBER_OF_COLORS = 4;
|
|
14
|
+
|
|
15
|
+
const shadeIncrements: number[] = [];
|
|
16
|
+
let increment = 90;
|
|
17
|
+
for (let i = 0; i < NUMBER_OF_COLORS; i++) {
|
|
18
|
+
shadeIncrements.push(increment);
|
|
19
|
+
if (i + 1 === HALF_NUMBER_OF_COLORS) {
|
|
20
|
+
increment = 0;
|
|
21
|
+
} else {
|
|
22
|
+
increment -=
|
|
23
|
+
i >= HALF_NUMBER_OF_COLORS
|
|
24
|
+
? SHADING_INCREMENT_MIN
|
|
25
|
+
: SHADING_INCREMENT_MAX;
|
|
61
26
|
}
|
|
62
27
|
}
|
|
63
28
|
|
|
64
|
-
|
|
65
|
-
|
|
29
|
+
// If 'reverse' is true, that means the color should be from dark to light
|
|
30
|
+
const decrementAmounts = reverse
|
|
31
|
+
? shadeIncrements.slice().reverse()
|
|
32
|
+
: shadeIncrements;
|
|
33
|
+
|
|
34
|
+
const shades: { [key: string]: string } = {};
|
|
35
|
+
|
|
36
|
+
// Generate shades
|
|
37
|
+
for (let i = 0; i < NUMBER_OF_COLORS; i++) {
|
|
38
|
+
const shadeIndex = BASE_SHADE_INDEX + i * BASE_SHADE_INDEX;
|
|
39
|
+
const decrementAmount = decrementAmounts[i];
|
|
40
|
+
|
|
41
|
+
const shade: { [key: string]: string } = {
|
|
42
|
+
[`${prefix}${shadeIndex}`]: generateShade(baseColor, decrementAmount),
|
|
43
|
+
};
|
|
44
|
+
Object.assign(shades, shade);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { ...shades, [prefix]: baseColor };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function generateShade(
|
|
51
|
+
baseColor: string,
|
|
52
|
+
decrementAmount: number
|
|
53
|
+
): string {
|
|
54
|
+
const [r, g, b] = convertToRGB(baseColor);
|
|
55
|
+
return `#${clamp(r + decrementAmount)}${clamp(g + decrementAmount)}${clamp(
|
|
56
|
+
b + decrementAmount
|
|
57
|
+
)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function convertToRGB(baseColor: string): number[] {
|
|
61
|
+
const COLOR_SLICE_START = 1;
|
|
62
|
+
const COLOR_SLICE_END = 3;
|
|
63
|
+
const BASE_COLOR_LENGTH = 7;
|
|
64
|
+
|
|
65
|
+
// Convert the base color to RGB components
|
|
66
|
+
const r: number = parseInt(
|
|
67
|
+
baseColor.slice(COLOR_SLICE_START, COLOR_SLICE_END),
|
|
68
|
+
16
|
|
69
|
+
);
|
|
70
|
+
const g: number = parseInt(
|
|
71
|
+
baseColor.slice(COLOR_SLICE_END, COLOR_SLICE_END + 2),
|
|
72
|
+
16
|
|
73
|
+
);
|
|
74
|
+
const b: number = parseInt(
|
|
75
|
+
baseColor.slice(COLOR_SLICE_END + 2, BASE_COLOR_LENGTH),
|
|
76
|
+
16
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return [r, g, b];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Function to clamp color component to valid range [0, 255] and convert to hex
|
|
83
|
+
function clamp(color: number): string {
|
|
84
|
+
const MAX_COLOR_VALUE = 255;
|
|
85
|
+
const HEX_BASE = 16;
|
|
86
|
+
const HEX_LENGTH = -2;
|
|
87
|
+
return (
|
|
88
|
+
'0' + Math.max(0, Math.min(MAX_COLOR_VALUE, color)).toString(HEX_BASE)
|
|
89
|
+
)
|
|
90
|
+
.slice(HEX_LENGTH)
|
|
91
|
+
.toUpperCase();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function isBright(baseColor: string) {
|
|
95
|
+
const BRIGHTNESS_THRESHOLD = 188;
|
|
96
|
+
const RED_COEFFICIENT = 299;
|
|
97
|
+
const GREEN_COEFFICIENT = 587;
|
|
98
|
+
const BLUE_COEFFICIENT = 114;
|
|
99
|
+
const BRIGHTNESS_DIVISOR = 1000;
|
|
100
|
+
|
|
101
|
+
const [r, g, b] = convertToRGB(baseColor);
|
|
102
|
+
const brightness =
|
|
103
|
+
(r * RED_COEFFICIENT + g * GREEN_COEFFICIENT + b * BLUE_COEFFICIENT) /
|
|
104
|
+
BRIGHTNESS_DIVISOR;
|
|
105
|
+
if (brightness > BRIGHTNESS_THRESHOLD) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
66
111
|
export const generateColors = (
|
|
67
112
|
mainColors: { [x: string]: string },
|
|
68
113
|
reverseNeutralRange: boolean,
|
|
@@ -83,25 +128,11 @@ export const generateColors = (
|
|
|
83
128
|
...listOfColors,
|
|
84
129
|
[colorKey]: color,
|
|
85
130
|
};
|
|
86
|
-
} else if (colorKey === 'neutral' && reverseNeutralRange) {
|
|
87
|
-
const range = generateRangeColors(colorKey, color);
|
|
88
|
-
listOfColors = {
|
|
89
|
-
...listOfColors,
|
|
90
|
-
// Reverse the neutral shade
|
|
91
|
-
[`${colorKey}100`]: range[`${colorKey}900`],
|
|
92
|
-
[`${colorKey}200`]: range[`${colorKey}800`],
|
|
93
|
-
[`${colorKey}300`]: range[`${colorKey}700`],
|
|
94
|
-
[`${colorKey}400`]: range[`${colorKey}600`],
|
|
95
|
-
[`${colorKey}500`]: range[`${colorKey}500`],
|
|
96
|
-
[`${colorKey}600`]: range[`${colorKey}400`],
|
|
97
|
-
[`${colorKey}700`]: range[`${colorKey}300`],
|
|
98
|
-
[`${colorKey}800`]: range[`${colorKey}200`],
|
|
99
|
-
[`${colorKey}900`]: range[`${colorKey}100`],
|
|
100
|
-
};
|
|
101
131
|
} else {
|
|
132
|
+
const reverse = colorKey === 'neutral' && reverseNeutralRange;
|
|
102
133
|
listOfColors = {
|
|
103
134
|
...listOfColors,
|
|
104
|
-
...
|
|
135
|
+
...generateShades(color, colorKey, reverse),
|
|
105
136
|
};
|
|
106
137
|
}
|
|
107
138
|
}
|