@dynamic-labs/sdk-react-core 4.29.0 → 4.29.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 (36) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/index.cjs +2 -0
  6. package/src/index.d.ts +1 -0
  7. package/src/index.js +1 -0
  8. package/src/lib/Main.cjs +1 -1
  9. package/src/lib/Main.js +1 -1
  10. package/src/lib/client/extension/user/useOnboardingCompleteUser/useOnboardingCompleteUser.js +1 -1
  11. package/src/lib/context/DynamicContext/DynamicContext.cjs +2 -2
  12. package/src/lib/context/DynamicContext/DynamicContext.js +2 -2
  13. package/src/lib/modals/SyncWalletPromptModal/SyncWalletPromptModal.cjs +2 -2
  14. package/src/lib/modals/SyncWalletPromptModal/SyncWalletPromptModal.js +2 -2
  15. package/src/lib/utils/hooks/index.d.ts +1 -0
  16. package/src/lib/utils/hooks/useConnectUnifiedForFunding/useConnectUnifiedForFunding.cjs +201 -0
  17. package/src/lib/utils/hooks/useConnectUnifiedForFunding/useConnectUnifiedForFunding.js +197 -0
  18. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +5 -2
  19. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.d.ts +1 -1
  20. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +5 -2
  21. package/src/lib/utils/hooks/useGetPasskeyErrorMessage/useGetPasskeyErrorMessage.cjs +3 -0
  22. package/src/lib/utils/hooks/useGetPasskeyErrorMessage/useGetPasskeyErrorMessage.js +3 -0
  23. package/src/lib/utils/hooks/usePayWithDynamic/index.d.ts +1 -1
  24. package/src/lib/utils/hooks/usePayWithDynamic/usePayWithDynamic.cjs +284 -0
  25. package/src/lib/utils/hooks/usePayWithDynamic/usePayWithDynamic.js +280 -0
  26. package/src/lib/utils/hooks/useWalletOptions/useWalletOptions.cjs +1 -0
  27. package/src/lib/utils/hooks/useWalletOptions/useWalletOptions.d.ts +2 -0
  28. package/src/lib/utils/hooks/useWalletOptions/useWalletOptions.js +1 -0
  29. package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.cjs +2 -2
  30. package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.js +2 -2
  31. package/src/lib/views/Passkey/ConfirmPasskeyView/ConfirmPasskeyView.cjs +1 -1
  32. package/src/lib/views/Passkey/ConfirmPasskeyView/ConfirmPasskeyView.js +1 -1
  33. package/src/lib/views/Passkey/SetupPasskeyView/SetupPasskeyView.cjs +1 -1
  34. package/src/lib/views/Passkey/SetupPasskeyView/SetupPasskeyView.js +1 -1
  35. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysMfaWidgetView/ManagePasskeysMfaWidgetView.cjs +5 -2
  36. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysMfaWidgetView/ManagePasskeysMfaWidgetView.js +5 -2
@@ -0,0 +1,197 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
+ import { useRef, useCallback } from 'react';
4
+ import { DynamicError, DeferredPromise } from '@dynamic-labs/utils';
5
+ import '../../../../index.js';
6
+ import '../../../context/DynamicContext/DynamicContext.js';
7
+ import '../../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
8
+ import '@dynamic-labs/sdk-api-core';
9
+ import '../../../shared/logger.js';
10
+ import '@dynamic-labs/iconic';
11
+ import '@dynamic-labs/wallet-connector-core';
12
+ import 'react/jsx-runtime';
13
+ import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
14
+ import '@dynamic-labs/wallet-book';
15
+ import '../../constants/colors.js';
16
+ import '../../constants/values.js';
17
+ import '../../../shared/consts/index.js';
18
+ import { useInternalDynamicEvents } from '../events/useDynamicEvents/useDynamicEvents.js';
19
+ import '../../../context/CaptchaContext/CaptchaContext.js';
20
+ import '../../../context/ErrorContext/ErrorContext.js';
21
+ import '@dynamic-labs/multi-wallet';
22
+ import 'react-international-phone';
23
+ import '../../../store/state/nonce/nonce.js';
24
+ import '@dynamic-labs-sdk/client/core';
25
+ import '../../../client/client.js';
26
+ import '@dynamic-labs-sdk/client';
27
+ import '../../../config/ApiEndpoint.js';
28
+ import { publicDynamicEvents } from '../../../events/dynamicEvents.js';
29
+ import '../../../store/state/projectSettings/projectSettings.js';
30
+ import '../../../locale/locale.js';
31
+ import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
32
+ import '../../../store/state/primaryWalletId/primaryWalletId.js';
33
+ import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
34
+ import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
35
+ import '../../../context/AccountExistsContext/AccountExistsContext.js';
36
+ import '../../../context/UserWalletsContext/UserWalletsContext.js';
37
+ import '../../../store/state/authMode/authMode.js';
38
+ import '../../../context/VerificationContext/VerificationContext.js';
39
+ import 'react-dom';
40
+ import '../../functions/compareChains/compareChains.js';
41
+ import '../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
42
+ import '../../../context/ThemeContext/ThemeContext.js';
43
+ import '../useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
44
+ import 'bs58';
45
+ import '@dynamic-labs/types';
46
+ import '../../../context/SocialRedirectContext/SocialRedirectContext.js';
47
+ import '../../../context/LoadingContext/LoadingContext.js';
48
+ import '../../../context/WalletContext/WalletContext.js';
49
+ import '../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js';
50
+ import 'yup';
51
+ import '../../../context/MockContext/MockContext.js';
52
+ import '../../../views/CollectUserDataView/useFields.js';
53
+ import '../../../context/FieldsStateContext/FieldsStateContext.js';
54
+ import '../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
55
+ import '@dynamic-labs/rpc-providers';
56
+ import '../../../store/state/walletOptions/walletOptions.js';
57
+ import 'react-i18next';
58
+ import '../../../components/Accordion/components/AccordionItem/AccordionItem.js';
59
+ import '../../../components/Alert/Alert.js';
60
+ import '../../../components/ShadowDOM/ShadowDOM.js';
61
+ import '../../../components/IconButton/IconButton.js';
62
+ import '../../../components/InlineWidget/InlineWidget.js';
63
+ import '../../../components/Input/Input.js';
64
+ import '../../../components/IsBrowser/IsBrowser.js';
65
+ import '../../../components/MenuList/Dropdown/Dropdown.js';
66
+ import '../../../components/OverlayCard/OverlayCard.js';
67
+ import '../../../components/Transition/ZoomTransition/ZoomTransition.js';
68
+ import '../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
69
+ import '../../../components/Transition/OpacityTransition/OpacityTransition.js';
70
+ import '../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
71
+ import '../../../components/Popper/Popper/Popper.js';
72
+ import '../../../components/Popper/PopperContext/PopperContext.js';
73
+ import 'react-focus-lock';
74
+ import 'qrcode';
75
+ import 'formik';
76
+ import '../useSubdomainCheck/useSubdomainCheck.js';
77
+ import '../../../context/WalletGroupContext/WalletGroupContext.js';
78
+ import '../../../context/IpConfigurationContext/IpConfigurationContext.js';
79
+ import '../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
80
+ import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
81
+ import '@hcaptcha/react-hcaptcha';
82
+ import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
83
+ import '../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.js';
84
+ import '../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.js';
85
+ import '../../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
86
+ import '../../../context/FooterAnimationContext/index.js';
87
+ import '../../../views/MfaChooseDeviceView/getMfaOptions/getMfaOptions.js';
88
+ import '../../../context/PasskeyContext/PasskeyContext.js';
89
+ import '../../../context/OnrampContext/OnrampContext.js';
90
+ import '../../../store/state/sendBalances.js';
91
+ import '../../../store/state/connectorsInitializing/connectorsInitializing.js';
92
+ import '../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
93
+ import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
94
+ import '../../../views/TransactionConfirmationView/TransactionConfirmationView.js';
95
+ import '../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.js';
96
+ import { resolvePromiseRef } from '../../functions/resolvePromiseRef/resolvePromiseRef.js';
97
+ import { rejectPromiseRef } from '../../functions/rejectPromiseRef/rejectPromiseRef.js';
98
+ import { useFundingHelpers } from '../useFundingHelpers/useFundingHelpers.js';
99
+ import '../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
100
+ import '../../../store/state/tokenBalances.js';
101
+ import '../../../store/state/multichainBalances.js';
102
+ import '../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
103
+ import { useFundingExchangeHelpers } from '../useFundingExchangeHelpers/useFundingExchangeHelpers.js';
104
+ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
105
+
106
+ const useConnectUnifiedForFunding = () => {
107
+ const { setShowAuthFlow } = useInternalDynamicContext();
108
+ const { clearStackAndPush } = useViewContext();
109
+ const { initiatedByWidgetRef, getWalletAddress, resetWalletConnectSession } = useFundingHelpers();
110
+ const { selectExchangeConfig } = useFundingExchangeHelpers();
111
+ const promiseRef = useRef(null);
112
+ useInternalDynamicEvents('authFlowClose', () => {
113
+ rejectPromiseRef(promiseRef, new DynamicError('User cancelled'));
114
+ });
115
+ const openList = useCallback((initiatedByWidget) => {
116
+ const { onSelectExchange } = selectExchangeConfig({
117
+ initiatedByWidget,
118
+ promiseRef,
119
+ resultBuilder: (exchange) => ({
120
+ exchange,
121
+ kind: 'exchange',
122
+ }),
123
+ });
124
+ clearStackAndPush('unified-wallet-exchange-list', {
125
+ onSelectExchange,
126
+ onSelectOnRamp: (onramp) => {
127
+ if (!promiseRef.current)
128
+ return;
129
+ try {
130
+ initiatedByWidgetRef.current = initiatedByWidget;
131
+ resolvePromiseRef(promiseRef, {
132
+ kind: 'onramp',
133
+ onramp,
134
+ });
135
+ }
136
+ catch (err) {
137
+ rejectPromiseRef(promiseRef, err);
138
+ }
139
+ finally {
140
+ setShowAuthFlow(false);
141
+ }
142
+ },
143
+ onSelectWallet: (_a) => __awaiter(void 0, [_a], void 0, function* ({ walletConnector, }) {
144
+ if (!promiseRef.current)
145
+ return;
146
+ try {
147
+ initiatedByWidgetRef.current = initiatedByWidget;
148
+ const walletAddress = yield getWalletAddress(walletConnector);
149
+ if (!walletAddress) {
150
+ rejectPromiseRef(promiseRef, new DynamicError('No wallet address found'));
151
+ return;
152
+ }
153
+ const wallet = walletConnector.createWallet({
154
+ address: walletAddress,
155
+ chain: walletConnector.connectedChain,
156
+ connector: walletConnector,
157
+ id: 'external-funding-wallet',
158
+ isAuthenticated: false,
159
+ key: walletConnector.key,
160
+ });
161
+ resolvePromiseRef(promiseRef, { kind: 'wallet', wallet });
162
+ publicDynamicEvents.emit('walletConnectedForFunding', {
163
+ initiatedByWidget,
164
+ isPhantomRedirect: false,
165
+ wallet,
166
+ });
167
+ }
168
+ catch (error) {
169
+ rejectPromiseRef(promiseRef, error);
170
+ }
171
+ }),
172
+ showDefaultFooter: true,
173
+ });
174
+ }, [
175
+ clearStackAndPush,
176
+ getWalletAddress,
177
+ initiatedByWidgetRef,
178
+ selectExchangeConfig,
179
+ setShowAuthFlow,
180
+ ]);
181
+ return useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ initiatedByWidget }) {
182
+ if (promiseRef.current)
183
+ return promiseRef.current.promise;
184
+ resetWalletConnectSession();
185
+ promiseRef.current = new DeferredPromise();
186
+ openList(initiatedByWidget);
187
+ setShowAuthFlow(true, {
188
+ emitCancelAuth: false,
189
+ ignoreIfIsEmbeddedWidget: true,
190
+ initializeWalletConnect: true,
191
+ performMultiWalletChecks: false,
192
+ });
193
+ return promiseRef.current.promise;
194
+ }), [openList, resetWalletConnectSession, setShowAuthFlow]);
195
+ };
196
+
197
+ export { useConnectUnifiedForFunding };
@@ -189,7 +189,7 @@ const useDynamicWaas = () => {
189
189
  ]);
190
190
  // If no chain names are provided, filter out chains that already have a wallet
191
191
  // and make a wallet for each enabled chain
192
- const createWalletAccount = React.useCallback((chainNames) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
192
+ const createWalletAccount = React.useCallback((chainNames, password) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
193
193
  if (!(enabledChainNames === null || enabledChainNames === void 0 ? void 0 : enabledChainNames.length)) {
194
194
  throw new utils.DynamicError(constants.NO_ENABLED_CHAINS_ERROR);
195
195
  }
@@ -202,7 +202,10 @@ const useDynamicWaas = () => {
202
202
  const walletConnector = getWalletConnector(chain);
203
203
  if (!walletConnector)
204
204
  throw new Error('No connector');
205
- const account = yield walletConnector.createWalletAccount();
205
+ const account = yield walletConnector.createWalletAccount({
206
+ password,
207
+ thresholdSignatureScheme: 'TWO_OF_TWO',
208
+ });
206
209
  return Object.assign(Object.assign({}, account), { chainName: chain });
207
210
  })));
208
211
  const failedChains = [];
@@ -13,7 +13,7 @@ export declare const configWaasWalletConnector: ({ walletConnector, environmentI
13
13
  }) => Promise<string | undefined>;
14
14
  }) => IDynamicWaasConnector;
15
15
  export declare const useDynamicWaas: () => {
16
- createWalletAccount: (chainNames: ChainEnum[]) => Promise<({
16
+ createWalletAccount: (chainNames: ChainEnum[], password?: string) => Promise<({
17
17
  chainName: ChainEnum;
18
18
  accountAddress: string;
19
19
  publicKeyHex: string;
@@ -185,7 +185,7 @@ const useDynamicWaas = () => {
185
185
  ]);
186
186
  // If no chain names are provided, filter out chains that already have a wallet
187
187
  // and make a wallet for each enabled chain
188
- const createWalletAccount = useCallback((chainNames) => __awaiter(void 0, void 0, void 0, function* () {
188
+ const createWalletAccount = useCallback((chainNames, password) => __awaiter(void 0, void 0, void 0, function* () {
189
189
  if (!(enabledChainNames === null || enabledChainNames === void 0 ? void 0 : enabledChainNames.length)) {
190
190
  throw new DynamicError(NO_ENABLED_CHAINS_ERROR);
191
191
  }
@@ -198,7 +198,10 @@ const useDynamicWaas = () => {
198
198
  const walletConnector = getWalletConnector(chain);
199
199
  if (!walletConnector)
200
200
  throw new Error('No connector');
201
- const account = yield walletConnector.createWalletAccount();
201
+ const account = yield walletConnector.createWalletAccount({
202
+ password,
203
+ thresholdSignatureScheme: 'TWO_OF_TWO',
204
+ });
202
205
  return Object.assign(Object.assign({}, account), { chainName: chain });
203
206
  })));
204
207
  const failedChains = [];
@@ -15,6 +15,9 @@ const useGetPasskeyErrorMessage = (error) => {
15
15
  if (error.name === 'NotAllowedError') {
16
16
  return t('dyn_mfa.confirm_passkey_view.error.not_allowed');
17
17
  }
18
+ if (error.name === 'InvalidStateError') {
19
+ return error.message;
20
+ }
18
21
  return error.message;
19
22
  }, [error, t]);
20
23
  };
@@ -11,6 +11,9 @@ const useGetPasskeyErrorMessage = (error) => {
11
11
  if (error.name === 'NotAllowedError') {
12
12
  return t('dyn_mfa.confirm_passkey_view.error.not_allowed');
13
13
  }
14
+ if (error.name === 'InvalidStateError') {
15
+ return error.message;
16
+ }
14
17
  return error.message;
15
18
  }, [error, t]);
16
19
  };
@@ -1 +1 @@
1
- export { usePayWithDynamic } from './usePayWithDynamic';
1
+ export { usePayWithDynamic, type PayWithDynamicProps, } from './usePayWithDynamic';
@@ -0,0 +1,284 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
+ var React = require('react');
8
+ require('@dynamic-labs-sdk/client/core');
9
+ require('@dynamic-labs/sdk-api-core');
10
+ require('../../../client/client.cjs');
11
+ require('@dynamic-labs-sdk/client');
12
+ require('../../../config/ApiEndpoint.cjs');
13
+ require('@dynamic-labs/utils');
14
+ require('../../constants/values.cjs');
15
+ require('@dynamic-labs/multi-wallet');
16
+ var logger = require('../../../shared/logger.cjs');
17
+ require('../../constants/colors.cjs');
18
+ require('react-international-phone');
19
+ require('@dynamic-labs/iconic');
20
+ require('@dynamic-labs/wallet-connector-core');
21
+ require('react/jsx-runtime');
22
+ require('../../../context/ViewContext/ViewContext.cjs');
23
+ require('@dynamic-labs/wallet-book');
24
+ require('../../../shared/consts/index.cjs');
25
+ require('../../../store/state/nonce/nonce.cjs');
26
+ var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
27
+ require('../../../locale/locale.cjs');
28
+ require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
29
+ require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
30
+ require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
31
+ require('../../../events/dynamicEvents.cjs');
32
+ var useOnboardingCompleteUser = require('../../../client/extension/user/useOnboardingCompleteUser/useOnboardingCompleteUser.cjs');
33
+ var OnrampContext = require('../../../context/OnrampContext/OnrampContext.cjs');
34
+ var useConnectUnifiedForFunding = require('../useConnectUnifiedForFunding/useConnectUnifiedForFunding.cjs');
35
+ var useSocialAccounts = require('../useSocialAccounts/useSocialAccounts.cjs');
36
+ var usePromptAmountAndFundWithWallet = require('../useFundWithWallet/usePromptAmountAndFundWithWallet/usePromptAmountAndFundWithWallet.cjs');
37
+ var usePromptAndFundWithExchange = require('../usePromptAndFundWithExchange/usePromptAndFundWithExchange.cjs');
38
+ var useWalletItemActions = require('../useWalletItemActions/useWalletItemActions.cjs');
39
+ var walletOptions = require('../../../store/state/walletOptions/walletOptions.cjs');
40
+ require('../../../context/DynamicContext/DynamicContext.cjs');
41
+ require('../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
42
+ require('../../../context/CaptchaContext/CaptchaContext.cjs');
43
+ require('../../../context/ErrorContext/ErrorContext.cjs');
44
+ require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
45
+ require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
46
+ require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
47
+ require('../../../store/state/authMode/authMode.cjs');
48
+ require('../../../context/VerificationContext/VerificationContext.cjs');
49
+ require('react-dom');
50
+ require('../../functions/compareChains/compareChains.cjs');
51
+ require('../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
52
+ require('../../../context/ThemeContext/ThemeContext.cjs');
53
+ require('../useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
54
+ require('bs58');
55
+ require('yup');
56
+ require('../../../context/MockContext/MockContext.cjs');
57
+ require('../../../views/CollectUserDataView/useFields.cjs');
58
+ require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
59
+ require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
60
+ require('@dynamic-labs/rpc-providers');
61
+ require('react-i18next');
62
+ require('../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
63
+ require('../../../components/Alert/Alert.cjs');
64
+ require('../../../context/WalletContext/WalletContext.cjs');
65
+ require('../../../components/ShadowDOM/ShadowDOM.cjs');
66
+ require('../../../components/IconButton/IconButton.cjs');
67
+ require('../../../components/InlineWidget/InlineWidget.cjs');
68
+ require('../../../components/Input/Input.cjs');
69
+ require('../../../components/IsBrowser/IsBrowser.cjs');
70
+ require('../../../components/MenuList/Dropdown/Dropdown.cjs');
71
+ require('../../../components/OverlayCard/OverlayCard.cjs');
72
+ require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
73
+ require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
74
+ require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
75
+ require('../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
76
+ require('../../../components/Popper/Popper/Popper.cjs');
77
+ require('../../../components/Popper/PopperContext/PopperContext.cjs');
78
+ require('react-focus-lock');
79
+ require('qrcode');
80
+ require('formik');
81
+ require('../useSubdomainCheck/useSubdomainCheck.cjs');
82
+ require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
83
+ require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
84
+ require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
85
+ require('../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
86
+ require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
87
+ require('@hcaptcha/react-hcaptcha');
88
+ require('../../../context/LoadingContext/LoadingContext.cjs');
89
+ require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
90
+ require('../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
91
+ require('../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
92
+ require('../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
93
+ require('../../../context/FooterAnimationContext/index.cjs');
94
+ require('@dynamic-labs/types');
95
+ require('../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
96
+ require('../../../views/MfaChooseDeviceView/getMfaOptions/getMfaOptions.cjs');
97
+ require('../../../context/PasskeyContext/PasskeyContext.cjs');
98
+ require('../../../store/state/sendBalances.cjs');
99
+ require('../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
100
+ require('../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
101
+ require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
102
+ require('../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
103
+ require('../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.cjs');
104
+ require('../../../../index.cjs');
105
+ require('../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
106
+ require('../../../store/state/tokenBalances.cjs');
107
+ require('../../../store/state/multichainBalances.cjs');
108
+ require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
109
+ var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
110
+
111
+ const usePayWithDynamic = () => {
112
+ const connectUnifiedForFunding = useConnectUnifiedForFunding.useConnectUnifiedForFunding();
113
+ const projectSettings$1 = projectSettings.useProjectSettings();
114
+ const { linkSocialAccount, signInWithSocialAccount } = useSocialAccounts.useSocialAccounts();
115
+ const user = useOnboardingCompleteUser.useOnboardingCompleteUser();
116
+ const { openOnramp, setEnabledOnrampProvidersTargetValue } = OnrampContext.useOnrampContext();
117
+ const promptWallet = usePromptAmountAndFundWithWallet.usePromptAmountAndFundWithWallet();
118
+ const promptExchange = usePromptAndFundWithExchange.usePromptAmountAndFundWithExchange();
119
+ const { handleWalletItemClick } = useWalletItemActions.useWalletItemActions();
120
+ const { walletConnectorOptions } = walletOptions.getWalletOptions();
121
+ const { setShowAuthFlow, setShowDynamicUserProfile } = useInternalDynamicContext.useInternalDynamicContext();
122
+ // Flow for funding via wallet
123
+ const handleWalletFlow = React.useCallback(({ wallet, props, onBack }) => {
124
+ // If user is not onboarded, trigger wallet connector UI
125
+ if (!user) {
126
+ const option = walletConnectorOptions.find(({ key }) => key === wallet.connector.key);
127
+ if (option)
128
+ handleWalletItemClick(option);
129
+ }
130
+ // Prompt for amount and execute wallet funding (shows deposit screen)
131
+ promptWallet({
132
+ amount: { rule: 'exact', value: props.tokenAmount },
133
+ destinationAddress: props.destinationAddress,
134
+ network: props.network,
135
+ onBack,
136
+ token: { rule: 'exact-with-amount', value: props.tokenSymbol },
137
+ wallet: wallet,
138
+ });
139
+ setShowAuthFlow(false);
140
+ }, [
141
+ handleWalletItemClick,
142
+ promptWallet,
143
+ setShowAuthFlow,
144
+ user,
145
+ walletConnectorOptions,
146
+ ]);
147
+ // Flow for linking or signing in with social account before exchange
148
+ const handleSocialConnect = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ provider, exchange, props, isSocialProviderAlreadyVerified, }) {
149
+ // if connected social return since already signed in
150
+ if (isSocialProviderAlreadyVerified) {
151
+ return false;
152
+ }
153
+ const payload = {
154
+ payingWithDynamic: {
155
+ chainName: props.chainName,
156
+ destinationAddress: props.destinationAddress,
157
+ network: props.network,
158
+ tokenAmount: props.tokenAmount,
159
+ tokenSymbol: props.tokenSymbol,
160
+ },
161
+ triggerFundFromExchangeOnSuccess: exchange,
162
+ };
163
+ if (user) {
164
+ // link if user exists
165
+ yield linkSocialAccount(provider, payload);
166
+ }
167
+ else {
168
+ // sign in if no user
169
+ yield signInWithSocialAccount(provider, payload);
170
+ }
171
+ return true;
172
+ }), [linkSocialAccount, signInWithSocialAccount, user]);
173
+ // exchange flow
174
+ const handleExchangeFlow = React.useCallback((_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ exchange, props, onBack }) {
175
+ var _c, _d, _e, _f, _g;
176
+ const fullExchange = (_c = projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.exchanges) === null || _c === void 0 ? void 0 : _c.find((e) => e.exchange === exchange);
177
+ // Social provider for this exchange, if any
178
+ const provider = fullExchange === null || fullExchange === void 0 ? void 0 : fullExchange.socialProvider;
179
+ const isProviderSocialConnectEnabled = provider &&
180
+ Boolean((_e = (_d = projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.providers) === null || _d === void 0 ? void 0 : _d.find((p) => p.provider === provider)) === null || _e === void 0 ? void 0 : _e.enabledAt);
181
+ // Check if user already verified this social provider
182
+ const isSocialProviderAlreadyVerified = (_g = (_f = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _f === void 0 ? void 0 : _f.some((c) => c.oauthProvider === provider)) !== null && _g !== void 0 ? _g : false;
183
+ // If exchange requires social connect, handle that first
184
+ if (isProviderSocialConnectEnabled && provider) {
185
+ const handled = yield handleSocialConnect({
186
+ exchange,
187
+ isSocialProviderAlreadyVerified,
188
+ props,
189
+ provider,
190
+ });
191
+ // Social connect flow opened, stop here
192
+ if (handled)
193
+ return;
194
+ // If already connected, prompt amount and fund with exchange
195
+ promptExchange({
196
+ exchange,
197
+ onBack,
198
+ payingWithDynamic: props,
199
+ });
200
+ return;
201
+ }
202
+ // No social provider = use on-ramp provider if configured
203
+ if (fullExchange === null || fullExchange === void 0 ? void 0 : fullExchange.onRampProvider) {
204
+ yield openOnramp({
205
+ address: props.destinationAddress,
206
+ chainName: props.chainName,
207
+ network: String(props.network),
208
+ onrampProvider: fullExchange.onRampProvider,
209
+ overrideOnRamp: true,
210
+ payingWithDynamic: true,
211
+ token: props.tokenSymbol,
212
+ tokenAmount: props.tokenAmount,
213
+ });
214
+ }
215
+ }), [
216
+ projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.exchanges,
217
+ projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.providers,
218
+ user === null || user === void 0 ? void 0 : user.verifiedCredentials,
219
+ handleSocialConnect,
220
+ promptExchange,
221
+ openOnramp,
222
+ ]);
223
+ const payWithDynamic = React.useCallback((props) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
224
+ try {
225
+ setEnabledOnrampProvidersTargetValue({
226
+ address: props.destinationAddress,
227
+ chainName: props.chainName,
228
+ network: String(props.network),
229
+ token: props.tokenSymbol,
230
+ tokenAmount: props.tokenAmount,
231
+ });
232
+ const result = yield connectUnifiedForFunding({
233
+ initiatedByWidget: false,
234
+ });
235
+ if (result.kind === 'wallet') {
236
+ handleWalletFlow({
237
+ onBack: () => {
238
+ setShowAuthFlow(true);
239
+ setShowDynamicUserProfile(false);
240
+ payWithDynamic(props);
241
+ },
242
+ props,
243
+ wallet: result.wallet,
244
+ });
245
+ }
246
+ else if (result.kind === 'exchange') {
247
+ yield handleExchangeFlow({
248
+ exchange: result.exchange,
249
+ onBack: () => {
250
+ setShowAuthFlow(true);
251
+ setShowDynamicUserProfile(false);
252
+ payWithDynamic(props);
253
+ },
254
+ props,
255
+ });
256
+ }
257
+ else {
258
+ yield openOnramp({
259
+ address: props.destinationAddress,
260
+ chainName: props.chainName,
261
+ network: String(props.network),
262
+ onrampProvider: result.onramp.id,
263
+ payingWithDynamic: true,
264
+ token: props.tokenSymbol,
265
+ tokenAmount: props.tokenAmount,
266
+ });
267
+ }
268
+ }
269
+ catch (error) {
270
+ logger.logger.error('usePayWithDynamic failed', error);
271
+ }
272
+ }), [
273
+ setEnabledOnrampProvidersTargetValue,
274
+ connectUnifiedForFunding,
275
+ handleWalletFlow,
276
+ setShowAuthFlow,
277
+ setShowDynamicUserProfile,
278
+ handleExchangeFlow,
279
+ openOnramp,
280
+ ]);
281
+ return payWithDynamic;
282
+ };
283
+
284
+ exports.usePayWithDynamic = usePayWithDynamic;