@rango-dev/widget-embedded 0.14.1-next.15 → 0.14.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.
Files changed (36) hide show
  1. package/dist/components/BlockchainsSection/BlockchainsSection.d.ts.map +1 -1
  2. package/dist/constants/configs.d.ts +2 -0
  3. package/dist/constants/configs.d.ts.map +1 -0
  4. package/dist/hooks/usePrepareBlockchainList/index.d.ts +2 -0
  5. package/dist/hooks/usePrepareBlockchainList/index.d.ts.map +1 -0
  6. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts +2 -0
  7. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.d.ts.map +1 -0
  8. package/dist/hooks/{usePrepareBlockchainList.d.ts → usePrepareBlockchainList/usePrepareBlockchainList.d.ts} +1 -9
  9. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.d.ts.map +1 -0
  10. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +10 -0
  11. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts.map +1 -0
  12. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts +3 -0
  13. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.d.ts.map +1 -0
  14. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts +2 -0
  15. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.d.ts.map +1 -0
  16. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts +11 -0
  17. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.d.ts.map +1 -0
  18. package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +4 -4
  21. package/dist/store/settings.d.ts +5 -0
  22. package/dist/store/settings.d.ts.map +1 -1
  23. package/package.json +1 -1
  24. package/src/components/BlockchainsSection/BlockchainsSection.tsx +21 -6
  25. package/src/constants/configs.ts +1 -0
  26. package/src/hooks/usePrepareBlockchainList/index.ts +1 -0
  27. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.constants.ts +1 -0
  28. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.ts +108 -0
  29. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.mock.ts +3101 -0
  30. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.test.ts +273 -0
  31. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.ts +38 -0
  32. package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.types.ts +12 -0
  33. package/src/hooks/useSyncStoresWithConfig.ts +49 -1
  34. package/src/store/settings.ts +34 -1
  35. package/dist/hooks/usePrepareBlockchainList.d.ts.map +0 -1
  36. package/src/hooks/usePrepareBlockchainList.ts +0 -125
@@ -1,6 +1,8 @@
1
1
  import { type Language } from '@rango-dev/ui';
2
2
  export type ThemeMode = 'auto' | 'dark' | 'light';
3
3
  export interface SettingsState {
4
+ /** Keeping a history of blockchains that user has selected (in Swap process) */
5
+ preferredBlockchains: string[];
4
6
  slippage: number;
5
7
  customSlippage: number | null;
6
8
  infiniteApprove: boolean;
@@ -24,6 +26,7 @@ export interface SettingsState {
24
26
  setAffiliateWallets: (affiliateWallets: {
25
27
  [key: string]: string;
26
28
  } | null) => void;
29
+ addPreferredBlockchain: (blockchain: string) => void;
27
30
  }
28
31
  export declare const useSettingsStore: {
29
32
  (): SettingsState;
@@ -48,6 +51,7 @@ export declare const useSettingsStore: {
48
51
  };
49
52
  } & {
50
53
  use: {
54
+ preferredBlockchains: () => string[];
51
55
  slippage: () => number;
52
56
  customSlippage: () => number | null;
53
57
  infiniteApprove: () => boolean;
@@ -71,6 +75,7 @@ export declare const useSettingsStore: {
71
75
  setAffiliateWallets: () => (affiliateWallets: {
72
76
  [key: string]: string;
73
77
  } | null) => void;
78
+ addPreferredBlockchain: () => (blockchain: string) => void;
74
79
  };
75
80
  };
76
81
  //# sourceMappingURL=settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/store/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAW9C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACnD,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,iBAAiB,EAAE,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3D,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC1C,yBAAyB,EAAE,CAAC,WAAW,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D,eAAe,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,mBAAmB,EAAE,CAAC,g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4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,28 +11,31 @@ import {
11
11
  } from '@rango-dev/ui';
12
12
  import React from 'react';
13
13
 
14
+ import { BLOCKCHAIN_LIST_SIZE } from '../../constants/configs';
14
15
  import { usePrepareBlockchainList } from '../../hooks/usePrepareBlockchainList';
15
16
  import { useBestRouteStore } from '../../store/bestRoute';
16
17
  import { useMetaStore } from '../../store/meta';
17
18
 
18
19
  import { Container } from './BlockchainsSection.styles';
19
20
 
20
- const LIST_SIZE = 10;
21
- const MAX_ITEMS = LIST_SIZE + 1;
22
21
  const NUMBER_OF_LOADING = 12;
23
22
 
24
23
  export function BlockchainsSection(props: PropTypes) {
25
24
  const { blockchains, type, blockchain, onChange, onMoreClick } = props;
26
25
  const blockchainsList = usePrepareBlockchainList(blockchains, {
27
- limit: blockchains.length === MAX_ITEMS ? MAX_ITEMS : LIST_SIZE,
26
+ limit: BLOCKCHAIN_LIST_SIZE,
28
27
  selected: blockchain?.name,
29
28
  });
30
29
 
31
30
  const loadingStatus = useMetaStore.use.loadingStatus();
32
31
  const resetToBlockchain = useBestRouteStore.use.resetToBlockchain();
33
32
  const resetFromBlockchain = useBestRouteStore.use.resetFromBlockchain();
34
- const showMoreButton =
35
- blockchains.length !== MAX_ITEMS && blockchainsList.more.length;
33
+ const hasMoreItemsInList = blockchainsList.more.length > 0;
34
+ /**
35
+ * When only one item is left on list, we will not show the `More` button and will show the item itself instead.
36
+ */
37
+ const onlyOneItemInList = blockchainsList.more.length === 1;
38
+ const showMoreButton = !onlyOneItemInList && hasMoreItemsInList;
36
39
 
37
40
  return (
38
41
  <div>
@@ -70,8 +73,20 @@ export function BlockchainsSection(props: PropTypes) {
70
73
  </BlockchainsChip>
71
74
  ))}
72
75
 
76
+ {onlyOneItemInList ? (
77
+ <BlockchainsChip
78
+ key={blockchainsList.more[0].name}
79
+ selected={
80
+ !!blockchain &&
81
+ blockchain.name === blockchainsList.more[0].name
82
+ }
83
+ onClick={() => onChange(blockchainsList.more[0])}>
84
+ <Image src={blockchainsList.more[0].logo} size={30} />
85
+ </BlockchainsChip>
86
+ ) : null}
87
+
73
88
  {showMoreButton ? (
74
- <BlockchainsChip onClick={onMoreClick}>
89
+ <BlockchainsChip onClick={onMoreClick} key="more-blockchains">
75
90
  <Typography variant="body" size="xsmall" color="secondary500">
76
91
  {i18n._('More +{count}', {
77
92
  count: blockchainsList.more.length,
@@ -0,0 +1 @@
1
+ export const BLOCKCHAIN_LIST_SIZE = 10;
@@ -0,0 +1 @@
1
+ export { usePrepareBlockchainList } from './usePrepareBlockchainList';
@@ -0,0 +1 @@
1
+ export const MOST_USED_BLOCKChAINS = ['ETH', 'COSMOS', 'OSMOSIS'];
@@ -0,0 +1,108 @@
1
+ import type { PrepareListOptions } from './usePrepareBlockchainList.types';
2
+ import type { BlockchainMeta } from 'rango-sdk';
3
+
4
+ import { MOST_USED_BLOCKChAINS } from './usePrepareBlockchainList.constants';
5
+
6
+ export function prepare(
7
+ blockchains: BlockchainMeta[],
8
+ preferredBlockchains: string[],
9
+ options?: PrepareListOptions
10
+ ) {
11
+ /*
12
+ * TODO:
13
+ * We copying the `blockchains` which can causes performance penalties but we should because we are mutating the original object.
14
+ * A better way to solve the problem maybe is using new JS features like Use toSpliced() but
15
+ * we can not use it right now because we need to upgrade our toolings first.
16
+ */
17
+ const list: BlockchainMeta[] = JSON.parse(JSON.stringify(blockchains));
18
+ let more: BlockchainMeta[] = [];
19
+
20
+ list.sort(sortByMostUsedBlockchains);
21
+
22
+ // Checking `limit` has set and it should be more than of the list items.
23
+ if (!!options?.limit && blockchains.length > options.limit) {
24
+ const start = options.limit;
25
+ let preferredBlockchainsWithoutMainList = preferredBlockchains;
26
+
27
+ if (preferredBlockchains.length <= options.limit) {
28
+ /*
29
+ * For first X (limit) numbers, we need to remove them from preferred if exists.
30
+ */
31
+ for (let i = 0; i < options.limit; i++) {
32
+ const blockchain = list[i];
33
+ preferredBlockchainsWithoutMainList =
34
+ preferredBlockchainsWithoutMainList.filter((preferredBlockchain) => {
35
+ return blockchain.name !== preferredBlockchain;
36
+ });
37
+ }
38
+ }
39
+ list.sort(
40
+ generateSortByPreferredBlockchainsFor(preferredBlockchainsWithoutMainList)
41
+ );
42
+
43
+ /*
44
+ * Splice will modify the original list and returns the deleted items
45
+ * We use the deleted items as `more`
46
+ */
47
+ more = list.splice(start);
48
+ }
49
+ return {
50
+ list,
51
+ more,
52
+ };
53
+ }
54
+
55
+ /** There is a hardcoded list of blockchains that we want to show them first in the list. */
56
+ export function sortByMostUsedBlockchains(
57
+ a: BlockchainMeta,
58
+ b: BlockchainMeta
59
+ ) {
60
+ const mostUsed = MOST_USED_BLOCKChAINS;
61
+ const aIndexInMostUsed = mostUsed.findIndex((token) => token === a.name);
62
+ const bIndexInMostUsed = mostUsed.findIndex((token) => token === b.name);
63
+ const aIsMostUsed = aIndexInMostUsed > -1;
64
+ const bIsMostUsed = bIndexInMostUsed > -1;
65
+
66
+ if (aIsMostUsed && bIsMostUsed) {
67
+ return aIndexInMostUsed > bIndexInMostUsed ? 1 : -1;
68
+ }
69
+
70
+ if (aIsMostUsed) {
71
+ return -1;
72
+ }
73
+
74
+ if (bIsMostUsed) {
75
+ return 1;
76
+ }
77
+
78
+ return 0;
79
+ }
80
+
81
+ export function generateSortByPreferredBlockchainsFor(
82
+ preferredBlockchains: string[]
83
+ ) {
84
+ return function sortByPreferred(a: BlockchainMeta, b: BlockchainMeta) {
85
+ const aIndexInPreferred = preferredBlockchains.findIndex(
86
+ (blockchain) => blockchain === a.name
87
+ );
88
+ const bIndexInPreferred = preferredBlockchains.findIndex(
89
+ (blockchain) => blockchain === b.name
90
+ );
91
+
92
+ const aIsPreferred = aIndexInPreferred > -1;
93
+ const bIsPreferred = bIndexInPreferred > -1;
94
+
95
+ if (aIsPreferred && bIsPreferred) {
96
+ return aIndexInPreferred > bIndexInPreferred ? 1 : -1;
97
+ }
98
+
99
+ if (preferredBlockchains.includes(a.name)) {
100
+ return -1;
101
+ }
102
+ if (preferredBlockchains.includes(b.name)) {
103
+ return 1;
104
+ }
105
+
106
+ return 0;
107
+ };
108
+ }