@rango-dev/widget-embedded 0.35.0 → 0.35.1-next.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.35.0",
3
+ "version": "0.35.1-next.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -54,4 +54,4 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
57
- }
57
+ }
@@ -15,7 +15,7 @@ import {
15
15
  getQuoteToTokenUsdPrice,
16
16
  sortQuotesBy,
17
17
  } from '../utils/quote';
18
- import { isFeatureEnabled } from '../utils/settings';
18
+ import { isRoutingEnabled } from '../utils/settings';
19
19
  import { createQuoteRequestBody } from '../utils/swap';
20
20
  import { areTokensEqual } from '../utils/wallets';
21
21
 
@@ -48,11 +48,8 @@ export function useSwapInput({
48
48
  refetchQuote,
49
49
  }: UseSwapInputProps): UseSwapInput {
50
50
  const { fetch: fetchQuote, cancelFetch } = useFetchAllQuotes();
51
- const {
52
- excludeLiquiditySources: configExcludeLiquiditySources,
53
- features,
54
- enableCentralizedSwappers,
55
- } = useAppStore().config;
51
+ const { excludeLiquiditySources: configExcludeLiquiditySources, routing } =
52
+ useAppStore().config;
56
53
  const connectedWallets = useWalletsStore.use.connectedWallets();
57
54
 
58
55
  const {
@@ -125,11 +122,23 @@ export function useSwapInput({
125
122
  affiliateRef,
126
123
  affiliatePercent,
127
124
  affiliateWallets,
128
- enableCentralizedSwappers,
129
125
  });
130
- if (isFeatureEnabled('experimentalRoute', features)) {
126
+ if (isRoutingEnabled('experimental', routing)) {
131
127
  requestBody.experimental = true;
132
128
  }
129
+
130
+ if (isRoutingEnabled('avoidNativeFee', routing)) {
131
+ requestBody.avoidNativeFee = true;
132
+ }
133
+
134
+ if (isRoutingEnabled('enableCentralizedSwappers', routing)) {
135
+ requestBody.enableCentralizedSwappers = true;
136
+ }
137
+
138
+ if (routing?.maxLength) {
139
+ requestBody.maxLength = routing.maxLength;
140
+ }
141
+
133
142
  fetchQuote(requestBody)
134
143
  .then((res) => {
135
144
  const sortQuotes = sortQuotesBy(sortStrategy, res.results);
@@ -20,6 +20,7 @@ import { compareWithSearchFor, containsText } from '../../utils/common';
20
20
  import { createTokenHash, isTokenNative } from '../../utils/meta';
21
21
  import {
22
22
  addCustomTokensToSupportedTokens,
23
+ isRoutingEnabled,
23
24
  sortLiquiditySourcesByGroupTitle,
24
25
  } from '../../utils/settings';
25
26
  import { areTokensEqual, compareTokenBalance } from '../../utils/wallets';
@@ -324,7 +325,12 @@ export const createDataSlice: StateCreator<
324
325
  // Actions
325
326
  fetch: async () => {
326
327
  try {
327
- const { enableCentralizedSwappers } = get().config;
328
+ const { routing } = get().config;
329
+ const enableCentralizedSwappers = isRoutingEnabled(
330
+ 'enableCentralizedSwappers',
331
+ routing
332
+ );
333
+
328
334
  const response = await sdk().getAllMetadata({
329
335
  enableCentralizedSwappers,
330
336
  });
@@ -121,9 +121,6 @@ export type SignersConfig = {
121
121
  * @property {'visible' | 'hidden'} [language]
122
122
  * - The visibility state for the language feature. Optional property.
123
123
  *
124
- * @property {'disabled' | 'enabled'} [experimentalRoute]
125
- * - The enablement state for the experimental route feature. Optional property.
126
- *
127
124
  * @property {'visible' | 'hidden'} [connectWalletButton]
128
125
  * - The visibility state for the connect wallet button feature. Optional property.
129
126
  *
@@ -143,8 +140,30 @@ export type Features = Partial<
143
140
  | 'customTokens',
144
141
  'visible' | 'hidden'
145
142
  >
143
+ >;
144
+
145
+ /**
146
+ * `Routing`
147
+ *
148
+ * @property {'disabled' | 'enabled'} [avoidNativeFee]
149
+ * - If you want to exclude swappers that have native tokens as fee, for example when you are using an AA account, you could set this parameter.
150
+ *
151
+ * @property {number} [maxLength]
152
+ * - If you want to limit the maximum acceptable length of a route, you could set this parameter.
153
+ *
154
+ * @property {'disabled' | 'enabled'} [experimental]
155
+ * - Use this parameter to enable experimental routes. This settings shouldn't be used in your production environment.
156
+ *
157
+ * @property {'disabled' | 'enabled'} [enableCentralizedSwappers]
158
+ * - If you want to enable routing from the centralized protocols like XO Swap, you could set this parameter.
159
+ */
160
+ export type Routing = Partial<
161
+ Record<
162
+ 'experimental' | 'avoidNativeFee' | 'enableCentralizedSwappers',
163
+ 'disabled' | 'enabled'
164
+ >
146
165
  > &
147
- Partial<Record<'experimentalRoute', 'disabled' | 'enabled'>>;
166
+ Partial<Record<'maxLength', number>>;
148
167
 
149
168
  export type TrezorManifest = {
150
169
  appUrl: string;
@@ -192,7 +211,7 @@ export type TrezorManifest = {
192
211
  * If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
193
212
  * @property {boolean} excludeLiquiditySources - The `excludeLiquiditySources` property is a boolean value that when you
194
213
  * set it to true, the list of liquidity sources provided in `liquiditySources` will be excluded; otherwise, they will be included.
195
- * @property {Features} features - An optional object for configuring the visibility or enablement of various features.
214
+ * @property {Features} features - An optional object for configuring the visibility of various features.
196
215
  * Keys include:
197
216
  * - 'notification': Visibility state for the notification icon.
198
217
  * - 'theme': Visibility state for the theme.
@@ -200,14 +219,16 @@ export type TrezorManifest = {
200
219
  * - 'connectWalletButton': Visibility state for the wallet connect icon.
201
220
  * - 'language': Visibility state for the language.
202
221
  * - 'customTokens': Visibility state for the custom tokens.
203
- * - 'experimentalRoute': Enablement state for the experimental route.
204
- *
222
+ * @property {Routing} routing - An optional object for configuring the enablement or numeric of various features.
223
+ * Keys include:
224
+ * - 'maxLength': If you want to limit the maximum acceptable length of a route, you could set this parameter.
225
+ * - 'avoidNativeFee': If you want to exclude swappers that have native tokens as fee, for example when you are using an AA account, you could set this parameter.
226
+ * - 'experimental': Use this parameter to enable experimental routes. This settings shouldn't be used in your production environment.
227
+ * - 'enableCentralizedSwappers': If you want to enable routing from the centralized protocols like XO Swap, you could set this parameter.
205
228
  * @property {WidgetVariant} variant
206
229
  * If it is expanded, multiple routes will show up on the home page;
207
230
  * If it is full-expanded, multiple routes will show up on the home page with full routes;
208
231
  * if not, you will need to go to a different page to see the suggested routes.
209
- * @property {boolean} enableCentralizedSwappers
210
- * If you want to enable routing from the centralized protocols like XO Swap, you could set this parameter to true.
211
232
  */
212
233
 
213
234
  export type WidgetConfig = {
@@ -231,11 +252,11 @@ export type WidgetConfig = {
231
252
  excludeLiquiditySources?: boolean;
232
253
  features?: Features;
233
254
  variant?: WidgetVariant;
234
- enableCentralizedSwappers?: boolean;
235
255
  signers?: SignersConfig;
236
256
  // These are likely to change or remove at anytime. Please use with a caution.
237
257
  __UNSTABLE_OR_INTERNAL__?: {
238
258
  walletConnectListedDesktopWalletLink?: string;
239
259
  autoUpdateSettings?: boolean; // If true, settings will be updated automatically based on the configuration.
240
260
  };
261
+ routing?: Routing;
241
262
  };
@@ -1,4 +1,4 @@
1
- import type { Features } from '../types';
1
+ import type { Features, Routing } from '../types';
2
2
  import type { SwapperMeta, SwapperType, Token } from 'rango-sdk';
3
3
 
4
4
  import { removeDuplicateFrom } from './common';
@@ -72,8 +72,8 @@ export function isFeatureHidden(feature: keyof Features, features?: Features) {
72
72
  return features?.[feature] === 'hidden';
73
73
  }
74
74
 
75
- export function isFeatureEnabled(feature: keyof Features, features?: Features) {
76
- return features?.[feature] === 'enabled';
75
+ export function isRoutingEnabled(item: keyof Routing, routing?: Routing) {
76
+ return routing?.[item] === 'enabled';
77
77
  }
78
78
 
79
79
  export const addCustomTokensToSupportedTokens = (
package/src/utils/swap.ts CHANGED
@@ -445,7 +445,6 @@ export function createQuoteRequestBody(params: {
445
445
  affiliatePercent: number | null;
446
446
  affiliateWallets: { [key: string]: string } | null;
447
447
  destination?: string;
448
- enableCentralizedSwappers?: boolean;
449
448
  }): BestRouteRequest {
450
449
  const {
451
450
  fromToken,
@@ -461,7 +460,6 @@ export function createQuoteRequestBody(params: {
461
460
  affiliatePercent,
462
461
  affiliateWallets,
463
462
  destination,
464
- enableCentralizedSwappers,
465
463
  } = params;
466
464
  const selectedWalletsMap = selectedWallets?.reduce(
467
465
  (
@@ -513,7 +511,6 @@ export function createQuoteRequestBody(params: {
513
511
  ),
514
512
  swappersGroupsExclude: false,
515
513
  }),
516
- enableCentralizedSwappers,
517
514
  };
518
515
  return requestBody;
519
516
  }