@rango-dev/widget-embedded 0.37.1-next.1 → 0.38.0

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 (156) hide show
  1. package/dist/QueueManager.d.ts.map +1 -1
  2. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  4. package/dist/components/Layout/Layout.d.ts.map +1 -1
  5. package/dist/components/Quote/Quote.d.ts.map +1 -1
  6. package/dist/components/Quote/Quote.styles.d.ts +1 -1
  7. package/dist/components/Quote/Quote.types.d.ts +0 -2
  8. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  9. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  10. package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
  11. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  12. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  13. package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
  14. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  15. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
  16. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  17. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  18. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  19. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +1 -2
  20. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  21. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  22. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
  23. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  24. package/dist/constants/quote.d.ts +0 -10
  25. package/dist/constants/quote.d.ts.map +1 -1
  26. package/dist/constants/warnings.d.ts +3 -0
  27. package/dist/constants/warnings.d.ts.map +1 -0
  28. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  29. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  30. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  31. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  32. package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
  33. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
  34. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -3
  35. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
  36. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  37. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +4 -6
  38. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  39. package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
  40. package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
  41. package/dist/hooks/useObserveBalanceChanges/index.d.ts +2 -0
  42. package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +1 -0
  43. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +4 -0
  44. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +1 -0
  45. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +1 -2
  46. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  47. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -3
  48. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  49. package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
  50. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  51. package/dist/hooks/useWalletList.d.ts.map +1 -1
  52. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +3 -2
  53. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  54. package/dist/index.d.ts +1 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +2 -2
  57. package/dist/index.js.map +4 -4
  58. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  59. package/dist/pages/Home.d.ts.map +1 -1
  60. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  61. package/dist/store/app.d.ts +4 -2
  62. package/dist/store/app.d.ts.map +1 -1
  63. package/dist/store/quote.d.ts.map +1 -1
  64. package/dist/store/slices/config.d.ts +0 -4
  65. package/dist/store/slices/config.d.ts.map +1 -1
  66. package/dist/store/slices/data.d.ts.map +1 -1
  67. package/dist/store/ui.d.ts +0 -4
  68. package/dist/store/ui.d.ts.map +1 -1
  69. package/dist/store/wallets.d.ts +66 -0
  70. package/dist/store/wallets.d.ts.map +1 -0
  71. package/dist/types/config.d.ts +9 -7
  72. package/dist/types/config.d.ts.map +1 -1
  73. package/dist/types/quote.d.ts +17 -8
  74. package/dist/types/quote.d.ts.map +1 -1
  75. package/dist/types/wallets.d.ts +7 -3
  76. package/dist/types/wallets.d.ts.map +1 -1
  77. package/dist/utils/providers.d.ts +9 -8
  78. package/dist/utils/providers.d.ts.map +1 -1
  79. package/dist/utils/quote.d.ts +6 -5
  80. package/dist/utils/quote.d.ts.map +1 -1
  81. package/dist/utils/settings.d.ts +0 -1
  82. package/dist/utils/settings.d.ts.map +1 -1
  83. package/dist/utils/swap.d.ts +5 -5
  84. package/dist/utils/swap.d.ts.map +1 -1
  85. package/dist/utils/wallets.d.ts +14 -12
  86. package/dist/utils/wallets.d.ts.map +1 -1
  87. package/dist/widget-embedded.build.json +1 -1
  88. package/package.json +9 -9
  89. package/src/QueueManager.tsx +11 -17
  90. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +24 -5
  91. package/src/components/ConfirmWalletsModal/WalletList.tsx +7 -10
  92. package/src/components/Layout/Layout.tsx +3 -1
  93. package/src/components/Quote/Quote.tsx +3 -22
  94. package/src/components/Quote/Quote.types.ts +0 -2
  95. package/src/components/Quote/QuoteCostDetails.styles.ts +1 -0
  96. package/src/components/Quote/QuoteCostDetails.tsx +4 -23
  97. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +22 -42
  98. package/src/components/Quotes/Quotes.tsx +3 -2
  99. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
  100. package/src/components/SwapDetails/SwapDetails.tsx +6 -14
  101. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
  102. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +13 -26
  103. package/src/components/TokenList/TokenList.tsx +27 -4
  104. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +1 -2
  105. package/src/components/WalletStatefulConnect/Namespaces.tsx +38 -31
  106. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
  107. package/src/constants/quote.ts +0 -25
  108. package/src/constants/warnings.ts +26 -0
  109. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +0 -1
  110. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
  111. package/src/containers/Inputs/Inputs.tsx +7 -20
  112. package/src/containers/QuoteInfo/QuoteInfo.tsx +9 -3
  113. package/src/containers/Wallets/Wallets.tsx +16 -82
  114. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
  115. package/src/containers/WidgetInfo/WidgetInfo.tsx +8 -10
  116. package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
  117. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +66 -29
  118. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +15 -10
  119. package/src/hooks/useFetchApiConfig.ts +1 -5
  120. package/src/hooks/useFetchCustomToken.ts +0 -5
  121. package/src/hooks/useObserveBalanceChanges/index.ts +1 -0
  122. package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +68 -0
  123. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +17 -50
  124. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +5 -3
  125. package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +6 -7
  126. package/src/hooks/useSwapInput.ts +11 -3
  127. package/src/hooks/useWalletList.ts +8 -6
  128. package/src/hooks/useWalletProviders/useWalletProviders.ts +12 -8
  129. package/src/index.ts +1 -1
  130. package/src/pages/ConfirmSwapPage.tsx +15 -7
  131. package/src/pages/Home.tsx +3 -5
  132. package/src/pages/SelectSwapItemsPage.tsx +2 -1
  133. package/src/store/app.ts +4 -4
  134. package/src/store/quote.ts +13 -3
  135. package/src/store/slices/config.ts +0 -76
  136. package/src/store/slices/data.test.ts +1 -23
  137. package/src/store/slices/data.ts +2 -3
  138. package/src/store/ui.ts +0 -6
  139. package/src/store/wallets.ts +268 -0
  140. package/src/types/config.ts +9 -8
  141. package/src/types/quote.ts +24 -10
  142. package/src/types/wallets.ts +7 -3
  143. package/src/utils/providers.ts +36 -88
  144. package/src/utils/quote.ts +45 -57
  145. package/src/utils/settings.ts +0 -4
  146. package/src/utils/swap.ts +37 -56
  147. package/src/utils/wallets.ts +141 -76
  148. package/dist/store/slices/types.d.ts +0 -6
  149. package/dist/store/slices/types.d.ts.map +0 -1
  150. package/dist/store/slices/wallets.d.ts +0 -80
  151. package/dist/store/slices/wallets.d.ts.map +0 -1
  152. package/dist/store/utils/wallets.d.ts +0 -17
  153. package/dist/store/utils/wallets.d.ts.map +0 -1
  154. package/src/store/slices/types.ts +0 -9
  155. package/src/store/slices/wallets.ts +0 -577
  156. package/src/store/utils/wallets.ts +0 -111
@@ -1,18 +1,26 @@
1
- import type { BalanceState, ConnectedWallet } from '../store/slices/wallets';
1
+ import type { FindToken } from '../store/slices/data';
2
+ import type { ConnectedWallet, TokenBalance } from '../store/wallets';
2
3
  import type {
3
4
  Balance,
4
5
  SelectedQuote,
6
+ TokensBalance,
5
7
  Wallet,
6
8
  WalletInfoWithExtra,
7
9
  } from '../types';
8
- import type { ExtendedWalletInfo } from '@rango-dev/wallets-react';
10
+ import type { WalletInfo as ModalWalletInfo } from '@rango-dev/ui';
9
11
  import type {
10
12
  Network,
13
+ WalletInfo,
11
14
  WalletState,
12
15
  WalletType,
13
16
  WalletTypes,
14
17
  } from '@rango-dev/wallets-shared';
15
- import type { BlockchainMeta, Token, TransactionType } from 'rango-sdk';
18
+ import type {
19
+ BlockchainMeta,
20
+ Token,
21
+ TransactionType,
22
+ WalletDetail,
23
+ } from 'rango-sdk';
16
24
 
17
25
  import {
18
26
  BlockchainCategories,
@@ -39,11 +47,9 @@ import {
39
47
  import { EXCLUDED_WALLETS } from '../constants/wallets';
40
48
 
41
49
  import { isBlockchainTypeInCategory, removeDuplicateFrom } from './common';
50
+ import { createTokenHash } from './meta';
42
51
  import { numberToString } from './numbers';
43
52
 
44
- export type ExtendedModalWalletInfo = WalletInfoWithExtra &
45
- Pick<ExtendedWalletInfo, 'properties' | 'isHub'>;
46
-
47
53
  export function mapStatusToWalletState(state: WalletState): WalletStatus {
48
54
  switch (true) {
49
55
  case state.connected:
@@ -59,10 +65,10 @@ export function mapStatusToWalletState(state: WalletState): WalletStatus {
59
65
 
60
66
  export function mapWalletTypesToWalletInfo(
61
67
  getState: (type: WalletType) => WalletState,
62
- getWalletInfo: (type: WalletType) => ExtendedWalletInfo,
68
+ getWalletInfo: (type: WalletType) => WalletInfo,
63
69
  list: WalletType[],
64
70
  chain?: string
65
- ): ExtendedModalWalletInfo[] {
71
+ ): WalletInfoWithExtra[] {
66
72
  return list
67
73
  .filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
68
74
  .filter((wallet) => {
@@ -87,11 +93,10 @@ export function mapWalletTypesToWalletInfo(
87
93
  img: image,
88
94
  installLink,
89
95
  showOnMobile,
90
- needsNamespace,
96
+ namespaces,
97
+ singleNamespace,
91
98
  supportedChains,
92
99
  needsDerivationPath,
93
- properties,
94
- isHub,
95
100
  } = getWalletInfo(type);
96
101
  const blockchainTypes = removeDuplicateFrom(
97
102
  supportedChains.map((item) => item.type)
@@ -105,11 +110,10 @@ export function mapWalletTypesToWalletInfo(
105
110
  state,
106
111
  type,
107
112
  showOnMobile,
108
- needsNamespace,
113
+ namespaces,
114
+ singleNamespace,
109
115
  blockchainTypes,
110
116
  needsDerivationPath,
111
- properties,
112
- isHub,
113
117
  };
114
118
  });
115
119
  }
@@ -261,6 +265,8 @@ export function getQuoteWallets(params: {
261
265
  return Array.from(wallets);
262
266
  }
263
267
 
268
+ type Blockchain = { name: string; accounts: ConnectedWallet[] };
269
+
264
270
  export function isAccountAndWalletMatched(
265
271
  account: Wallet,
266
272
  connectedWallet: ConnectedWallet
@@ -272,18 +278,74 @@ export function isAccountAndWalletMatched(
272
278
  );
273
279
  }
274
280
 
281
+ export function makeBalanceFor(
282
+ retrievedBalance: WalletDetail,
283
+ findToken: FindToken
284
+ ): TokenBalance[] {
285
+ const { blockChain: chain, balances = [] } = retrievedBalance;
286
+ return (
287
+ balances?.map((tokenBalance) => ({
288
+ chain,
289
+ symbol: tokenBalance.asset.symbol,
290
+ ticker: tokenBalance.asset.symbol,
291
+ address: tokenBalance.asset.address || null,
292
+ rawAmount: tokenBalance.amount.amount,
293
+ decimal: tokenBalance.amount.decimals,
294
+ amount: new BigNumber(tokenBalance.amount.amount)
295
+ .shiftedBy(-tokenBalance.amount.decimals)
296
+ .toFixed(),
297
+ logo: '',
298
+ usdPrice: findToken(tokenBalance.asset)?.usdPrice || null,
299
+ })) || []
300
+ );
301
+ }
302
+
275
303
  export function resetConnectedWalletState(
276
304
  connectedWallet: ConnectedWallet
277
305
  ): ConnectedWallet {
278
306
  return { ...connectedWallet, loading: false, error: true };
279
307
  }
280
308
 
281
- export const calculateWalletUsdValue = (balances: BalanceState) => {
282
- const total = Object.values(balances).reduce((prev, balance) => {
283
- return balance.usdValue ? prev.plus(balance.usdValue) : prev;
284
- }, new BigNumber(ZERO));
309
+ export const calculateWalletUsdValue = (connectedWallet: ConnectedWallet[]) => {
310
+ const uniqueAccountAddresses = new Set<string | null>();
311
+ const uniqueBalance: ConnectedWallet[] = connectedWallet?.reduce(
312
+ (acc: ConnectedWallet[], current: ConnectedWallet) => {
313
+ return acc.findIndex(
314
+ (i) => i.address === current.address && i.chain === current.chain
315
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
316
+ ) === -1
317
+ ? [...acc, current]
318
+ : acc;
319
+ },
320
+ []
321
+ );
285
322
 
286
- return numberWithThousandSeparator(total.toString());
323
+ const modifiedWalletBlockchains = uniqueBalance?.map((chain) => {
324
+ const modifiedWalletBlockchain: Blockchain = {
325
+ name: chain.chain,
326
+ accounts: [],
327
+ };
328
+ if (!uniqueAccountAddresses.has(chain.address)) {
329
+ uniqueAccountAddresses.add(chain.address);
330
+ }
331
+ uniqueAccountAddresses.forEach((accountAddress) => {
332
+ if (chain.address === accountAddress) {
333
+ modifiedWalletBlockchain.accounts.push(chain);
334
+ }
335
+ });
336
+ return modifiedWalletBlockchain;
337
+ });
338
+ const total = numberToString(
339
+ modifiedWalletBlockchains
340
+ ?.flatMap((b) => b.accounts)
341
+ ?.flatMap((a) => a?.balances)
342
+ ?.map((b) =>
343
+ new BigNumber(b?.amount || ZERO).multipliedBy(b?.usdPrice || 0)
344
+ )
345
+ ?.reduce((a, b) => a.plus(b), ZERO) || ZERO
346
+ ).toString();
347
+
348
+ return numberWithThousandSeparator(total);
287
349
  };
288
350
 
289
351
  function numberWithThousandSeparator(number: string | number): string {
@@ -322,31 +384,19 @@ export const getKeplrCompatibleConnectedWallets = (
322
384
  };
323
385
 
324
386
  export function formatBalance(balance: Balance | null): Balance | null {
325
- if (!balance) {
326
- return null;
327
- }
328
-
329
- const amount = new BigNumber(balance.amount)
330
- .shiftedBy(-balance.decimals)
331
- .toFixed();
332
- const usdValue = balance.usdValue
333
- ? new BigNumber(balance.usdValue).shiftedBy(-balance.decimals).toFixed()
334
- : null;
335
- const formattedAmount = numberToString(
336
- amount,
337
- BALANCE_MIN_DECIMALS,
338
- BALANCE_MAX_DECIMALS
339
- );
340
- // null is using for detecing uknown prices
341
- const formattedUsdValue = usdValue
342
- ? numberToString(usdValue, USD_VALUE_MIN_DECIMALS, USD_VALUE_MAX_DECIMALS)
343
- : null;
344
-
345
387
  const formattedBalance: Balance | null = balance
346
388
  ? {
347
389
  ...balance,
348
- amount: formattedAmount,
349
- usdValue: formattedUsdValue,
390
+ amount: numberToString(
391
+ balance.amount,
392
+ BALANCE_MIN_DECIMALS,
393
+ BALANCE_MAX_DECIMALS
394
+ ),
395
+ usdValue: numberToString(
396
+ balance.usdValue,
397
+ USD_VALUE_MIN_DECIMALS,
398
+ USD_VALUE_MAX_DECIMALS
399
+ ),
350
400
  }
351
401
  : null;
352
402
 
@@ -358,39 +408,17 @@ export function compareTokenBalance(
358
408
  token2Balance: Balance | null
359
409
  ): number {
360
410
  if (token1Balance?.usdValue || token2Balance?.usdValue) {
361
- const token1UsdValue =
362
- !!token1Balance && !!token1Balance.usdValue
363
- ? new BigNumber(token1Balance.usdValue).shiftedBy(
364
- -token1Balance.decimals
365
- )
366
- : ZERO;
367
- const token2UsdValue =
368
- !!token2Balance && !!token2Balance.usdValue
369
- ? new BigNumber(token2Balance.usdValue).shiftedBy(
370
- -token2Balance.decimals
371
- )
372
- : ZERO;
373
-
374
- if (token1UsdValue.isEqualTo(token2UsdValue)) {
375
- return 0;
376
- }
377
- return token1UsdValue.isGreaterThan(token2UsdValue) ? -1 : 1;
411
+ return (
412
+ parseFloat(token2Balance?.usdValue || '0') -
413
+ parseFloat(token1Balance?.usdValue || '0')
414
+ );
378
415
  }
379
416
 
380
417
  if (token1Balance?.amount || token2Balance?.amount) {
381
- const token1Amount =
382
- !!token1Balance && !!token1Balance.amount
383
- ? new BigNumber(token1Balance.amount).shiftedBy(-token1Balance.decimals)
384
- : ZERO;
385
- const token2Amount =
386
- !!token2Balance && !!token2Balance.amount
387
- ? new BigNumber(token2Balance.amount).shiftedBy(-token2Balance.decimals)
388
- : ZERO;
389
-
390
- if (token1Amount.isEqualTo(token2Amount)) {
391
- return 0;
392
- }
393
- return token1Amount.isGreaterThan(token2Amount) ? -1 : 1;
418
+ return (
419
+ parseFloat(token2Balance?.amount || '0') -
420
+ parseFloat(token1Balance?.amount || '0')
421
+ );
394
422
  }
395
423
 
396
424
  return 0;
@@ -408,8 +436,8 @@ export function areTokensEqual(
408
436
  }
409
437
 
410
438
  export function sortWalletsBasedOnConnectionState(
411
- wallets: ExtendedModalWalletInfo[]
412
- ): ExtendedModalWalletInfo[] {
439
+ wallets: WalletInfoWithExtra[]
440
+ ): WalletInfoWithExtra[] {
413
441
  return wallets.sort(
414
442
  (a, b) =>
415
443
  Number(b.state === WalletStatus.CONNECTED) -
@@ -456,6 +484,43 @@ export function getAddress({
456
484
  )?.address;
457
485
  }
458
486
 
487
+ export function makeTokensBalance(connectedWallets: ConnectedWallet[]) {
488
+ return connectedWallets
489
+ .flatMap((wallet) => wallet.balances)
490
+ .reduce((balances: TokensBalance, balance) => {
491
+ const currentBalance = {
492
+ amount: balance?.amount ?? '',
493
+ decimals: balance?.decimal ?? 0,
494
+ usdValue: balance?.usdPrice
495
+ ? new BigNumber(balance?.usdPrice ?? ZERO)
496
+ .multipliedBy(balance?.amount)
497
+ .toString()
498
+ : '',
499
+ };
500
+
501
+ const tokenHash = balance
502
+ ? createTokenHash({
503
+ symbol: balance.symbol,
504
+ blockchain: balance.chain,
505
+ address: balance.address,
506
+ })
507
+ : null;
508
+
509
+ const prevBalance = tokenHash ? balances[tokenHash] : null;
510
+
511
+ const shouldUpdateBalance =
512
+ tokenHash &&
513
+ (!prevBalance ||
514
+ (prevBalance && prevBalance.amount < currentBalance.amount));
515
+
516
+ if (shouldUpdateBalance) {
517
+ balances[tokenHash] = currentBalance;
518
+ }
519
+
520
+ return balances;
521
+ }, {});
522
+ }
523
+
459
524
  export const isFetchingBalance = (
460
525
  connectedWallets: ConnectedWallet[],
461
526
  blockchain: string
@@ -464,12 +529,12 @@ export const isFetchingBalance = (
464
529
  (wallet) => wallet.chain === blockchain && wallet.loading
465
530
  );
466
531
 
467
- export function hashWalletsState(walletsInfo: WalletInfoWithExtra[]) {
532
+ export function hashWalletsState(walletsInfo: ModalWalletInfo[]) {
468
533
  return walletsInfo.map((w) => w.state).join('-');
469
534
  }
470
535
 
471
536
  export function filterBlockchainsByWalletTypes(
472
- wallets: WalletInfoWithExtra[],
537
+ wallets: ModalWalletInfo[],
473
538
  blockchains: BlockchainMeta[]
474
539
  ) {
475
540
  const uniqueBlockchainTypes = new Set<TransactionType>();
@@ -486,7 +551,7 @@ export function filterBlockchainsByWalletTypes(
486
551
  }
487
552
 
488
553
  export function filterWalletsByCategory(
489
- wallets: ExtendedModalWalletInfo[],
554
+ wallets: WalletInfoWithExtra[],
490
555
  category: string
491
556
  ) {
492
557
  if (category === BlockchainCategories.ALL) {
@@ -1,6 +0,0 @@
1
- import type { ConfigSlice } from './config';
2
- import type { DataSlice } from './data';
3
- import type { SettingsSlice } from './settings';
4
- import type { WalletsSlice } from './wallets';
5
- export type AppStoreState = DataSlice & ConfigSlice & SettingsSlice & WalletsSlice;
6
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/store/slices/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG,SAAS,GACnC,WAAW,GACX,aAAa,GACb,YAAY,CAAC"}
@@ -1,80 +0,0 @@
1
- import type { AppStoreState } from './types';
2
- import type { Token } from 'rango-sdk';
3
- import type { StateCreator } from 'zustand';
4
- import { type Balance, type Wallet } from '../../types';
5
- type WalletAddress = string;
6
- type TokenAddress = string;
7
- type TokenSymbol = string;
8
- type BlockchainId = string;
9
- /** format: `BlockchainId-TokenAddress-TokenSymbol` */
10
- export type AssetKey = `${BlockchainId}-${TokenAddress}-${TokenSymbol}`;
11
- /** format: `BlockchainId-TokenAddress-TokenSymbol-WalletAddress` */
12
- export type BalanceKey = `${BlockchainId}-${TokenAddress}-${TokenSymbol}-${WalletAddress}`;
13
- export type BalanceState = {
14
- [key: BalanceKey]: Balance;
15
- };
16
- export type AggregatedBalanceState = {
17
- [key: AssetKey]: BalanceKey[];
18
- };
19
- export interface ConnectedWallet extends Wallet {
20
- explorerUrl: string | null;
21
- selected: boolean;
22
- loading: boolean;
23
- error: boolean;
24
- }
25
- interface DeprecatedTokenBalance {
26
- chain: string;
27
- symbol: string;
28
- ticker: string;
29
- address: string | null;
30
- rawAmount: string;
31
- decimal: number | null;
32
- amount: string;
33
- logo: string | null;
34
- usdPrice: number | null;
35
- }
36
- export interface DeprecatedWalletDetail extends ConnectedWallet {
37
- balances: DeprecatedTokenBalance[] | null;
38
- }
39
- export interface WalletsSlice {
40
- _balances: BalanceState;
41
- _aggregatedBalances: AggregatedBalanceState;
42
- connectedWallets: ConnectedWallet[];
43
- fetchingWallets: boolean;
44
- setConnectedWalletAsRefetching: (walletType: string) => void;
45
- setConnectedWalletHasError: (walletType: string) => void;
46
- setConnectedWalletRetrievedData: (walletType: string) => void;
47
- removeBalancesForWallet: (walletType: string, options?: {
48
- chains?: string[];
49
- }) => void;
50
- addConnectedWallet: (accounts: Wallet[]) => void;
51
- setWalletsAsSelected: (wallets: {
52
- walletType: string;
53
- chain: string;
54
- }[]) => void;
55
- /**
56
- * Add new accounts to store and fetch balances for them.
57
- */
58
- newWalletConnected: (accounts: Wallet[]) => Promise<void>;
59
- /**
60
- * Disconnect a wallet and clean up balances after that.
61
- */
62
- disconnectWallet: (walletType: string) => void;
63
- clearConnectedWallet: () => void;
64
- fetchBalances: (accounts: Wallet[], options?: {
65
- retryOnFailedBalances?: boolean;
66
- }) => Promise<void>;
67
- getBalanceFor: (token: Token) => Balance | null;
68
- getBalances: () => BalanceState;
69
- getBalancesForWalletAddress: (address: string) => BalanceState;
70
- /**
71
- * @deprecated
72
- * This is been added for backward compatibilty for WidgetInfo
73
- */
74
- getConnectedWalletsDetails: () => DeprecatedWalletDetail[];
75
- }
76
- export declare const createWalletsSlice: StateCreator<AppStoreState, [
77
- ], [
78
- ], WalletsSlice>;
79
- export {};
80
- //# sourceMappingURL=wallets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../../src/store/slices/wallets.ts"],"names":[],"mappings":"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"}
@@ -1,17 +0,0 @@
1
- import type { AppStoreState } from '../app';
2
- import type { AggregatedBalanceState, AssetKey, BalanceKey, BalanceState } from '../slices/wallets';
3
- import type { Asset, WalletDetail } from 'rango-types';
4
- /**
5
- * Note: We need to use `symbol` as well since native coins and cosmos blockchains don't have `address`
6
- * output format: BlockchainId-TokenAddress-TokenSymbol
7
- */
8
- export declare function createAssetKey(asset: Asset): AssetKey;
9
- /**
10
- * output format: BlockchainId-TokenAddress-TokenSymbol-WalletAddress
11
- */
12
- export declare function createBalanceKey(accountAddress: string, asset: Asset): BalanceKey;
13
- export declare function extractAssetFromBalanceKey(key: BalanceKey): Asset;
14
- export declare function createBalanceStateForNewAccount(account: WalletDetail, store: () => AppStoreState): BalanceState;
15
- export declare function updateAggregatedBalanceStateForNewAccount(aggregatedBalances: AggregatedBalanceState, balanceState: BalanceState): AggregatedBalanceState;
16
- export declare function removeBalanceFromAggregatedBalance(aggregatedBalances: AggregatedBalanceState, balanceKey: BalanceKey): AggregatedBalanceState;
17
- //# sourceMappingURL=wallets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../../src/store/utils/wallets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EACV,sBAAsB,EACtB,QAAQ,EACR,UAAU,EACV,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMvD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAErD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,KAAK,GACX,UAAU,CAGZ;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,UAAU,GAAG,KAAK,CAUjE;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE,MAAM,aAAa,GACzB,YAAY,CAuBd;AAED,wBAAgB,yCAAyC,CACvD,kBAAkB,EAAE,sBAAsB,EAC1C,YAAY,EAAE,YAAY,0BAmB3B;AAED,wBAAgB,kCAAkC,CAChD,kBAAkB,EAAE,sBAAsB,EAC1C,UAAU,EAAE,UAAU,0BAYvB"}
@@ -1,9 +0,0 @@
1
- import type { ConfigSlice } from './config';
2
- import type { DataSlice } from './data';
3
- import type { SettingsSlice } from './settings';
4
- import type { WalletsSlice } from './wallets';
5
-
6
- export type AppStoreState = DataSlice &
7
- ConfigSlice &
8
- SettingsSlice &
9
- WalletsSlice;