@dynamic-labs/sdk-react-core 4.20.6 → 4.20.8
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.
- package/CHANGELOG.md +14 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -11
- package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -2
- package/src/lib/context/DynamicContext/DynamicContext.js +2 -3
- package/src/lib/context/ViewContext/types/index.d.ts +1 -1
- package/src/lib/data/api/exchangeAccounts/exchangeAccounts.cjs +75 -0
- package/src/lib/data/api/exchangeAccounts/exchangeAccounts.js +70 -0
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.cjs +4 -0
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.js +4 -0
- package/src/lib/locale/en/translation.cjs +24 -1
- package/src/lib/locale/en/translation.d.ts +23 -0
- package/src/lib/locale/en/translation.js +24 -1
- package/src/lib/shared/assets/index.d.ts +2 -0
- package/src/lib/shared/assets/locked.cjs +52 -0
- package/src/lib/shared/assets/locked.js +28 -0
- package/src/lib/shared/assets/white-check-black-circle.cjs +61 -0
- package/src/lib/shared/assets/white-check-black-circle.js +37 -0
- package/src/lib/store/state/dynamicContextProps/dynamicContextProps.cjs +2 -3
- package/src/lib/store/state/dynamicContextProps/dynamicContextProps.js +2 -3
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/authViewLayoutChecks.cjs +1 -0
- package/src/lib/utils/constants/authViewLayoutChecks.js +1 -0
- package/src/lib/utils/functions/getTransactionLink/getTransactionLink.cjs +3 -0
- package/src/lib/utils/functions/getTransactionLink/getTransactionLink.d.ts +1 -1
- package/src/lib/utils/functions/getTransactionLink/getTransactionLink.js +3 -0
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +8 -5
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +8 -5
- package/src/lib/utils/hooks/useExchangeAccounts/useExchangeAccounts.cjs +57 -0
- package/src/lib/utils/hooks/useExchangeAccounts/useExchangeAccounts.js +53 -0
- package/src/lib/utils/hooks/usePromptAndFundWithExchange/index.d.ts +1 -0
- package/src/lib/utils/hooks/usePromptAndFundWithExchange/usePromptAndFundWithExchange.d.ts +4 -0
- package/src/lib/utils/hooks/useSubmitExchangeFunding/index.d.ts +1 -0
- package/src/lib/utils/hooks/useSubmitExchangeFunding/useSubmitExchangeFunding.cjs +199 -0
- package/src/lib/utils/hooks/useSubmitExchangeFunding/useSubmitExchangeFunding.d.ts +11 -0
- package/src/lib/utils/hooks/useSubmitExchangeFunding/useSubmitExchangeFunding.js +195 -0
- package/src/lib/views/BackupUnsuccessfulView/BackupUnsuccessfulView.cjs +14 -4
- package/src/lib/views/BackupUnsuccessfulView/BackupUnsuccessfulView.js +14 -4
- package/src/lib/views/MfaExchangeView/MfaExchangeView.cjs +127 -0
- package/src/lib/views/MfaExchangeView/MfaExchangeView.d.ts +7 -0
- package/src/lib/views/MfaExchangeView/MfaExchangeView.js +123 -0
- package/src/lib/views/MfaExchangeView/index.d.ts +1 -0
- package/src/lib/views/viewToComponentMap.cjs +2 -0
- package/src/lib/views/viewToComponentMap.d.ts +4 -0
- package/src/lib/views/viewToComponentMap.js +2 -0
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/mapViewToComponent.cjs +3 -0
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/mapViewToComponent.d.ts +9 -13
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/mapViewToComponent.js +3 -0
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.d.ts +1 -1
- package/src/lib/widgets/DynamicWidget/views/ConfirmExchangeTransferView/ConfirmExchangeTransferView.cjs +3 -3
- package/src/lib/widgets/DynamicWidget/views/ConfirmExchangeTransferView/ConfirmExchangeTransferView.d.ts +1 -2
- package/src/lib/widgets/DynamicWidget/views/ConfirmExchangeTransferView/ConfirmExchangeTransferView.js +3 -3
- package/src/lib/widgets/DynamicWidget/views/DepositedExchangeView/DepositedExchangeView.cjs +121 -0
- package/src/lib/widgets/DynamicWidget/views/DepositedExchangeView/DepositedExchangeView.d.ts +11 -0
- package/src/lib/widgets/DynamicWidget/views/DepositedExchangeView/DepositedExchangeView.js +117 -0
- package/src/lib/widgets/DynamicWidget/views/DepositedExchangeView/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs +85 -15
- package/src/lib/widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js +85 -15
- package/src/lib/widgets/DynamicWidget/views/ReceiveWalletFunds/types.d.ts +14 -1
- package/src/lib/widgets/DynamicWidget/views/ReceiveWalletFunds/utils/useExchangeTokensForFunding/useExchangeTokensForFunding.cjs +131 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveWalletFunds/utils/useExchangeTokensForFunding/useExchangeTokensForFunding.js +127 -0
|
@@ -7,13 +7,13 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var reactI18next = require('react-i18next');
|
|
9
9
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
10
|
+
var iconic = require('@dynamic-labs/iconic');
|
|
10
11
|
var classNames = require('../../../../utils/functions/classNames/classNames.cjs');
|
|
11
12
|
require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
|
|
12
13
|
var arrowLeft = require('../../../../shared/assets/arrow-left.cjs');
|
|
13
14
|
var chevronDown = require('../../../../shared/assets/chevron-down.cjs');
|
|
14
15
|
var footerInfoIcon = require('../../../../shared/assets/footer-info-icon.cjs');
|
|
15
16
|
var switchToggle = require('../../../../shared/assets/switch-toggle.cjs');
|
|
16
|
-
require('@dynamic-labs/iconic');
|
|
17
17
|
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
18
18
|
require('../../../../../../_virtual/_tslib.cjs');
|
|
19
19
|
require('@dynamic-labs/sdk-api-core');
|
|
@@ -29,6 +29,7 @@ require('../../../../events/dynamicEvents.cjs');
|
|
|
29
29
|
require('../../../../context/DynamicContext/DynamicContext.cjs');
|
|
30
30
|
require('../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
|
|
31
31
|
require('../../../../store/state/authMode/authMode.cjs');
|
|
32
|
+
var useInternalDynamicContext = require('../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
|
|
32
33
|
require('../../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
33
34
|
require('../../../../context/ErrorContext/ErrorContext.cjs');
|
|
34
35
|
require('@dynamic-labs/multi-wallet');
|
|
@@ -48,7 +49,7 @@ require('../../../../context/VerificationContext/VerificationContext.cjs');
|
|
|
48
49
|
require('react-dom');
|
|
49
50
|
require('../../../../utils/functions/compareChains/compareChains.cjs');
|
|
50
51
|
require('../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
|
|
51
|
-
require('../../../../
|
|
52
|
+
var useIconThemeVariant = require('../../../../utils/hooks/useIconThemeVariant/useIconThemeVariant.cjs');
|
|
52
53
|
require('../../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
53
54
|
require('bs58');
|
|
54
55
|
require('@dynamic-labs/types');
|
|
@@ -75,6 +76,7 @@ var Tooltip = require('../../../../components/Tooltip/Tooltip.cjs');
|
|
|
75
76
|
require('../../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
76
77
|
require('../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
77
78
|
require('react-focus-lock');
|
|
79
|
+
require('../../../../context/ThemeContext/ThemeContext.cjs');
|
|
78
80
|
var Icon = require('../../../../components/Icon/Icon.cjs');
|
|
79
81
|
var DynamicWidgetContext = require('../../context/DynamicWidgetContext.cjs');
|
|
80
82
|
var IconButton = require('../../../../components/IconButton/IconButton.cjs');
|
|
@@ -99,10 +101,11 @@ require('../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWall
|
|
|
99
101
|
require('@hcaptcha/react-hcaptcha');
|
|
100
102
|
require('../../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
|
|
101
103
|
require('../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
102
|
-
require('../../helpers/convertExchangeKeyAndProviderEnum.cjs');
|
|
104
|
+
var convertExchangeKeyAndProviderEnum = require('../../helpers/convertExchangeKeyAndProviderEnum.cjs');
|
|
103
105
|
require('../../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
|
|
104
106
|
require('../../../../store/state/tokenBalances.cjs');
|
|
105
107
|
require('../../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
108
|
+
var useSubmitExchangeFunding = require('../../../../utils/hooks/useSubmitExchangeFunding/useSubmitExchangeFunding.cjs');
|
|
106
109
|
require('../../../../components/InlineWidget/InlineWidget.cjs');
|
|
107
110
|
require('../../../../components/IsBrowser/IsBrowser.cjs');
|
|
108
111
|
require('../../../../components/Popper/Popper/Popper.cjs');
|
|
@@ -120,6 +123,7 @@ var useExchangeRatesForFunding = require('./utils/useExchangeRatesForFunding/use
|
|
|
120
123
|
var useSubmitWalletFunding = require('./utils/useSubmitWalletFunding/useSubmitWalletFunding.cjs');
|
|
121
124
|
var useTokensForFunding = require('./utils/useTokensForFunding/useTokensForFunding.cjs');
|
|
122
125
|
var calculateFiatBalance = require('./utils/calculateFiatBalance/calculateFiatBalance.cjs');
|
|
126
|
+
var useExchangeTokensForFunding = require('./utils/useExchangeTokensForFunding/useExchangeTokensForFunding.cjs');
|
|
123
127
|
|
|
124
128
|
const defaultQuickSuggestions = {
|
|
125
129
|
token: 'USD',
|
|
@@ -128,7 +132,7 @@ const defaultQuickSuggestions = {
|
|
|
128
132
|
const rulesThatHideQuickSuggestions = ['exact', 'minimum'];
|
|
129
133
|
const rulesThatDisableTokenSelect = ['exact', 'exact-with-amount'];
|
|
130
134
|
const inputEmitter = formattedInputEmitter.createFormattedInputEmitter();
|
|
131
|
-
const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wallet, quickSuggestions = defaultQuickSuggestions, }) => {
|
|
135
|
+
const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wallet, exchange, fundingWithExchange = false, accounts, quickSuggestions = defaultQuickSuggestions, }) => {
|
|
132
136
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
133
137
|
// For now we hardcode the default value, soon we will fetch this from project settings
|
|
134
138
|
const initialToken = initialTokenRaw !== null && initialTokenRaw !== void 0 ? initialTokenRaw : {
|
|
@@ -148,10 +152,31 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
148
152
|
const { t } = reactI18next.useTranslation();
|
|
149
153
|
const [hasUserInteracted, setHasUserInteracted] = React.useState(false);
|
|
150
154
|
const [conversionErrorIconRef, setConversionErrorIconRef] = React.useState(null);
|
|
155
|
+
const { primaryWallet } = useInternalDynamicContext.useInternalDynamicContext();
|
|
156
|
+
const iconThemeVariant = useIconThemeVariant.useIconThemeVariant();
|
|
157
|
+
const provider = exchange
|
|
158
|
+
? convertExchangeKeyAndProviderEnum.convertExchangeKeytoProviderEnum(exchange)
|
|
159
|
+
: undefined;
|
|
151
160
|
const { setDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
161
|
+
let tokenBalancesLoading = false;
|
|
162
|
+
let tokenBalances = [];
|
|
163
|
+
if (wallet) {
|
|
164
|
+
const { isLoading: tokenBalancesLoadingWallet, tokens: tokenBalancesWallet, } =
|
|
165
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
166
|
+
useTokensForFunding.useTokensForFunding({
|
|
167
|
+
wallet: wallet,
|
|
168
|
+
});
|
|
169
|
+
tokenBalancesLoading = tokenBalancesLoadingWallet;
|
|
170
|
+
tokenBalances = tokenBalancesWallet;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
tokenBalancesLoading = false;
|
|
174
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
175
|
+
const { tokens: tokenBalancesExchange } = useExchangeTokensForFunding.useExchangeTokensForFunding({
|
|
176
|
+
accounts: accounts !== null && accounts !== void 0 ? accounts : [],
|
|
177
|
+
});
|
|
178
|
+
tokenBalances = tokenBalancesExchange;
|
|
179
|
+
}
|
|
155
180
|
const exchangeRates = useExchangeRatesForFunding.useExchangeRatesForFunding({
|
|
156
181
|
// Initialize amounts after exchange rates are fetched
|
|
157
182
|
onFetch: (exchangeRates) => {
|
|
@@ -267,6 +292,13 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
267
292
|
tokenAmount !== undefined &&
|
|
268
293
|
(!currentToken || currentToken.balance < parseFloat(tokenAmount)));
|
|
269
294
|
const showMinimumRequired = Boolean(!isMinimumRespected && !showNotEnoughBalance);
|
|
295
|
+
let addressToDisplay = '';
|
|
296
|
+
if (wallet) {
|
|
297
|
+
addressToDisplay = shortenWalletAddress.shortenWalletAddress(wallet.address);
|
|
298
|
+
}
|
|
299
|
+
else if (exchange) {
|
|
300
|
+
addressToDisplay = exchange.charAt(0).toUpperCase() + exchange.slice(1);
|
|
301
|
+
}
|
|
270
302
|
const showQuickSuggestions = quickSuggestionsParsed.length > 0 &&
|
|
271
303
|
!hasUserInteracted &&
|
|
272
304
|
!rulesThatHideQuickSuggestions.includes(initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.rule) &&
|
|
@@ -291,6 +323,7 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
291
323
|
setAmountsByTokenValue,
|
|
292
324
|
]);
|
|
293
325
|
const handleSubmit = useSubmitWalletFunding.useSubmitWalletFunding();
|
|
326
|
+
const handleExchangeSubmit = useSubmitExchangeFunding.useSubmitExchangeFunding();
|
|
294
327
|
const disableSubmit = !isMinimumRespected || showNotEnoughBalance || !isNonZero.isNonZero(tokenAmount);
|
|
295
328
|
const closeTokenSelect = React.useCallback(() => {
|
|
296
329
|
setShowTokenSelect(false);
|
|
@@ -305,7 +338,9 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
305
338
|
const backButton = (jsxRuntime.jsx(IconButton.IconButton, { type: 'button', id: 'back-button', "data-testid": 'back-button', onClick: () => setDynamicWidgetView('choose-wallet-funding-method'), children: jsxRuntime.jsx(arrowLeft.ReactComponent, {}) }));
|
|
306
339
|
return (jsxRuntime.jsxs("div", { className: 'fund-from-wallet', children: [!disableTokenSelect && (jsxRuntime.jsx(TokenSelectScreen.TokenSelectScreen, { onClose: closeTokenSelect, onSelectToken: handleSelectToken, tokens: tokenBalances !== null && tokenBalances !== void 0 ? tokenBalances : [], currentToken: tokenSymbol, className: classNames.classNames('fund-from-wallet__token-select', {
|
|
307
340
|
'fund-from-wallet__token-select--open': showTokenSelect,
|
|
308
|
-
}), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates })), jsxRuntime.jsx(ModalHeader.ModalHeader, { leading: backButton, children: jsxRuntime.jsx(Typography.Typography, { variant: 'title', children:
|
|
341
|
+
}), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates })), jsxRuntime.jsx(ModalHeader.ModalHeader, { leading: backButton, children: jsxRuntime.jsx(Typography.Typography, { variant: 'title', children: fundingWithExchange
|
|
342
|
+
? t('dyn_fund_from_exchange.title')
|
|
343
|
+
: t('dyn_wallet_funding.from_wallet.amount_input.title') }) }), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content', children: [jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__amount-container', children: [minimum && (jsxRuntime.jsx(Typography.Typography, { color: 'error-1', className: classNames.classNames('fund-from-wallet__content__amount-container__minimum-error', {
|
|
309
344
|
'fund-from-wallet__content__amount-container__minimum-error--visible': showMinimumRequired,
|
|
310
345
|
}), variant: 'body_normal', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.minimum_error', {
|
|
311
346
|
minimum: formatValue.formatValue({
|
|
@@ -330,7 +365,7 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
330
365
|
value: consts.UNAVAILABLE_VALUE,
|
|
331
366
|
}) }), jsxRuntime.jsx("div", { ref: setConversionErrorIconRef, children: jsxRuntime.jsx(Icon.Icon, { size: 'medium', color: 'text-tertiary', children: jsxRuntime.jsx(footerInfoIcon.ReactComponent, {}) }) }), jsxRuntime.jsx(Tooltip.Tooltip, { content: t('dyn_wallet_funding.from_wallet.amount_input.pricing_unavailable'), targetRef: conversionErrorIconRef, className: 'fund-from-wallet__content__amount-container__secondary-missing__tooltip' })] })), jsxRuntime.jsx(Typography.Typography, { color: 'error-1', className: classNames.classNames('fund-from-wallet__content__amount-container__balance-error', {
|
|
332
367
|
'fund-from-wallet__content__amount-container__balance-error--visible': showNotEnoughBalance,
|
|
333
|
-
}), variant: 'body_normal', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.balance_error') })] }), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card', children: [jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details', children: [jsxRuntime.jsx(walletBook.WalletIcon, { icon: wallet.connector.metadata.icon, walletKey: wallet.connector.key, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' }), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details__rows', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.wallet_detail_from') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'secondary', weight: 'medium', children:
|
|
368
|
+
}), variant: 'body_normal', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.balance_error') })] }), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card', children: [jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details', children: [wallet && (jsxRuntime.jsx(walletBook.WalletIcon, { icon: wallet.connector.metadata.icon, walletKey: wallet.connector.key, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), provider && (jsxRuntime.jsx(iconic.SocialIcon, { name: provider, variant: iconThemeVariant, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), jsxRuntime.jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details__rows', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.wallet_detail_from') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'secondary', weight: 'medium', children: addressToDisplay })] })] }), tokenBalancesLoading && (jsxRuntime.jsx(Skeleton.Skeleton, { dataTestId: 'balance-skeleton', container: {
|
|
334
369
|
className: 'fund-from-wallet__content__wallet-card__balance-skeleton',
|
|
335
370
|
} })), !tokenBalancesLoading && (jsxRuntime.jsxs("div", { className: classNames.classNames('fund-from-wallet__content__wallet-card__balance', {
|
|
336
371
|
'fund-from-wallet__content__wallet-card__balance--disable-select': disableTokenSelect,
|
|
@@ -348,12 +383,47 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
348
383
|
symbol: secondaryBalance.symbol,
|
|
349
384
|
value: (_j = secondaryBalance.value) !== null && _j !== void 0 ? _j : consts.UNAVAILABLE_VALUE,
|
|
350
385
|
withFixedZeros: isFiatToken.isFiatOrStablecoin(secondaryBalance.symbol),
|
|
351
|
-
}) })] }), !disableTokenSelect && (jsxRuntime.jsx(Icon.Icon, { color: 'text-tertiary', size: 'small', className: 'fund-from-wallet__content__wallet-card__balance__icon', children: jsxRuntime.jsx(chevronDown.ReactComponent, { "data-testid": 'token-select-dropdown' }) }))] }))] })] }), jsxRuntime.jsx(TypographyButton.TypographyButton, { dataTestId: 'confirm-button', buttonVariant: 'brand-primary', buttonPadding: 'large', typographyProps: { color: 'white' }, className: 'fund-from-wallet__confirm-button', disabled: disableSubmit, onClick: () =>
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
386
|
+
}) })] }), !disableTokenSelect && (jsxRuntime.jsx(Icon.Icon, { color: 'text-tertiary', size: 'small', className: 'fund-from-wallet__content__wallet-card__balance__icon', children: jsxRuntime.jsx(chevronDown.ReactComponent, { "data-testid": 'token-select-dropdown' }) }))] }))] })] }), jsxRuntime.jsx(TypographyButton.TypographyButton, { dataTestId: 'confirm-button', buttonVariant: 'brand-primary', buttonPadding: 'large', typographyProps: { color: 'white' }, className: 'fund-from-wallet__confirm-button', disabled: disableSubmit, onClick: () => {
|
|
387
|
+
if (fundingWithExchange && exchange) {
|
|
388
|
+
const baseConfirmProps = {
|
|
389
|
+
amount: tokenAmount ? parseFloat(tokenAmount) : undefined,
|
|
390
|
+
exchange,
|
|
391
|
+
fiatAmount: fiatAmount ? parseFloat(fiatAmount) : undefined,
|
|
392
|
+
fiatCurrencySymbol: fiatSymbol,
|
|
393
|
+
onBack: () => setDynamicWidgetView('receive-wallet-funds', {
|
|
394
|
+
accounts,
|
|
395
|
+
amount: initialAmount,
|
|
396
|
+
exchange,
|
|
397
|
+
fundingWithExchange,
|
|
398
|
+
quickSuggestions,
|
|
399
|
+
token: { rule: 'recommended', value: tokenSymbol },
|
|
400
|
+
wallet,
|
|
401
|
+
}),
|
|
402
|
+
toAddress: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address,
|
|
403
|
+
token: currentToken,
|
|
404
|
+
};
|
|
405
|
+
const handleConfirmSubmit = () => {
|
|
406
|
+
var _a;
|
|
407
|
+
return handleExchangeSubmit({
|
|
408
|
+
exchange,
|
|
409
|
+
props: Object.assign(Object.assign({}, baseConfirmProps), { onSubmit: handleConfirmSubmit }),
|
|
410
|
+
toAddress: (_a = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address) !== null && _a !== void 0 ? _a : '',
|
|
411
|
+
tokenAmount,
|
|
412
|
+
tokenSymbol,
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
const confirmProps = Object.assign(Object.assign({}, baseConfirmProps), { onSubmit: handleConfirmSubmit });
|
|
416
|
+
setDynamicWidgetView('confirm-exchange-transfer', confirmProps);
|
|
417
|
+
}
|
|
418
|
+
else if (wallet) {
|
|
419
|
+
handleSubmit({
|
|
420
|
+
tokenAmount,
|
|
421
|
+
tokenBalances,
|
|
422
|
+
tokenSymbol,
|
|
423
|
+
wallet,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}, children: t('dyn_wallet_funding.from_wallet.amount_input.confirm_button') })] }));
|
|
357
427
|
};
|
|
358
428
|
|
|
359
429
|
exports.ReceiveWalletFunds = ReceiveWalletFunds;
|
|
@@ -3,13 +3,13 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
3
3
|
import { useState, useCallback } from 'react';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { WalletIcon } from '@dynamic-labs/wallet-book';
|
|
6
|
+
import { SocialIcon } from '@dynamic-labs/iconic';
|
|
6
7
|
import { classNames } from '../../../../utils/functions/classNames/classNames.js';
|
|
7
8
|
import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
|
|
8
9
|
import { ReactComponent as SvgArrowLeft } from '../../../../shared/assets/arrow-left.js';
|
|
9
10
|
import { ReactComponent as SvgChevronDown } from '../../../../shared/assets/chevron-down.js';
|
|
10
11
|
import { ReactComponent as SvgFooterInfoIcon } from '../../../../shared/assets/footer-info-icon.js';
|
|
11
12
|
import { ReactComponent as SvgSwitchToggle } from '../../../../shared/assets/switch-toggle.js';
|
|
12
|
-
import '@dynamic-labs/iconic';
|
|
13
13
|
import '../../../../context/ViewContext/ViewContext.js';
|
|
14
14
|
import '../../../../../../_virtual/_tslib.js';
|
|
15
15
|
import '@dynamic-labs/sdk-api-core';
|
|
@@ -25,6 +25,7 @@ import '../../../../events/dynamicEvents.js';
|
|
|
25
25
|
import '../../../../context/DynamicContext/DynamicContext.js';
|
|
26
26
|
import '../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
|
|
27
27
|
import '../../../../store/state/authMode/authMode.js';
|
|
28
|
+
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
|
|
28
29
|
import '../../../../context/CaptchaContext/CaptchaContext.js';
|
|
29
30
|
import '../../../../context/ErrorContext/ErrorContext.js';
|
|
30
31
|
import '@dynamic-labs/multi-wallet';
|
|
@@ -44,7 +45,7 @@ import '../../../../context/VerificationContext/VerificationContext.js';
|
|
|
44
45
|
import 'react-dom';
|
|
45
46
|
import '../../../../utils/functions/compareChains/compareChains.js';
|
|
46
47
|
import '../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
|
|
47
|
-
import '../../../../
|
|
48
|
+
import { useIconThemeVariant } from '../../../../utils/hooks/useIconThemeVariant/useIconThemeVariant.js';
|
|
48
49
|
import '../../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
|
|
49
50
|
import 'bs58';
|
|
50
51
|
import '@dynamic-labs/types';
|
|
@@ -71,6 +72,7 @@ import { Tooltip } from '../../../../components/Tooltip/Tooltip.js';
|
|
|
71
72
|
import '../../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
72
73
|
import '../../components/DynamicWidgetHeader/DynamicWidgetHeader.js';
|
|
73
74
|
import 'react-focus-lock';
|
|
75
|
+
import '../../../../context/ThemeContext/ThemeContext.js';
|
|
74
76
|
import { Icon } from '../../../../components/Icon/Icon.js';
|
|
75
77
|
import { useWidgetContext } from '../../context/DynamicWidgetContext.js';
|
|
76
78
|
import { IconButton } from '../../../../components/IconButton/IconButton.js';
|
|
@@ -95,10 +97,11 @@ import '../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWalle
|
|
|
95
97
|
import '@hcaptcha/react-hcaptcha';
|
|
96
98
|
import '../../../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
|
|
97
99
|
import '../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
|
|
98
|
-
import '../../helpers/convertExchangeKeyAndProviderEnum.js';
|
|
100
|
+
import { convertExchangeKeytoProviderEnum } from '../../helpers/convertExchangeKeyAndProviderEnum.js';
|
|
99
101
|
import '../../../../store/state/connectorsInitializing/connectorsInitializing.js';
|
|
100
102
|
import '../../../../store/state/tokenBalances.js';
|
|
101
103
|
import '../../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
104
|
+
import { useSubmitExchangeFunding } from '../../../../utils/hooks/useSubmitExchangeFunding/useSubmitExchangeFunding.js';
|
|
102
105
|
import '../../../../components/InlineWidget/InlineWidget.js';
|
|
103
106
|
import '../../../../components/IsBrowser/IsBrowser.js';
|
|
104
107
|
import '../../../../components/Popper/Popper/Popper.js';
|
|
@@ -116,6 +119,7 @@ import { useExchangeRatesForFunding } from './utils/useExchangeRatesForFunding/u
|
|
|
116
119
|
import { useSubmitWalletFunding } from './utils/useSubmitWalletFunding/useSubmitWalletFunding.js';
|
|
117
120
|
import { useTokensForFunding } from './utils/useTokensForFunding/useTokensForFunding.js';
|
|
118
121
|
import { calculateFiatBalance } from './utils/calculateFiatBalance/calculateFiatBalance.js';
|
|
122
|
+
import { useExchangeTokensForFunding } from './utils/useExchangeTokensForFunding/useExchangeTokensForFunding.js';
|
|
119
123
|
|
|
120
124
|
const defaultQuickSuggestions = {
|
|
121
125
|
token: 'USD',
|
|
@@ -124,7 +128,7 @@ const defaultQuickSuggestions = {
|
|
|
124
128
|
const rulesThatHideQuickSuggestions = ['exact', 'minimum'];
|
|
125
129
|
const rulesThatDisableTokenSelect = ['exact', 'exact-with-amount'];
|
|
126
130
|
const inputEmitter = createFormattedInputEmitter();
|
|
127
|
-
const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wallet, quickSuggestions = defaultQuickSuggestions, }) => {
|
|
131
|
+
const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wallet, exchange, fundingWithExchange = false, accounts, quickSuggestions = defaultQuickSuggestions, }) => {
|
|
128
132
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
129
133
|
// For now we hardcode the default value, soon we will fetch this from project settings
|
|
130
134
|
const initialToken = initialTokenRaw !== null && initialTokenRaw !== void 0 ? initialTokenRaw : {
|
|
@@ -144,10 +148,31 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
144
148
|
const { t } = useTranslation();
|
|
145
149
|
const [hasUserInteracted, setHasUserInteracted] = useState(false);
|
|
146
150
|
const [conversionErrorIconRef, setConversionErrorIconRef] = useState(null);
|
|
151
|
+
const { primaryWallet } = useInternalDynamicContext();
|
|
152
|
+
const iconThemeVariant = useIconThemeVariant();
|
|
153
|
+
const provider = exchange
|
|
154
|
+
? convertExchangeKeytoProviderEnum(exchange)
|
|
155
|
+
: undefined;
|
|
147
156
|
const { setDynamicWidgetView } = useWidgetContext();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
let tokenBalancesLoading = false;
|
|
158
|
+
let tokenBalances = [];
|
|
159
|
+
if (wallet) {
|
|
160
|
+
const { isLoading: tokenBalancesLoadingWallet, tokens: tokenBalancesWallet, } =
|
|
161
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
162
|
+
useTokensForFunding({
|
|
163
|
+
wallet: wallet,
|
|
164
|
+
});
|
|
165
|
+
tokenBalancesLoading = tokenBalancesLoadingWallet;
|
|
166
|
+
tokenBalances = tokenBalancesWallet;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
tokenBalancesLoading = false;
|
|
170
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
171
|
+
const { tokens: tokenBalancesExchange } = useExchangeTokensForFunding({
|
|
172
|
+
accounts: accounts !== null && accounts !== void 0 ? accounts : [],
|
|
173
|
+
});
|
|
174
|
+
tokenBalances = tokenBalancesExchange;
|
|
175
|
+
}
|
|
151
176
|
const exchangeRates = useExchangeRatesForFunding({
|
|
152
177
|
// Initialize amounts after exchange rates are fetched
|
|
153
178
|
onFetch: (exchangeRates) => {
|
|
@@ -263,6 +288,13 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
263
288
|
tokenAmount !== undefined &&
|
|
264
289
|
(!currentToken || currentToken.balance < parseFloat(tokenAmount)));
|
|
265
290
|
const showMinimumRequired = Boolean(!isMinimumRespected && !showNotEnoughBalance);
|
|
291
|
+
let addressToDisplay = '';
|
|
292
|
+
if (wallet) {
|
|
293
|
+
addressToDisplay = shortenWalletAddress(wallet.address);
|
|
294
|
+
}
|
|
295
|
+
else if (exchange) {
|
|
296
|
+
addressToDisplay = exchange.charAt(0).toUpperCase() + exchange.slice(1);
|
|
297
|
+
}
|
|
266
298
|
const showQuickSuggestions = quickSuggestionsParsed.length > 0 &&
|
|
267
299
|
!hasUserInteracted &&
|
|
268
300
|
!rulesThatHideQuickSuggestions.includes(initialAmount === null || initialAmount === void 0 ? void 0 : initialAmount.rule) &&
|
|
@@ -287,6 +319,7 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
287
319
|
setAmountsByTokenValue,
|
|
288
320
|
]);
|
|
289
321
|
const handleSubmit = useSubmitWalletFunding();
|
|
322
|
+
const handleExchangeSubmit = useSubmitExchangeFunding();
|
|
290
323
|
const disableSubmit = !isMinimumRespected || showNotEnoughBalance || !isNonZero(tokenAmount);
|
|
291
324
|
const closeTokenSelect = useCallback(() => {
|
|
292
325
|
setShowTokenSelect(false);
|
|
@@ -301,7 +334,9 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
301
334
|
const backButton = (jsx(IconButton, { type: 'button', id: 'back-button', "data-testid": 'back-button', onClick: () => setDynamicWidgetView('choose-wallet-funding-method'), children: jsx(SvgArrowLeft, {}) }));
|
|
302
335
|
return (jsxs("div", { className: 'fund-from-wallet', children: [!disableTokenSelect && (jsx(TokenSelectScreen, { onClose: closeTokenSelect, onSelectToken: handleSelectToken, tokens: tokenBalances !== null && tokenBalances !== void 0 ? tokenBalances : [], currentToken: tokenSymbol, className: classNames('fund-from-wallet__token-select', {
|
|
303
336
|
'fund-from-wallet__token-select--open': showTokenSelect,
|
|
304
|
-
}), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates })), jsx(ModalHeader, { leading: backButton, children: jsx(Typography, { variant: 'title', children:
|
|
337
|
+
}), showTokenAsPrimary: showTokenAsPrimary, exchangeRates: exchangeRates })), jsx(ModalHeader, { leading: backButton, children: jsx(Typography, { variant: 'title', children: fundingWithExchange
|
|
338
|
+
? t('dyn_fund_from_exchange.title')
|
|
339
|
+
: t('dyn_wallet_funding.from_wallet.amount_input.title') }) }), jsxs("div", { className: 'fund-from-wallet__content', children: [jsxs("div", { className: 'fund-from-wallet__content__amount-container', children: [minimum && (jsx(Typography, { color: 'error-1', className: classNames('fund-from-wallet__content__amount-container__minimum-error', {
|
|
305
340
|
'fund-from-wallet__content__amount-container__minimum-error--visible': showMinimumRequired,
|
|
306
341
|
}), variant: 'body_normal', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.minimum_error', {
|
|
307
342
|
minimum: formatValue({
|
|
@@ -326,7 +361,7 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
326
361
|
value: UNAVAILABLE_VALUE,
|
|
327
362
|
}) }), jsx("div", { ref: setConversionErrorIconRef, children: jsx(Icon, { size: 'medium', color: 'text-tertiary', children: jsx(SvgFooterInfoIcon, {}) }) }), jsx(Tooltip, { content: t('dyn_wallet_funding.from_wallet.amount_input.pricing_unavailable'), targetRef: conversionErrorIconRef, className: 'fund-from-wallet__content__amount-container__secondary-missing__tooltip' })] })), jsx(Typography, { color: 'error-1', className: classNames('fund-from-wallet__content__amount-container__balance-error', {
|
|
328
363
|
'fund-from-wallet__content__amount-container__balance-error--visible': showNotEnoughBalance,
|
|
329
|
-
}), variant: 'body_normal', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.balance_error') })] }), jsxs("div", { className: 'fund-from-wallet__content__wallet-card', children: [jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details', children: [jsx(WalletIcon, { icon: wallet.connector.metadata.icon, walletKey: wallet.connector.key, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' }), jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details__rows', children: [jsx(Typography, { variant: 'body_small', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.wallet_detail_from') }), jsx(Typography, { variant: 'body_small', color: 'secondary', weight: 'medium', children:
|
|
364
|
+
}), variant: 'body_normal', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.balance_error') })] }), jsxs("div", { className: 'fund-from-wallet__content__wallet-card', children: [jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details', children: [wallet && (jsx(WalletIcon, { icon: wallet.connector.metadata.icon, walletKey: wallet.connector.key, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), provider && (jsx(SocialIcon, { name: provider, variant: iconThemeVariant, className: 'fund-from-wallet__content__wallet-card__wallet-details__icon' })), jsxs("div", { className: 'fund-from-wallet__content__wallet-card__wallet-details__rows', children: [jsx(Typography, { variant: 'body_small', weight: 'medium', children: t('dyn_wallet_funding.from_wallet.amount_input.wallet_detail_from') }), jsx(Typography, { variant: 'body_small', color: 'secondary', weight: 'medium', children: addressToDisplay })] })] }), tokenBalancesLoading && (jsx(Skeleton, { dataTestId: 'balance-skeleton', container: {
|
|
330
365
|
className: 'fund-from-wallet__content__wallet-card__balance-skeleton',
|
|
331
366
|
} })), !tokenBalancesLoading && (jsxs("div", { className: classNames('fund-from-wallet__content__wallet-card__balance', {
|
|
332
367
|
'fund-from-wallet__content__wallet-card__balance--disable-select': disableTokenSelect,
|
|
@@ -344,12 +379,47 @@ const ReceiveWalletFunds = ({ amount: initialAmount, token: initialTokenRaw, wal
|
|
|
344
379
|
symbol: secondaryBalance.symbol,
|
|
345
380
|
value: (_j = secondaryBalance.value) !== null && _j !== void 0 ? _j : UNAVAILABLE_VALUE,
|
|
346
381
|
withFixedZeros: isFiatOrStablecoin(secondaryBalance.symbol),
|
|
347
|
-
}) })] }), !disableTokenSelect && (jsx(Icon, { color: 'text-tertiary', size: 'small', className: 'fund-from-wallet__content__wallet-card__balance__icon', children: jsx(SvgChevronDown, { "data-testid": 'token-select-dropdown' }) }))] }))] })] }), jsx(TypographyButton, { dataTestId: 'confirm-button', buttonVariant: 'brand-primary', buttonPadding: 'large', typographyProps: { color: 'white' }, className: 'fund-from-wallet__confirm-button', disabled: disableSubmit, onClick: () =>
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
382
|
+
}) })] }), !disableTokenSelect && (jsx(Icon, { color: 'text-tertiary', size: 'small', className: 'fund-from-wallet__content__wallet-card__balance__icon', children: jsx(SvgChevronDown, { "data-testid": 'token-select-dropdown' }) }))] }))] })] }), jsx(TypographyButton, { dataTestId: 'confirm-button', buttonVariant: 'brand-primary', buttonPadding: 'large', typographyProps: { color: 'white' }, className: 'fund-from-wallet__confirm-button', disabled: disableSubmit, onClick: () => {
|
|
383
|
+
if (fundingWithExchange && exchange) {
|
|
384
|
+
const baseConfirmProps = {
|
|
385
|
+
amount: tokenAmount ? parseFloat(tokenAmount) : undefined,
|
|
386
|
+
exchange,
|
|
387
|
+
fiatAmount: fiatAmount ? parseFloat(fiatAmount) : undefined,
|
|
388
|
+
fiatCurrencySymbol: fiatSymbol,
|
|
389
|
+
onBack: () => setDynamicWidgetView('receive-wallet-funds', {
|
|
390
|
+
accounts,
|
|
391
|
+
amount: initialAmount,
|
|
392
|
+
exchange,
|
|
393
|
+
fundingWithExchange,
|
|
394
|
+
quickSuggestions,
|
|
395
|
+
token: { rule: 'recommended', value: tokenSymbol },
|
|
396
|
+
wallet,
|
|
397
|
+
}),
|
|
398
|
+
toAddress: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address,
|
|
399
|
+
token: currentToken,
|
|
400
|
+
};
|
|
401
|
+
const handleConfirmSubmit = () => {
|
|
402
|
+
var _a;
|
|
403
|
+
return handleExchangeSubmit({
|
|
404
|
+
exchange,
|
|
405
|
+
props: Object.assign(Object.assign({}, baseConfirmProps), { onSubmit: handleConfirmSubmit }),
|
|
406
|
+
toAddress: (_a = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address) !== null && _a !== void 0 ? _a : '',
|
|
407
|
+
tokenAmount,
|
|
408
|
+
tokenSymbol,
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
const confirmProps = Object.assign(Object.assign({}, baseConfirmProps), { onSubmit: handleConfirmSubmit });
|
|
412
|
+
setDynamicWidgetView('confirm-exchange-transfer', confirmProps);
|
|
413
|
+
}
|
|
414
|
+
else if (wallet) {
|
|
415
|
+
handleSubmit({
|
|
416
|
+
tokenAmount,
|
|
417
|
+
tokenBalances,
|
|
418
|
+
tokenSymbol,
|
|
419
|
+
wallet,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}, children: t('dyn_wallet_funding.from_wallet.amount_input.confirm_button') })] }));
|
|
353
423
|
};
|
|
354
424
|
|
|
355
425
|
export { ReceiveWalletFunds };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Account, ExchangeKeyEnum } from '@dynamic-labs/sdk-api-core';
|
|
1
2
|
import { Wallet } from '../../../../shared/types/wallets';
|
|
2
3
|
export type FundingTokenData = {
|
|
3
4
|
name: string;
|
|
@@ -31,7 +32,7 @@ export type FundingAmountRule = 'exact' | 'minimum' | 'recommended';
|
|
|
31
32
|
export type FundingTokenRule = 'exact' | 'recommended' | 'exact-with-amount';
|
|
32
33
|
export type FiatToken = 'USD';
|
|
33
34
|
export type ReceiveWalletFundsProps = {
|
|
34
|
-
wallet
|
|
35
|
+
wallet?: Wallet;
|
|
35
36
|
/**
|
|
36
37
|
* Configure the amount input.
|
|
37
38
|
*
|
|
@@ -74,6 +75,18 @@ export type ReceiveWalletFundsProps = {
|
|
|
74
75
|
*/
|
|
75
76
|
rule: FundingTokenRule;
|
|
76
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* The exchange that is connected for funding if applicable
|
|
80
|
+
*/
|
|
81
|
+
exchange?: ExchangeKeyEnum;
|
|
82
|
+
/**
|
|
83
|
+
* True if funding with an exchange and false if funding with wallet
|
|
84
|
+
*/
|
|
85
|
+
fundingWithExchange?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Accounts associated with exchange
|
|
88
|
+
*/
|
|
89
|
+
accounts?: Account[];
|
|
77
90
|
/**
|
|
78
91
|
* Quick suggestions for the amount input.
|
|
79
92
|
*
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var useExchangeRatesForFunding = require('../useExchangeRatesForFunding/useExchangeRatesForFunding.cjs');
|
|
8
|
+
require('../../../../../../context/DynamicContext/DynamicContext.cjs');
|
|
9
|
+
require('../../../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
|
|
10
|
+
require('@dynamic-labs/sdk-api-core');
|
|
11
|
+
require('../../../../../../shared/logger.cjs');
|
|
12
|
+
require('@dynamic-labs/iconic');
|
|
13
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
14
|
+
require('react/jsx-runtime');
|
|
15
|
+
require('../../../../../../context/ViewContext/ViewContext.cjs');
|
|
16
|
+
require('@dynamic-labs/wallet-book');
|
|
17
|
+
require('@dynamic-labs/utils');
|
|
18
|
+
require('../../../../../../utils/constants/colors.cjs');
|
|
19
|
+
require('../../../../../../utils/constants/values.cjs');
|
|
20
|
+
require('../../../../../../shared/consts/index.cjs');
|
|
21
|
+
require('../../../../../../events/dynamicEvents.cjs');
|
|
22
|
+
require('../../../../../../../../_virtual/_tslib.cjs');
|
|
23
|
+
require('../../../../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
24
|
+
require('../../../../../../context/ErrorContext/ErrorContext.cjs');
|
|
25
|
+
require('@dynamic-labs/multi-wallet');
|
|
26
|
+
require('react-international-phone');
|
|
27
|
+
require('../../../../../../store/state/nonce/nonce.cjs');
|
|
28
|
+
require('../../../../../../store/state/projectSettings/projectSettings.cjs');
|
|
29
|
+
require('../../../../../../config/ApiEndpoint.cjs');
|
|
30
|
+
require('../../../../../../store/state/user/user.cjs');
|
|
31
|
+
require('../../../../../../locale/locale.cjs');
|
|
32
|
+
require('../../../../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
33
|
+
require('../../../../../../store/state/primaryWalletId/primaryWalletId.cjs');
|
|
34
|
+
require('../../../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
|
|
35
|
+
require('../../../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
36
|
+
require('../../../../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
37
|
+
require('../../../../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
38
|
+
require('../../../../../../store/state/authMode/authMode.cjs');
|
|
39
|
+
require('../../../../../../context/VerificationContext/VerificationContext.cjs');
|
|
40
|
+
require('react-dom');
|
|
41
|
+
require('../../../../../../utils/functions/compareChains/compareChains.cjs');
|
|
42
|
+
require('../../../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
|
|
43
|
+
require('../../../../../../context/ThemeContext/ThemeContext.cjs');
|
|
44
|
+
require('../../../../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
45
|
+
require('bs58');
|
|
46
|
+
require('@dynamic-labs/types');
|
|
47
|
+
require('../../../../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
48
|
+
require('../../../../../../context/LoadingContext/LoadingContext.cjs');
|
|
49
|
+
require('../../../../../../context/WalletContext/WalletContext.cjs');
|
|
50
|
+
require('../../../../../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
|
|
51
|
+
require('yup');
|
|
52
|
+
require('../../../../../../context/MockContext/MockContext.cjs');
|
|
53
|
+
require('../../../../../../views/CollectUserDataView/useFields.cjs');
|
|
54
|
+
require('../../../../../../context/FieldsStateContext/FieldsStateContext.cjs');
|
|
55
|
+
require('../../../../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
56
|
+
require('@dynamic-labs/rpc-providers');
|
|
57
|
+
require('../../../../../../store/state/walletOptions/walletOptions.cjs');
|
|
58
|
+
require('react-i18next');
|
|
59
|
+
require('../../../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
|
|
60
|
+
require('../../../../../../components/Alert/Alert.cjs');
|
|
61
|
+
require('../../../../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
62
|
+
require('../../../../../../components/IconButton/IconButton.cjs');
|
|
63
|
+
require('../../../../../../components/InlineWidget/InlineWidget.cjs');
|
|
64
|
+
require('../../../../../../components/Input/Input.cjs');
|
|
65
|
+
require('../../../../../../components/IsBrowser/IsBrowser.cjs');
|
|
66
|
+
require('../../../../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
67
|
+
require('../../../../../../components/OverlayCard/OverlayCard.cjs');
|
|
68
|
+
require('../../../../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
69
|
+
require('../../../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
70
|
+
require('../../../../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
71
|
+
require('../../../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
72
|
+
require('../../../../../../components/Popper/Popper/Popper.cjs');
|
|
73
|
+
require('../../../../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
74
|
+
require('react-focus-lock');
|
|
75
|
+
require('qrcode');
|
|
76
|
+
require('formik');
|
|
77
|
+
require('../../../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
|
|
78
|
+
require('../../../../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
79
|
+
require('../../../../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
|
|
80
|
+
require('../../../../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
|
|
81
|
+
require('../../../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
82
|
+
require('@hcaptcha/react-hcaptcha');
|
|
83
|
+
require('../../../../context/DynamicWidgetContext.cjs');
|
|
84
|
+
require('../../../../../../context/FooterAnimationContext/index.cjs');
|
|
85
|
+
require('../../../../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
|
|
86
|
+
require('../../../../../../context/PasskeyContext/PasskeyContext.cjs');
|
|
87
|
+
require('../../../../helpers/convertExchangeKeyAndProviderEnum.cjs');
|
|
88
|
+
require('../../../../../../store/state/sendBalances.cjs');
|
|
89
|
+
require('../../../../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
|
|
90
|
+
require('../../../../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
|
|
91
|
+
require('../../../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
92
|
+
require('../../../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
|
|
93
|
+
require('../../../ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
|
|
94
|
+
require('../../../../../../context/OnrampContext/OnrampContext.cjs');
|
|
95
|
+
require('../../ReceiveWalletFunds.cjs');
|
|
96
|
+
require('../../../../../../../index.cjs');
|
|
97
|
+
require('../../../../../../store/state/tokenBalances.cjs');
|
|
98
|
+
require('../../../../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
99
|
+
var useInternalDynamicContext = require('../../../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
|
|
100
|
+
|
|
101
|
+
const useExchangeTokensForFunding = ({ accounts, }) => {
|
|
102
|
+
var _a;
|
|
103
|
+
const { primaryWallet, network } = useInternalDynamicContext.useInternalDynamicContext();
|
|
104
|
+
const enabledNetworks = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.getEnabledNetworks();
|
|
105
|
+
const logoURI = (_a = enabledNetworks === null || enabledNetworks === void 0 ? void 0 : enabledNetworks.find(({ chainId }) => chainId === network)) === null || _a === void 0 ? void 0 : _a.iconUrls[0];
|
|
106
|
+
const fundingTokens = accounts.flatMap((account) => account.balances.map((balance) => ({
|
|
107
|
+
balance: balance.balance,
|
|
108
|
+
fiatBalance: undefined,
|
|
109
|
+
logoURI: logoURI, // INFORMATION WILL BE ADDED FROM BACKEND
|
|
110
|
+
name: balance.currency,
|
|
111
|
+
symbol: balance.currency,
|
|
112
|
+
token: 'native', // INFORMATION WILL BE ADDED FROM BACKEND
|
|
113
|
+
})));
|
|
114
|
+
const exchangeRates = useExchangeRatesForFunding.useExchangeRatesForFunding({
|
|
115
|
+
onFetch: () => { },
|
|
116
|
+
tokenBalances: fundingTokens,
|
|
117
|
+
});
|
|
118
|
+
const updatedFundingTokens = React.useMemo(() => {
|
|
119
|
+
if (!exchangeRates)
|
|
120
|
+
return fundingTokens;
|
|
121
|
+
return fundingTokens.map((t) => {
|
|
122
|
+
const price = exchangeRates[t.symbol];
|
|
123
|
+
return Object.assign(Object.assign({}, t), { fiatBalance: price !== undefined ? t.balance * price : undefined });
|
|
124
|
+
});
|
|
125
|
+
}, [fundingTokens, exchangeRates]);
|
|
126
|
+
return {
|
|
127
|
+
tokens: updatedFundingTokens,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
exports.useExchangeTokensForFunding = useExchangeTokensForFunding;
|