@rango-dev/widget-embedded 0.29.1-next.1 → 0.29.1-next.10

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 (84) hide show
  1. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  2. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  3. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts +0 -2
  4. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +1 -1
  5. package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
  6. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +4 -2
  7. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts.map +1 -1
  8. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -1
  9. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
  10. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  11. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +2 -1
  12. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  13. package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
  14. package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.d.ts.map +1 -1
  15. package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts +2 -2
  16. package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts.map +1 -1
  17. package/dist/hooks/useWalletList.d.ts.map +1 -1
  18. package/dist/index.js +2 -2
  19. package/dist/index.js.map +4 -4
  20. package/dist/pages/WalletsPage.d.ts.map +1 -1
  21. package/dist/store/notification.d.ts.map +1 -1
  22. package/dist/store/quote.d.ts +9 -3
  23. package/dist/store/quote.d.ts.map +1 -1
  24. package/dist/store/selectors.d.ts +1 -1
  25. package/dist/store/selectors.d.ts.map +1 -1
  26. package/dist/store/slices/data.d.ts +5 -3
  27. package/dist/store/slices/data.d.ts.map +1 -1
  28. package/dist/store/slices/settings.d.ts.map +1 -1
  29. package/dist/store/wallets.d.ts +5 -4
  30. package/dist/store/wallets.d.ts.map +1 -1
  31. package/dist/test-utils/fixtures.d.ts +1 -1
  32. package/dist/test-utils/fixtures.d.ts.map +1 -1
  33. package/dist/types/config.d.ts +3 -0
  34. package/dist/types/config.d.ts.map +1 -1
  35. package/dist/utils/common.d.ts +2 -0
  36. package/dist/utils/common.d.ts.map +1 -1
  37. package/dist/utils/meta.d.ts +3 -1
  38. package/dist/utils/meta.d.ts.map +1 -1
  39. package/dist/utils/quote.d.ts +4 -8
  40. package/dist/utils/quote.d.ts.map +1 -1
  41. package/dist/utils/swap.d.ts +3 -4
  42. package/dist/utils/swap.d.ts.map +1 -1
  43. package/dist/utils/wallets.d.ts +4 -5
  44. package/dist/utils/wallets.d.ts.map +1 -1
  45. package/dist/widget-embedded.build.json +1 -1
  46. package/package.json +7 -7
  47. package/src/components/NotificationContent/NotificationContent.tsx +13 -119
  48. package/src/components/Quote/Quote.tsx +3 -3
  49. package/src/components/Quotes/Quotes.tsx +2 -2
  50. package/src/components/SwapDetails/SwapDetails.tsx +8 -3
  51. package/src/components/WalletNamespacesModal/WalletNamespacesModal.tsx +2 -10
  52. package/src/containers/Wallets/Wallets.tsx +3 -3
  53. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +12 -3
  54. package/src/containers/WidgetInfo/WidgetInfo.tsx +7 -2
  55. package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -1
  56. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +4 -2
  57. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +3 -1
  58. package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +3 -3
  59. package/src/hooks/useSwapInput.ts +2 -2
  60. package/src/hooks/useSyncStoresWithConfig.ts +6 -7
  61. package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.ts +12 -26
  62. package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.ts +19 -12
  63. package/src/hooks/useWalletList.ts +2 -4
  64. package/src/pages/WalletsPage.tsx +23 -16
  65. package/src/store/notification.ts +3 -1
  66. package/src/store/quote.ts +12 -7
  67. package/src/store/selectors.ts +6 -4
  68. package/src/store/slices/data.test.ts +9 -5
  69. package/src/store/slices/data.ts +26 -7
  70. package/src/store/slices/settings.ts +3 -0
  71. package/src/store/wallets.ts +9 -8
  72. package/src/test-utils/fixtures.ts +9 -2
  73. package/src/types/config.ts +5 -0
  74. package/src/utils/common.ts +12 -1
  75. package/src/utils/meta.ts +13 -6
  76. package/src/utils/quote.ts +12 -20
  77. package/src/utils/swap.ts +5 -25
  78. package/src/utils/wallets.ts +4 -28
  79. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +0 -1559
  80. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +0 -1
  81. package/dist/components/NotificationContent/NotificationNotFound.d.ts +0 -3
  82. package/dist/components/NotificationContent/NotificationNotFound.d.ts.map +0 -1
  83. package/src/components/NotificationContent/NotificationContent.styles.ts +0 -63
  84. package/src/components/NotificationContent/NotificationNotFound.tsx +0 -17
@@ -1,3 +1,4 @@
1
+ import type { WalletInfoWithNamespaces } from '../types';
1
2
  import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
2
3
 
3
4
  import { i18n } from '@lingui/core';
@@ -18,7 +19,7 @@ import { WalletNamespacesModal } from '../components/WalletNamespacesModal';
18
19
  import { useWalletList } from '../hooks/useWalletList';
19
20
  import { useAppStore } from '../store/AppStore';
20
21
  import { useUiStore } from '../store/ui';
21
- import { getContainer } from '../utils/common';
22
+ import { getContainer, isSingleWalletActive } from '../utils/common';
22
23
  import {
23
24
  filterBlockchainsByWalletTypes,
24
25
  filterWalletsByCategory,
@@ -51,6 +52,7 @@ export function WalletsPage() {
51
52
  const { fetchStatus: fetchMetaStatus } = useAppStore();
52
53
  const [blockchainCategory, setBlockchainCategory] = useState<string>('ALL');
53
54
  const blockchains = useAppStore().blockchains();
55
+ const { config } = useAppStore();
54
56
 
55
57
  const [openModal, setOpenModal] = useState(false);
56
58
  const [namespacesModalState, setNamespacesModalState] =
@@ -95,6 +97,25 @@ export function WalletsPage() {
95
97
 
96
98
  const filteredWallets = filterWalletsByCategory(list, blockchainCategory);
97
99
 
100
+ const handleWalletClick = (
101
+ type: string,
102
+ wallet: WalletInfoWithNamespaces
103
+ ) => {
104
+ if (!!wallet.namespaces && wallet.state === WalletState.DISCONNECTED) {
105
+ if (isSingleWalletActive(list, config.multiWallets)) {
106
+ return;
107
+ }
108
+ setNamespacesModalState({
109
+ providerType: type,
110
+ providerImage: wallet.image,
111
+ availableNamespaces: wallet.namespaces,
112
+ singleNamespace: wallet.singleNamespace,
113
+ });
114
+ } else {
115
+ void handleClick(type);
116
+ }
117
+ };
118
+
98
119
  return (
99
120
  <Layout
100
121
  header={{
@@ -123,21 +144,7 @@ export function WalletsPage() {
123
144
  key={key}
124
145
  {...wallet}
125
146
  container={getContainer()}
126
- onClick={(type) => {
127
- if (
128
- !!wallet.namespaces &&
129
- wallet.state === WalletState.DISCONNECTED
130
- ) {
131
- setNamespacesModalState({
132
- providerType: type,
133
- providerImage: wallet.image,
134
- availableNamespaces: wallet.namespaces,
135
- singleNamespace: wallet.singleNamespace,
136
- });
137
- } else {
138
- void handleClick(type);
139
- }
140
- }}
147
+ onClick={(type) => handleWalletClick(type, wallet)}
141
148
  isLoading={fetchMetaStatus === 'loading'}
142
149
  disabled={!isActiveTab}
143
150
  />
@@ -66,7 +66,9 @@ export const useNotificationStore = createSelectors(
66
66
  },
67
67
  getNotifications: () => {
68
68
  const { isSynced, notifications } = get();
69
- return isSynced ? notifications : [];
69
+ return isSynced
70
+ ? notifications.sort((a, b) => b.creationTime - a.creationTime)
71
+ : [];
70
72
  },
71
73
  syncNotifications: (swaps) => {
72
74
  const { isSynced, notifications } = get();
@@ -6,7 +6,6 @@ import type {
6
6
  PreferenceType,
7
7
  Token,
8
8
  } from 'rango-sdk';
9
- import type { PendingSwap } from 'rango-types';
10
9
 
11
10
  import BigNumber from 'bignumber.js';
12
11
  import { create } from 'zustand';
@@ -14,7 +13,7 @@ import { subscribeWithSelector } from 'zustand/middleware';
14
13
 
15
14
  import { ZERO } from '../constants/numbers';
16
15
  import { isPositiveNumber } from '../utils/numbers';
17
- import { createRetryQuote, getQuoteToTokenUsdPrice } from '../utils/quote';
16
+ import { getQuoteToTokenUsdPrice } from '../utils/quote';
18
17
  import { calcOutputUsdValue } from '../utils/swap';
19
18
 
20
19
  import createSelectors from './selectors';
@@ -38,7 +37,13 @@ type SomeQuoteState = {
38
37
  error: QuoteError | null;
39
38
  warning: QuoteWarning | null;
40
39
  };
41
-
40
+ export type RetryQuote = {
41
+ fromBlockchain: BlockchainMeta | null;
42
+ fromToken?: Token;
43
+ toBlockchain: BlockchainMeta | null;
44
+ toToken?: Token;
45
+ inputAmount: string;
46
+ };
42
47
  export interface QuoteState {
43
48
  fromBlockchain: BlockchainMeta | null;
44
49
  toBlockchain: BlockchainMeta | null;
@@ -73,7 +78,7 @@ export interface QuoteState {
73
78
  ) => void;
74
79
  setInputAmount: (amount: string) => void;
75
80
  setSelectedQuote: (quote: SelectedQuote | null) => void;
76
- retry: (pendingSwap: PendingSwap, meta: Meta) => void;
81
+ retry: (retryQuote: RetryQuote) => void;
77
82
  switchFromAndTo: () => void;
78
83
  setQuoteWalletConfirmed: (flag: boolean) => void;
79
84
  setSelectedWallets: (wallets: Wallet[]) => void;
@@ -219,15 +224,15 @@ export const useQuoteStore = createSelectors(
219
224
  }),
220
225
  }));
221
226
  },
222
- retry: (pendingSwap, meta) => {
223
- const { tokens, blockchains } = meta;
227
+ retry: (retryQuote) => {
224
228
  const {
225
229
  fromBlockchain,
226
230
  fromToken,
227
231
  toBlockchain,
228
232
  toToken,
229
233
  inputAmount,
230
- } = createRetryQuote(pendingSwap, blockchains, tokens);
234
+ } = retryQuote;
235
+
231
236
  set({
232
237
  fromBlockchain,
233
238
  fromToken,
@@ -1,4 +1,4 @@
1
- import { StoreApi, UseBoundStore } from 'zustand';
1
+ import type { StoreApi, UseBoundStore } from 'zustand';
2
2
 
3
3
  type State = object;
4
4
 
@@ -6,10 +6,12 @@ type WithSelectors<S> = S extends { getState: () => infer T }
6
6
  ? S & { use: { [K in keyof T]: () => T[K] } }
7
7
  : never;
8
8
 
9
- const createSelectors = <S extends UseBoundStore<StoreApi<State>>>(_store: S) => {
10
- let store = _store as WithSelectors<typeof _store>;
9
+ const createSelectors = <S extends UseBoundStore<StoreApi<State>>>(
10
+ _store: S
11
+ ) => {
12
+ const store = _store as WithSelectors<typeof _store>;
11
13
  store.use = {};
12
- for (let k of Object.keys(store.getState())) {
14
+ for (const k of Object.keys(store.getState())) {
13
15
  (store.use as any)[k] = () => store((s) => s[k as keyof typeof s]);
14
16
  }
15
17
 
@@ -9,6 +9,7 @@ import {
9
9
  createToken,
10
10
  updateAppStoreConfig,
11
11
  } from '../../test-utils/fixtures';
12
+ import { createTokenHash } from '../../utils/meta';
12
13
  import { createAppStore } from '../app';
13
14
 
14
15
  let appStoreState: AppStoreState;
@@ -48,7 +49,10 @@ beforeEach(() => {
48
49
 
49
50
  const initData = createInitialAppStore();
50
51
  initData._blockchainsMapByName.set(rangoBlockchain.name, rangoBlockchain);
51
- customTokens.forEach((token) => initData._tokens.push(token));
52
+ customTokens.forEach((token) => {
53
+ const tokenHash = createTokenHash(token);
54
+ initData._tokensMapByTokenHash.set(tokenHash, token);
55
+ });
52
56
 
53
57
  const appStore = createAppStore();
54
58
  appStore.setState(initData);
@@ -149,10 +153,10 @@ describe('check sorting tokens is working correctly in app store', () => {
149
153
 
150
154
  test('put popular token with lowest blockchain sort at first', () => {
151
155
  const rangoToken = customTokens[0];
152
- const rangoIndex = appStoreState._tokens.findIndex(
153
- (tokenItem) => tokenItem.symbol === rangoToken.symbol
154
- );
155
- appStoreState._tokens[rangoIndex].isPopular = true;
156
+ const token = appStoreState.findToken(rangoToken);
157
+ if (token) {
158
+ token.isPopular = true;
159
+ }
156
160
  appStoreState._blockchainsMapByName.set(rangoToken.blockchain, {
157
161
  ...rangoBlockchain,
158
162
  sort: 0,
@@ -1,14 +1,14 @@
1
1
  // We keep all the received data from server in this slice
2
2
 
3
3
  import type { ConfigSlice } from './config';
4
- import type { Balance } from '../../types';
5
- import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
4
+ import type { Balance, TokenHash } from '../../types';
5
+ import type { Asset, BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
6
6
  import type { StateCreator } from 'zustand';
7
7
 
8
8
  import { httpService as sdk } from '../../services/httpService';
9
9
  import { compareWithSearchFor, containsText } from '../../utils/common';
10
10
  import { isTokenExcludedInConfig } from '../../utils/configs';
11
- import { isTokenNative } from '../../utils/meta';
11
+ import { createTokenHash, isTokenNative } from '../../utils/meta';
12
12
  import { sortLiquiditySourcesByGroupTitle } from '../../utils/settings';
13
13
  import { areTokensEqual, compareTokenBalance } from '../../utils/wallets';
14
14
 
@@ -24,10 +24,12 @@ type TokenOptions = {
24
24
  getBalanceFor?: (token: Token) => Balance | null;
25
25
  };
26
26
 
27
+ export type FindToken = (asset: Asset) => Token | undefined;
28
+
27
29
  export type FetchStatus = 'loading' | 'success' | 'failed';
28
30
  export interface DataSlice {
29
31
  _blockchainsMapByName: Map<string, BlockchainMeta>;
30
- _tokens: Token[];
32
+ _tokensMapByTokenHash: Map<TokenHash, Token>;
31
33
  _popularTokens: Token[];
32
34
  _swappers: SwapperMeta[];
33
35
  fetchStatus: FetchStatus;
@@ -35,6 +37,7 @@ export interface DataSlice {
35
37
  tokens: (options?: TokenOptions) => Token[];
36
38
  swappers: () => SwapperMeta[];
37
39
  isTokenPinned: (token: Token, type: 'source' | 'destination') => boolean;
40
+ findToken: FindToken;
38
41
  fetch: () => Promise<void>;
39
42
  }
40
43
 
@@ -46,7 +49,7 @@ export const createDataSlice: StateCreator<
46
49
  > = (set, get) => ({
47
50
  // State
48
51
  _blockchainsMapByName: new Map<string, BlockchainMeta>(),
49
- _tokens: [],
52
+ _tokensMapByTokenHash: new Map<TokenHash, Token>(),
50
53
  _popularTokens: [],
51
54
  _swappers: [],
52
55
  fetchStatus: 'loading',
@@ -81,7 +84,8 @@ export const createDataSlice: StateCreator<
81
84
  return list;
82
85
  },
83
86
  tokens: (options) => {
84
- const tokensFromState = get()._tokens;
87
+ const tokensMapByHashToken = get()._tokensMapByTokenHash;
88
+ const tokensFromState = Array.from(tokensMapByHashToken?.values() || []);
85
89
  const blockchainsMapByName = get()._blockchainsMapByName;
86
90
 
87
91
  if (!options || !options?.type) {
@@ -197,6 +201,12 @@ export const createDataSlice: StateCreator<
197
201
 
198
202
  return list;
199
203
  },
204
+ findToken: (asset) => {
205
+ const tokensMapByHashToken = get()._tokensMapByTokenHash;
206
+ const tokenHash = createTokenHash(asset);
207
+ const token = tokensMapByHashToken.get(tokenHash);
208
+ return token;
209
+ },
200
210
  isTokenPinned: (token, type) => {
201
211
  const pinnedTokens =
202
212
  type === 'source'
@@ -258,6 +268,10 @@ export const createDataSlice: StateCreator<
258
268
  BlockchainMeta
259
269
  >();
260
270
 
271
+ const tokensMapByHashToken: Map<TokenHash, Token> = new Map<
272
+ TokenHash,
273
+ Token
274
+ >();
261
275
  const tokens: Token[] = [];
262
276
  const popularTokens: Token[] = response.popularTokens;
263
277
  const swappers: SwapperMeta[] = response.swappers;
@@ -283,9 +297,14 @@ export const createDataSlice: StateCreator<
283
297
  }
284
298
  });
285
299
 
300
+ tokens.forEach((token) => {
301
+ const tokenHash = createTokenHash(token);
302
+ tokensMapByHashToken.set(tokenHash, token);
303
+ });
304
+
286
305
  set({
287
306
  _blockchainsMapByName: blockchainsMapByName,
288
- _tokens: tokens,
307
+ _tokensMapByTokenHash: tokensMapByHashToken,
289
308
  _popularTokens: popularTokens,
290
309
  _swappers: swappers,
291
310
  });
@@ -169,6 +169,9 @@ export const createSettingsSlice: StateCreator<
169
169
  ...(isLiquidityHidden && {
170
170
  disabledLiquiditySources: nextConfig.liquiditySources || [],
171
171
  }),
172
+ ...(nextConfig?._INTERNAL_SETTINGS_?.autoUpdateSettings && {
173
+ language: nextConfig.language || DEFAULT_LANGUAGE,
174
+ }),
172
175
  });
173
176
  },
174
177
  });
@@ -1,3 +1,4 @@
1
+ import type { FindToken } from './slices/data';
1
2
  import type { Balance, TokensBalance, Wallet } from '../types';
2
3
  import type { WalletType } from '@rango-dev/wallets-shared';
3
4
  import type { Token } from 'rango-sdk';
@@ -6,8 +7,8 @@ import { create } from 'zustand';
6
7
  import { subscribeWithSelector } from 'zustand/middleware';
7
8
 
8
9
  import { httpService } from '../services/httpService';
10
+ import { createTokenHash } from '../utils/meta';
9
11
  import {
10
- createTokenHash,
11
12
  isAccountAndWalletMatched,
12
13
  makeBalanceFor,
13
14
  makeTokensBalance,
@@ -39,13 +40,13 @@ interface WalletsStore {
39
40
  connectedWallets: ConnectedWallet[];
40
41
  balances: TokensBalance;
41
42
  loading: boolean;
42
- connectWallet: (accounts: Wallet[], tokens: Token[]) => void;
43
+ connectWallet: (accounts: Wallet[], findToken: FindToken) => void;
43
44
  disconnectWallet: (walletType: WalletType) => void;
44
45
  selectWallets: (wallets: { walletType: string; chain: string }[]) => void;
45
46
  clearConnectedWallet: () => void;
46
47
  getWalletsDetails: (
47
48
  accounts: Wallet[],
48
- tokens: Token[],
49
+ findToken: FindToken,
49
50
  shouldRetry?: boolean
50
51
  ) => void;
51
52
  getBalanceFor: (token: Token) => Balance | null;
@@ -57,7 +58,7 @@ export const useWalletsStore = createSelectors(
57
58
  connectedWallets: [],
58
59
  balances: {},
59
60
  loading: false,
60
- connectWallet: (accounts, tokens) => {
61
+ connectWallet: (accounts, findToken) => {
61
62
  const getWalletsDetails = get().getWalletsDetails;
62
63
  set((state) => ({
63
64
  loading: true,
@@ -88,7 +89,7 @@ export const useWalletsStore = createSelectors(
88
89
  })
89
90
  ),
90
91
  }));
91
- getWalletsDetails(accounts, tokens);
92
+ getWalletsDetails(accounts, findToken);
92
93
  },
93
94
  disconnectWallet: (walletType) => {
94
95
  set((state) => {
@@ -152,7 +153,7 @@ export const useWalletsStore = createSelectors(
152
153
  connectedWallets: [],
153
154
  selectedWallets: [],
154
155
  })),
155
- getWalletsDetails: async (accounts, tokens, shouldRetry = true) => {
156
+ getWalletsDetails: async (accounts, findToken, shouldRetry = true) => {
156
157
  const getWalletsDetails = get().getWalletsDetails;
157
158
  set((state) => ({
158
159
  loading: true,
@@ -188,7 +189,7 @@ export const useWalletsStore = createSelectors(
188
189
  matchedAccount &&
189
190
  shouldRetry
190
191
  ) {
191
- getWalletsDetails([matchedAccount], tokens, false);
192
+ getWalletsDetails([matchedAccount], findToken, false);
192
193
  }
193
194
  return matchedAccount && retrievedBalanceAccount
194
195
  ? {
@@ -196,7 +197,7 @@ export const useWalletsStore = createSelectors(
196
197
  explorerUrl: retrievedBalanceAccount.explorerUrl,
197
198
  balances: makeBalanceFor(
198
199
  retrievedBalanceAccount,
199
- tokens
200
+ findToken
200
201
  ),
201
202
  loading: false,
202
203
  }
@@ -1,10 +1,12 @@
1
1
  import type { AppStoreState } from '../store/app';
2
- import type { WidgetConfig } from '../types';
2
+ import type { TokenHash, WidgetConfig } from '../types';
3
3
  import type { BlockchainMeta, EvmBlockchainMeta, Token } from 'rango-sdk';
4
4
 
5
5
  import { faker } from '@faker-js/faker';
6
6
  import { TransactionType } from 'rango-sdk';
7
7
 
8
+ import { createTokenHash } from '../utils/meta';
9
+
8
10
  const TOKENS_COUNT = 20;
9
11
  const BLOCKCHAINS_COUNT = 20;
10
12
 
@@ -230,7 +232,12 @@ export function createInitialAppStore() {
230
232
  });
231
233
 
232
234
  return {
233
- _tokens: tokens,
235
+ _tokensMapByTokenHash: new Map<TokenHash, Token>(
236
+ tokens.map((token) => {
237
+ const tokenHash = createTokenHash(token);
238
+ return [tokenHash, token];
239
+ })
240
+ ),
234
241
  _blockchainsMapByName: new Map<string, BlockchainMeta>(
235
242
  blockchains.map((meta) => [meta.name, meta])
236
243
  ),
@@ -224,4 +224,9 @@ export type WidgetConfig = {
224
224
  __UNSTABLE_OR_INTERNAL__?: {
225
225
  walletConnectListedDesktopWalletLink?: string;
226
226
  };
227
+
228
+ // Internal configuration options. Not intended for public use or modification.
229
+ _INTERNAL_SETTINGS_?: {
230
+ autoUpdateSettings?: boolean; // If true, settings will be updated automatically based on the configuration.
231
+ };
227
232
  };
@@ -1,6 +1,7 @@
1
+ import type { WalletInfoWithNamespaces } from '../types';
1
2
  import type { Token } from 'rango-sdk';
2
3
 
3
- import { BlockchainCategories } from '@rango-dev/ui';
4
+ import { BlockchainCategories, WalletState } from '@rango-dev/ui';
4
5
  import { TransactionType } from 'rango-sdk';
5
6
 
6
7
  import { WIDGET_UI_ID } from '../constants';
@@ -247,3 +248,13 @@ export const getFontUrlByName = (fontName: string) => {
247
248
  const font = SUPPORTED_FONTS.find((font) => font.value === fontName);
248
249
  return font?.url;
249
250
  };
251
+
252
+ export function isSingleWalletActive(
253
+ wallets: WalletInfoWithNamespaces[],
254
+ multiWallets?: boolean
255
+ ) {
256
+ const atLeastOneWalletIsConnected = !!wallets.find(
257
+ (w) => w.state === WalletState.CONNECTED
258
+ );
259
+ return multiWallets === false && atLeastOneWalletIsConnected;
260
+ }
package/src/utils/meta.ts CHANGED
@@ -1,7 +1,6 @@
1
+ import type { TokenHash } from '../types';
1
2
  import type { Asset, BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
2
3
 
3
- import { areTokensEqual } from './wallets';
4
-
5
4
  export function getBlockchainDisplayNameFor(
6
5
  blockchainName: string,
7
6
  blockchains: BlockchainMeta[]
@@ -17,6 +16,14 @@ export function getBlockchainShortNameFor(
17
16
  ?.shortName;
18
17
  }
19
18
 
19
+ export function getBlockchainImage(
20
+ blockchainName: string,
21
+ blockchains: BlockchainMeta[]
22
+ ): string | undefined {
23
+ return blockchains.find((blockchain) => blockchain.name === blockchainName)
24
+ ?.logo;
25
+ }
26
+
20
27
  export function getSwapperDisplayName(
21
28
  swapperId: string,
22
29
  swappers: SwapperMeta[]
@@ -24,10 +31,6 @@ export function getSwapperDisplayName(
24
31
  return swappers.find((swapper) => swapper.id === swapperId)?.title;
25
32
  }
26
33
 
27
- export function findToken(t: Asset, tokens: Token[]) {
28
- return tokens.find((token) => areTokensEqual(token, t)) ?? null;
29
- }
30
-
31
34
  export function findBlockchain(name: string, blockchains: BlockchainMeta[]) {
32
35
  return blockchains.find((blockchain) => blockchain.name === name) ?? null;
33
36
  }
@@ -52,3 +55,7 @@ export function isTokenNative(
52
55
 
53
56
  return false;
54
57
  }
58
+
59
+ export function createTokenHash(asset: Asset): TokenHash {
60
+ return `${asset.blockchain}-${asset.symbol}-${asset.address ?? ''}`;
61
+ }
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+ import type { RetryQuote } from '../store/quote';
3
+ import type { FindToken } from '../store/slices/data';
2
4
  import type { QuoteWarning, SelectedQuote, Wallet } from '../types';
3
5
  import type {
4
6
  PriceImpactWarningLevel,
@@ -27,7 +29,7 @@ import { getUsdValue } from '../store/quote';
27
29
  import { QuoteWarningType } from '../types';
28
30
 
29
31
  import { areEqual } from './common';
30
- import { findBlockchain, findToken } from './meta';
32
+ import { createTokenHash, findBlockchain } from './meta';
31
33
  import {
32
34
  checkSlippageWarnings,
33
35
  getMinRequiredSlippage,
@@ -130,27 +132,18 @@ export function findCommonTokens<T extends Asset[], R extends Asset[]>(
130
132
  listA: T,
131
133
  listB: R
132
134
  ) {
133
- const tokenToString = (token: Asset): string =>
134
- `${token.symbol}-${token.blockchain}-${token.address ?? ''}`;
135
-
136
135
  const set = new Set();
137
136
 
138
- listA.forEach((token) => set.add(tokenToString(token)));
137
+ listA.forEach((token) => set.add(createTokenHash(token)));
139
138
 
140
- return listB.filter((token) => set.has(tokenToString(token))) as R;
139
+ return listB.filter((token) => set.has(createTokenHash(token))) as R;
141
140
  }
142
141
 
143
142
  export function createRetryQuote(
144
143
  pendingSwap: PendingSwap,
145
144
  blockchains: BlockchainMeta[],
146
- tokens: Token[]
147
- ): {
148
- fromBlockchain: BlockchainMeta | null;
149
- fromToken: Token | null;
150
- toBlockchain: BlockchainMeta | null;
151
- toToken: Token | null;
152
- inputAmount: string;
153
- } {
145
+ findToken: FindToken
146
+ ): RetryQuote {
154
147
  const firstStep = pendingSwap.steps[0];
155
148
  const lastStep = pendingSwap.steps[pendingSwap.steps.length - 1];
156
149
  const lastSuccessfulStep = getLastSuccessfulStep(pendingSwap.steps);
@@ -179,10 +172,9 @@ export function createRetryQuote(
179
172
  blockchain: fromBlockchainMeta?.name ?? '',
180
173
  symbol: firstStep.fromSymbol,
181
174
  address: firstStep.fromSymbolAddress,
182
- },
183
- tokens
175
+ }
184
176
  );
185
- const toTokenMeta = findToken(toToken, tokens);
177
+ const toTokenMeta = findToken(toToken);
186
178
  const inputAmount = lastSuccessfulStep
187
179
  ? lastSuccessfulStep.outputAmount ?? ''
188
180
  : pendingSwap.inputAmount;
@@ -201,11 +193,11 @@ export function generateQuoteWarnings(
201
193
  params: {
202
194
  fromToken: Token;
203
195
  toToken: Token;
204
- tokens: Token[];
196
+ findToken: FindToken;
205
197
  userSlippage: number;
206
198
  }
207
199
  ): QuoteWarning | null {
208
- const { fromToken, toToken, tokens, userSlippage } = params;
200
+ const { fromToken, toToken, findToken, userSlippage } = params;
209
201
  const inputUsdValue = getUsdValue(fromToken, quote.requestAmount);
210
202
  const outputUsdValue = getUsdValue(toToken, quote?.outputAmount ?? '');
211
203
 
@@ -218,7 +210,7 @@ export function generateQuoteWarnings(
218
210
  !!priceImpact && hasHighValueLoss(inputUsdValue, priceImpact);
219
211
 
220
212
  if (highValueLoss) {
221
- const totalFee = getTotalFeeInUsd(quote?.swaps, tokens);
213
+ const totalFee = getTotalFeeInUsd(quote?.swaps, findToken);
222
214
  const warningLevel = getPriceImpactLevel(priceImpact);
223
215
  return {
224
216
  type: QuoteWarningType.HIGH_VALUE_LOSS,
package/src/utils/swap.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-magic-numbers */
2
2
  import type { FeesGroup, NameOfFees } from '../constants/quote';
3
- import type { FetchStatus } from '../store/slices/data';
3
+ import type { FetchStatus, FindToken } from '../store/slices/data';
4
4
  import type { ConnectedWallet } from '../store/wallets';
5
5
  import type {
6
6
  ConvertedToken,
@@ -260,24 +260,9 @@ export function canComputePriceImpact(
260
260
  );
261
261
  }
262
262
 
263
- export const getUsdPrice = (
264
- blockchain: string,
265
- symbol: string,
266
- address: string | null,
267
- allTokens: Token[]
268
- ): number | null => {
269
- const token = allTokens?.find(
270
- (t) =>
271
- t.blockchain === blockchain &&
272
- t.symbol?.toUpperCase() === symbol?.toUpperCase() &&
273
- t.address === address
274
- );
275
- return token?.usdPrice || null;
276
- };
277
-
278
263
  export function getUsdFeeOfStep(
279
264
  step: SwapResult,
280
- allTokens: Token[]
265
+ findToken: FindToken
281
266
  ): BigNumber {
282
267
  let totalFeeInUsd = ZERO;
283
268
  for (let i = 0; i < step.fee.length; i++) {
@@ -286,12 +271,7 @@ export function getUsdFeeOfStep(
286
271
  continue;
287
272
  }
288
273
 
289
- const unitPrice = getUsdPrice(
290
- fee.asset.blockchain,
291
- fee.asset.symbol,
292
- fee.asset.address,
293
- allTokens
294
- );
274
+ const unitPrice = findToken(fee.asset)?.usdPrice || null;
295
275
  totalFeeInUsd = totalFeeInUsd.plus(
296
276
  new BigNumber(fee.amount).multipliedBy(unitPrice || 0)
297
277
  );
@@ -302,11 +282,11 @@ export function getUsdFeeOfStep(
302
282
 
303
283
  export function getTotalFeeInUsd(
304
284
  swaps: SwapResult[],
305
- allTokens: Token[]
285
+ findToken: FindToken
306
286
  ): BigNumber {
307
287
  return swaps.reduce(
308
288
  (totalFee: BigNumber, step) =>
309
- totalFee.plus(getUsdFeeOfStep(step, allTokens)),
289
+ totalFee.plus(getUsdFeeOfStep(step, findToken)),
310
290
  ZERO
311
291
  );
312
292
  }