@rango-dev/widget-embedded 0.14.1-next.2 → 0.14.1-next.21
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/BlockchainList/BlockchainList.styles.d.ts +8 -0
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +4 -0
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +60 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +12 -0
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +16 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +12 -0
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +4 -0
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +12 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts +12 -0
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +16 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts +16 -0
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +4 -0
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +16 -0
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +16 -0
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.Placeholder.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +24 -0
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +4 -0
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +4 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +16 -0
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +40 -0
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +16 -0
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/constants/configs.d.ts +2 -0
- package/dist/constants/configs.d.ts.map +1 -0
- package/dist/constants/errors.d.ts +1 -1
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/constants/fonts.d.ts +2 -0
- package/dist/constants/fonts.d.ts.map +1 -0
- package/dist/{constants.d.ts → constants/index.d.ts} +1 -1
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/languages.d.ts +11 -0
- package/dist/constants/languages.d.ts.map +1 -0
- package/dist/constants/messages.d.ts +1 -1
- package/dist/constants/messages.d.ts.map +1 -1
- package/dist/hooks/useLanguage.d.ts +11 -0
- package/dist/hooks/useLanguage.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/index.d.ts +2 -0
- package/dist/hooks/usePrepareBlockchainList/index.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts +2 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts.map +1 -0
- package/dist/hooks/{usePrepareBlockchainList.d.ts → usePrepareBlockchainList/usePrepareBlockchainList.d.ts} +1 -9
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +10 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts +3 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts +2 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts +11 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts.map +1 -0
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -2
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LanguagePage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/settings.d.ts +15 -6
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +11 -13
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/colors.d.ts +11 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/common.d.ts +0 -4
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +2 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/meta.d.ts +3 -1
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +8 -1
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/utils/ui.d.ts +13 -0
- package/dist/utils/ui.d.ts.map +1 -0
- package/dist/utils/wallets.d.ts +0 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/Widget.tsx +15 -3
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +21 -6
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -11
- package/src/components/ConfirmWalletsModal/WalletList.tsx +35 -24
- package/src/components/Layout/Layout.styles.ts +7 -2
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +1 -1
- package/src/components/NoRoutes/NoRoutes.helper.ts +4 -4
- package/src/components/NoRoutes/NoRoutes.tsx +2 -2
- package/src/components/NotificationContent/NotificationContent.tsx +1 -1
- package/src/components/NotificationContent/NotificationNotFound.tsx +1 -1
- package/src/components/RouteErrors/RouteErrors.tsx +2 -2
- package/src/components/RouteErrors/RouteErrorsModal.tsx +6 -6
- package/src/components/RouteErrors/RouteErrorsModalItem.tsx +1 -1
- package/src/components/Slippage/SlippageTooltipContent.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +5 -6
- package/src/components/SwapDetails/SwapDetails.tsx +6 -10
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +1 -1
- package/src/components/SwapsGroup/SwapsGroup.tsx +2 -2
- package/src/components/TokenList/TokenList.styles.ts +1 -1
- package/src/components/TokenList/TokenList.tsx +2 -2
- package/src/constants/configs.ts +1 -0
- package/src/constants/errors.ts +44 -41
- package/src/constants/fonts.ts +1 -0
- package/src/constants/languages.ts +19 -0
- package/src/constants/messages.ts +7 -5
- package/src/hooks/useConfirmSwap.ts +1 -1
- package/src/hooks/useLanguage.ts +27 -0
- package/src/hooks/usePrepareBlockchainList/index.ts +1 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.ts +1 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.ts +108 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.ts +3101 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.ts +273 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.ts +38 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.ts +12 -0
- package/src/hooks/useSyncStoresWithConfig.ts +49 -1
- package/src/hooks/useTheme.ts +44 -26
- package/src/index.ts +33 -26
- package/src/pages/ConfirmSwapPage.tsx +9 -18
- package/src/pages/Home.tsx +6 -7
- package/src/pages/LanguagePage.tsx +16 -39
- package/src/pages/SettingsPage.tsx +1 -1
- package/src/store/bestRoute.ts +12 -38
- package/src/store/settings.ts +46 -4
- package/src/types/config.ts +10 -12
- package/src/utils/colors.ts +109 -0
- package/src/utils/common.ts +0 -49
- package/src/utils/configs.ts +3 -0
- package/src/utils/hash.ts +27 -0
- package/src/utils/meta.ts +11 -1
- package/src/utils/routing.ts +58 -0
- package/src/utils/settings.ts +1 -1
- package/src/utils/swap.ts +15 -20
- package/src/utils/time.ts +2 -4
- package/src/utils/ui.ts +72 -0
- package/src/utils/wallets.ts +4 -25
- package/dist/constants.d.ts.map +0 -1
- package/dist/hooks/usePrepareBlockchainList.d.ts.map +0 -1
- package/src/hooks/usePrepareBlockchainList.ts +0 -125
- /package/src/{constants.ts → constants/index.ts} +0 -0
package/src/utils/swap.ts
CHANGED
|
@@ -120,8 +120,7 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
120
120
|
let recommendation = '';
|
|
121
121
|
if (!isExclusive && !!minimum && minimum.gt(swap.fromAmount)) {
|
|
122
122
|
fromAmountRangeError = i18n.t({
|
|
123
|
-
id: '
|
|
124
|
-
message: 'Required: >= {min} {symbol}',
|
|
123
|
+
id: 'Required: >= {min} {symbol}',
|
|
125
124
|
values: {
|
|
126
125
|
min: numberToString(
|
|
127
126
|
minimum,
|
|
@@ -131,11 +130,10 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
131
130
|
symbol: swap.from.symbol,
|
|
132
131
|
},
|
|
133
132
|
});
|
|
134
|
-
recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
|
|
133
|
+
recommendation = errorMessages().bridgeLimitErrors.increaseAmount;
|
|
135
134
|
} else if (isExclusive && !!minimum && minimum.gte(swap.fromAmount)) {
|
|
136
135
|
fromAmountRangeError = i18n.t({
|
|
137
|
-
id: '
|
|
138
|
-
message: 'Required: > {min} {symbol}',
|
|
136
|
+
id: 'Required: > {min} {symbol}',
|
|
139
137
|
values: {
|
|
140
138
|
min: numberToString(
|
|
141
139
|
minimum,
|
|
@@ -145,13 +143,12 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
145
143
|
symbol: swap.from.symbol,
|
|
146
144
|
},
|
|
147
145
|
});
|
|
148
|
-
recommendation = errorMessages.bridgeLimitErrors.increaseAmount;
|
|
146
|
+
recommendation = errorMessages().bridgeLimitErrors.increaseAmount;
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
if (!isExclusive && !!maximum && maximum.lt(swap.fromAmount)) {
|
|
152
150
|
fromAmountRangeError = i18n.t({
|
|
153
|
-
id: '
|
|
154
|
-
message: 'Required: <= {max} {symbol}',
|
|
151
|
+
id: 'Required: <= {max} {symbol}',
|
|
155
152
|
values: {
|
|
156
153
|
max: numberToString(
|
|
157
154
|
maximum,
|
|
@@ -161,11 +158,10 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
161
158
|
symbol: swap.from.symbol,
|
|
162
159
|
},
|
|
163
160
|
});
|
|
164
|
-
recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
|
|
161
|
+
recommendation = errorMessages().bridgeLimitErrors.decreaseAmount;
|
|
165
162
|
} else if (isExclusive && !!maximum && maximum.lte(swap.fromAmount)) {
|
|
166
163
|
fromAmountRangeError = i18n.t({
|
|
167
|
-
id: '
|
|
168
|
-
message: 'Required: < {max} {symbol}',
|
|
164
|
+
id: 'Required: < {max} {symbol}',
|
|
169
165
|
values: {
|
|
170
166
|
max: numberToString(
|
|
171
167
|
maximum,
|
|
@@ -175,7 +171,7 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
175
171
|
symbol: swap.from.symbol,
|
|
176
172
|
},
|
|
177
173
|
});
|
|
178
|
-
recommendation = errorMessages.bridgeLimitErrors.decreaseAmount;
|
|
174
|
+
recommendation = errorMessages().bridgeLimitErrors.decreaseAmount;
|
|
179
175
|
}
|
|
180
176
|
|
|
181
177
|
return { swap, fromAmountRangeError, recommendation };
|
|
@@ -194,14 +190,14 @@ export function getSwapButtonState(
|
|
|
194
190
|
): SwapButtonState {
|
|
195
191
|
if (loadingMetaStatus !== 'success') {
|
|
196
192
|
return {
|
|
197
|
-
title: swapButtonTitles.connectWallet,
|
|
193
|
+
title: swapButtonTitles().connectWallet,
|
|
198
194
|
state: ButtonState.WAITFORCONNECTING,
|
|
199
195
|
disabled: true,
|
|
200
196
|
};
|
|
201
197
|
}
|
|
202
198
|
if (connectedWallets.length == 0) {
|
|
203
199
|
return {
|
|
204
|
-
title: swapButtonTitles.connectWallet,
|
|
200
|
+
title: swapButtonTitles().connectWallet,
|
|
205
201
|
state: ButtonState.WAITFORCONNECTING,
|
|
206
202
|
disabled: false,
|
|
207
203
|
};
|
|
@@ -215,27 +211,27 @@ export function getSwapButtonState(
|
|
|
215
211
|
inputAmount === '0'
|
|
216
212
|
) {
|
|
217
213
|
return {
|
|
218
|
-
title: swapButtonTitles.swap,
|
|
214
|
+
title: swapButtonTitles().swap,
|
|
219
215
|
disabled: true,
|
|
220
216
|
state: ButtonState.SWAP,
|
|
221
217
|
};
|
|
222
218
|
} else if (highValueLoss || priceImpactCanNotBeComputed) {
|
|
223
219
|
return {
|
|
224
|
-
title: swapButtonTitles.swapAnyway,
|
|
220
|
+
title: swapButtonTitles().swapAnyway,
|
|
225
221
|
disabled: false,
|
|
226
222
|
hasWarning: true,
|
|
227
223
|
state: ButtonState.NEEDTOCONFIRM,
|
|
228
224
|
};
|
|
229
225
|
} else if (needsToWarnEthOnPath) {
|
|
230
226
|
return {
|
|
231
|
-
title: swapButtonTitles.ethRouteWarning,
|
|
227
|
+
title: swapButtonTitles().ethRouteWarning,
|
|
232
228
|
disabled: false,
|
|
233
229
|
hasWarning: true,
|
|
234
230
|
state: ButtonState.WARNING,
|
|
235
231
|
};
|
|
236
232
|
}
|
|
237
233
|
return {
|
|
238
|
-
title: swapButtonTitles.swap,
|
|
234
|
+
title: swapButtonTitles().swap,
|
|
239
235
|
disabled: false,
|
|
240
236
|
state: ButtonState.SWAP,
|
|
241
237
|
};
|
|
@@ -608,8 +604,7 @@ export function getBalanceWarnings(
|
|
|
608
604
|
reason = i18n.t(' for input and network fee');
|
|
609
605
|
}
|
|
610
606
|
const warningMessage = i18n.t({
|
|
611
|
-
id:
|
|
612
|
-
message: `Needs ≈ {requiredAmount} {symbol}{reason}, but you have {currentAmount} {symbol} in your {blockchain} wallet.`,
|
|
607
|
+
id: `Needs ≈ {requiredAmount} {symbol}{reason}, but you have {currentAmount} {symbol} in your {blockchain} wallet.`,
|
|
613
608
|
values: {
|
|
614
609
|
requiredAmount,
|
|
615
610
|
symbol,
|
package/src/utils/time.ts
CHANGED
|
@@ -67,13 +67,11 @@ export function timeSince(millisecond: number): string {
|
|
|
67
67
|
export function getSwapDate(pendingSwap: PendingSwap) {
|
|
68
68
|
return pendingSwap.finishTime
|
|
69
69
|
? i18n.t({
|
|
70
|
-
id: '
|
|
71
|
-
message: '{time} ago',
|
|
70
|
+
id: '{time} ago',
|
|
72
71
|
values: { time: timeSince(parseInt(pendingSwap.finishTime)) },
|
|
73
72
|
})
|
|
74
73
|
: i18n.t({
|
|
75
|
-
id: '
|
|
76
|
-
message: '{time} ago',
|
|
74
|
+
id: '{time} ago',
|
|
77
75
|
values: { time: timeSince(parseInt(pendingSwap.creationTime)) },
|
|
78
76
|
});
|
|
79
77
|
}
|
package/src/utils/ui.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import type { WidgetTheme } from '../types';
|
|
3
|
+
import type { createTheme } from '@rango-dev/ui';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
theme as baseThemeTokens,
|
|
7
|
+
darkColors as defaultDarkColors,
|
|
8
|
+
} from '@rango-dev/ui';
|
|
9
|
+
|
|
10
|
+
import { generateColors } from '../utils/colors';
|
|
11
|
+
import { toHash } from '../utils/hash';
|
|
12
|
+
|
|
13
|
+
import { THEME_CLASS_NAME_PREFIX } from './configs';
|
|
14
|
+
|
|
15
|
+
interface CustomizedThemeValues {
|
|
16
|
+
id: string;
|
|
17
|
+
tokens: Parameters<typeof createTheme>[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface CustomizedTheme {
|
|
21
|
+
light: undefined | CustomizedThemeValues;
|
|
22
|
+
dark: undefined | CustomizedThemeValues;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function customizedThemeTokens(
|
|
26
|
+
colors: WidgetTheme['colors']
|
|
27
|
+
): CustomizedTheme {
|
|
28
|
+
const baseColors = baseThemeTokens.colors;
|
|
29
|
+
|
|
30
|
+
const darkColorsWithDefaults = generateColors(
|
|
31
|
+
{
|
|
32
|
+
...baseColors,
|
|
33
|
+
...defaultDarkColors,
|
|
34
|
+
},
|
|
35
|
+
true,
|
|
36
|
+
colors?.dark
|
|
37
|
+
);
|
|
38
|
+
const lightColorsWithDefaults = generateColors(
|
|
39
|
+
baseColors,
|
|
40
|
+
false,
|
|
41
|
+
colors?.light
|
|
42
|
+
);
|
|
43
|
+
const hasDefaultDarkColors = Object.keys(darkColorsWithDefaults).length > 0;
|
|
44
|
+
const hasDefaultLightColors = Object.keys(lightColorsWithDefaults).length > 0;
|
|
45
|
+
|
|
46
|
+
let light: CustomizedTheme['light'] = undefined;
|
|
47
|
+
let dark: CustomizedTheme['dark'] = undefined;
|
|
48
|
+
|
|
49
|
+
if (hasDefaultLightColors) {
|
|
50
|
+
const tokens = { colors: lightColorsWithDefaults };
|
|
51
|
+
const id = `${THEME_CLASS_NAME_PREFIX}-light-${toHash(tokens)}`;
|
|
52
|
+
light = {
|
|
53
|
+
id,
|
|
54
|
+
tokens,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (hasDefaultDarkColors) {
|
|
58
|
+
const tokens = {
|
|
59
|
+
colors: darkColorsWithDefaults,
|
|
60
|
+
};
|
|
61
|
+
const id = `${THEME_CLASS_NAME_PREFIX}-dark-${toHash(tokens)}`;
|
|
62
|
+
dark = {
|
|
63
|
+
id,
|
|
64
|
+
tokens,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
light,
|
|
70
|
+
dark,
|
|
71
|
+
};
|
|
72
|
+
}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -55,8 +55,11 @@ export function mapWalletTypesToWalletInfo(
|
|
|
55
55
|
return list
|
|
56
56
|
.filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
|
|
57
57
|
.filter((wallet) => {
|
|
58
|
+
const { supportedChains, hideWhenNotInstalled } = getWalletInfo(wallet);
|
|
59
|
+
if (hideWhenNotInstalled && !getState(wallet).installed) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
58
62
|
if (chain) {
|
|
59
|
-
const { supportedChains } = getWalletInfo(wallet);
|
|
60
63
|
return !!supportedChains.find(
|
|
61
64
|
(supportedChain) => supportedChain.name === chain
|
|
62
65
|
);
|
|
@@ -203,30 +206,6 @@ export function getRequiredChains(route: BestRouteResponse | null) {
|
|
|
203
206
|
|
|
204
207
|
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
205
208
|
|
|
206
|
-
export function getSelectableWallets(
|
|
207
|
-
connectedWallets: ConnectedWallet[],
|
|
208
|
-
getWalletInfo: (type: WalletType) => WalletInfo,
|
|
209
|
-
destinationChain?: string
|
|
210
|
-
): Wallet[] {
|
|
211
|
-
const selectableWallets = connectedWallets.map(
|
|
212
|
-
(connectedWallet: ConnectedWallet) => {
|
|
213
|
-
return {
|
|
214
|
-
address: connectedWallet.address,
|
|
215
|
-
walletType: connectedWallet.walletType,
|
|
216
|
-
chain: connectedWallet.chain,
|
|
217
|
-
image: getWalletInfo(connectedWallet.walletType).img,
|
|
218
|
-
name: getWalletInfo(connectedWallet.walletType).name,
|
|
219
|
-
selected:
|
|
220
|
-
destinationChain === connectedWallet.chain
|
|
221
|
-
? false
|
|
222
|
-
: connectedWallet.selected,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
return selectableWallets;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
209
|
export function getBalanceFromWallet(
|
|
231
210
|
connectedWallets: ConnectedWallet[],
|
|
232
211
|
chain: string,
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,yCAAyC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePrepareBlockchainList.d.ts","sourceRoot":"","sources":["../../src/hooks/usePrepareBlockchainList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIhD,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,iBAAiB;IACzB,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,IAAI,EAAE,cAAc,EAAE,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,cAAc,EAAE,EAC7B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,iBAAiB,CAgEnB"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { BlockchainMeta } from 'rango-sdk';
|
|
2
|
-
|
|
3
|
-
import { useMemo, useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
interface PrepareListOptions {
|
|
6
|
-
limit?: number;
|
|
7
|
-
selected?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface PrepareListOutput {
|
|
11
|
-
list: BlockchainMeta[];
|
|
12
|
-
more: BlockchainMeta[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* UI needs some specific logics like limiting the list and sorting,
|
|
18
|
-
* this function is getting the raw blockchains list and return a list for showing in UI.
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export function usePrepareBlockchainList(
|
|
22
|
-
blockchains: BlockchainMeta[],
|
|
23
|
-
options?: PrepareListOptions
|
|
24
|
-
): PrepareListOutput {
|
|
25
|
-
const prevSelectedBlockchain = useRef({ index: -1, name: '' });
|
|
26
|
-
|
|
27
|
-
blockchains.sort(sortByMostUsedBlockchains);
|
|
28
|
-
|
|
29
|
-
const blockchainsHash = blockchains
|
|
30
|
-
.map((blockchain) => blockchain.name)
|
|
31
|
-
.join('-');
|
|
32
|
-
|
|
33
|
-
return useMemo(() => {
|
|
34
|
-
const list: BlockchainMeta[] = blockchains;
|
|
35
|
-
let more: BlockchainMeta[] = [];
|
|
36
|
-
|
|
37
|
-
// Checking `limit` has set and it should be more than of the list items.
|
|
38
|
-
if (options?.limit && blockchains.length > options.limit) {
|
|
39
|
-
const start = options.limit;
|
|
40
|
-
/** Try find the blockchain and returns the index. */
|
|
41
|
-
const selectedIndex = options.selected
|
|
42
|
-
? blockchains.findIndex(
|
|
43
|
-
(blockchains) => blockchains.name === options.selected
|
|
44
|
-
)
|
|
45
|
-
: -1;
|
|
46
|
-
|
|
47
|
-
const prevSelectedBlockchainWasInMoreSection =
|
|
48
|
-
prevSelectedBlockchain.current.index > options.limit - 1 &&
|
|
49
|
-
!!blockchains.find(
|
|
50
|
-
(blockchains) =>
|
|
51
|
-
blockchains.name === prevSelectedBlockchain.current.name
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
* If the selected blockchain is in `more` section, we should move it to front of the list
|
|
56
|
-
*/
|
|
57
|
-
if (
|
|
58
|
-
options.selected &&
|
|
59
|
-
((prevSelectedBlockchainWasInMoreSection &&
|
|
60
|
-
selectedIndex < options.limit - 1) ||
|
|
61
|
-
selectedIndex > options.limit - 1)
|
|
62
|
-
) {
|
|
63
|
-
blockchains.sort(
|
|
64
|
-
generateSortBySelectedFor(
|
|
65
|
-
prevSelectedBlockchainWasInMoreSection
|
|
66
|
-
? prevSelectedBlockchain.current.name
|
|
67
|
-
: options.selected
|
|
68
|
-
)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/*
|
|
73
|
-
* Splice will modify the original list and returns the deleted items
|
|
74
|
-
* We use the deleted items as `more`
|
|
75
|
-
*/
|
|
76
|
-
more = list.splice(start);
|
|
77
|
-
prevSelectedBlockchain.current = {
|
|
78
|
-
index: selectedIndex,
|
|
79
|
-
name: options.selected ?? '',
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
list,
|
|
85
|
-
more,
|
|
86
|
-
};
|
|
87
|
-
}, [blockchainsHash]);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function generateSortBySelectedFor(selected: string) {
|
|
91
|
-
/** Move `selected` blockchain to the front of list. */
|
|
92
|
-
return function sortBySelected(a: BlockchainMeta, b: BlockchainMeta) {
|
|
93
|
-
if (a.name === selected) {
|
|
94
|
-
return -1;
|
|
95
|
-
}
|
|
96
|
-
if (b.name === selected) {
|
|
97
|
-
return 1;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return 0;
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** There is a hardcoded list of blockchains that we want to show them first in the list. */
|
|
105
|
-
function sortByMostUsedBlockchains(a: BlockchainMeta, b: BlockchainMeta) {
|
|
106
|
-
const mostUsed = ['ETH', 'COSMOS', 'OSMOSIS'];
|
|
107
|
-
const aIndexInMostUsed = mostUsed.findIndex((token) => token === a.name);
|
|
108
|
-
const bIndexInMostUsed = mostUsed.findIndex((token) => token === b.name);
|
|
109
|
-
const aIsMostUsed = aIndexInMostUsed > -1;
|
|
110
|
-
const bIsMostUsed = bIndexInMostUsed > -1;
|
|
111
|
-
|
|
112
|
-
if (aIsMostUsed && bIsMostUsed) {
|
|
113
|
-
return aIndexInMostUsed > bIndexInMostUsed ? 1 : -1;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (aIsMostUsed) {
|
|
117
|
-
return -1;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (bIsMostUsed) {
|
|
121
|
-
return 1;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return 0;
|
|
125
|
-
}
|
|
File without changes
|