@dynamic-labs/sdk-react-core 4.5.1 → 4.5.2

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 (79) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/lib/components/NetworkPicker/NetworkPicker.cjs +11 -40
  6. package/src/lib/components/NetworkPicker/NetworkPicker.d.ts +2 -6
  7. package/src/lib/components/NetworkPicker/NetworkPicker.js +12 -41
  8. package/src/lib/components/NetworkPicker/components/NetworkControl/NetworkControl.cjs +6 -8
  9. package/src/lib/components/NetworkPicker/components/NetworkControl/NetworkControl.d.ts +2 -4
  10. package/src/lib/components/NetworkPicker/components/NetworkControl/NetworkControl.js +6 -8
  11. package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.cjs +67 -0
  12. package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.d.ts +14 -0
  13. package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.js +63 -0
  14. package/src/lib/components/NetworkPicker/components/NetworkDropdown/index.d.ts +1 -0
  15. package/src/lib/components/NetworkPicker/components/{EvmNetworkControl/EvmNetworkControl.cjs → NetworkSwitchControl/NetworkSwitchControl.cjs} +27 -36
  16. package/src/lib/components/NetworkPicker/components/NetworkSwitchControl/NetworkSwitchControl.d.ts +16 -0
  17. package/src/lib/components/NetworkPicker/components/{EvmNetworkControl/EvmNetworkControl.js → NetworkSwitchControl/NetworkSwitchControl.js} +27 -35
  18. package/src/lib/components/NetworkPicker/components/NetworkSwitchControl/index.d.ts +1 -0
  19. package/src/lib/components/Portal/Portal.cjs +3 -2
  20. package/src/lib/components/Portal/Portal.js +3 -2
  21. package/src/lib/locale/en/translation.cjs +13 -29
  22. package/src/lib/locale/en/translation.d.ts +11 -27
  23. package/src/lib/locale/en/translation.js +13 -29
  24. package/src/lib/shared/assets/index.d.ts +1 -0
  25. package/src/lib/shared/assets/{currency.cjs → wallet-with-sunglasses.cjs} +14 -26
  26. package/src/lib/shared/assets/wallet-with-sunglasses.js +34 -0
  27. package/src/lib/styles/index.shadow.cjs +1 -1
  28. package/src/lib/styles/index.shadow.js +1 -1
  29. package/src/lib/utils/functions/isNetworkUnsupported/isNetworkUnsupported.cjs +2 -4
  30. package/src/lib/utils/functions/isNetworkUnsupported/isNetworkUnsupported.d.ts +2 -2
  31. package/src/lib/utils/functions/isNetworkUnsupported/isNetworkUnsupported.js +2 -4
  32. package/src/lib/views/CollectUserDataView/CollectUserDataView.cjs +2 -4
  33. package/src/lib/views/CollectUserDataView/CollectUserDataView.js +2 -4
  34. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +3 -4
  35. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +3 -4
  36. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +6 -9
  37. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +7 -10
  38. package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.cjs +2 -6
  39. package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.js +2 -6
  40. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/ReceiveExternalWalletFunds.cjs +98 -49
  41. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/ReceiveExternalWalletFunds.js +94 -45
  42. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenOption/TokenOption.cjs +21 -10
  43. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenOption/TokenOption.d.ts +2 -0
  44. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenOption/TokenOption.js +21 -10
  45. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenSelectScreen.cjs +3 -3
  46. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenSelectScreen.d.ts +2 -0
  47. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenSelectScreen.js +3 -3
  48. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/types.d.ts +2 -0
  49. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/calculateFiatBalance.cjs +27 -0
  50. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/calculateFiatBalance.d.ts +2 -0
  51. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/calculateFiatBalance.js +23 -0
  52. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/index.d.ts +1 -0
  53. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/convert/convert.cjs +4 -0
  54. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/convert/convert.js +4 -0
  55. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/convertScientificToDecimal.cjs +33 -0
  56. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/convertScientificToDecimal.d.ts +8 -0
  57. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/convertScientificToDecimal.js +29 -0
  58. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/index.d.ts +1 -0
  59. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/formatValue.cjs +26 -27
  60. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/formatValue.d.ts +6 -0
  61. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/formatValue.js +26 -27
  62. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/isFiatToken/isFiatToken.cjs +2 -0
  63. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/isFiatToken/isFiatToken.d.ts +1 -0
  64. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/isFiatToken/isFiatToken.js +2 -1
  65. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/index.d.ts +1 -0
  66. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/useExchangeRatesForFunding.cjs +32 -0
  67. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/useExchangeRatesForFunding.d.ts +9 -0
  68. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/useExchangeRatesForFunding.js +28 -0
  69. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useTokensForFunding/useTokensForFunding.cjs +27 -15
  70. package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useTokensForFunding/useTokensForFunding.js +27 -15
  71. package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/EmptyScreen.cjs +20 -0
  72. package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/EmptyScreen.d.ts +2 -0
  73. package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/EmptyScreen.js +16 -0
  74. package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/index.d.ts +1 -0
  75. package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.cjs +3 -6
  76. package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.js +3 -6
  77. package/src/lib/components/NetworkPicker/components/EvmNetworkControl/EvmNetworkControl.d.ts +0 -23
  78. package/src/lib/components/NetworkPicker/components/EvmNetworkControl/index.d.ts +0 -1
  79. package/src/lib/shared/assets/currency.js +0 -46
@@ -4,8 +4,6 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
- var reactI18next = require('react-i18next');
8
- var Image = require('../../../../../../components/Image/Image.cjs');
9
7
  var classNames = require('../../../../../../utils/functions/classNames/classNames.cjs');
10
8
  require('../../../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
11
9
  require('../../../../../../components/Alert/Alert.cjs');
@@ -56,6 +54,7 @@ require('../../../../../../context/UserFieldEditorContext/UserFieldEditorContext
56
54
  require('@dynamic-labs/rpc-providers');
57
55
  require('../../../../../../store/state/loadingAndLifecycle.cjs');
58
56
  require('../../../../../../store/state/walletOptions/walletOptions.cjs');
57
+ require('react-i18next');
59
58
  var Typography = require('../../../../../../components/Typography/Typography.cjs');
60
59
  require('../../../../../../context/FooterAnimationContext/index.cjs');
61
60
  require('../../../../../../components/ShadowDOM/ShadowDOM.cjs');
@@ -69,6 +68,7 @@ require('react-focus-lock');
69
68
  require('../../../../context/DynamicWidgetContext.cjs');
70
69
  require('../../../../../../components/IconButton/IconButton.cjs');
71
70
  require('../../../../../../components/MenuList/Dropdown/Dropdown.cjs');
71
+ var Image = require('../../../../../../components/Image/Image.cjs');
72
72
  require('formik');
73
73
  require('../../../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
74
74
  require('../../../../../../store/state/sendBalances.cjs');
@@ -93,18 +93,29 @@ require('../../../../../../components/InlineWidget/InlineWidget.cjs');
93
93
  require('../../../../../../components/IsBrowser/IsBrowser.cjs');
94
94
  require('../../../../../../components/Popper/Popper/Popper.cjs');
95
95
  require('../../../../../../components/Popper/PopperContext/PopperContext.cjs');
96
+ var calculateFiatBalance = require('../../utils/calculateFiatBalance/calculateFiatBalance.cjs');
96
97
  var formatValue = require('../../utils/formatValue/formatValue.cjs');
98
+ var isFiatToken = require('../../utils/isFiatToken/isFiatToken.cjs');
97
99
 
98
- const TokenOption = ({ token, isSelected, onSelect, }) => {
99
- const { t } = reactI18next.useTranslation();
100
+ const TokenOption = ({ token, isSelected, onSelect, showTokenAsPrimary, exchangeRates, }) => {
101
+ const fiatBalance = formatValue.formatValue({
102
+ maxDecimals: 2,
103
+ symbol: 'USD',
104
+ value: calculateFiatBalance.calculateFiatBalance(token, exchangeRates),
105
+ withFixedZeros: true,
106
+ });
107
+ const tokenBalance = formatValue.formatValue({
108
+ maxDecimals: isFiatToken.isFiatOrStablecoin(token.symbol) ? 2 : 6,
109
+ symbol: token.symbol,
110
+ value: token.balance,
111
+ withFixedZeros: isFiatToken.isFiatOrStablecoin(token.symbol),
112
+ });
113
+ const [primaryBalance, secondaryBalance] = showTokenAsPrimary
114
+ ? [tokenBalance, fiatBalance]
115
+ : [fiatBalance, tokenBalance];
100
116
  return (jsxRuntime.jsxs("div", { className: classNames.classNames('token-option', {
101
117
  'token-option--selected': isSelected,
102
- }), onClick: onSelect, "data-testid": `token-option-${token.symbol}`, children: [token.logoURI ? (jsxRuntime.jsx(Image.Image, { src: token.logoURI, alt: token.symbol, className: 'token-option__icon', dataTestId: 'token-option-icon' })) : (jsxRuntime.jsx("div", { className: 'token-option__icon--skeleton', "data-testid": 'token-option__icon--skeleton' })), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', className: 'token-option__name', children: token.name }), jsxRuntime.jsxs("div", { className: 'token-option__balance-container', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', className: 'token-option__balance-label', color: 'secondary', weight: 'medium', children: t('dyn_wallet_funding.from_external_wallet.token_select.token_option.balance_label') }), jsxRuntime.jsx("div", { className: 'token-option__balance-container__balance-value-container', children: jsxRuntime.jsx(Typography.Typography, { weight: 'medium', variant: 'body_small', children: formatValue.formatValue({
103
- maxDecimals: 8,
104
- symbol: token.symbol,
105
- value: token.balance,
106
- withFixedZeros: token.symbol === 'USDC',
107
- }) }) })] })] }));
118
+ }), onClick: onSelect, "data-testid": `token-option-${token.symbol}`, children: [token.logoURI ? (jsxRuntime.jsx(Image.Image, { src: token.logoURI, alt: token.symbol, className: 'token-option__icon', dataTestId: 'token-option-icon' })) : (jsxRuntime.jsx("div", { className: 'token-option__icon--skeleton', "data-testid": 'token-option__icon--skeleton' })), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', className: 'token-option__name', children: token.name }), jsxRuntime.jsxs("div", { className: 'token-option__balance-container', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'medium', "data-testid": 'token-option__primary-balance', children: primaryBalance }), jsxRuntime.jsx(Typography.Typography, { weight: 'medium', variant: 'body_small', color: 'secondary', "data-testid": 'token-option__secondary-balance', children: secondaryBalance })] })] }));
108
119
  };
109
120
 
110
121
  exports.TokenOption = TokenOption;
@@ -4,6 +4,8 @@ type TokenOptionProps = {
4
4
  token: FundingTokenData;
5
5
  isSelected: boolean;
6
6
  onSelect: () => void;
7
+ showTokenAsPrimary: boolean;
8
+ exchangeRates: Record<string, number>;
7
9
  };
8
10
  export declare const TokenOption: FC<TokenOptionProps>;
9
11
  export {};
@@ -1,7 +1,5 @@
1
1
  'use client'
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { useTranslation } from 'react-i18next';
4
- import { Image } from '../../../../../../components/Image/Image.js';
5
3
  import { classNames } from '../../../../../../utils/functions/classNames/classNames.js';
6
4
  import '../../../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
7
5
  import '../../../../../../components/Alert/Alert.js';
@@ -52,6 +50,7 @@ import '../../../../../../context/UserFieldEditorContext/UserFieldEditorContext.
52
50
  import '@dynamic-labs/rpc-providers';
53
51
  import '../../../../../../store/state/loadingAndLifecycle.js';
54
52
  import '../../../../../../store/state/walletOptions/walletOptions.js';
53
+ import 'react-i18next';
55
54
  import { Typography } from '../../../../../../components/Typography/Typography.js';
56
55
  import '../../../../../../context/FooterAnimationContext/index.js';
57
56
  import '../../../../../../components/ShadowDOM/ShadowDOM.js';
@@ -65,6 +64,7 @@ import 'react-focus-lock';
65
64
  import '../../../../context/DynamicWidgetContext.js';
66
65
  import '../../../../../../components/IconButton/IconButton.js';
67
66
  import '../../../../../../components/MenuList/Dropdown/Dropdown.js';
67
+ import { Image } from '../../../../../../components/Image/Image.js';
68
68
  import 'formik';
69
69
  import '../../../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
70
70
  import '../../../../../../store/state/sendBalances.js';
@@ -89,18 +89,29 @@ import '../../../../../../components/InlineWidget/InlineWidget.js';
89
89
  import '../../../../../../components/IsBrowser/IsBrowser.js';
90
90
  import '../../../../../../components/Popper/Popper/Popper.js';
91
91
  import '../../../../../../components/Popper/PopperContext/PopperContext.js';
92
+ import { calculateFiatBalance } from '../../utils/calculateFiatBalance/calculateFiatBalance.js';
92
93
  import { formatValue } from '../../utils/formatValue/formatValue.js';
94
+ import { isFiatOrStablecoin } from '../../utils/isFiatToken/isFiatToken.js';
93
95
 
94
- const TokenOption = ({ token, isSelected, onSelect, }) => {
95
- const { t } = useTranslation();
96
+ const TokenOption = ({ token, isSelected, onSelect, showTokenAsPrimary, exchangeRates, }) => {
97
+ const fiatBalance = formatValue({
98
+ maxDecimals: 2,
99
+ symbol: 'USD',
100
+ value: calculateFiatBalance(token, exchangeRates),
101
+ withFixedZeros: true,
102
+ });
103
+ const tokenBalance = formatValue({
104
+ maxDecimals: isFiatOrStablecoin(token.symbol) ? 2 : 6,
105
+ symbol: token.symbol,
106
+ value: token.balance,
107
+ withFixedZeros: isFiatOrStablecoin(token.symbol),
108
+ });
109
+ const [primaryBalance, secondaryBalance] = showTokenAsPrimary
110
+ ? [tokenBalance, fiatBalance]
111
+ : [fiatBalance, tokenBalance];
96
112
  return (jsxs("div", { className: classNames('token-option', {
97
113
  'token-option--selected': isSelected,
98
- }), onClick: onSelect, "data-testid": `token-option-${token.symbol}`, children: [token.logoURI ? (jsx(Image, { src: token.logoURI, alt: token.symbol, className: 'token-option__icon', dataTestId: 'token-option-icon' })) : (jsx("div", { className: 'token-option__icon--skeleton', "data-testid": 'token-option__icon--skeleton' })), jsx(Typography, { variant: 'body_normal', className: 'token-option__name', children: token.name }), jsxs("div", { className: 'token-option__balance-container', children: [jsx(Typography, { variant: 'body_small', className: 'token-option__balance-label', color: 'secondary', weight: 'medium', children: t('dyn_wallet_funding.from_external_wallet.token_select.token_option.balance_label') }), jsx("div", { className: 'token-option__balance-container__balance-value-container', children: jsx(Typography, { weight: 'medium', variant: 'body_small', children: formatValue({
99
- maxDecimals: 8,
100
- symbol: token.symbol,
101
- value: token.balance,
102
- withFixedZeros: token.symbol === 'USDC',
103
- }) }) })] })] }));
114
+ }), onClick: onSelect, "data-testid": `token-option-${token.symbol}`, children: [token.logoURI ? (jsx(Image, { src: token.logoURI, alt: token.symbol, className: 'token-option__icon', dataTestId: 'token-option-icon' })) : (jsx("div", { className: 'token-option__icon--skeleton', "data-testid": 'token-option__icon--skeleton' })), jsx(Typography, { variant: 'body_normal', className: 'token-option__name', children: token.name }), jsxs("div", { className: 'token-option__balance-container', children: [jsx(Typography, { variant: 'body_small', weight: 'medium', "data-testid": 'token-option__primary-balance', children: primaryBalance }), jsx(Typography, { weight: 'medium', variant: 'body_small', color: 'secondary', "data-testid": 'token-option__secondary-balance', children: secondaryBalance })] })] }));
104
115
  };
105
116
 
106
117
  export { TokenOption };
@@ -81,6 +81,7 @@ require('../../../../../components/OverlayCard/OverlayCard.cjs');
81
81
  require('../../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
82
82
  require('../../../../../context/PasskeyContext/PasskeyContext.cjs');
83
83
  require('../../ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
84
+ var LinearGradientFrame = require('../../../../../components/LinearGradientFrame/LinearGradientFrame.cjs');
84
85
  require('../../../../../context/OnrampContext/OnrampContext.cjs');
85
86
  require('qrcode');
86
87
  require('../ReceiveExternalWalletFunds.cjs');
@@ -97,10 +98,9 @@ require('../../../../../components/InlineWidget/InlineWidget.cjs');
97
98
  require('../../../../../components/IsBrowser/IsBrowser.cjs');
98
99
  require('../../../../../components/Popper/Popper/Popper.cjs');
99
100
  require('../../../../../components/Popper/PopperContext/PopperContext.cjs');
100
- var LinearGradientFrame = require('../../../../../components/LinearGradientFrame/LinearGradientFrame.cjs');
101
101
  var TokenOption = require('./TokenOption/TokenOption.cjs');
102
102
 
103
- const TokenSelectScreen = ({ onClose, onSelectToken, currentToken, tokens, className, style, }) => {
103
+ const TokenSelectScreen = ({ onClose, onSelectToken, currentToken, tokens, className, style, showTokenAsPrimary, exchangeRates, }) => {
104
104
  const { t } = reactI18next.useTranslation();
105
105
  const [search$1, setSearch] = React.useState('');
106
106
  const filteredTokens = tokens.filter((token) => {
@@ -114,7 +114,7 @@ const TokenSelectScreen = ({ onClose, onSelectToken, currentToken, tokens, class
114
114
  const closeButton = (jsxRuntime.jsx(IconButton.IconButton, { type: 'button', id: 'close-button', "data-testid": 'close-button', onClick: onClose, children: jsxRuntime.jsx(close.ReactComponent, {}) }));
115
115
  return (jsxRuntime.jsxs("div", { className: classNames.classNames('token-select', className), style: style, "data-testid": 'token-select', children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { trailing: closeButton, children: jsxRuntime.jsx(Typography.Typography, { variant: 'title', children: t(noAssets
116
116
  ? 'dyn_wallet_funding.from_external_wallet.token_select.no_assets_title'
117
- : 'dyn_wallet_funding.from_external_wallet.token_select.title') }) }), noAssets && (jsxRuntime.jsxs("div", { className: 'token-select__no-assets', children: [jsxRuntime.jsx(LinearGradientFrame.LinearGradientFrame, { Icon: jsxRuntime.jsx(walletIllustration.ReactComponent, {}) }), jsxRuntime.jsx(Typography.Typography, { variant: 'title', color: 'secondary', weight: 'medium', children: t('dyn_wallet_funding.from_external_wallet.token_select.no_assets_description') })] })), !noAssets && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("label", { htmlFor: 'token-select-search', className: 'token-select__search', children: [jsxRuntime.jsx(Icon.Icon, { color: 'text-tertiary', size: 'small', children: jsxRuntime.jsx(search.ReactComponent, {}) }), jsxRuntime.jsx("input", { id: 'token-select-search', placeholder: t('dyn_wallet_funding.from_external_wallet.token_select.search_placeholder'), className: 'token-select__search__input', value: search$1, onChange: (e) => setSearch(e.target.value) })] }), jsxRuntime.jsx("div", { className: 'token-select__tokens', children: filteredTokens.map((token) => (jsxRuntime.jsx(TokenOption.TokenOption, { token: token, isSelected: token.symbol === currentToken, onSelect: () => onSelectToken(token.symbol) }, token.symbol))) })] }))] }));
117
+ : 'dyn_wallet_funding.from_external_wallet.token_select.title') }) }), noAssets && (jsxRuntime.jsxs("div", { className: 'token-select__no-assets', children: [jsxRuntime.jsx(LinearGradientFrame.LinearGradientFrame, { Icon: jsxRuntime.jsx(walletIllustration.ReactComponent, {}) }), jsxRuntime.jsx(Typography.Typography, { variant: 'title', color: 'secondary', weight: 'medium', children: t('dyn_wallet_funding.from_external_wallet.token_select.no_assets_description') })] })), !noAssets && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("label", { htmlFor: 'token-select-search', className: 'token-select__search', children: [jsxRuntime.jsx(Icon.Icon, { color: 'text-tertiary', size: 'small', children: jsxRuntime.jsx(search.ReactComponent, {}) }), jsxRuntime.jsx("input", { id: 'token-select-search', placeholder: t('dyn_wallet_funding.from_external_wallet.token_select.search_placeholder'), className: 'token-select__search__input', value: search$1, onChange: (e) => setSearch(e.target.value) })] }), jsxRuntime.jsx("div", { className: 'token-select__tokens', children: filteredTokens.map((token) => (jsxRuntime.jsx(TokenOption.TokenOption, { token: token, isSelected: token.symbol === currentToken, onSelect: () => onSelectToken(token.symbol), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates }, token.symbol))) })] }))] }));
118
118
  };
119
119
 
120
120
  exports.TokenSelectScreen = TokenSelectScreen;
@@ -6,6 +6,8 @@ type TokenSelectScreenProps = ClassStyleProps & {
6
6
  onSelectToken: (token: FundingTokenData['symbol']) => void;
7
7
  tokens: FundingTokenData[];
8
8
  currentToken: FundingTokenData['symbol'];
9
+ showTokenAsPrimary: boolean;
10
+ exchangeRates: Record<string, number>;
9
11
  };
10
12
  export declare const TokenSelectScreen: FC<TokenSelectScreenProps>;
11
13
  export {};
@@ -77,6 +77,7 @@ import '../../../../../components/OverlayCard/OverlayCard.js';
77
77
  import '../../../../../views/TransactionConfirmationView/TransactionConfirmationView.js';
78
78
  import '../../../../../context/PasskeyContext/PasskeyContext.js';
79
79
  import '../../ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
80
+ import { LinearGradientFrame } from '../../../../../components/LinearGradientFrame/LinearGradientFrame.js';
80
81
  import '../../../../../context/OnrampContext/OnrampContext.js';
81
82
  import 'qrcode';
82
83
  import '../ReceiveExternalWalletFunds.js';
@@ -93,10 +94,9 @@ import '../../../../../components/InlineWidget/InlineWidget.js';
93
94
  import '../../../../../components/IsBrowser/IsBrowser.js';
94
95
  import '../../../../../components/Popper/Popper/Popper.js';
95
96
  import '../../../../../components/Popper/PopperContext/PopperContext.js';
96
- import { LinearGradientFrame } from '../../../../../components/LinearGradientFrame/LinearGradientFrame.js';
97
97
  import { TokenOption } from './TokenOption/TokenOption.js';
98
98
 
99
- const TokenSelectScreen = ({ onClose, onSelectToken, currentToken, tokens, className, style, }) => {
99
+ const TokenSelectScreen = ({ onClose, onSelectToken, currentToken, tokens, className, style, showTokenAsPrimary, exchangeRates, }) => {
100
100
  const { t } = useTranslation();
101
101
  const [search, setSearch] = useState('');
102
102
  const filteredTokens = tokens.filter((token) => {
@@ -110,7 +110,7 @@ const TokenSelectScreen = ({ onClose, onSelectToken, currentToken, tokens, class
110
110
  const closeButton = (jsx(IconButton, { type: 'button', id: 'close-button', "data-testid": 'close-button', onClick: onClose, children: jsx(SvgClose, {}) }));
111
111
  return (jsxs("div", { className: classNames('token-select', className), style: style, "data-testid": 'token-select', children: [jsx(ModalHeader, { trailing: closeButton, children: jsx(Typography, { variant: 'title', children: t(noAssets
112
112
  ? 'dyn_wallet_funding.from_external_wallet.token_select.no_assets_title'
113
- : 'dyn_wallet_funding.from_external_wallet.token_select.title') }) }), noAssets && (jsxs("div", { className: 'token-select__no-assets', children: [jsx(LinearGradientFrame, { Icon: jsx(SvgWalletIllustration, {}) }), jsx(Typography, { variant: 'title', color: 'secondary', weight: 'medium', children: t('dyn_wallet_funding.from_external_wallet.token_select.no_assets_description') })] })), !noAssets && (jsxs(Fragment, { children: [jsxs("label", { htmlFor: 'token-select-search', className: 'token-select__search', children: [jsx(Icon, { color: 'text-tertiary', size: 'small', children: jsx(SvgSearch, {}) }), jsx("input", { id: 'token-select-search', placeholder: t('dyn_wallet_funding.from_external_wallet.token_select.search_placeholder'), className: 'token-select__search__input', value: search, onChange: (e) => setSearch(e.target.value) })] }), jsx("div", { className: 'token-select__tokens', children: filteredTokens.map((token) => (jsx(TokenOption, { token: token, isSelected: token.symbol === currentToken, onSelect: () => onSelectToken(token.symbol) }, token.symbol))) })] }))] }));
113
+ : 'dyn_wallet_funding.from_external_wallet.token_select.title') }) }), noAssets && (jsxs("div", { className: 'token-select__no-assets', children: [jsx(LinearGradientFrame, { Icon: jsx(SvgWalletIllustration, {}) }), jsx(Typography, { variant: 'title', color: 'secondary', weight: 'medium', children: t('dyn_wallet_funding.from_external_wallet.token_select.no_assets_description') })] })), !noAssets && (jsxs(Fragment, { children: [jsxs("label", { htmlFor: 'token-select-search', className: 'token-select__search', children: [jsx(Icon, { color: 'text-tertiary', size: 'small', children: jsx(SvgSearch, {}) }), jsx("input", { id: 'token-select-search', placeholder: t('dyn_wallet_funding.from_external_wallet.token_select.search_placeholder'), className: 'token-select__search__input', value: search, onChange: (e) => setSearch(e.target.value) })] }), jsx("div", { className: 'token-select__tokens', children: filteredTokens.map((token) => (jsx(TokenOption, { token: token, isSelected: token.symbol === currentToken, onSelect: () => onSelectToken(token.symbol), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates }, token.symbol))) })] }))] }));
114
114
  };
115
115
 
116
116
  export { TokenSelectScreen };
@@ -3,7 +3,9 @@ export type FundingTokenData = {
3
3
  name: string;
4
4
  symbol: string;
5
5
  balance: number;
6
+ fiatBalance: number | undefined;
6
7
  logoURI: string | undefined;
8
+ price?: number;
7
9
  token: 'native' | {
8
10
  address: string;
9
11
  decimals?: number;
@@ -0,0 +1,27 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var isFiatToken = require('../isFiatToken/isFiatToken.cjs');
7
+
8
+ const calculateFiatBalance = (token, exchangeRates) => {
9
+ // If there is no token, return 0 instead of undefined because token is only undefined
10
+ // when and only when user has no balance for it.
11
+ if (!token)
12
+ return 0;
13
+ if (token.fiatBalance)
14
+ return token.fiatBalance;
15
+ // Fixing price to 1 for stablecoins to match user expectation
16
+ if (isFiatToken.isFiatOrStablecoin(token.symbol))
17
+ return token.balance;
18
+ if (token.price)
19
+ return token.balance * token.price;
20
+ if (exchangeRates[token.symbol])
21
+ return token.balance * exchangeRates[token.symbol];
22
+ // Here we return undefined instead of 0 because we know user HAS balance for this token,
23
+ // but we cannot calculate the fiat balance, so show as unavailable.
24
+ return undefined;
25
+ };
26
+
27
+ exports.calculateFiatBalance = calculateFiatBalance;
@@ -0,0 +1,2 @@
1
+ import { FundingTokenData } from '../../types';
2
+ export declare const calculateFiatBalance: (token: FundingTokenData | undefined, exchangeRates: Record<string, number>) => number | undefined;
@@ -0,0 +1,23 @@
1
+ 'use client'
2
+ import { isFiatOrStablecoin } from '../isFiatToken/isFiatToken.js';
3
+
4
+ const calculateFiatBalance = (token, exchangeRates) => {
5
+ // If there is no token, return 0 instead of undefined because token is only undefined
6
+ // when and only when user has no balance for it.
7
+ if (!token)
8
+ return 0;
9
+ if (token.fiatBalance)
10
+ return token.fiatBalance;
11
+ // Fixing price to 1 for stablecoins to match user expectation
12
+ if (isFiatOrStablecoin(token.symbol))
13
+ return token.balance;
14
+ if (token.price)
15
+ return token.balance * token.price;
16
+ if (exchangeRates[token.symbol])
17
+ return token.balance * exchangeRates[token.symbol];
18
+ // Here we return undefined instead of 0 because we know user HAS balance for this token,
19
+ // but we cannot calculate the fiat balance, so show as unavailable.
20
+ return undefined;
21
+ };
22
+
23
+ export { calculateFiatBalance };
@@ -10,6 +10,8 @@ const convertToFiat = (amount, token, exchangeRates) => {
10
10
  if (amount === '')
11
11
  return '';
12
12
  const value = parseFloat(amount);
13
+ if (isNaN(value))
14
+ return '';
13
15
  return exchangeRates[token] !== undefined
14
16
  ? roundToMaxDisplayLength(value * exchangeRates[token])
15
17
  : undefined;
@@ -18,6 +20,8 @@ const convertFromFiat = (amount, token, exchangeRates) => {
18
20
  if (amount === '')
19
21
  return '';
20
22
  const value = parseFloat(amount);
23
+ if (isNaN(value))
24
+ return '';
21
25
  return exchangeRates[token] !== undefined
22
26
  ? roundToMaxDisplayLength(value / exchangeRates[token])
23
27
  : undefined;
@@ -6,6 +6,8 @@ const convertToFiat = (amount, token, exchangeRates) => {
6
6
  if (amount === '')
7
7
  return '';
8
8
  const value = parseFloat(amount);
9
+ if (isNaN(value))
10
+ return '';
9
11
  return exchangeRates[token] !== undefined
10
12
  ? roundToMaxDisplayLength(value * exchangeRates[token])
11
13
  : undefined;
@@ -14,6 +16,8 @@ const convertFromFiat = (amount, token, exchangeRates) => {
14
16
  if (amount === '')
15
17
  return '';
16
18
  const value = parseFloat(amount);
19
+ if (isNaN(value))
20
+ return '';
17
21
  return exchangeRates[token] !== undefined
18
22
  ? roundToMaxDisplayLength(value / exchangeRates[token])
19
23
  : undefined;
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Converts a scientific notation number to a decimal number.
8
+ *
9
+ * It might be simpler to just call "toFixed", however, "toFixed" will return
10
+ * incorrect values for numbers that are too large or too small.
11
+ * Try (9.1).toFixed(16) and see for yourself.
12
+ */
13
+ const convertScientificToDecimal = (value) => {
14
+ const str = value.toString();
15
+ // If the number is already in standard form (no 'e'), return it
16
+ if (!str.includes('e'))
17
+ return str;
18
+ const [base, exponent] = str.split('e').map(parseFloat);
19
+ const isNegativeExp = exponent < 0;
20
+ const absoluteExponent = Math.abs(exponent);
21
+ const absoluteBase = Math.abs(base).toString();
22
+ if (isNegativeExp) {
23
+ // Move the decimal point to the left
24
+ const newNumber = '0.' + '0'.repeat(absoluteExponent - 1) + absoluteBase.replace('.', '');
25
+ return value < 0 ? '-' + newNumber : newNumber;
26
+ }
27
+ // Move the decimal point to the right
28
+ const [intPart, decimalPart = ''] = absoluteBase.split('.');
29
+ const newNumber = intPart + decimalPart.padEnd(absoluteExponent, '0');
30
+ return value < 0 ? '-' + newNumber : newNumber;
31
+ };
32
+
33
+ exports.convertScientificToDecimal = convertScientificToDecimal;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts a scientific notation number to a decimal number.
3
+ *
4
+ * It might be simpler to just call "toFixed", however, "toFixed" will return
5
+ * incorrect values for numbers that are too large or too small.
6
+ * Try (9.1).toFixed(16) and see for yourself.
7
+ */
8
+ export declare const convertScientificToDecimal: (value: number) => string;
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+ /**
3
+ * Converts a scientific notation number to a decimal number.
4
+ *
5
+ * It might be simpler to just call "toFixed", however, "toFixed" will return
6
+ * incorrect values for numbers that are too large or too small.
7
+ * Try (9.1).toFixed(16) and see for yourself.
8
+ */
9
+ const convertScientificToDecimal = (value) => {
10
+ const str = value.toString();
11
+ // If the number is already in standard form (no 'e'), return it
12
+ if (!str.includes('e'))
13
+ return str;
14
+ const [base, exponent] = str.split('e').map(parseFloat);
15
+ const isNegativeExp = exponent < 0;
16
+ const absoluteExponent = Math.abs(exponent);
17
+ const absoluteBase = Math.abs(base).toString();
18
+ if (isNegativeExp) {
19
+ // Move the decimal point to the left
20
+ const newNumber = '0.' + '0'.repeat(absoluteExponent - 1) + absoluteBase.replace('.', '');
21
+ return value < 0 ? '-' + newNumber : newNumber;
22
+ }
23
+ // Move the decimal point to the right
24
+ const [intPart, decimalPart = ''] = absoluteBase.split('.');
25
+ const newNumber = intPart + decimalPart.padEnd(absoluteExponent, '0');
26
+ return value < 0 ? '-' + newNumber : newNumber;
27
+ };
28
+
29
+ export { convertScientificToDecimal };
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var consts = require('../../consts.cjs');
7
+ var convertScientificToDecimal = require('./convertScientificToDecimal/convertScientificToDecimal.cjs');
7
8
 
8
9
  /* eslint-disable prefer-destructuring */
9
10
  const categorizeValue = (value) => {
@@ -32,38 +33,36 @@ const formatValue = ({ value, symbol, withFixedZeros = false, maxDecimals, }) =>
32
33
  if (value === undefined)
33
34
  return undefined;
34
35
  const parsed = value === '' ? 0 : parseFloat(value.toString());
36
+ // Deal with 0 values so we can assume value is not zero from here on
35
37
  if (parsed === 0)
36
- return addSymbol(withFixedZeros ? '0.00' : '0', symbol);
37
- // When value is inferior to 0.01 and withFixedZeros is true, we would return 0.00,
38
- // so to avoid this misleading behavior, we return a less than 0.01 value
39
- if (withFixedZeros && parsed < 0.0099)
40
- return `< ${addSymbol('0.01', symbol)}`;
38
+ return addSymbol(withFixedZeros && maxDecimals ? (0).toFixed(maxDecimals) : '0', symbol);
41
39
  const categorized = categorizeValue(parsed);
42
40
  const categorySymbol = typeof categorized === 'object' ? categorized.symbol : '';
43
- let formattedValue;
44
- if (typeof categorized === 'object') {
45
- const fixedValue = withFixedZeros
46
- ? categorized.value.toFixed(2)
47
- : categorized.value.toString();
48
- const [integerPart, decimalPart] = fixedValue.split('.');
49
- // Add commas
50
- const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
51
- if (maxDecimals !== undefined &&
52
- decimalPart &&
53
- decimalPart.length > maxDecimals) {
54
- const rounded = parseFloat(`0.${decimalPart}`)
55
- .toFixed(maxDecimals)
56
- .split('.')[1];
57
- formattedValue = `${formattedInteger}.${rounded}`;
58
- }
59
- else {
60
- formattedValue = decimalPart
61
- ? `${formattedInteger}.${decimalPart}`
62
- : formattedInteger;
41
+ if (typeof categorized === 'string')
42
+ return addSymbol(categorized + categorySymbol, symbol);
43
+ const expandedValue = convertScientificToDecimal.convertScientificToDecimal(categorized.value);
44
+ let [integerPart, decimalPart] = expandedValue.split('.');
45
+ if (maxDecimals !== undefined) {
46
+ const [roundedInteger, roundedDecimal] = parseFloat(`0.${decimalPart}`)
47
+ .toFixed(maxDecimals)
48
+ .split('.');
49
+ decimalPart = withFixedZeros
50
+ ? roundedDecimal
51
+ : roundedDecimal.replace(/0+$/, '');
52
+ if (roundedInteger !== '0') {
53
+ integerPart = convertScientificToDecimal.convertScientificToDecimal(parseFloat(integerPart) + parseFloat(roundedInteger));
63
54
  }
64
55
  }
65
- else
66
- formattedValue = categorized;
56
+ // Add commas
57
+ integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
58
+ const formattedValue = decimalPart
59
+ ? `${integerPart}.${decimalPart}`
60
+ : integerPart;
61
+ // If we ended up with 0 after all rounding, show less than symbol
62
+ if (maxDecimals && parseFloat(formattedValue) === 0) {
63
+ const number = `${(0).toFixed(maxDecimals - 1)}1`;
64
+ return `<${addSymbol(number, symbol)}`;
65
+ }
67
66
  return addSymbol(formattedValue + categorySymbol, symbol);
68
67
  };
69
68
 
@@ -1,7 +1,13 @@
1
1
  type FormatValueProps = {
2
2
  value: string | number | undefined;
3
3
  symbol: string | undefined;
4
+ /**
5
+ * When maxDecimals is defined, this being true will display leading zeros up until the maxDecimals case
6
+ */
4
7
  withFixedZeros?: boolean;
8
+ /**
9
+ * Rounds off any extra decimals to the maxDecimals value
10
+ */
5
11
  maxDecimals?: number;
6
12
  };
7
13
  export declare const formatValue: ({ value, symbol, withFixedZeros, maxDecimals, }: FormatValueProps) => string | undefined;
@@ -1,5 +1,6 @@
1
1
  'use client'
2
2
  import { UNAVAILABLE_VALUE } from '../../consts.js';
3
+ import { convertScientificToDecimal } from './convertScientificToDecimal/convertScientificToDecimal.js';
3
4
 
4
5
  /* eslint-disable prefer-destructuring */
5
6
  const categorizeValue = (value) => {
@@ -28,38 +29,36 @@ const formatValue = ({ value, symbol, withFixedZeros = false, maxDecimals, }) =>
28
29
  if (value === undefined)
29
30
  return undefined;
30
31
  const parsed = value === '' ? 0 : parseFloat(value.toString());
32
+ // Deal with 0 values so we can assume value is not zero from here on
31
33
  if (parsed === 0)
32
- return addSymbol(withFixedZeros ? '0.00' : '0', symbol);
33
- // When value is inferior to 0.01 and withFixedZeros is true, we would return 0.00,
34
- // so to avoid this misleading behavior, we return a less than 0.01 value
35
- if (withFixedZeros && parsed < 0.0099)
36
- return `< ${addSymbol('0.01', symbol)}`;
34
+ return addSymbol(withFixedZeros && maxDecimals ? (0).toFixed(maxDecimals) : '0', symbol);
37
35
  const categorized = categorizeValue(parsed);
38
36
  const categorySymbol = typeof categorized === 'object' ? categorized.symbol : '';
39
- let formattedValue;
40
- if (typeof categorized === 'object') {
41
- const fixedValue = withFixedZeros
42
- ? categorized.value.toFixed(2)
43
- : categorized.value.toString();
44
- const [integerPart, decimalPart] = fixedValue.split('.');
45
- // Add commas
46
- const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
47
- if (maxDecimals !== undefined &&
48
- decimalPart &&
49
- decimalPart.length > maxDecimals) {
50
- const rounded = parseFloat(`0.${decimalPart}`)
51
- .toFixed(maxDecimals)
52
- .split('.')[1];
53
- formattedValue = `${formattedInteger}.${rounded}`;
54
- }
55
- else {
56
- formattedValue = decimalPart
57
- ? `${formattedInteger}.${decimalPart}`
58
- : formattedInteger;
37
+ if (typeof categorized === 'string')
38
+ return addSymbol(categorized + categorySymbol, symbol);
39
+ const expandedValue = convertScientificToDecimal(categorized.value);
40
+ let [integerPart, decimalPart] = expandedValue.split('.');
41
+ if (maxDecimals !== undefined) {
42
+ const [roundedInteger, roundedDecimal] = parseFloat(`0.${decimalPart}`)
43
+ .toFixed(maxDecimals)
44
+ .split('.');
45
+ decimalPart = withFixedZeros
46
+ ? roundedDecimal
47
+ : roundedDecimal.replace(/0+$/, '');
48
+ if (roundedInteger !== '0') {
49
+ integerPart = convertScientificToDecimal(parseFloat(integerPart) + parseFloat(roundedInteger));
59
50
  }
60
51
  }
61
- else
62
- formattedValue = categorized;
52
+ // Add commas
53
+ integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
54
+ const formattedValue = decimalPart
55
+ ? `${integerPart}.${decimalPart}`
56
+ : integerPart;
57
+ // If we ended up with 0 after all rounding, show less than symbol
58
+ if (maxDecimals && parseFloat(formattedValue) === 0) {
59
+ const number = `${(0).toFixed(maxDecimals - 1)}1`;
60
+ return `<${addSymbol(number, symbol)}`;
61
+ }
63
62
  return addSymbol(formattedValue + categorySymbol, symbol);
64
63
  };
65
64
 
@@ -4,5 +4,7 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  const isFiatToken = (symbol) => symbol === 'USD';
7
+ const isFiatOrStablecoin = (symbol) => isFiatToken(symbol) || symbol === 'USDC' || symbol === 'USDT';
7
8
 
9
+ exports.isFiatOrStablecoin = isFiatOrStablecoin;
8
10
  exports.isFiatToken = isFiatToken;
@@ -1 +1,2 @@
1
1
  export declare const isFiatToken: (symbol: string) => symbol is "USD";
2
+ export declare const isFiatOrStablecoin: (symbol: string) => boolean;
@@ -1,4 +1,5 @@
1
1
  'use client'
2
2
  const isFiatToken = (symbol) => symbol === 'USD';
3
+ const isFiatOrStablecoin = (symbol) => isFiatToken(symbol) || symbol === 'USDC' || symbol === 'USDT';
3
4
 
4
- export { isFiatToken };
5
+ export { isFiatOrStablecoin, isFiatToken };
@@ -0,0 +1,32 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var React = require('react');
7
+ var exchangeRates = require('../../../../../../data/api/exchangeRates/exchangeRates.cjs');
8
+ var usePromise = require('../../../../../../utils/hooks/usePromise/usePromise.cjs');
9
+
10
+ const overrideBalances = (exchangeRates, tokenBalances) => {
11
+ const updatedExchangeRates = Object.assign({}, exchangeRates);
12
+ if (tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length) {
13
+ tokenBalances.forEach(({ symbol, price }) => {
14
+ if (price) {
15
+ updatedExchangeRates[symbol] = price;
16
+ }
17
+ });
18
+ }
19
+ // Fix stablecoin exchange rates for better UX
20
+ updatedExchangeRates['USDC'] = 1;
21
+ updatedExchangeRates['USDT'] = 1;
22
+ return updatedExchangeRates;
23
+ };
24
+ const useExchangeRatesForFunding = ({ onFetch, tokenBalances, }) => {
25
+ const { data: exchangeRates$1 } = usePromise.usePromise(exchangeRates.getExchangeRates, {
26
+ initialData: {},
27
+ onResolve: (rates) => onFetch(overrideBalances(rates, tokenBalances)),
28
+ });
29
+ return React.useMemo(() => overrideBalances(exchangeRates$1, tokenBalances), [tokenBalances, exchangeRates$1]);
30
+ };
31
+
32
+ exports.useExchangeRatesForFunding = useExchangeRatesForFunding;