@rango-dev/widget-embedded 0.17.1-next.4 → 0.17.1-next.5

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 (104) hide show
  1. package/dist/QueueManager.d.ts +2 -1
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/Wallets.d.ts +1 -0
  4. package/dist/Wallets.d.ts.map +1 -1
  5. package/dist/Widget.d.ts +1 -1
  6. package/dist/Widget.d.ts.map +1 -1
  7. package/dist/components/AppRouter.d.ts +0 -2
  8. package/dist/components/AppRouter.d.ts.map +1 -1
  9. package/dist/components/AppRoutes.d.ts +1 -6
  10. package/dist/components/AppRoutes.d.ts.map +1 -1
  11. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -1
  12. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  13. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +0 -2
  14. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
  15. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  16. package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts +1 -4
  17. package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts.map +1 -1
  18. package/dist/components/NoResult/NoResult.d.ts.map +1 -1
  19. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  20. package/dist/components/Quote/Quote.d.ts.map +1 -1
  21. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  22. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  23. package/dist/components/UpdateUrl.d.ts +1 -6
  24. package/dist/components/UpdateUrl.d.ts.map +1 -1
  25. package/dist/components/WidgetEvents.d.ts.map +1 -1
  26. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  27. package/dist/hooks/useSyncStoresWithConfig.d.ts +1 -2
  28. package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
  29. package/dist/hooks/useWalletList.d.ts.map +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/index.js.map +4 -4
  32. package/dist/pages/ConfirmSwapPage.d.ts +1 -6
  33. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  34. package/dist/pages/LiquiditySourcePage.d.ts +1 -2
  35. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  36. package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
  37. package/dist/pages/SettingsPage.d.ts +1 -6
  38. package/dist/pages/SettingsPage.d.ts.map +1 -1
  39. package/dist/pages/WalletsPage.d.ts +1 -8
  40. package/dist/pages/WalletsPage.d.ts.map +1 -1
  41. package/dist/store/AppStore.d.ts +59 -0
  42. package/dist/store/AppStore.d.ts.map +1 -0
  43. package/dist/store/app.d.ts +12 -6
  44. package/dist/store/app.d.ts.map +1 -1
  45. package/dist/store/quote.d.ts +14 -7
  46. package/dist/store/quote.d.ts.map +1 -1
  47. package/dist/store/settings.d.ts +3 -2
  48. package/dist/store/settings.d.ts.map +1 -1
  49. package/dist/store/slices/config.d.ts +3 -2
  50. package/dist/store/slices/config.d.ts.map +1 -1
  51. package/dist/store/slices/data.d.ts +3 -0
  52. package/dist/store/slices/data.d.ts.map +1 -1
  53. package/dist/store/wallets.d.ts +5 -4
  54. package/dist/store/wallets.d.ts.map +1 -1
  55. package/dist/types/config.d.ts +5 -5
  56. package/dist/types/config.d.ts.map +1 -1
  57. package/dist/utils/settings.d.ts +3 -2
  58. package/dist/utils/settings.d.ts.map +1 -1
  59. package/dist/utils/swap.d.ts +4 -3
  60. package/dist/utils/swap.d.ts.map +1 -1
  61. package/package.json +3 -3
  62. package/src/QueueManager.tsx +14 -14
  63. package/src/Wallets.tsx +30 -5
  64. package/src/Widget.tsx +11 -25
  65. package/src/components/AppRouter.tsx +3 -5
  66. package/src/components/AppRoutes.tsx +6 -39
  67. package/src/components/BlockchainList/BlockchainList.tsx +4 -4
  68. package/src/components/BlockchainsSection/BlockchainsSection.tsx +4 -4
  69. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -14
  70. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +0 -2
  71. package/src/components/ConfirmWalletsModal/WalletList.tsx +6 -5
  72. package/src/components/ConfirmWalletsModal/WalletList.type.ts +1 -4
  73. package/src/components/NoResult/NoResult.tsx +4 -1
  74. package/src/components/NotificationContent/NotificationContent.tsx +3 -2
  75. package/src/components/Quote/Quote.tsx +2 -4
  76. package/src/components/SwapDetails/SwapDetails.tsx +5 -6
  77. package/src/components/TokenList/TokenList.tsx +6 -7
  78. package/src/components/UpdateUrl.tsx +20 -14
  79. package/src/components/WidgetEvents.tsx +7 -4
  80. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +5 -5
  81. package/src/hooks/useSwapInput.ts +6 -4
  82. package/src/hooks/useSyncStoresWithConfig.ts +20 -17
  83. package/src/hooks/useWalletList.ts +3 -5
  84. package/src/pages/ConfirmSwapPage.tsx +1 -9
  85. package/src/pages/Home.tsx +7 -7
  86. package/src/pages/LiquiditySourcePage.tsx +22 -31
  87. package/src/pages/SelectBlockchainPage.tsx +4 -5
  88. package/src/pages/SelectSwapItemsPage.tsx +5 -5
  89. package/src/pages/SettingsPage.tsx +8 -12
  90. package/src/pages/SwapDetailsPage.tsx +3 -3
  91. package/src/pages/WalletsPage.tsx +4 -11
  92. package/src/store/AppStore.tsx +35 -0
  93. package/src/store/app.ts +20 -5
  94. package/src/store/quote.ts +26 -22
  95. package/src/store/settings.ts +7 -4
  96. package/src/store/slices/config.ts +25 -15
  97. package/src/store/slices/data.ts +64 -29
  98. package/src/store/wallets.ts +11 -8
  99. package/src/types/config.ts +5 -5
  100. package/src/utils/settings.ts +8 -7
  101. package/src/utils/swap.ts +14 -16
  102. package/dist/store/meta.d.ts +0 -23
  103. package/dist/store/meta.d.ts.map +0 -1
  104. package/src/store/meta.ts +0 -39
@@ -1,4 +1,3 @@
1
- import type { WidgetConfig } from '../types';
2
1
  import type { WalletType } from '@rango-dev/wallets-shared';
3
2
 
4
3
  import { i18n } from '@lingui/core';
@@ -10,15 +9,9 @@ import { WalletModal } from '../components/WalletModal';
10
9
  import { navigationRoutes } from '../constants/navigationRoutes';
11
10
  import { useNavigateBack } from '../hooks/useNavigateBack';
12
11
  import { useWalletList } from '../hooks/useWalletList';
13
- import { useMetaStore } from '../store/meta';
12
+ import { useAppStore } from '../store/AppStore';
14
13
  import { getContainer } from '../utils/common';
15
14
 
16
- interface PropTypes {
17
- supportedWallets: WidgetConfig['wallets'];
18
- multiWallets: boolean;
19
- config?: WidgetConfig;
20
- }
21
-
22
15
  const ListContainer = styled('div', {
23
16
  display: 'grid',
24
17
  gap: '$10',
@@ -35,7 +28,8 @@ const Container = styled('div', {
35
28
  export const TIME_TO_CLOSE_MODAL = 3_000;
36
29
  export const TIME_TO_IGNORE_MODAL = 300;
37
30
 
38
- export function WalletsPage({ config }: PropTypes) {
31
+ export function WalletsPage() {
32
+ const { config, fetchStatus: fetchMetaStatus } = useAppStore()();
39
33
  const { navigateBackFrom } = useNavigateBack();
40
34
  const [openModal, setOpenModal] = useState(false);
41
35
  const [selectedWalletType, setSelectedWalletType] = useState<WalletType>('');
@@ -59,7 +53,6 @@ export function WalletsPage({ config }: PropTypes) {
59
53
  },
60
54
  });
61
55
 
62
- const loadingMetaStatus = useMetaStore.use.loadingStatus();
63
56
  const selectedWallet = list.find(
64
57
  (wallet) => wallet.type === selectedWalletType
65
58
  );
@@ -88,7 +81,7 @@ export function WalletsPage({ config }: PropTypes) {
88
81
  onClick={(type) => {
89
82
  void handleClick(type);
90
83
  }}
91
- isLoading={loadingMetaStatus === 'loading'}
84
+ isLoading={fetchMetaStatus === 'loading'}
92
85
  />
93
86
  </Fragment>
94
87
  );
@@ -0,0 +1,35 @@
1
+ import type { WidgetConfig } from '../types';
2
+ import type { PropsWithChildren } from 'react';
3
+
4
+ import React, { createContext, useContext, useRef } from 'react';
5
+
6
+ import { createAppStore } from './app';
7
+
8
+ type AppStore = ReturnType<typeof createAppStore>;
9
+ type AppStoreProviderProps = PropsWithChildren<{ config?: WidgetConfig }>;
10
+
11
+ export const AppStoreContext = createContext<AppStore | null>(null);
12
+
13
+ export function useAppStore() {
14
+ const store = useContext(AppStoreContext);
15
+
16
+ if (!store) {
17
+ throw new Error('Missing AppStoreContext.Provider in the tree');
18
+ }
19
+
20
+ return store;
21
+ }
22
+
23
+ export function AppStoreProvider(props: AppStoreProviderProps) {
24
+ const appStoreRef = useRef<AppStore>();
25
+
26
+ if (!appStoreRef.current) {
27
+ appStoreRef.current = createAppStore(props.config);
28
+ }
29
+
30
+ return (
31
+ <AppStoreContext.Provider value={appStoreRef.current}>
32
+ {props.children}
33
+ </AppStoreContext.Provider>
34
+ );
35
+ }
package/src/store/app.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { ConfigSlice } from './slices/config';
2
2
  import type { DataSlice } from './slices/data';
3
+ import type { WidgetConfig } from '../types';
4
+ import type { StateCreator } from 'zustand';
3
5
 
4
6
  import { create } from 'zustand';
5
7
 
@@ -7,9 +9,22 @@ import createSelectors from './selectors';
7
9
  import { createConfigSlice } from './slices/config';
8
10
  import { createDataSlice } from './slices/data';
9
11
 
10
- const store = create<DataSlice & ConfigSlice>()((...a) => ({
11
- ...createDataSlice(...a),
12
- ...createConfigSlice(...a),
13
- }));
12
+ export type StateCreatorWithInitialData<
13
+ T extends Partial<WidgetConfig>,
14
+ R extends Record<string, unknown>,
15
+ V extends Record<string, unknown>
16
+ > = (
17
+ initialData: T | undefined,
18
+ ...rest: Parameters<StateCreator<R, [], [], V>>
19
+ ) => ReturnType<StateCreator<R, [], [], V>>;
14
20
 
15
- export const useAppStore = createSelectors(store);
21
+ export type AppStoreState = DataSlice & ConfigSlice;
22
+
23
+ export function createAppStore(initialData?: WidgetConfig) {
24
+ return createSelectors(
25
+ create<AppStoreState>()((...a) => ({
26
+ ...createDataSlice(...a),
27
+ ...createConfigSlice(initialData, ...a),
28
+ }))
29
+ );
30
+ }
@@ -1,7 +1,12 @@
1
1
  import type { TokenWithBalance } from '../components/TokenList';
2
2
  import type { Wallet } from '../types';
3
3
  import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset/dist/shared';
4
- import type { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
4
+ import type {
5
+ BestRouteResponse,
6
+ BlockchainMeta,
7
+ MetaResponse,
8
+ Token,
9
+ } from 'rango-sdk';
5
10
 
6
11
  import BigNumber from 'bignumber.js';
7
12
  import { create } from 'zustand';
@@ -12,7 +17,6 @@ import { isPositiveNumber } from '../utils/numbers';
12
17
  import { createRetryQuote, getQuoteToTokenUsdPrice } from '../utils/quote';
13
18
  import { calcOutputUsdValue } from '../utils/swap';
14
19
 
15
- import { useMetaStore } from './meta';
16
20
  import createSelectors from './selectors';
17
21
 
18
22
  export const getUsdValue = (
@@ -23,6 +27,10 @@ export const getUsdValue = (
23
27
  ? new BigNumber(amount || ZERO).multipliedBy(token?.usdPrice || 0)
24
28
  : null;
25
29
 
30
+ export type Meta = Pick<MetaResponse, 'blockchains' | 'tokens'>;
31
+
32
+ export type SetTokenParams = { token: Token; meta: Meta } | { token: null };
33
+
26
34
  export interface QuoteState {
27
35
  fromBlockchain: BlockchainMeta | null;
28
36
  toBlockchain: BlockchainMeta | null;
@@ -41,12 +49,12 @@ export interface QuoteState {
41
49
  setFromBlockchain: (chain: BlockchainMeta | null) => void;
42
50
  setToBlockchain: (chian: BlockchainMeta | null) => void;
43
51
 
44
- setFromToken: (token: Token | null) => void;
45
- setToToken: (token: Token | null) => void;
52
+ setFromToken: (params: SetTokenParams) => void;
53
+ setToToken: (params: SetTokenParams) => void;
46
54
  setInputAmount: (amount: string) => void;
47
55
  quote: BestRouteResponse | null;
48
56
  setQuote: (quote: BestRouteResponse | null) => void;
49
- retry: (pendingSwap: PendingSwap) => void;
57
+ retry: (pendingSwap: PendingSwap, meta: Meta) => void;
50
58
  switchFromAndTo: () => void;
51
59
  setQuoteWalletConfirmed: (flag: boolean) => void;
52
60
  setSelectedWallets: (wallets: Wallet[]) => void;
@@ -119,18 +127,17 @@ export const useQuoteStore = createSelectors(
119
127
  };
120
128
  });
121
129
  },
122
- setFromToken: (token) => {
123
- const { blockchains } = useMetaStore.getState().meta;
130
+ setFromToken: (params) => {
124
131
  return set((state) => ({
125
- fromToken: token,
126
- ...(token && {
132
+ fromToken: params.token,
133
+ ...(params.token && {
127
134
  fromBlockchain:
128
- blockchains.find(
129
- (blockchain) => blockchain.name === token.blockchain
135
+ params.meta.blockchains.find(
136
+ (blockchain) => blockchain.name === params.token.blockchain
130
137
  ) ?? null,
131
138
  }),
132
139
  ...(!!state.inputAmount && {
133
- inputUsdValue: getUsdValue(token, state.inputAmount),
140
+ inputUsdValue: getUsdValue(params.token, state.inputAmount),
134
141
  }),
135
142
  }));
136
143
  },
@@ -151,14 +158,13 @@ export const useQuoteStore = createSelectors(
151
158
  };
152
159
  });
153
160
  },
154
- setToToken: (token) => {
155
- const { blockchains } = useMetaStore.getState().meta;
161
+ setToToken: (params) => {
156
162
  return set(() => ({
157
- toToken: token,
158
- ...(token && {
163
+ toToken: params.token,
164
+ ...(params.token && {
159
165
  toBlockchain:
160
- blockchains.find(
161
- (blockchain) => blockchain.name === token.blockchain
166
+ params.meta.blockchains.find(
167
+ (blockchain) => blockchain.name === params.token.blockchain
162
168
  ) ?? null,
163
169
  }),
164
170
  }));
@@ -176,9 +182,8 @@ export const useQuoteStore = createSelectors(
176
182
  }),
177
183
  }));
178
184
  },
179
- retry: (pendingSwap) => {
180
- const { tokens, blockchains } = useMetaStore.getState().meta;
181
-
185
+ retry: (pendingSwap, meta) => {
186
+ const { tokens, blockchains } = meta;
182
187
  const {
183
188
  fromBlockchain,
184
189
  fromToken,
@@ -186,7 +191,6 @@ export const useQuoteStore = createSelectors(
186
191
  toToken,
187
192
  inputAmount,
188
193
  } = createRetryQuote(pendingSwap, blockchains, tokens);
189
-
190
194
  set({
191
195
  fromBlockchain,
192
196
  fromToken,
@@ -1,3 +1,5 @@
1
+ import type { SwapperMeta } from 'rango-sdk';
2
+
1
3
  import { type Language } from '@rango-dev/ui';
2
4
  import { create } from 'zustand';
3
5
  import { persist, subscribeWithSelector } from 'zustand/middleware';
@@ -7,7 +9,6 @@ import { DEFAULT_LANGUAGE } from '../constants/languages';
7
9
  import { DEFAULT_SLIPPAGE } from '../constants/swapSettings';
8
10
  import { removeDuplicateFrom } from '../utils/common';
9
11
 
10
- import { useMetaStore } from './meta';
11
12
  import createSelectors from './selectors';
12
13
 
13
14
  export type ThemeMode = 'auto' | 'dark' | 'light';
@@ -31,7 +32,10 @@ export interface SettingsState {
31
32
  toggleLiquiditySource: (name: string) => void;
32
33
  setTheme: (theme: ThemeMode) => void;
33
34
  setLanguage: (language: Language) => void;
34
- toggleAllLiquiditySources: (shouldReset?: boolean) => void;
35
+ toggleAllLiquiditySources: (
36
+ swappers: SwapperMeta[],
37
+ shouldReset?: boolean
38
+ ) => void;
35
39
  setAffiliateRef: (affiliateRef: string | null) => void;
36
40
  setAffiliatePercent: (affiliatePercent: number | null) => void;
37
41
  setAffiliateWallets: (
@@ -102,12 +106,11 @@ export const useSettingsStore = createSelectors(
102
106
  set(() => ({
103
107
  affiliateWallets,
104
108
  })),
105
- toggleAllLiquiditySources: (shouldReset?: boolean) =>
109
+ toggleAllLiquiditySources: (swappers, shouldReset) =>
106
110
  set((state) => {
107
111
  if (shouldReset) {
108
112
  return { disabledLiquiditySources: [] };
109
113
  }
110
- const { swappers } = useMetaStore.getState().meta;
111
114
  const swappersGroup = removeDuplicateFrom(
112
115
  swappers.map((swapper) => swapper.swapperGroup)
113
116
  );
@@ -1,7 +1,11 @@
1
1
  import type { WidgetConfig } from '../../types';
2
- import type { StateCreator } from 'zustand';
2
+ import type { StateCreatorWithInitialData } from '../app';
3
3
 
4
- const initConfig: WidgetConfig = { apiKey: '' };
4
+ export const DEFAULT_CONFIG: WidgetConfig = {
5
+ apiKey: '',
6
+ multiWallets: true,
7
+ enableNewLiquiditySources: true,
8
+ };
5
9
 
6
10
  export type ConfigSlice = {
7
11
  config: WidgetConfig;
@@ -9,18 +13,24 @@ export type ConfigSlice = {
9
13
  updateConfig: (config: WidgetConfig) => void;
10
14
  };
11
15
 
12
- export const createConfigSlice: StateCreator<ConfigSlice> = (set, get) => ({
13
- config: initConfig,
16
+ export const createConfigSlice: StateCreatorWithInitialData<
17
+ WidgetConfig,
18
+ ConfigSlice,
19
+ ConfigSlice
20
+ > = (initialData, set, get) => {
21
+ return {
22
+ config: { ...DEFAULT_CONFIG, ...initialData },
14
23
 
15
- // Actions
16
- updateConfig: (nextConfig: WidgetConfig) => {
17
- const currentConfig = get().config;
24
+ // Actions
25
+ updateConfig: (nextConfig: WidgetConfig) => {
26
+ const currentConfig = get().config;
18
27
 
19
- set({
20
- config: {
21
- ...currentConfig,
22
- ...nextConfig,
23
- },
24
- });
25
- },
26
- });
28
+ set({
29
+ config: {
30
+ ...currentConfig,
31
+ ...nextConfig,
32
+ },
33
+ });
34
+ },
35
+ };
36
+ };
@@ -6,6 +6,7 @@ import type { StateCreator } from 'zustand';
6
6
 
7
7
  import { httpService as sdk } from '../../services/httpService';
8
8
  import { containsText } from '../../utils/common';
9
+ import { sortLiquiditySourcesByGroupTitle } from '../../utils/settings';
9
10
  import { tokensAreEqual } from '../../utils/wallets';
10
11
 
11
12
  type BlockchainOptions = {
@@ -18,15 +19,16 @@ type TokenOptions = {
18
19
  blockchain?: string;
19
20
  searchFor?: string;
20
21
  };
21
-
22
+ export type FetchStatus = 'loading' | 'success' | 'failed';
22
23
  export interface DataSlice {
23
24
  _blockchains: BlockchainMeta[];
24
25
  _tokens: Token[];
25
26
  _popularTokens: Token[];
26
27
  _swappers: SwapperMeta[];
27
-
28
+ fetchStatus: FetchStatus;
28
29
  blockchains: (options?: BlockchainOptions) => BlockchainMeta[];
29
30
  tokens: (options?: TokenOptions) => Token[];
31
+ swappers: () => SwapperMeta[];
30
32
  isTokenPinned: (token: Token) => boolean;
31
33
 
32
34
  fetch: () => Promise<void>;
@@ -43,7 +45,7 @@ export const createDataSlice: StateCreator<
43
45
  _tokens: [],
44
46
  _popularTokens: [],
45
47
  _swappers: [],
46
-
48
+ fetchStatus: 'loading',
47
49
  // Selectors
48
50
  blockchains: (options) => {
49
51
  const blockchainsFromState = get()._blockchains;
@@ -163,41 +165,74 @@ export const createDataSlice: StateCreator<
163
165
  );
164
166
  return pinned;
165
167
  },
168
+ swappers: () => {
169
+ const {
170
+ config: { enableNewLiquiditySources, liquiditySources },
171
+ } = get();
172
+
173
+ /*
174
+ * If the enableNewLiquiditySources flag is set to true, we return all swappers that are not included in the config.
175
+ * Otherwise, we return all swappers that are included in the config.
176
+ */
177
+ const swappers = get()._swappers.filter((swapper) => {
178
+ const swapperGroupIncludedInLiquiditySources = liquiditySources?.includes(
179
+ swapper.swapperGroup
180
+ );
181
+
182
+ const shouldExcludeLiquiditySources =
183
+ enableNewLiquiditySources ||
184
+ !liquiditySources ||
185
+ liquiditySources.length === 0;
186
+
187
+ return shouldExcludeLiquiditySources
188
+ ? !swapperGroupIncludedInLiquiditySources
189
+ : swapperGroupIncludedInLiquiditySources;
190
+ });
191
+
192
+ const sortedSwappers = swappers.sort(sortLiquiditySourcesByGroupTitle);
166
193
 
194
+ return sortedSwappers;
195
+ },
167
196
  // Actions
168
197
  fetch: async () => {
169
- const response = await sdk().getAllMetadata();
198
+ try {
199
+ const response = await sdk().getAllMetadata();
170
200
 
171
- const blockchains: BlockchainMeta[] = [];
172
- const tokens: Token[] = [];
173
- const popularTokens: Token[] = response.popularTokens;
174
- const swappers: SwapperMeta[] = response.swappers;
201
+ set({ fetchStatus: 'success' });
202
+ const blockchains: BlockchainMeta[] = [];
203
+ const tokens: Token[] = [];
204
+ const popularTokens: Token[] = response.popularTokens;
205
+ const swappers: SwapperMeta[] = response.swappers;
175
206
 
176
- const blockchainsWithAtLeastOneToken = new Set();
207
+ const blockchainsWithAtLeastOneToken = new Set();
177
208
 
178
- response.tokens.forEach((token) => {
179
- blockchainsWithAtLeastOneToken.add(token.blockchain);
209
+ response.tokens.forEach((token) => {
210
+ blockchainsWithAtLeastOneToken.add(token.blockchain);
180
211
 
181
- tokens.push(token);
182
- });
212
+ tokens.push(token);
213
+ });
183
214
 
184
- response.blockchains.forEach((blockchain) => {
185
- if (
186
- blockchain.enabled &&
187
- blockchainsWithAtLeastOneToken.has(blockchain.name)
188
- ) {
189
- blockchains.push(blockchain);
190
- }
191
- });
215
+ response.blockchains.forEach((blockchain) => {
216
+ if (
217
+ blockchain.enabled &&
218
+ blockchainsWithAtLeastOneToken.has(blockchain.name)
219
+ ) {
220
+ blockchains.push(blockchain);
221
+ }
222
+ });
192
223
 
193
- // Sort
194
- blockchains.sort((a, b) => a.sort - b.sort);
224
+ // Sort
225
+ blockchains.sort((a, b) => a.sort - b.sort);
195
226
 
196
- set({
197
- _blockchains: blockchains,
198
- _tokens: tokens,
199
- _popularTokens: popularTokens,
200
- _swappers: swappers,
201
- });
227
+ set({
228
+ _blockchains: blockchains,
229
+ _tokens: tokens,
230
+ _popularTokens: popularTokens,
231
+ _swappers: swappers,
232
+ });
233
+ } catch (error) {
234
+ set({ fetchStatus: 'failed' });
235
+ throw error;
236
+ }
202
237
  },
203
238
  });
@@ -1,5 +1,6 @@
1
1
  import type { Wallet } from '../types';
2
2
  import type { WalletType } from '@rango-dev/wallets-shared';
3
+ import type { Token } from 'rango-sdk';
3
4
 
4
5
  import { create } from 'zustand';
5
6
  import { subscribeWithSelector } from 'zustand/middleware';
@@ -11,7 +12,6 @@ import {
11
12
  resetConnectedWalletState,
12
13
  } from '../utils/wallets';
13
14
 
14
- import { useMetaStore } from './meta';
15
15
  import createSelectors from './selectors';
16
16
 
17
17
  export type TokenBalance = {
@@ -38,11 +38,15 @@ interface WalletsStore {
38
38
  connectedWallets: ConnectedWallet[];
39
39
  customDestination: string;
40
40
  loading: boolean;
41
- connectWallet: (accounts: Wallet[]) => void;
41
+ connectWallet: (accounts: Wallet[], tokens: Token[]) => void;
42
42
  disconnectWallet: (walletType: WalletType) => void;
43
43
  selectWallets: (wallets: { walletType: string; chain: string }[]) => void;
44
44
  clearConnectedWallet: () => void;
45
- getWalletsDetails: (accounts: Wallet[], shouldRetry?: boolean) => void;
45
+ getWalletsDetails: (
46
+ accounts: Wallet[],
47
+ tokens: Token[],
48
+ shouldRetry?: boolean
49
+ ) => void;
46
50
  }
47
51
 
48
52
  export const useWalletsStore = createSelectors(
@@ -51,7 +55,7 @@ export const useWalletsStore = createSelectors(
51
55
  connectedWallets: [],
52
56
  customDestination: '',
53
57
  loading: false,
54
- connectWallet: (accounts) => {
58
+ connectWallet: (accounts, tokens) => {
55
59
  const getWalletsDetails = get().getWalletsDetails;
56
60
  set((state) => ({
57
61
  loading: true,
@@ -77,7 +81,7 @@ export const useWalletsStore = createSelectors(
77
81
  })
78
82
  ),
79
83
  }));
80
- getWalletsDetails(accounts);
84
+ getWalletsDetails(accounts, tokens);
81
85
  },
82
86
  disconnectWallet: (walletType) => {
83
87
  set((state) => {
@@ -135,9 +139,8 @@ export const useWalletsStore = createSelectors(
135
139
  connectedWallets: [],
136
140
  selectedWallets: [],
137
141
  })),
138
- getWalletsDetails: async (accounts, shouldRetry = true) => {
142
+ getWalletsDetails: async (accounts, tokens, shouldRetry = true) => {
139
143
  const getWalletsDetails = get().getWalletsDetails;
140
- const { tokens } = useMetaStore.getState().meta;
141
144
  set((state) => ({
142
145
  loading: true,
143
146
  connectedWallets: state.connectedWallets.map((wallet) => {
@@ -173,7 +176,7 @@ export const useWalletsStore = createSelectors(
173
176
  matchedAccount &&
174
177
  shouldRetry
175
178
  ) {
176
- getWalletsDetails([matchedAccount], false);
179
+ getWalletsDetails([matchedAccount], tokens, false);
177
180
  }
178
181
  return matchedAccount && retrievedBalanceAccount
179
182
  ? {
@@ -61,7 +61,7 @@ export type WidgetTheme = {
61
61
  * @property {{ [key: string]: string }} wallets - If you want to change the default affiliate wallet
62
62
  * addresses, you can provide new values here. (Map of route blockchains to affiliate address)
63
63
  */
64
- export type WidgeAffiliate = {
64
+ export type WidgetAffiliate = {
65
65
  ref?: string;
66
66
  percent?: number;
67
67
  wallets?: { [key: string]: string };
@@ -91,7 +91,7 @@ export type BlockchainAndTokenConfig = {
91
91
  * and theme.
92
92
  *
93
93
  * @property {string} apiKey - The API key used to communicate with Rango API
94
- * @property {WidgeAffiliate} affiliate - If you want to charge users fee per transaction, you should
94
+ * @property {WidgetAffiliate} affiliate - If you want to charge users fee per transaction, you should
95
95
  * pass `WidgetAffiliate` including affiliateRef, affiliatePercent, and affiliateWallets.
96
96
  * @property {number} amount - The default input amount.
97
97
  * @property {BlockchainAndTokenConfig} from - The `from` property is an optional property of type
@@ -121,13 +121,13 @@ export type BlockchainAndTokenConfig = {
121
121
  * If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
122
122
  * @property {Asset} pinnedTokens - The `pinnedTokens` property is an optional array of `Asset` objects that
123
123
  * you could use to pin tokens of your choice to the top of the token list.
124
- * @property {boolean} includeNewLiquiditySources - The `includeNewLiquiditySources` property is a boolean value that when you
124
+ * @property {boolean} enableNewLiquiditySources - The `enableNewLiquiditySources` property is a boolean value that when you
125
125
  * set it to true, whenever a new liquidity source is added, it will be added to your list as well.
126
126
  */
127
127
  export type WidgetConfig = {
128
128
  apiKey: string;
129
129
  walletConnectProjectId?: string;
130
- affiliate?: WidgeAffiliate;
130
+ affiliate?: WidgetAffiliate;
131
131
  amount?: number;
132
132
  from?: BlockchainAndTokenConfig;
133
133
  to?: BlockchainAndTokenConfig;
@@ -139,5 +139,5 @@ export type WidgetConfig = {
139
139
  theme?: WidgetTheme;
140
140
  externalWallets?: boolean;
141
141
  pinnedTokens?: Asset[];
142
- includeNewLiquiditySources?: boolean;
142
+ enableNewLiquiditySources?: boolean;
143
143
  };
@@ -1,4 +1,5 @@
1
- import { useMetaStore } from '../store/meta';
1
+ import type { SwapperMeta } from 'rango-sdk';
2
+
2
3
  import { useSettingsStore } from '../store/settings';
3
4
 
4
5
  import { removeDuplicateFrom } from './common';
@@ -14,11 +15,11 @@ export type UniqueSwappersGroupType = {
14
15
  };
15
16
 
16
17
  export function getUniqueSwappersGroups(
17
- supportedSwappers?: string[]
18
+ swappers: SwapperMeta[]
18
19
  ): UniqueSwappersGroupType[] {
19
- const swappers = useMetaStore.use.meta().swappers;
20
20
  const disabledLiquiditySources =
21
21
  useSettingsStore.use.disabledLiquiditySources();
22
+ const supportedSwappers = swappers.map((swapper) => swapper.swapperGroup);
22
23
 
23
24
  const uniqueSupportedSwappersGroups: Array<UniqueSwappersGroupType> = [];
24
25
 
@@ -57,14 +58,14 @@ export function getUniqueSwappersGroups(
57
58
  }
58
59
 
59
60
  export function sortLiquiditySourcesByGroupTitle(
60
- a: UniqueSwappersGroupType,
61
- b: UniqueSwappersGroupType
61
+ a: SwapperMeta,
62
+ b: SwapperMeta
62
63
  ) {
63
- if (a.groupTitle < b.groupTitle) {
64
+ if (a.swapperGroup < b.swapperGroup) {
64
65
  return -1;
65
66
  }
66
67
 
67
- if (a.groupTitle > b.groupTitle) {
68
+ if (a.swapperGroup > b.swapperGroup) {
68
69
  return 1;
69
70
  }
70
71