@rango-dev/widget-embedded 0.17.1-next.15 → 0.17.1-next.17
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/QueueManager.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/containers/App/App.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts +1 -1
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.d.ts +2 -2
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.d.ts.map +1 -1
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +3 -5
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts.map +1 -1
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts.map +1 -1
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts +5 -1
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/types/config.d.ts +14 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +1 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/QueueManager.tsx +1 -0
- package/src/constants/index.ts +1 -0
- package/src/containers/App/App.tsx +1 -9
- package/src/containers/WidgetProvider/WidgetProvider.tsx +10 -1
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +4 -2
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.ts +1 -1
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.ts +37 -7
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.ts +60 -0
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.ts +78 -3
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.ts +13 -4
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.ts +6 -1
- package/src/hooks/useSwapInput.ts +5 -1
- package/src/services/httpService.ts +1 -1
- package/src/types/config.ts +15 -0
- package/src/utils/configs.ts +2 -1
package/dist/types/config.d.ts
CHANGED
|
@@ -85,12 +85,22 @@ export type BlockchainAndTokenConfig = {
|
|
|
85
85
|
blockchains?: string[];
|
|
86
86
|
tokens?: Asset[];
|
|
87
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* `ExperimentalFeatures`
|
|
90
|
+
*
|
|
91
|
+
* @property {boolean} routing
|
|
92
|
+
*- This property is optional and sets experimental in quote api.
|
|
93
|
+
*/
|
|
94
|
+
type ExperimentalFeatures = {
|
|
95
|
+
routing?: boolean;
|
|
96
|
+
};
|
|
88
97
|
/**
|
|
89
98
|
* The type WidgetConfig defines the configuration options for a widget, including API key, affiliate
|
|
90
99
|
* reference, amount, blockchain and token configurations, liquidity sources, wallet types, language,
|
|
91
100
|
* and theme.
|
|
92
101
|
*
|
|
93
102
|
* @property {string} apiKey - The API key used to communicate with Rango API
|
|
103
|
+
* @property {string} apiUrl - The API url used to set custom API url
|
|
94
104
|
* @property {WidgetAffiliate} affiliate - If you want to charge users fee per transaction, you should
|
|
95
105
|
* pass `WidgetAffiliate` including affiliateRef, affiliatePercent, and affiliateWallets.
|
|
96
106
|
* @property {number} amount - The default input amount.
|
|
@@ -123,9 +133,11 @@ export type BlockchainAndTokenConfig = {
|
|
|
123
133
|
* you could use to pin tokens of your choice to the top of the token list.
|
|
124
134
|
* @property {boolean} enableNewLiquiditySources - The `enableNewLiquiditySources` property is a boolean value that when you
|
|
125
135
|
* set it to true, whenever a new liquidity source is added, it will be added to your list as well.
|
|
136
|
+
* @property {ExperimentalFeatures} experimental - The `experimental` property is an optional object that specifies some experimental features.
|
|
126
137
|
*/
|
|
127
138
|
export type WidgetConfig = {
|
|
128
139
|
apiKey: string;
|
|
140
|
+
apiUrl?: string;
|
|
129
141
|
walletConnectProjectId?: string;
|
|
130
142
|
affiliate?: WidgetAffiliate;
|
|
131
143
|
amount?: number;
|
|
@@ -140,5 +152,7 @@ export type WidgetConfig = {
|
|
|
140
152
|
externalWallets?: boolean;
|
|
141
153
|
pinnedTokens?: Asset[];
|
|
142
154
|
enableNewLiquiditySources?: boolean;
|
|
155
|
+
experimental?: ExperimentalFeatures;
|
|
143
156
|
};
|
|
157
|
+
export {};
|
|
144
158
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,YAAY,CAAC;AAClD,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IA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AEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,wBAAwB,CAAC;IAChC,EAAE,CAAC,EAAE,wBAAwB,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,CAAC,UAAU,GAAG,iBAAiB,CAAC,EAAE,CAAC;IAC7C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;IACvB,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC,CAAC"}
|
package/dist/utils/configs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../src/utils/configs.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../src/utils/configs.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,OAAO,UAE5C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,OAAO,EAAE,KAAK,EAAE,GAAG,OAIxD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,OAAO,WAS9C;AAED,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,eAAO,MAAM,uBAAuB,iBAAiB,CAAC"}
|
package/package.json
CHANGED
package/src/QueueManager.tsx
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
2
2
|
|
|
3
3
|
import { I18nManager } from '@rango-dev/ui';
|
|
4
|
-
import React, { useContext, useEffect,
|
|
4
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
5
5
|
|
|
6
6
|
import { AppRouter } from '../../components/AppRouter';
|
|
7
7
|
import { AppRoutes } from '../../components/AppRoutes';
|
|
@@ -12,7 +12,6 @@ import { useTheme } from '../../hooks/useTheme';
|
|
|
12
12
|
import { useAppStore } from '../../store/AppStore';
|
|
13
13
|
import { useNotificationStore } from '../../store/notification';
|
|
14
14
|
import { useSettingsStore } from '../../store/settings';
|
|
15
|
-
import { initConfig } from '../../utils/configs';
|
|
16
15
|
import { WidgetContext } from '../Wallets';
|
|
17
16
|
|
|
18
17
|
import { MainContainer } from './App.styles';
|
|
@@ -28,13 +27,6 @@ export function Main() {
|
|
|
28
27
|
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
29
28
|
const widgetContext = useContext(WidgetContext);
|
|
30
29
|
|
|
31
|
-
useMemo(() => {
|
|
32
|
-
if (config?.apiKey) {
|
|
33
|
-
initConfig({
|
|
34
|
-
API_KEY: config?.apiKey,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}, [config]);
|
|
38
30
|
useEffect(() => {
|
|
39
31
|
void fetchMeta().catch();
|
|
40
32
|
void useSettingsStore.persist.rehydrate();
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import type { PropTypes } from './WidgetProvider.types';
|
|
2
2
|
import type { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
|
-
import React from 'react';
|
|
4
|
+
import React, { useMemo } from 'react';
|
|
5
5
|
|
|
6
|
+
import { DEFAULT_BASE_URL, RANGO_PUBLIC_API_KEY } from '../../constants';
|
|
6
7
|
import QueueManager from '../../QueueManager';
|
|
8
|
+
import { initConfig } from '../../utils/configs';
|
|
7
9
|
import { WidgetWallets } from '../Wallets';
|
|
8
10
|
import { WidgetInfo } from '../WidgetInfo';
|
|
9
11
|
|
|
10
12
|
export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
|
|
11
13
|
const { onUpdateState, config } = props;
|
|
14
|
+
|
|
15
|
+
useMemo(() => {
|
|
16
|
+
initConfig({
|
|
17
|
+
API_KEY: config?.apiKey || RANGO_PUBLIC_API_KEY,
|
|
18
|
+
BASE_URL: config?.apiUrl || DEFAULT_BASE_URL,
|
|
19
|
+
});
|
|
20
|
+
}, [config]);
|
|
12
21
|
return (
|
|
13
22
|
<WidgetWallets config={config} onUpdateState={onUpdateState}>
|
|
14
23
|
<QueueManager apiKey={config.apiKey}>
|
|
@@ -42,7 +42,7 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
42
42
|
const { connectedWallets } = useWalletsStore();
|
|
43
43
|
const blockchains = useAppStore().blockchains();
|
|
44
44
|
const tokens = useAppStore().tokens();
|
|
45
|
-
|
|
45
|
+
const { experimental } = useAppStore().config;
|
|
46
46
|
const userSlippage = customSlippage || slippage;
|
|
47
47
|
|
|
48
48
|
const { fetch: fetchQuote, cancelFetch, loading } = useFetchQuote();
|
|
@@ -77,7 +77,9 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
77
77
|
initialQuote: initialQuote,
|
|
78
78
|
destination: customDestination,
|
|
79
79
|
});
|
|
80
|
-
|
|
80
|
+
if (experimental?.routing) {
|
|
81
|
+
requestBody.experimental = true;
|
|
82
|
+
}
|
|
81
83
|
let currentQuote: BestRouteResponse;
|
|
82
84
|
try {
|
|
83
85
|
currentQuote = await fetchQuote(requestBody).then((response) =>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const MOST_USED_BLOCKCHAINS = ['ETH', 'COSMOS', 'OSMOSIS'];
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
PrepareListOptions,
|
|
3
|
+
PrepareOutput,
|
|
4
|
+
} from './usePrepareBlockchainList.types';
|
|
2
5
|
import type { BlockchainMeta } from 'rango-sdk';
|
|
3
6
|
|
|
4
|
-
import {
|
|
7
|
+
import { MOST_USED_BLOCKCHAINS } from './usePrepareBlockchainList.constants';
|
|
5
8
|
|
|
6
9
|
export function prepare(
|
|
7
10
|
blockchains: BlockchainMeta[],
|
|
8
11
|
preferredBlockchains: string[],
|
|
9
12
|
options?: PrepareListOptions
|
|
10
|
-
) {
|
|
13
|
+
): PrepareOutput {
|
|
11
14
|
/*
|
|
12
15
|
* TODO:
|
|
13
16
|
* We copying the `blockchains` which can causes performance penalties but we should because we are mutating the original object.
|
|
@@ -25,17 +28,37 @@ export function prepare(
|
|
|
25
28
|
let preferredBlockchainsWithoutMainList = preferredBlockchains;
|
|
26
29
|
|
|
27
30
|
if (preferredBlockchains.length <= options.limit) {
|
|
28
|
-
|
|
29
|
-
*
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* if we want to show 10 items (aka `options.limit`)
|
|
34
|
+
* and have these items as our preferred list: [x,y,z]
|
|
35
|
+
* and these as our main list: [A, B, C, D, E, F, G, H, I, J]
|
|
36
|
+
* the final list will be like this: [...preferred, ...mainList].
|
|
37
|
+
*
|
|
38
|
+
* Since we have a limit (e.g. 10) on our list (preferred + mainList),
|
|
39
|
+
* we only should check those items from main list that will be in final list.
|
|
40
|
+
*
|
|
41
|
+
* finalListWithoutLimit = [x,y,z, A, B, C, D, E, F, G, H, I, J]
|
|
42
|
+
* finalListWithLimit = [x,y,z, A, B, C, D, E, F, G]
|
|
43
|
+
*
|
|
44
|
+
* As you can see, [H, I, J] will not be in our list.
|
|
45
|
+
*
|
|
46
|
+
* The following code only check preffred blockchain
|
|
47
|
+
* shouldn't be in first 7 of 10 items in main list. (Since, the last 3 items will not be in the final list and we should check those.)
|
|
30
48
|
*/
|
|
31
|
-
|
|
49
|
+
const howManyItemsShouldBeCheckedFromMainList =
|
|
50
|
+
options.limit - preferredBlockchains.length;
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i <= howManyItemsShouldBeCheckedFromMainList; i++) {
|
|
32
53
|
const blockchain = list[i];
|
|
54
|
+
|
|
33
55
|
preferredBlockchainsWithoutMainList =
|
|
34
56
|
preferredBlockchainsWithoutMainList.filter((preferredBlockchain) => {
|
|
35
57
|
return blockchain.name !== preferredBlockchain;
|
|
36
58
|
});
|
|
37
59
|
}
|
|
38
60
|
}
|
|
61
|
+
|
|
39
62
|
list.sort(
|
|
40
63
|
generateSortByPreferredBlockchainsFor(preferredBlockchainsWithoutMainList)
|
|
41
64
|
);
|
|
@@ -57,7 +80,7 @@ export function sortByMostUsedBlockchains(
|
|
|
57
80
|
a: BlockchainMeta,
|
|
58
81
|
b: BlockchainMeta
|
|
59
82
|
) {
|
|
60
|
-
const mostUsed =
|
|
83
|
+
const mostUsed = MOST_USED_BLOCKCHAINS;
|
|
61
84
|
const aIndexInMostUsed = mostUsed.findIndex((token) => token === a.name);
|
|
62
85
|
const bIndexInMostUsed = mostUsed.findIndex((token) => token === b.name);
|
|
63
86
|
const aIsMostUsed = aIndexInMostUsed > -1;
|
|
@@ -106,3 +129,10 @@ export function generateSortByPreferredBlockchainsFor(
|
|
|
106
129
|
return 0;
|
|
107
130
|
};
|
|
108
131
|
}
|
|
132
|
+
|
|
133
|
+
export function isInVisibleList(
|
|
134
|
+
blockchain: string,
|
|
135
|
+
prepareOutput: PrepareOutput
|
|
136
|
+
): boolean {
|
|
137
|
+
return !!prepareOutput.list.find((item) => item.name === blockchain);
|
|
138
|
+
}
|
|
@@ -2,6 +2,66 @@ import type { BlockchainMeta } from 'rango-sdk';
|
|
|
2
2
|
|
|
3
3
|
import { TransactionType } from 'rango-sdk';
|
|
4
4
|
|
|
5
|
+
export const sampleDefaultBlockchainNames = [
|
|
6
|
+
'ETH',
|
|
7
|
+
'COSMOS',
|
|
8
|
+
'OSMOSIS',
|
|
9
|
+
'BSC',
|
|
10
|
+
'ARBITRUM',
|
|
11
|
+
'POLYGON',
|
|
12
|
+
'ZKSYNC',
|
|
13
|
+
'STARKNET',
|
|
14
|
+
'OPTIMISM',
|
|
15
|
+
'AVAX_CCHAIN',
|
|
16
|
+
'POLYGONZK',
|
|
17
|
+
'LINEA',
|
|
18
|
+
'TRON',
|
|
19
|
+
'BTC',
|
|
20
|
+
'NEUTRON',
|
|
21
|
+
'NOBLE',
|
|
22
|
+
'SOLANA',
|
|
23
|
+
'CRONOS',
|
|
24
|
+
'BNB',
|
|
25
|
+
'AURORA',
|
|
26
|
+
'MAYA',
|
|
27
|
+
'THOR',
|
|
28
|
+
'BOBA',
|
|
29
|
+
'MOONBEAM',
|
|
30
|
+
'MOONRIVER',
|
|
31
|
+
'OKC',
|
|
32
|
+
'BOBA_AVALANCHE',
|
|
33
|
+
'LTC',
|
|
34
|
+
'BCH',
|
|
35
|
+
'HECO',
|
|
36
|
+
'STARGAZE',
|
|
37
|
+
'CRYPTO_ORG',
|
|
38
|
+
'CHIHUAHUA',
|
|
39
|
+
'BANDCHAIN',
|
|
40
|
+
'COMDEX',
|
|
41
|
+
'REGEN',
|
|
42
|
+
'IRIS',
|
|
43
|
+
'EMONEY',
|
|
44
|
+
'JUNO',
|
|
45
|
+
'STRIDE',
|
|
46
|
+
'MARS',
|
|
47
|
+
'TERRA',
|
|
48
|
+
'BITSONG',
|
|
49
|
+
'AKASH',
|
|
50
|
+
'KI',
|
|
51
|
+
'PERSISTENCE',
|
|
52
|
+
'MEDIBLOC',
|
|
53
|
+
'KUJIRA',
|
|
54
|
+
'SENTINEL',
|
|
55
|
+
'INJECTIVE',
|
|
56
|
+
'SECRET',
|
|
57
|
+
'KONSTELLATION',
|
|
58
|
+
'STARNAME',
|
|
59
|
+
'BITCANNA',
|
|
60
|
+
'UMEE',
|
|
61
|
+
'DESMOS',
|
|
62
|
+
'LUMNETWORK',
|
|
63
|
+
];
|
|
64
|
+
|
|
5
65
|
export const sampleBlockchains: BlockchainMeta[] = [
|
|
6
66
|
{
|
|
7
67
|
name: 'ETH',
|
|
@@ -2,7 +2,7 @@ import type { BlockchainMeta } from 'rango-sdk';
|
|
|
2
2
|
|
|
3
3
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { MOST_USED_BLOCKCHAINS } from './usePrepareBlockchainList.constants';
|
|
6
6
|
import {
|
|
7
7
|
generateSortByPreferredBlockchainsFor,
|
|
8
8
|
prepare,
|
|
@@ -20,8 +20,8 @@ describe('usePrepareBlockchainList', () => {
|
|
|
20
20
|
it('should sort blockchains by most used ones.', () => {
|
|
21
21
|
const sortedBlockchainsList = sample.sort(sortByMostUsedBlockchains);
|
|
22
22
|
|
|
23
|
-
const mostUsedCount =
|
|
24
|
-
const expected =
|
|
23
|
+
const mostUsedCount = MOST_USED_BLOCKCHAINS.length;
|
|
24
|
+
const expected = MOST_USED_BLOCKCHAINS;
|
|
25
25
|
const received = sortedBlockchainsList
|
|
26
26
|
.map((blockchain) => blockchain.name)
|
|
27
27
|
.slice(0, mostUsedCount);
|
|
@@ -270,4 +270,79 @@ describe('usePrepareBlockchainList', () => {
|
|
|
270
270
|
...received.more.map((blockchain) => blockchain.name),
|
|
271
271
|
]);
|
|
272
272
|
});
|
|
273
|
+
|
|
274
|
+
it.only('Last item of the main list should be moved to front if it selected again.', () => {
|
|
275
|
+
const listLimit = 10;
|
|
276
|
+
const preferredBlockchains = ['AVAX_CCHAIN', 'BTC'];
|
|
277
|
+
const expected = [
|
|
278
|
+
'AVAX_CCHAIN',
|
|
279
|
+
'BTC',
|
|
280
|
+
'ETH',
|
|
281
|
+
'COSMOS',
|
|
282
|
+
'OSMOSIS',
|
|
283
|
+
'BSC',
|
|
284
|
+
'ARBITRUM',
|
|
285
|
+
'POLYGON',
|
|
286
|
+
'ZKSYNC',
|
|
287
|
+
'STARKNET',
|
|
288
|
+
'OPTIMISM',
|
|
289
|
+
'POLYGONZK',
|
|
290
|
+
'LINEA',
|
|
291
|
+
'TRON',
|
|
292
|
+
'NEUTRON',
|
|
293
|
+
'NOBLE',
|
|
294
|
+
'SOLANA',
|
|
295
|
+
'CRONOS',
|
|
296
|
+
'BNB',
|
|
297
|
+
'AURORA',
|
|
298
|
+
'MAYA',
|
|
299
|
+
'THOR',
|
|
300
|
+
'BOBA',
|
|
301
|
+
'MOONBEAM',
|
|
302
|
+
'MOONRIVER',
|
|
303
|
+
'OKC',
|
|
304
|
+
'BOBA_AVALANCHE',
|
|
305
|
+
'LTC',
|
|
306
|
+
'BCH',
|
|
307
|
+
'HECO',
|
|
308
|
+
'STARGAZE',
|
|
309
|
+
'CRYPTO_ORG',
|
|
310
|
+
'CHIHUAHUA',
|
|
311
|
+
'BANDCHAIN',
|
|
312
|
+
'COMDEX',
|
|
313
|
+
'REGEN',
|
|
314
|
+
'IRIS',
|
|
315
|
+
'EMONEY',
|
|
316
|
+
'JUNO',
|
|
317
|
+
'STRIDE',
|
|
318
|
+
'MARS',
|
|
319
|
+
'TERRA',
|
|
320
|
+
'BITSONG',
|
|
321
|
+
'AKASH',
|
|
322
|
+
'KI',
|
|
323
|
+
'PERSISTENCE',
|
|
324
|
+
'MEDIBLOC',
|
|
325
|
+
'KUJIRA',
|
|
326
|
+
'SENTINEL',
|
|
327
|
+
'INJECTIVE',
|
|
328
|
+
'SECRET',
|
|
329
|
+
'KONSTELLATION',
|
|
330
|
+
'STARNAME',
|
|
331
|
+
'BITCANNA',
|
|
332
|
+
'UMEE',
|
|
333
|
+
'DESMOS',
|
|
334
|
+
'LUMNETWORK',
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
const output = prepare(sample, preferredBlockchains, {
|
|
338
|
+
limit: listLimit,
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const received = [
|
|
342
|
+
...output.list.map((blockchain) => blockchain.name),
|
|
343
|
+
...output.more.map((blockchain) => blockchain.name),
|
|
344
|
+
];
|
|
345
|
+
|
|
346
|
+
expect(expected).toEqual(received);
|
|
347
|
+
});
|
|
273
348
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
PrepareListOptions,
|
|
3
|
-
|
|
3
|
+
UsePrepareList,
|
|
4
4
|
} from './usePrepareBlockchainList.types';
|
|
5
5
|
import type { BlockchainMeta } from 'rango-sdk';
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ import { useEffect } from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { useSettingsStore } from '../../store/settings';
|
|
10
10
|
|
|
11
|
-
import { prepare } from './usePrepareBlockchainList.helpers';
|
|
11
|
+
import { isInVisibleList, prepare } from './usePrepareBlockchainList.helpers';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
@@ -19,12 +19,21 @@ import { prepare } from './usePrepareBlockchainList.helpers';
|
|
|
19
19
|
export function usePrepareBlockchainList(
|
|
20
20
|
blockchains: BlockchainMeta[],
|
|
21
21
|
options?: PrepareListOptions
|
|
22
|
-
):
|
|
22
|
+
): UsePrepareList {
|
|
23
23
|
const { preferredBlockchains, addPreferredBlockchain } = useSettingsStore();
|
|
24
24
|
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
if (options?.selected) {
|
|
27
|
-
|
|
27
|
+
const output = prepare(blockchains, preferredBlockchains, options);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* We only add a new blockchain to preferred when it's not in the main list
|
|
31
|
+
* In this way we can guarantee we will be able to regenerate the same list always.
|
|
32
|
+
* And also it helps us to avoid jumping for the last item of the main list (e.g. tenth item of our list).
|
|
33
|
+
*/
|
|
34
|
+
if (!isInVisibleList(options.selected, output)) {
|
|
35
|
+
addPreferredBlockchain(options?.selected);
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
}, [options?.selected]);
|
|
30
39
|
|
|
@@ -5,8 +5,13 @@ export interface PrepareListOptions {
|
|
|
5
5
|
selected?: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export interface
|
|
8
|
+
export interface PrepareOutput {
|
|
9
9
|
list: BlockchainMeta[];
|
|
10
10
|
more: BlockchainMeta[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UsePrepareList {
|
|
14
|
+
list: PrepareOutput['list'];
|
|
15
|
+
more: PrepareOutput['more'];
|
|
11
16
|
history: string[];
|
|
12
17
|
}
|
|
@@ -33,7 +33,8 @@ type UseSwapInput = {
|
|
|
33
33
|
*/
|
|
34
34
|
export function useSwapInput(): UseSwapInput {
|
|
35
35
|
const { fetch: fetchQuote, cancelFetch } = useFetchQuote();
|
|
36
|
-
const { liquiditySources, enableNewLiquiditySources } =
|
|
36
|
+
const { liquiditySources, enableNewLiquiditySources, experimental } =
|
|
37
|
+
useAppStore().config;
|
|
37
38
|
const tokens = useAppStore().tokens();
|
|
38
39
|
const {
|
|
39
40
|
fromToken,
|
|
@@ -86,6 +87,9 @@ export function useSwapInput(): UseSwapInput {
|
|
|
86
87
|
affiliatePercent,
|
|
87
88
|
affiliateWallets,
|
|
88
89
|
});
|
|
90
|
+
if (experimental?.routing) {
|
|
91
|
+
requestBody.experimental = true;
|
|
92
|
+
}
|
|
89
93
|
fetchQuote(requestBody)
|
|
90
94
|
.then((res) => {
|
|
91
95
|
setLoading(false);
|
package/src/types/config.ts
CHANGED
|
@@ -85,12 +85,23 @@ export type BlockchainAndTokenConfig = {
|
|
|
85
85
|
tokens?: Asset[];
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* `ExperimentalFeatures`
|
|
90
|
+
*
|
|
91
|
+
* @property {boolean} routing
|
|
92
|
+
*- This property is optional and sets experimental in quote api.
|
|
93
|
+
*/
|
|
94
|
+
type ExperimentalFeatures = {
|
|
95
|
+
routing?: boolean;
|
|
96
|
+
};
|
|
97
|
+
|
|
88
98
|
/**
|
|
89
99
|
* The type WidgetConfig defines the configuration options for a widget, including API key, affiliate
|
|
90
100
|
* reference, amount, blockchain and token configurations, liquidity sources, wallet types, language,
|
|
91
101
|
* and theme.
|
|
92
102
|
*
|
|
93
103
|
* @property {string} apiKey - The API key used to communicate with Rango API
|
|
104
|
+
* @property {string} apiUrl - The API url used to set custom API url
|
|
94
105
|
* @property {WidgetAffiliate} affiliate - If you want to charge users fee per transaction, you should
|
|
95
106
|
* pass `WidgetAffiliate` including affiliateRef, affiliatePercent, and affiliateWallets.
|
|
96
107
|
* @property {number} amount - The default input amount.
|
|
@@ -123,9 +134,12 @@ export type BlockchainAndTokenConfig = {
|
|
|
123
134
|
* you could use to pin tokens of your choice to the top of the token list.
|
|
124
135
|
* @property {boolean} enableNewLiquiditySources - The `enableNewLiquiditySources` property is a boolean value that when you
|
|
125
136
|
* set it to true, whenever a new liquidity source is added, it will be added to your list as well.
|
|
137
|
+
* @property {ExperimentalFeatures} experimental - The `experimental` property is an optional object that specifies some experimental features.
|
|
126
138
|
*/
|
|
139
|
+
|
|
127
140
|
export type WidgetConfig = {
|
|
128
141
|
apiKey: string;
|
|
142
|
+
apiUrl?: string;
|
|
129
143
|
walletConnectProjectId?: string;
|
|
130
144
|
affiliate?: WidgetAffiliate;
|
|
131
145
|
amount?: number;
|
|
@@ -140,4 +154,5 @@ export type WidgetConfig = {
|
|
|
140
154
|
externalWallets?: boolean;
|
|
141
155
|
pinnedTokens?: Asset[];
|
|
142
156
|
enableNewLiquiditySources?: boolean;
|
|
157
|
+
experimental?: ExperimentalFeatures;
|
|
143
158
|
};
|
package/src/utils/configs.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { RANGO_PUBLIC_API_KEY } from '../constants';
|
|
|
2
2
|
|
|
3
3
|
export interface Configs {
|
|
4
4
|
API_KEY: string;
|
|
5
|
+
BASE_URL?: string;
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
let configs: Configs = {
|
|
@@ -9,7 +10,7 @@ let configs: Configs = {
|
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
export function getConfig(name: keyof Configs) {
|
|
12
|
-
return configs[name];
|
|
13
|
+
return configs[name] || '';
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export function setConfig(name: keyof Configs, value: any) {
|