@rango-dev/widget-embedded 0.17.1-next.14 → 0.17.1-next.16
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/containers/App/App.d.ts.map +1 -1
- package/dist/hooks/useLanguage.d.ts +1 -1
- package/dist/hooks/useLanguage.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/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
- package/src/containers/App/App.tsx +1 -3
- package/src/hooks/useLanguage.ts +2 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.17.1-next.
|
|
3
|
+
"version": "0.17.1-next.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@rango-dev/queue-manager-core": "^0.22.1-next.0",
|
|
24
24
|
"@rango-dev/queue-manager-rango-preset": "^0.22.1-next.5",
|
|
25
25
|
"@rango-dev/queue-manager-react": "^0.22.1-next.0",
|
|
26
|
-
"@rango-dev/ui": "^0.22.1-next.
|
|
26
|
+
"@rango-dev/ui": "^0.22.1-next.8",
|
|
27
27
|
"@rango-dev/wallets-react": "^0.8.1-next.3",
|
|
28
28
|
"@rango-dev/wallets-shared": "^0.21.1-next.3",
|
|
29
29
|
"bignumber.js": "^9.1.1",
|
|
@@ -42,9 +42,7 @@ export function Main() {
|
|
|
42
42
|
widgetContext.onConnectWallet(setLastConnectedWalletWithNetwork);
|
|
43
43
|
}, []);
|
|
44
44
|
useEffect(() => {
|
|
45
|
-
|
|
46
|
-
changeLanguage(config.language);
|
|
47
|
-
}
|
|
45
|
+
changeLanguage(config?.language);
|
|
48
46
|
}, [config?.language]);
|
|
49
47
|
|
|
50
48
|
return (
|
package/src/hooks/useLanguage.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface UseLanguage {
|
|
|
9
9
|
languages: LanguageItem[];
|
|
10
10
|
defaultLanguage: Language;
|
|
11
11
|
activeLanguage: Language;
|
|
12
|
-
changeLanguage: (language
|
|
12
|
+
changeLanguage: (language?: Language) => void;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function useLanguage(): UseLanguage {
|
|
@@ -22,6 +22,6 @@ export function useLanguage(): UseLanguage {
|
|
|
22
22
|
activeLanguage: language,
|
|
23
23
|
languages,
|
|
24
24
|
defaultLanguage,
|
|
25
|
-
changeLanguage: setLanguage,
|
|
25
|
+
changeLanguage: (language) => setLanguage(language || DEFAULT_LANGUAGE),
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -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
|
}
|