@dynamic-labs/sdk-react-core 3.0.0-alpha.57 → 3.0.0-alpha.59

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 (39) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +11 -12
  5. package/src/index.cjs +2 -1
  6. package/src/index.d.ts +1 -1
  7. package/src/index.js +1 -1
  8. package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -3
  9. package/src/lib/context/DynamicContext/DynamicContext.js +1 -3
  10. package/src/lib/context/DynamicContext/hooks/useSelectedWalletConnector/useSelectedWalletConnector.d.ts +1 -1
  11. package/src/lib/context/DynamicContext/types/DynamicContextProps.d.ts +0 -1
  12. package/src/lib/context/DynamicContext/types/IDynamicContext.d.ts +0 -2
  13. package/src/lib/context/UserWalletsContext/UserWalletsContext.d.ts +1 -1
  14. package/src/lib/context/ViewContext/types/index.d.ts +1 -1
  15. package/src/lib/locale/en/translation.cjs +42 -0
  16. package/src/lib/locale/en/translation.d.ts +42 -0
  17. package/src/lib/locale/en/translation.js +42 -0
  18. package/src/lib/styles/index.shadow.cjs +1 -1
  19. package/src/lib/styles/index.shadow.js +1 -1
  20. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +1 -0
  21. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +1 -0
  22. package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.d.ts +1 -1
  23. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +2 -2
  24. package/src/lib/utils/hooks/useSyncOnboardingFlow/useSyncOnboardingFlow.cjs +1 -6
  25. package/src/lib/utils/hooks/useSyncOnboardingFlow/useSyncOnboardingFlow.js +1 -6
  26. package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.cjs +5 -2
  27. package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.js +5 -2
  28. package/src/lib/views/GlobalWalletInfoView/GlobalWalletInfoView.cjs +34 -0
  29. package/src/lib/views/GlobalWalletInfoView/GlobalWalletInfoView.d.ts +3 -0
  30. package/src/lib/views/GlobalWalletInfoView/GlobalWalletInfoView.js +29 -0
  31. package/src/lib/views/viewToComponentMap.cjs +2 -0
  32. package/src/lib/views/viewToComponentMap.d.ts +1 -0
  33. package/src/lib/views/viewToComponentMap.js +2 -0
  34. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/GlobalWalletTypes.d.ts +31 -0
  35. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/GlobalWalletView.cjs +84 -95
  36. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/GlobalWalletView.js +86 -97
  37. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/scanner/GlobalWalletScanner.cjs +54 -0
  38. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/scanner/GlobalWalletScanner.d.ts +7 -0
  39. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/scanner/GlobalWalletScanner.js +49 -0
@@ -148,6 +148,7 @@ const useAuthLayoutChecks = () => {
148
148
  view.type !== 'wallet-claim-intro' &&
149
149
  view.type !== 'passkey-recovery-add-email' &&
150
150
  view.type !== 'global-wallet-confirm' &&
151
+ view.type !== 'global-wallet-info' &&
151
152
  view.type !== 'mfa-choose-device' &&
152
153
  view.type !== 'mfa-verification';
153
154
  const showConnectedWalletProgress = isBridgeFlow &&
@@ -144,6 +144,7 @@ const useAuthLayoutChecks = () => {
144
144
  view.type !== 'wallet-claim-intro' &&
145
145
  view.type !== 'passkey-recovery-add-email' &&
146
146
  view.type !== 'global-wallet-confirm' &&
147
+ view.type !== 'global-wallet-info' &&
147
148
  view.type !== 'mfa-choose-device' &&
148
149
  view.type !== 'mfa-verification';
149
150
  const showConnectedWalletProgress = isBridgeFlow &&
@@ -1,2 +1,2 @@
1
1
  import { Wallet, WalletConnector } from '../../../..';
2
- export declare const useConnectedAccountWallet: (connector: WalletConnector | undefined, secondaryWallets: Wallet[]) => import("../usePromise").PromiseState<Wallet<import("@dynamic-labs/wallet-connector-core").WalletConnectorCore.WalletConnector> | undefined, Error>;
2
+ export declare const useConnectedAccountWallet: (connector: WalletConnector | undefined, secondaryWallets: Wallet[]) => import("../usePromise").PromiseState<Wallet<import("dist/packages/wallet-connector-core/src").WalletConnectorCore.WalletConnector> | undefined, Error>;
@@ -17,7 +17,7 @@ import { UserProfile } from '../../../..';
17
17
  */
18
18
  export declare const useEmbeddedWallet: () => {
19
19
  readonly createEmbeddedWallet: (chains?: EmbeddedWalletChainEnum[], options?: {
20
- webAuthnAttestation: import("@dynamic-labs/wallet-connector-core").WebAuthnAttestation;
20
+ webAuthnAttestation: import("dist/packages/wallet-connector-core/src").WebAuthnAttestation;
21
21
  } | undefined) => Promise<Wallet | undefined>;
22
22
  readonly createEmbeddedWalletAccount: ({ chain }: {
23
23
  chain: EmbeddedWalletChainEnum;
@@ -27,7 +27,7 @@ export declare const useEmbeddedWallet: () => {
27
27
  } | undefined) => Promise<string | undefined>;
28
28
  readonly createPasskey: (options: {
29
29
  oneTimeCode: string;
30
- } | undefined) => Promise<import("@dynamic-labs/wallet-connector-core").WebAuthnAttestation>;
30
+ } | undefined) => Promise<import("dist/packages/wallet-connector-core/src").WebAuthnAttestation>;
31
31
  readonly createPassword: (showIntro?: boolean | undefined) => Promise<string>;
32
32
  readonly getPasskeys: () => Promise<import("@dynamic-labs/sdk-api-core").UserPasskey[]>;
33
33
  readonly getWalletVersion: () => import(".").EmbeddedWalletVersion | undefined;
@@ -99,7 +99,7 @@ require('../../../store/state/tokenBalances.cjs');
99
99
  var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
100
100
 
101
101
  const useSyncOnboardingFlow = () => {
102
- const { setShowAuthFlow, userWithMissingInfo, handlers, headless, sdkHasLoaded, setSelectedWalletConnectorKey, } = useInternalDynamicContext.useInternalDynamicContext();
102
+ const { setShowAuthFlow, userWithMissingInfo, handlers, sdkHasLoaded, setSelectedWalletConnectorKey, } = useInternalDynamicContext.useInternalDynamicContext();
103
103
  const { setView } = ViewContext.useViewContext();
104
104
  const { updateUser } = useUserUpdateRequest.useUserUpdateRequestInternal({
105
105
  validationSchemaStripUnknown: false,
@@ -184,10 +184,6 @@ const useSyncOnboardingFlow = () => {
184
184
  handleHeadlessOnboarding();
185
185
  return;
186
186
  }
187
- if (headless) {
188
- logger.logger.error('No onboarding handler found. Please add a handleUserOnboarding handler to your dynamic provider settings.');
189
- return;
190
- }
191
187
  handleOnboarding();
192
188
  return;
193
189
  }, [
@@ -196,7 +192,6 @@ const useSyncOnboardingFlow = () => {
196
192
  handlers,
197
193
  completeAuth,
198
194
  updateUser,
199
- headless,
200
195
  setShowAuthFlow,
201
196
  setView,
202
197
  formattedPhone,
@@ -95,7 +95,7 @@ import '../../../store/state/tokenBalances.js';
95
95
  import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
96
96
 
97
97
  const useSyncOnboardingFlow = () => {
98
- const { setShowAuthFlow, userWithMissingInfo, handlers, headless, sdkHasLoaded, setSelectedWalletConnectorKey, } = useInternalDynamicContext();
98
+ const { setShowAuthFlow, userWithMissingInfo, handlers, sdkHasLoaded, setSelectedWalletConnectorKey, } = useInternalDynamicContext();
99
99
  const { setView } = useViewContext();
100
100
  const { updateUser } = useUserUpdateRequestInternal({
101
101
  validationSchemaStripUnknown: false,
@@ -180,10 +180,6 @@ const useSyncOnboardingFlow = () => {
180
180
  handleHeadlessOnboarding();
181
181
  return;
182
182
  }
183
- if (headless) {
184
- logger.error('No onboarding handler found. Please add a handleUserOnboarding handler to your dynamic provider settings.');
185
- return;
186
- }
187
183
  handleOnboarding();
188
184
  return;
189
185
  }, [
@@ -192,7 +188,6 @@ const useSyncOnboardingFlow = () => {
192
188
  handlers,
193
189
  completeAuth,
194
190
  updateUser,
195
- headless,
196
191
  setShowAuthFlow,
197
192
  setView,
198
193
  formattedPhone,
@@ -175,7 +175,11 @@ const useWalletItemActions = () => {
175
175
  });
176
176
  const handleAlreadyConnectedWallet = (walletConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
177
177
  logger.logger.debug('handleAlreadyConnectedWallet', walletConnector);
178
- const connectedAccounts = yield walletConnector.getConnectedAccounts(true);
178
+ setShowAuthFlow(false);
179
+ const connectedAccounts = yield walletConnector.getConnectedAccounts({
180
+ chooseAccounts: true,
181
+ forceFetch: true,
182
+ });
179
183
  const activeAccountAlreadyLinked = linkedWallets.find((wallet) => { var _a; return wallet.address.toLowerCase() === ((_a = connectedAccounts[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase()); });
180
184
  logVerboseTroubleshootingMessage.logVerboseTroubleshootingMessage('[handleAlreadyConnectedWallet]', {
181
185
  activeAccountAlreadyLinked,
@@ -188,7 +192,6 @@ const useWalletItemActions = () => {
188
192
  else {
189
193
  setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
190
194
  }
191
- setShowAuthFlow(false);
192
195
  setSelectedWalletConnectorKey(walletConnector.key);
193
196
  });
194
197
  const openWallet = (walletKey, handlers) => {
@@ -171,7 +171,11 @@ const useWalletItemActions = () => {
171
171
  });
172
172
  const handleAlreadyConnectedWallet = (walletConnector) => __awaiter(void 0, void 0, void 0, function* () {
173
173
  logger.debug('handleAlreadyConnectedWallet', walletConnector);
174
- const connectedAccounts = yield walletConnector.getConnectedAccounts(true);
174
+ setShowAuthFlow(false);
175
+ const connectedAccounts = yield walletConnector.getConnectedAccounts({
176
+ chooseAccounts: true,
177
+ forceFetch: true,
178
+ });
175
179
  const activeAccountAlreadyLinked = linkedWallets.find((wallet) => { var _a; return wallet.address.toLowerCase() === ((_a = connectedAccounts[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase()); });
176
180
  logVerboseTroubleshootingMessage('[handleAlreadyConnectedWallet]', {
177
181
  activeAccountAlreadyLinked,
@@ -184,7 +188,6 @@ const useWalletItemActions = () => {
184
188
  else {
185
189
  setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
186
190
  }
187
- setShowAuthFlow(false);
188
191
  setSelectedWalletConnectorKey(walletConnector.key);
189
192
  });
190
193
  const openWallet = (walletKey, handlers) => {
@@ -0,0 +1,34 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var reactI18next = require('react-i18next');
8
+ var Typography = require('../../components/Typography/Typography.cjs');
9
+ require('@dynamic-labs/sdk-api-core');
10
+ require('../../shared/logger.cjs');
11
+ require('@dynamic-labs/iconic');
12
+ require('@dynamic-labs/wallet-connector-core');
13
+ require('../../context/ViewContext/ViewContext.cjs');
14
+ require('react');
15
+ var copy = require('../../shared/assets/copy.cjs');
16
+ var blueWalletconnect = require('../../shared/assets/blue-walletconnect.cjs');
17
+ require('@dynamic-labs/wallet-book');
18
+ require('../../utils/constants/colors.cjs');
19
+ require('../../utils/constants/values.cjs');
20
+ require('../../shared/utils/classes/storage/localStorage.cjs');
21
+ require('../../shared/utils/classes/storage/sessionStorage.cjs');
22
+ require('../../store/state/loadingAndLifecycle.cjs');
23
+ require('@dynamic-labs/utils');
24
+ require('../../shared/consts/index.cjs');
25
+
26
+ const InlineIconTypography = ({ children }) => (jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: jsxRuntime.jsx("span", { className: 'inline-icon-text', children: children }) }));
27
+ const GlobalWalletInfoView = () => {
28
+ const { t } = reactI18next.useTranslation();
29
+ // we cannot translate some of this as we have icons inline with text
30
+ return (jsxRuntime.jsx("div", { className: 'info-card', children: jsxRuntime.jsxs("div", { className: 'wrapper', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'bold', color: 'primary', as: 'h2', children: "How do I find the URI or QR code?" }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.1') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.2') }), jsxRuntime.jsxs(InlineIconTypography, { children: ["3. Open", ' ', jsxRuntime.jsxs("span", { className: 'nowrap', children: ["WalletConnect ", jsxRuntime.jsx(blueWalletconnect.ReactComponent, {})] }), "from the list, this should show a QR code to scan"] }), jsxRuntime.jsxs(InlineIconTypography, { children: ["4. If you are not using the QR code, locate and click", jsxRuntime.jsxs("span", { className: 'nowrap', children: [jsxRuntime.jsx(copy.ReactComponent, {}), " to copy"] }), ' ', "the URI code"] })] }) }));
31
+ };
32
+
33
+ exports.GlobalWalletInfoView = GlobalWalletInfoView;
34
+ exports["default"] = GlobalWalletInfoView;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const GlobalWalletInfoView: () => JSX.Element;
3
+ export default GlobalWalletInfoView;
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { Typography } from '../../components/Typography/Typography.js';
5
+ import '@dynamic-labs/sdk-api-core';
6
+ import '../../shared/logger.js';
7
+ import '@dynamic-labs/iconic';
8
+ import '@dynamic-labs/wallet-connector-core';
9
+ import '../../context/ViewContext/ViewContext.js';
10
+ import 'react';
11
+ import { ReactComponent as SvgCopy } from '../../shared/assets/copy.js';
12
+ import { ReactComponent as SvgBlueWalletconnect } from '../../shared/assets/blue-walletconnect.js';
13
+ import '@dynamic-labs/wallet-book';
14
+ import '../../utils/constants/colors.js';
15
+ import '../../utils/constants/values.js';
16
+ import '../../shared/utils/classes/storage/localStorage.js';
17
+ import '../../shared/utils/classes/storage/sessionStorage.js';
18
+ import '../../store/state/loadingAndLifecycle.js';
19
+ import '@dynamic-labs/utils';
20
+ import '../../shared/consts/index.js';
21
+
22
+ const InlineIconTypography = ({ children }) => (jsx(Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: jsx("span", { className: 'inline-icon-text', children: children }) }));
23
+ const GlobalWalletInfoView = () => {
24
+ const { t } = useTranslation();
25
+ // we cannot translate some of this as we have icons inline with text
26
+ return (jsx("div", { className: 'info-card', children: jsxs("div", { className: 'wrapper', children: [jsx(Typography, { variant: 'body_small', weight: 'bold', color: 'primary', as: 'h2', children: "How do I find the URI or QR code?" }), jsx(Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.1') }), jsx(Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.2') }), jsxs(InlineIconTypography, { children: ["3. Open", ' ', jsxs("span", { className: 'nowrap', children: ["WalletConnect ", jsx(SvgBlueWalletconnect, {})] }), "from the list, this should show a QR code to scan"] }), jsxs(InlineIconTypography, { children: ["4. If you are not using the QR code, locate and click", jsxs("span", { className: 'nowrap', children: [jsx(SvgCopy, {}), " to copy"] }), ' ', "the URI code"] })] }) }));
27
+ };
28
+
29
+ export { GlobalWalletInfoView, GlobalWalletInfoView as default };
@@ -133,6 +133,7 @@ var MfaRecoveryView = require('./MfaRecoveryView/MfaRecoveryView.cjs');
133
133
  var MfaSecureDeviceHelpView = require('./MfaSecureDeviceHelpView/MfaSecureDeviceHelpView.cjs');
134
134
  var SandboxMaximumThresholdReached = require('./SandboxMaximumThresholdReached/SandboxMaximumThresholdReached.cjs');
135
135
  var GlobalWalletConfirmView = require('./GlobalWalletConfirmView/GlobalWalletConfirmView.cjs');
136
+ var GlobalWalletInfoView = require('./GlobalWalletInfoView/GlobalWalletInfoView.cjs');
136
137
  require('../context/SendBalanceContext/SendBalanceContext.cjs');
137
138
  require('../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
138
139
  require('../context/ConnectWithOtpContext/constants.cjs');
@@ -161,6 +162,7 @@ const viewToComponentMap = {
161
162
  'farcaster-connect-view': FarcasterConnectView.FarcasterConnectView,
162
163
  'gate-blocked-wallet': NoAccess.NoAccess,
163
164
  'global-wallet-confirm': GlobalWalletConfirmView.GlobalWalletConfirmView,
165
+ 'global-wallet-info': GlobalWalletInfoView.GlobalWalletInfoView,
164
166
  'login-with-email-or-wallet': LoginView.LoginView,
165
167
  'login-with-email-or-wallet-full-wallet-list': WalletList.WalletList,
166
168
  'login-with-email-verification': EmailVerification.EmailVerification,
@@ -20,6 +20,7 @@ export declare const viewToComponentMap: {
20
20
  'farcaster-connect-view': ({ url }: import("./FarcasterConnectView/FarcasterConnectView").FarcasterConnectViewProps) => JSX.Element;
21
21
  'gate-blocked-wallet': () => JSX.Element;
22
22
  'global-wallet-confirm': import("react").FC<import("./GlobalWalletConfirmView").GlobalWalletConfirmViewProps>;
23
+ 'global-wallet-info': () => JSX.Element;
23
24
  'login-with-email-or-wallet': () => JSX.Element;
24
25
  'login-with-email-or-wallet-full-wallet-list': ({ isWalletConnectList, }: import("./WalletList").WalletListProps) => JSX.Element;
25
26
  'login-with-email-verification': import("react").FC<import("./EmailVerification/EmailVerification").EmailVerificationProps>;
@@ -129,6 +129,7 @@ import { MfaRecoveryView } from './MfaRecoveryView/MfaRecoveryView.js';
129
129
  import { MfaSecureDeviceHelper } from './MfaSecureDeviceHelpView/MfaSecureDeviceHelpView.js';
130
130
  import { SandboxMaximumThresholdReached } from './SandboxMaximumThresholdReached/SandboxMaximumThresholdReached.js';
131
131
  import { GlobalWalletConfirmView } from './GlobalWalletConfirmView/GlobalWalletConfirmView.js';
132
+ import { GlobalWalletInfoView } from './GlobalWalletInfoView/GlobalWalletInfoView.js';
132
133
  import '../context/SendBalanceContext/SendBalanceContext.js';
133
134
  import '../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
134
135
  import '../context/ConnectWithOtpContext/constants.js';
@@ -157,6 +158,7 @@ const viewToComponentMap = {
157
158
  'farcaster-connect-view': FarcasterConnectView,
158
159
  'gate-blocked-wallet': NoAccess,
159
160
  'global-wallet-confirm': GlobalWalletConfirmView,
161
+ 'global-wallet-info': GlobalWalletInfoView,
160
162
  'login-with-email-or-wallet': LoginView,
161
163
  'login-with-email-or-wallet-full-wallet-list': WalletList,
162
164
  'login-with-email-verification': EmailVerification,
@@ -0,0 +1,31 @@
1
+ export interface PairingInfo {
2
+ id: number;
3
+ params: {
4
+ id: number;
5
+ pairingTopic: string;
6
+ expiryTimestamp: number;
7
+ requiredNamespaces: Record<string, unknown>;
8
+ optionalNamespaces: {
9
+ eip155: {
10
+ chains: string[];
11
+ methods: string[];
12
+ events: string[];
13
+ rpcMap: {
14
+ [key: string]: string;
15
+ };
16
+ };
17
+ };
18
+ relays: Array<{
19
+ protocol: string;
20
+ }>;
21
+ proposer: {
22
+ publicKey: string;
23
+ metadata: {
24
+ name: string;
25
+ description: string;
26
+ url: string;
27
+ icons: string[];
28
+ };
29
+ };
30
+ };
31
+ }
@@ -7,6 +7,7 @@ var _tslib = require('../../../../../../_virtual/_tslib.cjs');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
8
  var React = require('react');
9
9
  var reactI18next = require('react-i18next');
10
+ var utils = require('@dynamic-labs/utils');
10
11
  require('@dynamic-labs/sdk-api-core');
11
12
  require('../../../../shared/logger.cjs');
12
13
  require('@dynamic-labs/iconic');
@@ -15,13 +16,13 @@ var ViewContext = require('../../../../context/ViewContext/ViewContext.cjs');
15
16
  var arrowLeft = require('../../../../shared/assets/arrow-left.cjs');
16
17
  var copy = require('../../../../shared/assets/copy.cjs');
17
18
  var blueWalletconnect = require('../../../../shared/assets/blue-walletconnect.cjs');
19
+ var questionMark = require('../../../../shared/assets/question-mark.cjs');
18
20
  require('@dynamic-labs/wallet-book');
19
21
  require('../../../../utils/constants/colors.cjs');
20
22
  require('../../../../utils/constants/values.cjs');
21
23
  require('../../../../shared/utils/classes/storage/localStorage.cjs');
22
24
  require('../../../../shared/utils/classes/storage/sessionStorage.cjs');
23
25
  require('../../../../store/state/loadingAndLifecycle.cjs');
24
- require('@dynamic-labs/utils');
25
26
  require('../../../../shared/consts/index.cjs');
26
27
  var IconButton = require('../../../../components/IconButton/IconButton.cjs');
27
28
  var DynamicWidgetContext = require('../../context/DynamicWidgetContext.cjs');
@@ -68,6 +69,7 @@ require('../../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
68
69
  require('../../../../context/WalletGroupContext/WalletGroupContext.cjs');
69
70
  require('../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
70
71
  require('react-focus-lock');
72
+ var Divider = require('../../../../components/Divider/Divider.cjs');
71
73
  require('../../../../components/MenuList/Dropdown/Dropdown.cjs');
72
74
  require('formik');
73
75
  require('../../../../store/state/sendBalances/sendBalances.cjs');
@@ -75,6 +77,7 @@ require('../../../../views/TransactionConfirmationView/helpers/transactionErrorM
75
77
  var Input = require('../../../../components/Input/Input.cjs');
76
78
  require('../../../../context/PasskeyContext/PasskeyContext.cjs');
77
79
  require('../ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
80
+ var GlobalWalletScanner = require('./scanner/GlobalWalletScanner.cjs');
78
81
  require('../../../../../polyfills.cjs');
79
82
  require('../../../../context/DynamicContext/DynamicContext.cjs');
80
83
  require('../../../../context/ErrorBoundary/ErrorBoundaryBase.cjs');
@@ -101,6 +104,7 @@ require('../../../../components/InlineWidget/InlineWidget.cjs');
101
104
  require('qrcode');
102
105
 
103
106
  const GlobalWalletView = () => {
107
+ var _a;
104
108
  const { t } = reactI18next.useTranslation();
105
109
  const { setDynamicWidgetView, goToInitialDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
106
110
  const { setView } = ViewContext.useViewContext();
@@ -108,47 +112,60 @@ const GlobalWalletView = () => {
108
112
  const { primaryWallet } = useDynamicContext.useDynamicContext();
109
113
  const [walletConnectUri, setWalletConnectUri] = React.useState('');
110
114
  const [bannerMessage, setBannerMessage] = React.useState(null);
111
- const [isHovered, setIsHovered] = React.useState(false);
112
- const [isFocused, setIsFocused] = React.useState(false);
113
- const { globalWallet } = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
115
+ const [isScanned, setIsScanned] = React.useState(false);
116
+ const { globalWallet } =
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
+ (_a = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) !== null && _a !== void 0 ? _a : {};
114
119
  if (!globalWallet)
115
120
  throw new Error('Global Wallet not found');
116
- React.useEffect(() => {
117
- let timeoutId;
118
- if (bannerMessage) {
119
- timeoutId = setTimeout(() => {
120
- setBannerMessage(null);
121
- }, 3000);
122
- }
123
- return () => {
124
- if (timeoutId) {
125
- clearTimeout(timeoutId);
126
- }
127
- };
128
- }, [bannerMessage]);
129
- const onClickBack = () => {
130
- goToInitialDynamicWidgetView();
131
- };
132
- const onConnectClick = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
121
+ const showBanner = React.useCallback((message, type) => {
122
+ setBannerMessage({ message, type });
123
+ const timeout = type === 'success' ? 2000 : 3000;
124
+ setTimeout(() => {
125
+ setBannerMessage(null);
126
+ if (type === 'success')
127
+ goToInitialDynamicWidgetView();
128
+ }, timeout);
129
+ }, [goToInitialDynamicWidgetView]);
130
+ const handlePairing = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
133
131
  if (!walletConnectUri.startsWith('wc:')) {
134
- setBannerMessage({
135
- message: t('global_wallet.banner.bad_input'),
136
- type: 'error',
137
- });
132
+ showBanner(t('global_wallet.banner.bad_input'), 'error');
138
133
  return;
139
134
  }
140
135
  try {
141
136
  yield globalWallet.pairWithWC(walletConnectUri);
142
- // wait 0.5 second to receive the pairing request event
143
137
  yield new Promise((resolve) => setTimeout(resolve, 500));
144
138
  const pendingPairing = globalWallet.getPendingPairing();
145
139
  if (!pendingPairing)
146
140
  throw new Error('No pending pairing');
147
- const { name, url, icons } = pendingPairing.params
148
- .proposer.metadata;
141
+ const { name, url, icons } = pendingPairing.params.proposer.metadata;
149
142
  setView('global-wallet-confirm', {
150
- onCancel: onCancelPairing,
151
- onConfirm: onConfirmPairing,
143
+ onCancel: () => {
144
+ setDynamicWidgetView('global-wallet');
145
+ setShowAuthFlow(false, {
146
+ ignoreIfIsEmbeddedWidget: false,
147
+ performMultiWalletChecks: false,
148
+ });
149
+ setWalletConnectUri('');
150
+ },
151
+ onConfirm: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
152
+ try {
153
+ yield globalWallet.confirmPairing(true);
154
+ setDynamicWidgetView('global-wallet');
155
+ setShowAuthFlow(false, {
156
+ ignoreIfIsEmbeddedWidget: false,
157
+ performMultiWalletChecks: false,
158
+ });
159
+ showBanner(t('global_wallet.banner.success', {
160
+ name: name !== null && name !== void 0 ? name : t('global_wallet.the_dapp'),
161
+ }), 'success');
162
+ }
163
+ catch (error) {
164
+ showBanner(t('global_wallet.banner.warning', {
165
+ name: name !== null && name !== void 0 ? name : t('global_wallet.the_dapp'),
166
+ }), 'error');
167
+ }
168
+ }),
152
169
  pairingInfo: { icons, name, url },
153
170
  });
154
171
  setShowAuthFlow(true, {
@@ -157,78 +174,50 @@ const GlobalWalletView = () => {
157
174
  });
158
175
  }
159
176
  catch (error) {
160
- if (String(error).includes('expired')) {
161
- setBannerMessage({
162
- message: t('global_wallet.banner.expired', {
163
- name: 'this app',
164
- }),
165
- type: 'error',
166
- });
177
+ const errorMessage = String(error);
178
+ if (errorMessage.includes('expired')) {
179
+ showBanner(t('global_wallet.banner.expired'), 'error');
167
180
  }
168
- else if (String(error).includes('exists')) {
169
- setBannerMessage({
170
- message: t('global_wallet.banner.already_connected', {
171
- name: 'this app',
172
- }),
173
- type: 'success',
174
- });
181
+ else if (errorMessage.includes('exists')) {
182
+ showBanner(t('global_wallet.banner.already_connected', {
183
+ name: t('global_wallet.this_app'),
184
+ }), 'success');
175
185
  }
176
186
  else {
177
- setBannerMessage({
178
- message: t('global_wallet.banner.warning', { name: 'the app' }),
179
- type: 'error',
180
- });
187
+ showBanner(t('global_wallet.banner.warning', {
188
+ name: t('global_wallet.the_dapp'),
189
+ }), 'error');
181
190
  }
182
191
  }
183
- });
184
- const onConfirmPairing = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
185
- var _a;
186
- const pendingConnection = (_a = globalWallet.getPendingPairing()) !== null && _a !== void 0 ? _a : {};
187
- const { name } = pendingConnection.params.proposer.metadata;
188
- try {
189
- yield globalWallet.confirmPairing(true);
190
- setDynamicWidgetView('global-wallet');
191
- setShowAuthFlow(false, {
192
- ignoreIfIsEmbeddedWidget: false,
193
- performMultiWalletChecks: false,
194
- });
195
- setBannerMessage({
196
- message: t('global_wallet.banner.success', {
197
- name: name !== null && name !== void 0 ? name : 'the dApp',
198
- }),
199
- type: 'success',
200
- });
201
- }
202
- catch (error) {
203
- setBannerMessage({
204
- message: t('global_wallet.banner.warning', {
205
- name: name !== null && name !== void 0 ? name : 'the dApp',
206
- }),
207
- type: 'error',
208
- });
192
+ }), // eslint-disable-next-line react-hooks/exhaustive-deps
193
+ [walletConnectUri]);
194
+ const handleScan = React.useCallback((result) => {
195
+ if (result) {
196
+ setIsScanned(true);
197
+ setWalletConnectUri(result);
209
198
  }
210
- });
211
- const onCancelPairing = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
212
- setDynamicWidgetView('global-wallet');
213
- setShowAuthFlow(false, {
214
- ignoreIfIsEmbeddedWidget: false,
215
- performMultiWalletChecks: false,
216
- });
217
- });
218
- const handleSubmit = (e) => {
219
- e.preventDefault();
220
- onConnectClick();
221
- };
222
- const handleKeyDown = (e) => {
223
- if (e.key === 'Enter') {
224
- handleSubmit(e);
199
+ }, []);
200
+ React.useEffect(() => {
201
+ if (walletConnectUri.startsWith('wc:')) {
202
+ handlePairing();
225
203
  }
226
- };
227
- const InlineWalletConnectTypography = () => (jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: jsxRuntime.jsxs("span", { className: 'inline-logo-text', children: ["3. Open WalletConnect ", jsxRuntime.jsx(blueWalletconnect.ReactComponent, { className: 'inline-logo' }), ' ', "from the list"] }) }));
228
- const InlineCopyTextTypography = () => (jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: jsxRuntime.jsxs("span", { className: 'inline-logo-text', children: ["4. Locate and click ", jsxRuntime.jsx(copy.ReactComponent, { className: 'inline-logo' }), " to copy the URI code"] }) }));
229
- return (jsxRuntime.jsxs("div", { className: 'connect-dapps-view', children: [jsxRuntime.jsxs("div", { className: 'header', children: [jsxRuntime.jsx(IconButton.IconButton, { type: 'button', onClick: onClickBack, "data-testid": 'back-button', children: jsxRuntime.jsx(arrowLeft.ReactComponent, {}) }), jsxRuntime.jsx(Typography.Typography, { variant: 'title', weight: 'medium', color: 'primary', as: 'h1', children: "Connect to apps" })] }), jsxRuntime.jsxs("div", { className: 'wallet-connect-card', children: [jsxRuntime.jsx("div", { className: 'input-group', children: jsxRuntime.jsx(Input.Input, { id: 'walletconnect-uri', label: 'WalletConnect URI', placeholder: 'wc:...', value: walletConnectUri, onChange: (e) => setWalletConnectUri(e.target.value), variant: 'dense', onKeyDown: handleKeyDown, suffix:
230
- // eslint-disable-next-line react/jsx-wrap-multilines
231
- jsxRuntime.jsx("div", { className: 'input-suffix', onClick: handleSubmit, role: 'button', tabIndex: 0, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), onFocus: () => setIsFocused(true), onBlur: () => setIsFocused(false), children: jsxRuntime.jsx(InlineSubmitButton.InlineSubmitButton, { disabled: false, highlighted: Boolean(walletConnectUri), isFocused: isFocused, isHovered: isHovered, emailSubmitButtonInsideInput: true }) }) }) }), bannerMessage && (jsxRuntime.jsx("div", { className: `banner ${bannerMessage.type}`, children: jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'primary', children: bannerMessage.message }) }))] }), jsxRuntime.jsx("div", { className: 'info-card', children: jsxRuntime.jsxs("div", { className: 'wrapper', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'bold', color: 'primary', as: 'h2', children: t('global_wallet.help.title') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.1') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.2') }), jsxRuntime.jsx(InlineWalletConnectTypography, {}), jsxRuntime.jsx(InlineCopyTextTypography, {})] }) })] }));
204
+ }, [walletConnectUri, handlePairing]);
205
+ const renderHeader = () => (jsxRuntime.jsxs("div", { className: 'header', children: [jsxRuntime.jsx(IconButton.IconButton, { type: 'button', onClick: goToInitialDynamicWidgetView, "data-testid": 'back-button', children: jsxRuntime.jsx(arrowLeft.ReactComponent, {}) }), jsxRuntime.jsx(Typography.Typography, { variant: 'title', weight: 'medium', color: 'primary', as: 'h1', copykey: 'global_wallet.connect_to_apps', children: t('global_wallet.connect_to_apps') }), utils.isMobile() && (jsxRuntime.jsx(IconButton.IconButton, { type: 'button', onClick: () => {
206
+ setView('global-wallet-info');
207
+ setShowAuthFlow(true, {
208
+ ignoreIfIsEmbeddedWidget: false,
209
+ performMultiWalletChecks: false,
210
+ });
211
+ }, "data-testid": 'info-button', children: jsxRuntime.jsx(questionMark.ReactComponent, {}) }))] }));
212
+ const renderScanner = () => utils.isMobile() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: 'scanner-wrapper', children: [jsxRuntime.jsx(GlobalWalletScanner.GlobalWalletScanner, { onScan: handleScan, jsQR: globalWallet.qrScanner }), jsxRuntime.jsxs("div", { className: 'scanner-overlay', children: [jsxRuntime.jsxs("div", { className: 'scanner-frame', children: [jsxRuntime.jsx("div", { className: 'corner top-left' }), jsxRuntime.jsx("div", { className: 'corner top-right' }), jsxRuntime.jsx("div", { className: 'corner bottom-left' }), jsxRuntime.jsx("div", { className: 'corner bottom-right' })] }), jsxRuntime.jsxs("div", { className: 'scanner-overlay-content', children: [jsxRuntime.jsx(blueWalletconnect.ReactComponent, { className: 'scanner-icon' }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'white', copykey: 'global_wallet.scan_qr_code', children: t('global_wallet.scan_qr_code') })] })] })] }), jsxRuntime.jsx(Divider.Divider, { text: t('global_wallet.or') })] }));
213
+ const renderInput = () => (jsxRuntime.jsxs("div", { className: 'wallet-connect-card', children: [jsxRuntime.jsx("div", { className: 'input-group', children: jsxRuntime.jsx(Input.Input, { copykey: 'global_wallet.walletconnect_uri', id: 'walletconnect-uri', label: t('global_wallet.walletconnect_uri'), placeholder: 'wc:...', value: isScanned ? '' : walletConnectUri, onChange: (e) => {
214
+ setWalletConnectUri(e.target.value);
215
+ setIsScanned(false);
216
+ }, variant: 'dense', onKeyDown: (e) => e.key === 'Enter' && handlePairing(), suffix:
217
+ // eslint-disable-next-line react/jsx-wrap-multilines
218
+ jsxRuntime.jsx("div", { className: 'input-suffix', onClick: handlePairing, role: 'button', tabIndex: 0, children: jsxRuntime.jsx(InlineSubmitButton.InlineSubmitButton, { disabled: false, highlighted: Boolean(walletConnectUri) && !isScanned, isFocused: false, isHovered: false, emailSubmitButtonInsideInput: true }) }) }) }), bannerMessage && (jsxRuntime.jsx("div", { className: `banner ${bannerMessage.type}`, children: jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'primary', children: bannerMessage.message }) }))] }));
219
+ const renderInfoCard = () => !utils.isMobile() && (jsxRuntime.jsx("div", { className: 'info-card', children: jsxRuntime.jsxs("div", { className: 'wrapper', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'bold', color: 'primary', as: 'h2', children: t('global_wallet.help.title') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.1') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: t('global_wallet.help.step.2') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: jsxRuntime.jsxs("span", { className: 'inline-logo-text', children: ["3. Open WalletConnect", jsxRuntime.jsx(blueWalletconnect.ReactComponent, { className: 'inline-logo' }), " from the list"] }) }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', weight: 'regular', color: 'secondary', children: jsxRuntime.jsxs("span", { className: 'inline-logo-text', children: ["4. Locate and click ", jsxRuntime.jsx(copy.ReactComponent, { className: 'inline-logo' }), " to copy the URI code"] }) })] }) }));
220
+ return (jsxRuntime.jsxs("div", { className: 'connect-dapps-view', children: [renderHeader(), renderScanner(), renderInput(), renderInfoCard()] }));
232
221
  };
233
222
 
234
223
  exports.GlobalWalletView = GlobalWalletView;