@rango-dev/widget-embedded 0.1.11-next.8 → 0.1.11

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.
Files changed (80) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/ConfirmSwapErrors.d.ts +1 -1
  4. package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
  5. package/dist/components/ConfirmSwapWarnings.d.ts +1 -2
  6. package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
  7. package/dist/components/SwapDetailsPlaceholder.d.ts +1 -0
  8. package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -1
  9. package/dist/components/TokenInfo.d.ts.map +1 -1
  10. package/dist/components/warnings/BalanceErrors.d.ts +7 -0
  11. package/dist/components/warnings/BalanceErrors.d.ts.map +1 -0
  12. package/dist/globalStyles.d.ts.map +1 -1
  13. package/dist/hooks/useTheme.d.ts +2 -2
  14. package/dist/hooks/useTheme.d.ts.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/lib.d.ts +4 -2
  18. package/dist/lib.d.ts.map +1 -1
  19. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  20. package/dist/pages/HistoryPage.d.ts.map +1 -1
  21. package/dist/pages/Home.d.ts.map +1 -1
  22. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  23. package/dist/pages/WalletsPage.d.ts +0 -1
  24. package/dist/pages/WalletsPage.d.ts.map +1 -1
  25. package/dist/services/httpService.d.ts +2 -1
  26. package/dist/services/httpService.d.ts.map +1 -1
  27. package/dist/store/bestRoute.d.ts.map +1 -1
  28. package/dist/store/meta.d.ts.map +1 -1
  29. package/dist/types/config.d.ts +78 -9
  30. package/dist/types/config.d.ts.map +1 -1
  31. package/dist/types/routing.d.ts +8 -8
  32. package/dist/types/routing.d.ts.map +1 -1
  33. package/dist/utils/configs.d.ts +7 -0
  34. package/dist/utils/configs.d.ts.map +1 -0
  35. package/dist/utils/numbers.d.ts +1 -0
  36. package/dist/utils/numbers.d.ts.map +1 -1
  37. package/dist/utils/routing.d.ts +4 -4
  38. package/dist/utils/routing.d.ts.map +1 -1
  39. package/dist/utils/swap.d.ts +2 -2
  40. package/dist/utils/swap.d.ts.map +1 -1
  41. package/dist/utils/time.d.ts.map +1 -1
  42. package/dist/widget-embedded.cjs.development.js +346 -277
  43. package/dist/widget-embedded.cjs.development.js.map +1 -1
  44. package/dist/widget-embedded.cjs.production.min.js +346 -277
  45. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  46. package/dist/widget-embedded.esm.js +342 -278
  47. package/dist/widget-embedded.esm.js.map +1 -1
  48. package/package.json +5 -5
  49. package/src/App.tsx +10 -16
  50. package/src/QueueManager.tsx +9 -3
  51. package/src/app.css +0 -15
  52. package/src/components/ConfirmSwapErrors.tsx +8 -16
  53. package/src/components/ConfirmSwapWarnings.tsx +5 -15
  54. package/src/components/SwapDetailsPlaceholder.tsx +8 -1
  55. package/src/components/TokenInfo.tsx +6 -5
  56. package/src/components/warnings/BalanceErrors.tsx +45 -0
  57. package/src/globalStyles.ts +4 -0
  58. package/src/hooks/useConfirmSwap.ts +5 -5
  59. package/src/hooks/useTheme.ts +2 -2
  60. package/src/index.tsx +1 -1
  61. package/src/lib.tsx +16 -15
  62. package/src/pages/ConfirmSwapPage.tsx +4 -2
  63. package/src/pages/HistoryPage.tsx +4 -1
  64. package/src/pages/Home.tsx +6 -8
  65. package/src/pages/SwapDetailsPage.tsx +8 -21
  66. package/src/pages/WalletsPage.tsx +2 -2
  67. package/src/services/httpService.ts +9 -4
  68. package/src/store/bestRoute.ts +7 -5
  69. package/src/store/meta.ts +6 -4
  70. package/src/store/wallets.ts +2 -2
  71. package/src/types/config.ts +79 -12
  72. package/src/types/routing.ts +4 -4
  73. package/src/utils/configs.ts +30 -0
  74. package/src/utils/numbers.ts +4 -0
  75. package/src/utils/routing.ts +31 -11
  76. package/src/utils/swap.ts +16 -5
  77. package/src/utils/time.ts +2 -8
  78. package/dist/components/warnings/BalanceWarnings.d.ts +0 -7
  79. package/dist/components/warnings/BalanceWarnings.d.ts.map +0 -1
  80. package/src/components/warnings/BalanceWarnings.tsx +0 -40
@@ -1,9 +1,14 @@
1
1
  import { RangoClient } from 'rango-sdk';
2
+ import { getConfig } from '../utils/configs';
2
3
 
3
4
  // this API key is limited and
4
5
  // it is only for test purpose
5
- const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
6
+ export const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
6
7
 
7
- export const httpService = new RangoClient(
8
- (process.env.REACT_APP_API_KEY as string) || RANGO_PUBLIC_API_KEY
9
- );
8
+ let rango: RangoClient | undefined = undefined;
9
+
10
+ export const httpService = () => {
11
+ if (rango) return rango;
12
+ rango = new RangoClient(getConfig('API_KEY'));
13
+ return rango;
14
+ };
@@ -22,6 +22,8 @@ import { useWalletsStore } from './wallets';
22
22
  import { TokenWithBalance } from '../pages/SelectTokenPage';
23
23
  import { PendingSwap } from '@rango-dev/queue-manager-rango-preset/dist/shared';
24
24
  import { debounce } from '../utils/common';
25
+ import { isPositiveNumber } from '../utils/numbers';
26
+
25
27
  const getUsdValue = (token: Token | null, amount: string) =>
26
28
  new BigNumber(amount || ZERO).multipliedBy(token?.usdPrice || 0);
27
29
 
@@ -72,7 +74,7 @@ export const useBestRouteStore = createSelectors(
72
74
  set((state) => {
73
75
  let outputAmount: BigNumber | null = null;
74
76
  let outputUsdValue: BigNumber = ZERO;
75
- if (!state.inputAmount || state.inputAmount === '0') return {};
77
+ if (!isPositiveNumber(state.inputAmount)) return {};
76
78
  if (!!bestRoute) {
77
79
  outputAmount = !!bestRoute.result?.outputAmount
78
80
  ? new BigNumber(bestRoute.result?.outputAmount)
@@ -251,7 +253,7 @@ const bestRoute = (
251
253
  const { fromToken, toToken, inputAmount } = bestRouteStore.getState();
252
254
  const { slippage, customSlippage, disabledLiquiditySources, affiliateRef } =
253
255
  settingsStore.getState();
254
- if (!fromToken || !toToken || !inputAmount || inputAmount === '0') return;
256
+ if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
255
257
  abortController?.abort();
256
258
  abortController = new AbortController();
257
259
  const userSlippage = !!customSlippage ? customSlippage : slippage;
@@ -263,7 +265,6 @@ const bestRoute = (
263
265
  [],
264
266
  disabledLiquiditySources,
265
267
  userSlippage,
266
- false,
267
268
  affiliateRef
268
269
  );
269
270
  if (!bestRouteStore.getState().loading)
@@ -273,7 +274,7 @@ const bestRoute = (
273
274
  outputAmount: null,
274
275
  outputUsdValue: new BigNumber(0),
275
276
  });
276
- httpService
277
+ httpService()
277
278
  .getBestRoute(requestBody, {
278
279
  signal: abortController.signal,
279
280
  })
@@ -297,7 +298,8 @@ const bestRoute = (
297
298
  const bestRouteParamsListener = () => {
298
299
  const { fromToken, toToken, inputAmount, inputUsdValue } =
299
300
  useBestRouteStore.getState();
300
- if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0)) return;
301
+ if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0))
302
+ return bestRouteStore.setState({ loading: false });
301
303
 
302
304
  if (tokensAreEqual(fromToken, toToken))
303
305
  return bestRouteStore.setState({
package/src/store/meta.ts CHANGED
@@ -18,12 +18,14 @@ export const useMetaStore = createSelectors(
18
18
  loadingStatus: 'loading',
19
19
  fetchMeta: async () => {
20
20
  try {
21
- const response = await httpService.getAllMetadata();
21
+ const response = await httpService().getAllMetadata();
22
22
  const chainThatHasTokenInMetaResponse = removeDuplicateFrom(
23
- response.tokens.map((t) => t.blockchain),
23
+ response.tokens.map((t) => t.blockchain)
24
24
  );
25
25
  const enabledChains = response.blockchains.filter(
26
- (chain) => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name),
26
+ (chain) =>
27
+ chain.enabled &&
28
+ chainThatHasTokenInMetaResponse.includes(chain.name)
27
29
  );
28
30
  response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
29
31
  set({ meta: response, loadingStatus: 'success' });
@@ -31,5 +33,5 @@ export const useMetaStore = createSelectors(
31
33
  set({ loadingStatus: 'failed' });
32
34
  }
33
35
  },
34
- })),
36
+ }))
35
37
  );
@@ -81,7 +81,7 @@ export const useWalletsStore = createSelectors(
81
81
  }));
82
82
  accounts.forEach(async (account) => {
83
83
  try {
84
- const response = await httpService.getWalletsDetails([
84
+ const response = await httpService().getWalletsDetails([
85
85
  { address: account.address, blockchain: account.chain },
86
86
  ]);
87
87
  const retrivedBalance = response.wallets[0];
@@ -142,7 +142,7 @@ export const useWalletsStore = createSelectors(
142
142
  }
143
143
  });
144
144
  return {
145
- selectedWallets: selectedWallets,
145
+ selectedWallets: state.selectedWallets.concat(selectedWallets),
146
146
  };
147
147
  }),
148
148
  setSelectedWallet: (wallet) =>
@@ -1,42 +1,109 @@
1
1
  import { Asset } from 'rango-sdk';
2
2
  import { WalletType } from '@rango-dev/wallets-shared';
3
3
 
4
- export type Colors = {
4
+ /**
5
+ * The above type defines a set of optional color properties for a widget.
6
+ * @property {string} background
7
+ * @property {string} foreground
8
+ * @property {string} primary
9
+ * @property {string} success
10
+ * @property {string} error
11
+ * @property {string} warning
12
+ */
13
+ export type WidgetColors = {
5
14
  background?: string;
6
- // inputBackground?: string;
7
- // icons?: string;
8
- primary?: string;
9
15
  foreground?: string;
10
- // text?: string;
16
+ primary?: string;
11
17
  success?: string;
12
18
  error?: string;
13
19
  warning?: string;
14
20
  };
15
21
 
16
- export type Theme = {
17
- mode?: 'dark' | 'light' | 'auto';
22
+ /**
23
+ * The `WidgetTheme` defines the properties of a widget theme, including mode, font family, colors, border
24
+ * radius, width, and height.
25
+ * @property {'auto' | 'light' | 'dark'} mode - The mode property is used to specify the default theme for
26
+ * the widget.
27
+ * @property {string} fontFamily - The font family to be used in the widget.
28
+ * @property {Colors} colors - The `colors` property is a sub-property of the `WidgetTheme` object that
29
+ * defines the color scheme for the widget. It is of type `Colors`, which is likely another object that
30
+ * contains specific color values for various parts of the widget (e.g. background color, text color,
31
+ * border color
32
+ * @property {number} borderRadius - `borderRadius` is a property of the `WidgetTheme` type that
33
+ * specifies the radius of the corners of a widget.
34
+ * @property {number} width - The `width` property is a number that represents the width of the widget.
35
+ * @property {number} height - The `height` property is a number that specifies the height of the widget.
36
+ */
37
+ export type WidgetTheme = {
38
+ mode?: 'auto' | 'light' | 'dark';
18
39
  fontFamily?: string;
19
- colors?: Colors;
40
+ colors?: WidgetColors;
20
41
  borderRadius?: number;
21
42
  width?: number;
22
43
  height?: number;
23
44
  };
24
- export type Support = {
45
+
46
+ /**
47
+ * `BlockchainAndTokenConfig`
48
+ *
49
+ * @property {string} blockchain - This property is optional and represents the default selected blockchain.
50
+ * @property {Asset} token - The `token` property is a type of `Asset` and represents the default token
51
+ * which is selected. e.g. {blockchain: 'BSC', symbol: 'BNB', address: null}
52
+ * @property {string[]} blockchains - An optional array of strings representing the supported
53
+ * blockchains. e.g. ['BSC','ETHEREUM']
54
+ * @property {Asset[]} tokens - The `tokens` property is an optional array of `Asset` objects that
55
+ * you could use that to limit tokens to some limited ones.
56
+ */
57
+ export type BlockchainAndTokenConfig = {
25
58
  blockchain?: string;
26
59
  token?: Asset;
27
60
  blockchains?: string[];
28
61
  tokens?: Asset[];
29
62
  };
30
63
 
64
+ /**
65
+ * The type WidgetConfig defines the configuration options for a widget, including API key, affiliate
66
+ * reference, amount, blockchain and token configurations, liquidity sources, wallet types, language,
67
+ * and theme.
68
+ *
69
+ * @property {string} apiKey - The API key used to communicate with Rango API
70
+ * @property {string} affiliateRef - The affiliate reference is an optional string property in the
71
+ * WidgetConfig type. It is used to set and track referrals or affiliations for the dApps.
72
+ * @property {number} amount - The default input amount.
73
+ * @property {BlockchainAndTokenConfig} from - The `from` property is an optional property of type
74
+ * `BlockchainAndTokenConfig` that specifies the default blockchain and token from which the user wants to
75
+ * exchange.It can also used to limit source swap blockchains/tokens to some limited ones.
76
+ * @property {BlockchainAndTokenConfig} to - The "to" property is an optional property of type
77
+ * "BlockchainAndTokenConfig" that specifies the default blockchain and token to which the user wants to
78
+ * exchange.It can also used to limit destination swap blockchains/tokens to some limited ones.
79
+ * blockchain during the transaction.
80
+ * @property {string[]} liquiditySources - The `liquiditySources` property is an optional array of
81
+ * strings that specifies the liquidity sources allowed dexes and bridges for the routing
82
+ * @property {WalletType[]} wallets - The `wallets` property is an optional array of `WalletType`
83
+ * values that represent the types of wallets that the widget should support. For example, it could
84
+ * include values like `"metamask"`, `"kepler"`, or `"phantom"`.
85
+ * @property {boolean} multiWallets - The `multiWallets` property is a boolean value that indicates
86
+ * whether the widget should allow the user to select multiple wallets for the transaction.
87
+ * @property {boolean} customAddress - A boolean value indicating whether the user can input a custom
88
+ * address for the transaction. If set to true, the widget will allow the user to input a custom
89
+ * address for the destination.
90
+ * @property {string} language - The language property is an optional string that specifies the
91
+ * default language in which the widget should be displayed. If not provided, the widget will default to the
92
+ * language of the user's browser.
93
+ * @property {WidgetTheme} theme - The `theme` property is a part of the `WidgetConfig` type and is
94
+ * used to specify the visual theme of the widget. It is of type `WidgetTheme`, which is an interface
95
+ * that defines the various properties of the theme, such as colors, fonts, and others.
96
+ */
31
97
  export type WidgetConfig = {
98
+ apiKey: string;
32
99
  affiliateRef?: string;
33
100
  amount?: number;
34
- from?: Support;
35
- to?: Support;
101
+ from?: BlockchainAndTokenConfig;
102
+ to?: BlockchainAndTokenConfig;
36
103
  liquiditySources?: string[];
37
104
  wallets?: WalletType[];
38
105
  multiWallets?: boolean;
39
106
  customAddress?: boolean;
40
107
  language?: string;
41
- theme?: Theme;
108
+ theme?: WidgetTheme;
42
109
  };
@@ -33,6 +33,7 @@ export enum ConfirmSwapErrorTypes {
33
33
  ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS,
34
34
  REQUEST_FAILED,
35
35
  INSUFFICIENT_SLIPPAGE,
36
+ INSUFFICIENT_BALANCE,
36
37
  }
37
38
 
38
39
  export type ConfirmSwapError =
@@ -44,11 +45,13 @@ export type ConfirmSwapError =
44
45
  type: ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE;
45
46
  minRequiredSlippage: string | null;
46
47
  }
48
+ | { type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE; messages: string[] }
47
49
  | {
48
50
  type: Exclude<
49
51
  ConfirmSwapErrorTypes,
50
52
  | ConfirmSwapErrorTypes.REQUEST_FAILED
51
53
  | ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE
54
+ | ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE
52
55
  >;
53
56
  };
54
57
 
@@ -58,12 +61,10 @@ export type ConfirmSwapWarnings =
58
61
  newOutputAmount: string;
59
62
  percentageChange: string;
60
63
  }
61
- | { type: ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE; messages: string[] }
62
64
  | {
63
65
  type: Exclude<
64
66
  ConfirmSwapWarningTypes,
65
- | ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED
66
- | ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE
67
+ ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED
67
68
  >;
68
69
  };
69
70
 
@@ -72,5 +73,4 @@ export enum ConfirmSwapWarningTypes {
72
73
  ROUTE_SWAPPERS_UPDATED,
73
74
  ROUTE_COINS_UPDATED,
74
75
  ROUTE_AND_OUTPUT_AMOUNT_UPDATED,
75
- INSUFFICIENT_BALANCE,
76
76
  }
@@ -0,0 +1,30 @@
1
+ export interface Configs {
2
+ API_KEY: string;
3
+ }
4
+
5
+ const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
6
+
7
+ let configs: Configs = {
8
+ API_KEY: RANGO_PUBLIC_API_KEY,
9
+ };
10
+
11
+ export function getConfig(name: keyof Configs) {
12
+ return configs[name];
13
+ }
14
+
15
+ export function setConfig(name: keyof Configs, value: any) {
16
+ configs[name] = value;
17
+
18
+ return value;
19
+ }
20
+
21
+ export function initConfig(nextConfigs: Configs) {
22
+ let clonedConfigs;
23
+ if (typeof structuredClone === 'function') {
24
+ clonedConfigs = structuredClone(nextConfigs);
25
+ } else {
26
+ clonedConfigs = JSON.parse(JSON.stringify(nextConfigs));
27
+ }
28
+ configs = clonedConfigs;
29
+ return configs;
30
+ }
@@ -131,3 +131,7 @@ export const decimalNumber = (number = '0', toFixed: number) =>
131
131
 
132
132
  export const containsText = (text: string, searchText: string) =>
133
133
  text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
134
+
135
+ export const isPositiveNumber = (text?: string) =>
136
+ !!text && parseFloat(text) > 0;
137
+ 10;
@@ -7,10 +7,8 @@ import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
7
7
  import { areEqual } from './common';
8
8
  import { SelectedWallet } from './wallets';
9
9
  import { BestRouteEqualityParams } from '../types';
10
- import { TokenMeta } from '@rango-dev/ui/dist/types/meta';
11
10
  import { numberToString } from './numbers';
12
- import { getUsdFeeOfStep } from './swap';
13
- import { BestRouteWithFee } from '@rango-dev/ui';
11
+ import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
14
12
 
15
13
  export function searchParamsToToken(
16
14
  tokens: Token[],
@@ -142,19 +140,41 @@ export function isRouteParametersChanged(params: BestRouteEqualityParams) {
142
140
  return false;
143
141
  }
144
142
 
145
- export function getBestRouteWithCalculatedFees(
146
- bestRoute: BestRouteResponse | null,
147
- tokens: TokenMeta[]
148
- ): BestRouteWithFee | null {
149
- if (!bestRoute || !bestRoute.result) return null;
150
- const swapsWithFee = (bestRoute?.result?.swaps || []).map((swap) => ({
143
+ export function getFormatedBestRoute(
144
+ bestRoute: BestRouteResponse | null
145
+ ): BestRouteResponse | null {
146
+ if (!bestRoute) return null;
147
+
148
+ const formatedSwaps = (bestRoute.result?.swaps || []).map((swap) => ({
151
149
  ...swap,
152
- feeInUsd: numberToString(getUsdFeeOfStep(swap, tokens), 0, 2),
150
+ fromAmount: numberToString(swap.fromAmount, 6, 6),
151
+ toAmount: numberToString(swap.toAmount, 6, 6),
153
152
  }));
154
153
 
155
154
  return {
156
155
  ...bestRoute,
157
- result: { ...bestRoute.result, swaps: swapsWithFee },
156
+ ...(bestRoute.result && {
157
+ result: { ...bestRoute.result, swaps: formatedSwaps },
158
+ }),
159
+ };
160
+ }
161
+
162
+ export function getFormatedPendingSwap(pendingSwap: PendingSwap): PendingSwap {
163
+ const formatedSteps = pendingSwap.steps.map((step) => ({
164
+ ...step,
165
+ feeInUsd: numberToString(step.feeInUsd, 4, 4),
166
+ outputAmount: numberToString(step.outputAmount, 6, 6),
167
+ expectedOutputAmountHumanReadable: numberToString(
168
+ step.expectedOutputAmountHumanReadable,
169
+ 6,
170
+ 6
171
+ ),
172
+ }));
173
+
174
+ return {
175
+ ...pendingSwap,
176
+ inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
177
+ steps: formatedSteps,
158
178
  };
159
179
  }
160
180
 
package/src/utils/swap.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  PendingSwapStep,
20
20
  } from '@rango-dev/queue-manager-rango-preset';
21
21
  import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
22
+ import { removeDuplicateFrom } from './common';
22
23
 
23
24
  export function getOutputRatio(
24
25
  inputUsdValue: BigNumber,
@@ -128,13 +129,14 @@ export function getSwapButtonState(
128
129
  highValueLoss: boolean,
129
130
  priceImpactCanNotBeComputed: boolean,
130
131
  needsToWarnEthOnPath: boolean,
131
- inputIsZero: boolean
132
+ inputAmount: string
132
133
  ): SwapButtonState {
133
134
  if (loadingMetaStatus !== 'success')
134
135
  return { title: 'Connect Wallet', disabled: true };
135
136
  if (accounts.length == 0) return { title: 'Connect Wallet', disabled: false };
136
137
  if (loading) return { title: 'Finding Best Route...', disabled: true };
137
- else if (inputIsZero) return { title: 'Enter an amount', disabled: true };
138
+ else if (!inputAmount || inputAmount === '0')
139
+ return { title: 'Enter an amount', disabled: true };
138
140
  else if (!bestRoute || !bestRoute.result)
139
141
  return { title: 'Swap', disabled: true };
140
142
  else if (hasLimitError) return { title: 'Limit Error', disabled: true };
@@ -313,8 +315,8 @@ export function createBestRouteRequestBody(
313
315
  selectedWallets: SelectedWallet[],
314
316
  disabledLiquiditySources: string[],
315
317
  slippage: number,
316
- checkPrerequisites: boolean,
317
- affiliateRef: string | null
318
+ affiliateRef: string | null,
319
+ initialRoute?: BestRouteResponse
318
320
  ): BestRouteRequest {
319
321
  const selectedWalletsMap = selectedWallets.reduce(
320
322
  (
@@ -341,7 +343,16 @@ export function createBestRouteRequestBody(
341
343
  });
342
344
  });
343
345
 
344
- const filteredBlockchains = selectedWallets.map((wallet) => wallet.chain);
346
+ const checkPrerequisites = !!initialRoute;
347
+
348
+ const filteredBlockchains = removeDuplicateFrom(
349
+ (initialRoute?.result?.swaps || []).reduce(
350
+ (blockchains: string[], swap) => (
351
+ blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains
352
+ ),
353
+ []
354
+ )
355
+ );
345
356
 
346
357
  const requestBody: BestRouteRequest = {
347
358
  amount: inputAmount.toString(),
package/src/utils/time.ts CHANGED
@@ -41,12 +41,6 @@ export function timeSince(timeMillis: number): string {
41
41
 
42
42
  export function getSwapDate(pendingSwap: PendingSwap) {
43
43
  return pendingSwap.finishTime
44
- ? `Finished ${timeSince(parseInt(pendingSwap.finishTime))} ago @ ${new Date(
45
- parseInt(pendingSwap.finishTime)
46
- ).toLocaleString()}`
47
- : `Started ${timeSince(
48
- parseInt(pendingSwap.creationTime)
49
- )} ago @ ${new Date(
50
- parseInt(pendingSwap.creationTime)
51
- ).toLocaleString()}`;
44
+ ? `${timeSince(parseInt(pendingSwap.finishTime))} ago`
45
+ : `${timeSince(parseInt(pendingSwap.creationTime))} ago`;
52
46
  }
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- interface PropTypes {
3
- messages: string[];
4
- }
5
- export declare function BalanceWarnings({ messages }: PropTypes): JSX.Element;
6
- export {};
7
- //# sourceMappingURL=BalanceWarnings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BalanceWarnings.d.ts","sourceRoot":"","sources":["../../src/components/warnings/BalanceWarnings.tsx"],"names":[],"mappings":";AAGA,UAAU,SAAS;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAuBD,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE,SAAS,eAWtD"}
@@ -1,40 +0,0 @@
1
- import { styled, Typography } from '@rango-dev/ui';
2
- import React from 'react';
3
-
4
- interface PropTypes {
5
- messages: string[];
6
- }
7
-
8
- const List = styled('ul', {
9
- variants: {
10
- showListStyle: {
11
- true: { paddingLeft: '$24' },
12
- },
13
- },
14
- });
15
-
16
- const ListItem = styled('li', {
17
- variants: {
18
- showListStyle: {
19
- true: { listStyleType: 'disc', listStylePosition: 'outside' },
20
- },
21
- },
22
- });
23
-
24
- const Message = styled(Typography, {
25
- display: 'block',
26
- color: '$warning500 !important',
27
- });
28
-
29
- export function BalanceWarnings({ messages }: PropTypes) {
30
- const showListStyle = messages.length > 1;
31
- return (
32
- <List showListStyle={showListStyle}>
33
- {messages.map((warning) => (
34
- <ListItem showListStyle={showListStyle}>
35
- <Message variant="body2">{warning}</Message>
36
- </ListItem>
37
- ))}
38
- </List>
39
- );
40
- }