@openfort/react 0.1.1 → 0.1.3

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/build/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Openfort as Openfort$1, EmbeddedState, AccountTypeEnum, RecoveryMethod, MissingRecoveryPasswordError, ChainTypeEnum, OAuthProvider, OpenfortError as OpenfortError$1, OpenfortErrorType as OpenfortErrorType$1 } from '@openfort/openfort-js';
2
2
  export { AccountTypeEnum, OAuthProvider, OpenfortEvents, RecoveryMethod, ThirdPartyOAuthProvider, openfortEvents } from '@openfort/openfort-js';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
- import React, { useState, useEffect, createContext, useRef, useId, useMemo, useCallback, createElement, useLayoutEffect, useContext } from 'react';
4
+ import React, { useState, useEffect, createContext, useRef, useId, useMemo, useCallback, createElement, useLayoutEffect } from 'react';
5
5
  import { normalize } from 'viem/ens';
6
6
  import { useEnsAddress, useEnsName, useEnsAvatar, useConfig, useAccount, useBlockNumber, useBalance, useConnectors as useConnectors$1, useConnect as useConnect$1, useDisconnect, useChainId, http, useSwitchChain, usePublicClient, WagmiContext, useWalletClient } from 'wagmi';
7
7
  import { motion, AnimatePresence, MotionConfig } from 'framer-motion';
@@ -15,7 +15,6 @@ import { safe, injected, coinbaseWallet, walletConnect } from '@wagmi/connectors
15
15
  import { useTransition } from 'react-transition-state';
16
16
  import ResizeObserver from 'resize-observer-polyfill';
17
17
  import { createPortal } from 'react-dom';
18
- import { walletConnect as walletConnect$1 } from 'wagmi/connectors';
19
18
  import calculateEntropy from 'fast-password-entropy';
20
19
  import QRCodeUtil from 'qrcode';
21
20
  import { switchChain, signMessage } from '@wagmi/core';
@@ -3683,9 +3682,7 @@ function flattenChildren(children) {
3683
3682
  }, []);
3684
3683
  }
3685
3684
  const isWalletConnectConnector = (connectorId) => connectorId === 'walletConnect';
3686
- const isFamilyAccountsConnector = (connectorId) => connectorId === 'familyAccountsProvider';
3687
3685
  const isCoinbaseWalletConnector = (connectorId) => connectorId === 'coinbaseWalletSDK';
3688
- const isPortoConnector = (connectorId) => connectorId === 'xyz.ithaca.porto';
3689
3686
  const isSafeConnector = (connectorId) => connectorId === 'safe';
3690
3687
  const isInjectedConnector = (connectorId) => connectorId === 'injected';
3691
3688
 
@@ -3984,7 +3981,7 @@ styled(motion.div) `
3984
3981
  display: block;
3985
3982
  }
3986
3983
  `;
3987
- const IconContainer$5 = styled(motion.div) `
3984
+ const IconContainer$4 = styled(motion.div) `
3988
3985
  pointer-events: none;
3989
3986
  user-select: none;
3990
3987
  position: relative;
@@ -4144,7 +4141,7 @@ function OpenfortButtonInner({ label, showAvatar, separator, }) {
4144
4141
  return (jsx(AnimatePresence, { initial: false, children: user || address ? (jsxs(TextContainer, { initial: 'initial', animate: 'animate', exit: 'exit', variants: addressVariants, style: {
4145
4142
  height: 40,
4146
4143
  //padding: !showAvatar ? '0 5px' : undefined,
4147
- }, children: [showAvatar && (jsxs(IconContainer$5, { children: [jsx(AnimatePresence, { initial: false, children: !isChainSupported && (jsx(UnsupportedNetworkContainer, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, children: jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("title", { children: "Unsupported network" }), jsx("path", { d: "M1.68831 13.5H12.0764C13.1026 13.5 13.7647 12.7197 13.7647 11.763C13.7647 11.4781 13.6985 11.1863 13.5462 10.9149L8.34225 1.37526C8.02445 0.791754 7.45505 0.5 6.88566 0.5C6.31627 0.5 5.73364 0.791754 5.42246 1.37526L0.225108 10.9217C0.0728291 11.1863 0 11.4781 0 11.763C0 12.7197 0.662083 13.5 1.68831 13.5ZM6.88566 8.8048C6.49503 8.8048 6.27655 8.5809 6.26331 8.1738L6.16399 5.0595C6.15075 4.64562 6.44869 4.34708 6.87904 4.34708C7.30278 4.34708 7.61396 4.6524 7.60071 5.06628L7.5014 8.16701C7.48154 8.5809 7.26305 8.8048 6.88566 8.8048ZM6.88566 11.3492C6.44207 11.3492 6.07792 11.0303 6.07792 10.5757C6.07792 10.1211 6.44207 9.80219 6.88566 9.80219C7.32926 9.80219 7.69341 10.1143 7.69341 10.5757C7.69341 11.0371 7.32264 11.3492 6.88566 11.3492Z", fill: "currentColor" })] }) })) }), jsx(Avatar, { size: 24, address: address })] })), jsx("div", { style: {
4144
+ }, children: [showAvatar && (jsxs(IconContainer$4, { children: [jsx(AnimatePresence, { initial: false, children: !isChainSupported && (jsx(UnsupportedNetworkContainer, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, children: jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("title", { children: "Unsupported network" }), jsx("path", { d: "M1.68831 13.5H12.0764C13.1026 13.5 13.7647 12.7197 13.7647 11.763C13.7647 11.4781 13.6985 11.1863 13.5462 10.9149L8.34225 1.37526C8.02445 0.791754 7.45505 0.5 6.88566 0.5C6.31627 0.5 5.73364 0.791754 5.42246 1.37526L0.225108 10.9217C0.0728291 11.1863 0 11.4781 0 11.763C0 12.7197 0.662083 13.5 1.68831 13.5ZM6.88566 8.8048C6.49503 8.8048 6.27655 8.5809 6.26331 8.1738L6.16399 5.0595C6.15075 4.64562 6.44869 4.34708 6.87904 4.34708C7.30278 4.34708 7.61396 4.6524 7.60071 5.06628L7.5014 8.16701C7.48154 8.5809 7.26305 8.8048 6.88566 8.8048ZM6.88566 11.3492C6.44207 11.3492 6.07792 11.0303 6.07792 10.5757C6.07792 10.1211 6.44207 9.80219 6.88566 9.80219C7.32926 9.80219 7.69341 10.1143 7.69341 10.5757C7.69341 11.0371 7.32264 11.3492 6.88566 11.3492Z", fill: "currentColor" })] }) })) }), jsx(Avatar, { size: 24, address: address })] })), jsx("div", { style: {
4148
4145
  position: 'relative',
4149
4146
  paddingRight: showAvatar ? 1 : 0,
4150
4147
  }, children: jsx(AnimatePresence, { initial: false, children: jsx(TextContainer, { initial: 'initial', animate: 'animate', exit: 'exit', variants: textVariants$2, style: {
@@ -4235,16 +4232,6 @@ function useFamilyAccountsConnector() {
4235
4232
  function useFamilyConnector() {
4236
4233
  return useConnector('co.family.wallet');
4237
4234
  }
4238
- function useWalletConnectConnector() {
4239
- /*
4240
- options: {
4241
- qrcode: false,
4242
- // or
4243
- showQrModal: false,
4244
- }
4245
- */
4246
- return useConnector('walletConnect');
4247
- }
4248
4235
 
4249
4236
  function useGoogleFont(font) {
4250
4237
  useEffect(() => {
@@ -4424,29 +4411,31 @@ const ConnectCallback = ({ onConnect, onDisconnect }) => {
4424
4411
  });
4425
4412
  return null;
4426
4413
  };
4427
- const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, ...openfortProps }) => {
4414
+ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfig, }) => {
4428
4415
  const { connectors, connect, reset } = useConnect();
4429
4416
  const { address } = useAccount();
4430
4417
  const [user, setUser] = useState(null);
4431
4418
  const [walletStatus, setWalletStatus] = useState({ status: 'idle' });
4432
4419
  const { disconnectAsync } = useDisconnect();
4433
4420
  const { walletConfig } = useOpenfort();
4421
+ const wagmiConfig = useConfig();
4422
+ const chainId = useChainId();
4434
4423
  // ---- Openfort instance ----
4435
4424
  const openfort = useMemo(() => {
4436
4425
  var _a;
4437
- logger.log('Creating Openfort instance.', openfortProps);
4438
- if (!openfortProps.baseConfiguration.publishableKey)
4426
+ logger.log('Creating Openfort instance.', openfortConfig);
4427
+ if (!openfortConfig.baseConfiguration.publishableKey)
4439
4428
  throw Error('CoreOpenfortProvider requires a publishableKey to be set in the baseConfiguration.');
4440
- if (openfortProps.shieldConfiguration &&
4441
- !((_a = openfortProps.shieldConfiguration) === null || _a === void 0 ? void 0 : _a.passkeyRpId) &&
4429
+ if (openfortConfig.shieldConfiguration &&
4430
+ !((_a = openfortConfig.shieldConfiguration) === null || _a === void 0 ? void 0 : _a.passkeyRpId) &&
4442
4431
  typeof window !== 'undefined') {
4443
- openfortProps.shieldConfiguration = {
4432
+ openfortConfig.shieldConfiguration = {
4444
4433
  passkeyRpId: window.location.hostname,
4445
4434
  passkeyRpName: document.title || 'Openfort DApp',
4446
- ...openfortProps.shieldConfiguration,
4435
+ ...openfortConfig.shieldConfiguration,
4447
4436
  };
4448
4437
  }
4449
- const newClient = createOpenfortClient(openfortProps);
4438
+ const newClient = createOpenfortClient(openfortConfig);
4450
4439
  return newClient;
4451
4440
  }, []);
4452
4441
  // ---- Embedded state ----
@@ -4520,8 +4509,27 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, ...openfortPr
4520
4509
  return null;
4521
4510
  }
4522
4511
  }, [openfort]);
4523
- const chainId = useChainId();
4524
- const wagmiConfig = useConfig();
4512
+ // Embedded accounts list. Will reset on logout.
4513
+ const { data: embeddedAccounts, refetch: fetchEmbeddedAccounts, isPending: isLoadingAccounts, } = useQuery({
4514
+ queryKey: ['openfortEmbeddedAccountsList'],
4515
+ queryFn: async () => {
4516
+ try {
4517
+ return await openfort.embeddedWallet.list({
4518
+ limit: 100,
4519
+ // If its EOA we want all accounts, otherwise we want only smart accounts
4520
+ accountType: (walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.accountType) === AccountTypeEnum.EOA ? undefined : AccountTypeEnum.SMART_ACCOUNT,
4521
+ });
4522
+ }
4523
+ catch (error) {
4524
+ handleOAuthConfigError(error);
4525
+ throw error;
4526
+ }
4527
+ },
4528
+ refetchOnMount: false,
4529
+ refetchOnWindowFocus: false,
4530
+ retry: false,
4531
+ });
4532
+ // Update ethereum provider when chainId changes
4525
4533
  useEffect(() => {
4526
4534
  if (!openfort || !walletConfig)
4527
4535
  return;
@@ -4551,28 +4559,10 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, ...openfortPr
4551
4559
  ...resolvePolicy(),
4552
4560
  chains: rpcUrls,
4553
4561
  });
4562
+ // Refresh embedded accounts to reflect any changes in the selected chain
4563
+ fetchEmbeddedAccounts();
4554
4564
  }, [openfort, walletConfig, chainId]);
4555
4565
  const [isConnectedWithEmbeddedSigner, setIsConnectedWithEmbeddedSigner] = useState(false);
4556
- // will reset on logout
4557
- const { data: embeddedAccounts, refetch: fetchEmbeddedAccounts, isPending: isLoadingAccounts, } = useQuery({
4558
- queryKey: ['openfortEmbeddedAccountsList'],
4559
- queryFn: async () => {
4560
- try {
4561
- return await openfort.embeddedWallet.list({
4562
- limit: 100,
4563
- // If its EOA we want all accounts, otherwise we want only smart accounts
4564
- accountType: (walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.accountType) === AccountTypeEnum.EOA ? undefined : AccountTypeEnum.SMART_ACCOUNT,
4565
- });
4566
- }
4567
- catch (error) {
4568
- handleOAuthConfigError(error);
4569
- throw error;
4570
- }
4571
- },
4572
- refetchOnMount: false,
4573
- refetchOnWindowFocus: false,
4574
- retry: false,
4575
- });
4576
4566
  useEffect(() => {
4577
4567
  if (!openfort)
4578
4568
  return;
@@ -4685,6 +4675,7 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, ...openfortPr
4685
4675
  needsRecovery,
4686
4676
  user,
4687
4677
  updateUser,
4678
+ updateEmbeddedAccounts: fetchEmbeddedAccounts,
4688
4679
  embeddedAccounts,
4689
4680
  isLoadingAccounts,
4690
4681
  walletStatus,
@@ -4713,7 +4704,6 @@ const defaultConnectors = ({ app, walletConnectProjectId, coinbaseWalletPreferen
4713
4704
  }));
4714
4705
  if (walletConnectProjectId) {
4715
4706
  connectors.push(walletConnect({
4716
- showQrModal: false,
4717
4707
  projectId: walletConnectProjectId,
4718
4708
  metadata: hasAllAppData
4719
4709
  ? {
@@ -4725,13 +4715,6 @@ const defaultConnectors = ({ app, walletConnectProjectId, coinbaseWalletPreferen
4725
4715
  : undefined,
4726
4716
  }));
4727
4717
  }
4728
- /*
4729
- connectors.push(
4730
- injected({
4731
- shimDisconnect: true,
4732
- })
4733
- );
4734
- */
4735
4718
  return connectors;
4736
4719
  };
4737
4720
 
@@ -4763,10 +4746,6 @@ const defaultConfig = ({ appName = 'Openfort', appIcon, appDescription, appUrl,
4763
4746
  return config;
4764
4747
  };
4765
4748
 
4766
- const ExternalLinkIcon = ({ ...props }) => (jsxs("svg", { "aria-hidden": "true", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", style: {
4767
- left: 0,
4768
- top: 0,
4769
- }, ...props, children: [jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M4 4C2.89543 4 2 4.89543 2 6V12C2 13.1046 2.89543 14 4 14H10C11.1046 14 12 13.1046 12 12V9.66667C12 9.11438 12.4477 8.66667 13 8.66667C13.5523 8.66667 14 9.11438 14 9.66667V12C14 14.2091 12.2091 16 10 16H4C1.79086 16 0 14.2091 0 12V6C0 3.79086 1.79086 2 4 2H6.33333C6.88562 2 7.33333 2.44772 7.33333 3C7.33333 3.55228 6.88562 4 6.33333 4H4Z", fill: "currentColor", fillOpacity: 0.3 }), jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M9.5 1C9.5 0.447715 9.94772 0 10.5 0H15C15.5523 0 16 0.447715 16 1V5.5C16 6.05228 15.5523 6.5 15 6.5C14.4477 6.5 14 6.05228 14 5.5V3.41421L8.70711 8.70711C8.31658 9.09763 7.68342 9.09763 7.29289 8.70711C6.90237 8.31658 6.90237 7.68342 7.29289 7.29289L12.5858 2H10.5C9.94772 2 9.5 1.55228 9.5 1Z", fill: "currentColor", fillOpacity: 0.3 })] }));
4770
4749
  const AlertIcon = ({ ...props }) => {
4771
4750
  return (jsxs("svg", { "aria-hidden": "true", width: "19", height: "18", viewBox: "0 0 19 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: [jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M6.81753 1.60122C7.39283 0.530035 8.46953 0 9.50409 0C10.5507 0 11.6022 0.539558 12.1805 1.59767L18.6047 13.3334C18.882 13.8283 19 14.3568 19 14.8622C19 16.5296 17.7949 18 15.9149 18H3.08514C1.20508 18 0 16.5296 0 14.8622C0 14.3454 0.131445 13.8172 0.405555 13.3379L6.81753 1.60122ZM9.50409 2C9.13355 2 8.77256 2.18675 8.57866 2.54907L8.57458 2.5567L2.14992 14.3166L2.144 14.3268C2.04638 14.4959 2 14.6817 2 14.8622C2 15.5497 2.43032 16 3.08514 16H15.9149C16.5697 16 17 15.5497 17 14.8622C17 14.6681 16.9554 14.4805 16.8588 14.309L16.8529 14.2986L10.4259 2.55741C10.2191 2.1792 9.86395 2 9.50409 2Z", fill: "currentColor" }), jsx("path", { d: "M9.5 11.2297C9.01639 11.2297 8.7459 10.9419 8.72951 10.4186L8.60656 6.4157C8.59016 5.88372 8.95902 5.5 9.4918 5.5C10.0164 5.5 10.4016 5.89244 10.3852 6.42442L10.2623 10.4099C10.2377 10.9419 9.96721 11.2297 9.5 11.2297ZM9.5 14.5C8.95082 14.5 8.5 14.0901 8.5 13.5058C8.5 12.9215 8.95082 12.5116 9.5 12.5116C10.0492 12.5116 10.5 12.9128 10.5 13.5058C10.5 14.0988 10.041 14.5 9.5 14.5Z", fill: "currentColor" })] }));
4772
4751
  };
@@ -5246,13 +5225,13 @@ const walletConfigs = {
5246
5225
  };
5247
5226
 
5248
5227
  const useWallet = (id) => {
5249
- const wallets = useWallets$1();
5228
+ const wallets = useWagmiWallets();
5250
5229
  const wallet = wallets.find((c) => c.id === id);
5251
5230
  if (!wallet)
5252
5231
  return null;
5253
5232
  return wallet;
5254
5233
  };
5255
- const useWallets$1 = () => {
5234
+ const useWagmiWallets = () => {
5256
5235
  const connectors = useConnectors();
5257
5236
  const context = useOpenfort();
5258
5237
  const wallets = connectors.map((connector) => {
@@ -5481,7 +5460,7 @@ const FitText = ({ children, maxFontSize = 100, minFontSize = 70, }) => {
5481
5460
  };
5482
5461
  FitText.displayName = 'FitText';
5483
5462
 
5484
- const OPENFORT_VERSION = '0.1.1';
5463
+ const OPENFORT_VERSION = '0.1.3';
5485
5464
 
5486
5465
  const Portal = (props) => {
5487
5466
  props = {
@@ -6719,7 +6698,7 @@ const InnerContainer = styled.div `
6719
6698
  text-overflow: ellipsis;
6720
6699
  */
6721
6700
  `;
6722
- const IconContainer$4 = styled(motion.div) `
6701
+ const IconContainer$3 = styled(motion.div) `
6723
6702
  position: relative;
6724
6703
  display: inline-block;
6725
6704
  vertical-align: middle;
@@ -6784,7 +6763,7 @@ disabled, icon, iconPosition = 'left', roundedIcon, waiting, arrow, download, hr
6784
6763
  }, transition: {
6785
6764
  ...transition,
6786
6765
  delay: 0.2,
6787
- }, children: [icon && iconPosition === 'left' && jsx(IconContainer$4, { "$rounded": roundedIcon, children: icon }), download && (jsx(DownloadArrow, { children: jsx(DownloadArrowInner, { children: jsxs(Arrow, { width: "13", height: "12", viewBox: "0 0 13 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx(ArrowLine, { stroke: "currentColor", x1: "1", y1: "6", x2: "12", y2: "6", strokeWidth: "var(--stroke-width)", strokeLinecap: "round" }), jsx(ArrowChevron, { stroke: "currentColor", d: "M7.51431 1.5L11.757 5.74264M7.5 10.4858L11.7426 6.24314", strokeWidth: "var(--stroke-width)", strokeLinecap: "round" })] }) }) })), jsx(InnerContainer, { style: { paddingLeft: arrow ? 6 : 0 }, children: jsx(FitText, { children: children }) }), icon && iconPosition === 'right' && jsx(IconContainer$4, { "$rounded": roundedIcon, children: icon }), arrow && (jsxs(Arrow, { width: "13", height: "12", viewBox: "0 0 13 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx(ArrowLine, { stroke: "currentColor", x1: "1", y1: "6", x2: "12", y2: "6", strokeWidth: "2", strokeLinecap: "round" }), jsx(ArrowChevron, { stroke: "currentColor", d: "M7.51431 1.5L11.757 5.74264M7.5 10.4858L11.7426 6.24314", strokeWidth: "2", strokeLinecap: "round" })] }))] }, key), waiting && (jsx(SpinnerContainer$2, { children: jsx(Spinner$3, {}) }))] }) }));
6766
+ }, children: [icon && iconPosition === 'left' && jsx(IconContainer$3, { "$rounded": roundedIcon, children: icon }), download && (jsx(DownloadArrow, { children: jsx(DownloadArrowInner, { children: jsxs(Arrow, { width: "13", height: "12", viewBox: "0 0 13 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx(ArrowLine, { stroke: "currentColor", x1: "1", y1: "6", x2: "12", y2: "6", strokeWidth: "var(--stroke-width)", strokeLinecap: "round" }), jsx(ArrowChevron, { stroke: "currentColor", d: "M7.51431 1.5L11.757 5.74264M7.5 10.4858L11.7426 6.24314", strokeWidth: "var(--stroke-width)", strokeLinecap: "round" })] }) }) })), jsx(InnerContainer, { style: { paddingLeft: arrow ? 6 : 0 }, children: jsx(FitText, { children: children }) }), icon && iconPosition === 'right' && jsx(IconContainer$3, { "$rounded": roundedIcon, children: icon }), arrow && (jsxs(Arrow, { width: "13", height: "12", viewBox: "0 0 13 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx(ArrowLine, { stroke: "currentColor", x1: "1", y1: "6", x2: "12", y2: "6", strokeWidth: "2", strokeLinecap: "round" }), jsx(ArrowChevron, { stroke: "currentColor", d: "M7.51431 1.5L11.757 5.74264M7.5 10.4858L11.7426 6.24314", strokeWidth: "2", strokeLinecap: "round" })] }))] }, key), waiting && (jsx(SpinnerContainer$2, { children: jsx(Spinner$3, {}) }))] }) }));
6788
6767
  };
6789
6768
 
6790
6769
  var OpenfortErrorType;
@@ -6986,7 +6965,7 @@ const PageContent = ({ children, width, onBack = 'back', logoutOnBack }) => {
6986
6965
  else
6987
6966
  setOnBack(null);
6988
6967
  // else setOnBack(() => () => alert('REMOVE DEBUG ON BACK STRING!'))
6989
- }, [onBack, logoutOnBack]);
6968
+ }, []);
6990
6969
  return jsx(PageContentStyle, { style: { width }, children: children });
6991
6970
  };
6992
6971
 
@@ -7901,18 +7880,17 @@ function useWalletConnectModal() {
7901
7880
  const w3mcss = document.createElement('style');
7902
7881
  w3mcss.innerHTML = `w3m-modal, wcm-modal{ --wcm-z-index: 2147483647; --w3m-z-index:2147483647; }`;
7903
7882
  document.head.appendChild(w3mcss);
7883
+ const removeChild = () => {
7884
+ if (document.head.contains(w3mcss)) {
7885
+ document.head.removeChild(w3mcss);
7886
+ }
7887
+ };
7904
7888
  const clientConnector = connectors.find((c) => isWalletConnectConnector(c.id));
7905
7889
  if (clientConnector) {
7906
7890
  try {
7907
- const provider = await clientConnector.getProvider();
7908
- const projectId = provider.rpc.projectId;
7909
- const connector = walletConnect$1({
7910
- projectId,
7911
- showQrModal: true,
7912
- });
7913
7891
  setIsOpen(true);
7914
7892
  try {
7915
- await connectAsync({ connector: connector });
7893
+ await connectAsync({ connector: clientConnector });
7916
7894
  }
7917
7895
  catch (err) {
7918
7896
  logger.log('WalletConnect', err);
@@ -7921,18 +7899,19 @@ function useWalletConnectModal() {
7921
7899
  };
7922
7900
  }
7923
7901
  setIsOpen(false);
7924
- // remove modal styling
7925
- document.head.removeChild(w3mcss);
7902
+ removeChild();
7926
7903
  return {};
7927
7904
  }
7928
7905
  catch (err) {
7929
7906
  logger.log('Could not get WalletConnect provider', err);
7907
+ removeChild();
7930
7908
  return {
7931
7909
  error: 'Could not get WalletConnect provider',
7932
7910
  };
7933
7911
  }
7934
7912
  }
7935
7913
  else {
7914
+ removeChild();
7936
7915
  logger.log('Configuration error: Please provide a WalletConnect Project ID in your wagmi config.');
7937
7916
  return {
7938
7917
  error: 'Configuration error: Please provide a WalletConnect Project ID in your wagmi config.',
@@ -7963,140 +7942,6 @@ const useLastConnector = () => {
7963
7942
  };
7964
7943
  };
7965
7944
 
7966
- function useWalletConnectUri({ enabled } = {
7967
- enabled: true,
7968
- }) {
7969
- const [uri, setUri] = useState(undefined);
7970
- const connector = useWalletConnectConnector();
7971
- const { isConnected } = useAccount();
7972
- const { connectAsync } = useConnect();
7973
- const { disconnect } = useDisconnect();
7974
- useEffect(() => {
7975
- if (!enabled)
7976
- return;
7977
- async function handleMessage(message) {
7978
- const { type, data } = message;
7979
- logger.log('WC Message', type, data);
7980
- if (type === 'display_uri') {
7981
- setUri(data);
7982
- }
7983
- /*
7984
- // This has the URI as well, but we're probably better off using the one in the display_uri event
7985
- if (type === 'connecting') {
7986
- const p = await connector.getProvider();
7987
- const uri = p.signer.uri;
7988
- setConnectorUri(uri);
7989
- }
7990
- */
7991
- }
7992
- async function handleDisconnect() {
7993
- logger.log('WC Disconnect');
7994
- if (connector)
7995
- connectWallet(connector);
7996
- }
7997
- async function connectWallet(connector) {
7998
- if (isConnected)
7999
- disconnect();
8000
- const result = await connectAsync({ connector });
8001
- if (result)
8002
- return result;
8003
- return false;
8004
- }
8005
- async function connectWalletConnect(connector) {
8006
- try {
8007
- await connectWallet(connector);
8008
- }
8009
- catch (error) {
8010
- logger.log('catch error');
8011
- logger.log(error);
8012
- if (error.code) {
8013
- switch (error.code) {
8014
- case 4001:
8015
- logger.log('error.code - User rejected');
8016
- connectWalletConnect(connector); // Regenerate QR code
8017
- break;
8018
- default:
8019
- logger.log('error.code - Unknown Error');
8020
- break;
8021
- }
8022
- }
8023
- else {
8024
- // Sometimes the error doesn't respond with a code
8025
- logger.log('WalletConnect cannot connect.', error);
8026
- }
8027
- }
8028
- }
8029
- if (isConnected) {
8030
- setUri(undefined);
8031
- }
8032
- else {
8033
- if (!connector || uri)
8034
- return;
8035
- if (connector && !isConnected) {
8036
- connectWalletConnect(connector);
8037
- logger.log('add wc listeners');
8038
- connector.emitter.on('message', handleMessage);
8039
- connector.emitter.on('disconnect', handleDisconnect);
8040
- return () => {
8041
- logger.log('remove wc listeners');
8042
- connector.emitter.off('message', handleMessage);
8043
- connector.emitter.off('disconnect', handleDisconnect);
8044
- };
8045
- }
8046
- }
8047
- }, [enabled, connector, isConnected]);
8048
- return {
8049
- uri,
8050
- };
8051
- }
8052
-
8053
- const Web3Context = createContext({
8054
- connect: {
8055
- getUri: () => '',
8056
- },
8057
- dapp: {
8058
- chains: [],
8059
- },
8060
- account: undefined,
8061
- });
8062
- const Web3ContextProvider = ({ enabled, children }) => {
8063
- const { uri: walletConnectUri } = useWalletConnectUri({
8064
- enabled,
8065
- });
8066
- const { address: currentAddress, chain } = useAccount();
8067
- const chainIsSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
8068
- const chains = useChains();
8069
- const value = {
8070
- connect: {
8071
- getUri: (_id) => {
8072
- return walletConnectUri;
8073
- },
8074
- },
8075
- dapp: {
8076
- chains,
8077
- },
8078
- account: currentAddress
8079
- ? {
8080
- chain,
8081
- chainIsSupported,
8082
- address: currentAddress,
8083
- }
8084
- : undefined,
8085
- };
8086
- return jsx(Web3Context.Provider, { value: value, children: children });
8087
- };
8088
- /**
8089
- * React hook to access the {@link Web3Context} values.
8090
- *
8091
- * @returns Shared Web3 utilities exposed by the provider.
8092
- *
8093
- * @example
8094
- * ```ts
8095
- * const { account } = useWeb3();
8096
- * ```
8097
- */
8098
- const useWeb3 = () => useContext(Web3Context);
8099
-
8100
7945
  const AlertContainer = styled(motion.div) `
8101
7946
  display: flex;
8102
7947
  gap: 8px;
@@ -8132,7 +7977,7 @@ const AlertContainer = styled(motion.div) `
8132
7977
  `;
8133
7978
  }}
8134
7979
  `;
8135
- const IconContainer$3 = styled(motion.div) `
7980
+ const IconContainer$2 = styled(motion.div) `
8136
7981
  width: 24px;
8137
7982
  height: 24px;
8138
7983
  display: flex;
@@ -8146,7 +7991,7 @@ const IconContainer$3 = styled(motion.div) `
8146
7991
  `;
8147
7992
 
8148
7993
  const Alert = ({ children, error, icon }) => {
8149
- return (jsxs(AlertContainer, { "$error": error, children: [icon && jsx(IconContainer$3, { children: icon }), jsx("div", { children: children })] }));
7994
+ return (jsxs(AlertContainer, { "$error": error, children: [icon && jsx(IconContainer$2, { children: icon }), jsx("div", { children: children })] }));
8150
7995
  };
8151
7996
  Alert.displayName = 'Alert';
8152
7997
 
@@ -8685,7 +8530,7 @@ const ConnectorsContainer = styled.div `
8685
8530
  const ConnectorList = () => {
8686
8531
  const context = useOpenfort();
8687
8532
  const isMobile = useIsMobile();
8688
- const wallets = useWallets$1();
8533
+ const wallets = useWagmiWallets();
8689
8534
  const { lastConnectorId } = useLastConnector();
8690
8535
  const familyConnector = useFamilyConnector();
8691
8536
  const familyAccountsConnector = useFamilyAccountsConnector();
@@ -8704,47 +8549,19 @@ const ConnectorList = () => {
8704
8549
  return (jsxs(ScrollArea, { mobileDirection: 'horizontal', children: [filteredWallets.length === 0 && jsx(Alert, { error: true, children: "No connectors found in Openfort config." }), filteredWallets.length > 0 && (jsx(ConnectorsContainer, { "$mobile": isMobile, "$totalResults": walletsToDisplay.length, children: filteredWallets.map((wallet) => (jsx(ConnectorItem, { wallet: wallet, isRecent: wallet.id === lastConnectorId }, wallet.id))) }))] }));
8705
8550
  };
8706
8551
  const ConnectorItem = ({ wallet, isRecent }) => {
8707
- var _a;
8708
- const { connect: { getUri }, } = useWeb3();
8709
- const wcUri = getUri();
8710
8552
  const isMobile = useIsMobile();
8711
8553
  const context = useOpenfort();
8712
- const { connect } = useConnect();
8713
- /*
8714
- const [ready, setReady] = useState(false);
8715
- useEffect(() => {
8716
- (async () => {
8717
- const provider = await wallet.connector.getProvider();
8718
- setReady(!!provider);
8719
- })();
8720
- }, [wallet, setReady]);
8721
- */
8722
- let deeplink = (!wallet.isInstalled && isMobile) || (wallet.shouldDeeplinkDesktop && !isMobile)
8723
- ? (_a = wallet.getWalletConnectDeeplink) === null || _a === void 0 ? void 0 : _a.call(wallet, wcUri !== null && wcUri !== void 0 ? wcUri : '')
8724
- : undefined;
8725
8554
  const redirectToMoreWallets = isMobile && isWalletConnectConnector(wallet.id);
8726
8555
  // Safari requires opening popup on user gesture, so we connect immediately here
8727
- const shouldConnectImmediately = (detectBrowser() === 'safari' || detectBrowser() === 'ios') &&
8728
- (isCoinbaseWalletConnector(wallet.connector.id) || isPortoConnector(wallet.connector.id));
8729
- if (redirectToMoreWallets || shouldConnectImmediately)
8730
- deeplink = undefined; // mobile redirects to more wallets page
8731
8556
  const content = () => {
8732
8557
  var _a, _b;
8733
8558
  return (jsxs(Fragment, { children: [jsx(ConnectorIcon, { "data-small": wallet.iconShouldShrink, "data-shape": wallet.iconShape, "data-background": redirectToMoreWallets, children: (_a = wallet.iconConnector) !== null && _a !== void 0 ? _a : wallet.icon }), jsxs(ConnectorLabel, { children: [isMobile ? ((_b = wallet.shortName) !== null && _b !== void 0 ? _b : wallet.name) : wallet.name, !context.uiConfig.hideRecentBadge && isRecent && (jsx(RecentlyUsedTag, { children: jsx("span", { children: "Recent" }) }))] })] }));
8734
8559
  };
8735
8560
  return (jsx(ConnectorButton, { type: "button", onClick: () => {
8736
- if (isMobile && deeplink) {
8737
- context.setRoute(routes.CONNECT_WITH_MOBILE);
8738
- context.setConnector({ id: wallet.id });
8739
- return;
8740
- }
8741
8561
  if (redirectToMoreWallets) {
8742
8562
  context.setRoute(routes.MOBILECONNECTORS);
8743
8563
  }
8744
8564
  else {
8745
- if (shouldConnectImmediately) {
8746
- connect({ connector: wallet === null || wallet === void 0 ? void 0 : wallet.connector });
8747
- }
8748
8565
  context.setRoute({ route: routes.CONNECT, connectType: 'linkIfUserConnectIfNoUser' });
8749
8566
  context.setConnector({ id: wallet.id });
8750
8567
  }
@@ -8754,7 +8571,6 @@ const ConnectorItem = ({ wallet, isRecent }) => {
8754
8571
  const ConnectWithMobile$1 = () => {
8755
8572
  const { open: openWalletConnectModal } = useWalletConnectModal();
8756
8573
  const [error, setError] = useState(undefined);
8757
- const { connect, connectors } = useConnect();
8758
8574
  const { connector, address } = useAccount();
8759
8575
  const { setRoute, setConnector } = useOpenfort();
8760
8576
  const openWCModal = async () => {
@@ -8766,7 +8582,7 @@ const ConnectWithMobile$1 = () => {
8766
8582
  };
8767
8583
  useEffect(() => {
8768
8584
  openWCModal();
8769
- }, [connect, connectors]);
8585
+ }, []);
8770
8586
  useEffect(() => {
8771
8587
  if (connector && address) {
8772
8588
  const walletConnectDeeplinkChoice = localStorage.getItem('WALLETCONNECT_DEEPLINK_CHOICE');
@@ -8784,9 +8600,7 @@ const ConnectWithMobile$1 = () => {
8784
8600
  };
8785
8601
  const Connectors = ({ logoutOnBack }) => {
8786
8602
  const isMobile = useIsMobile();
8787
- return (
8788
- // TODO: logout on back
8789
- jsx(PageContent, { logoutOnBack: logoutOnBack, width: 312, children: isMobile ? jsx(ConnectWithMobile$1, {}) : jsx(ConnectorList, {}) }));
8603
+ return (jsx(PageContent, { logoutOnBack: logoutOnBack, width: 312, children: isMobile ? jsx(ConnectWithMobile$1, {}) : jsx(ConnectorList, {}) }));
8790
8604
  };
8791
8605
 
8792
8606
  /**
@@ -8951,15 +8765,16 @@ const mapWalletStatus = (status) => {
8951
8765
  * ```
8952
8766
  */
8953
8767
  function useWallets(hookOptions = {}) {
8954
- const { client, embeddedAccounts, isLoadingAccounts: isLoadingWallets } = useOpenfortCore();
8768
+ const { client, embeddedAccounts, isLoadingAccounts: isLoadingWallets, updateEmbeddedAccounts } = useOpenfortCore();
8955
8769
  const { user } = useUser();
8956
8770
  const { walletConfig, setOpen, setRoute, setConnector, uiConfig } = useOpenfort();
8957
8771
  const { connector, isConnected, address } = useAccount();
8958
8772
  const chainId = useChainId();
8959
- const availableWallets = useWallets$1(); // TODO: Map wallets object to be the same as wallets
8773
+ const availableWallets = useWagmiWallets(); // TODO: Map wallets object to be the same as wallets
8960
8774
  const { disconnect, disconnectAsync } = useDisconnect();
8961
8775
  const [status, setStatus] = useWalletStatus();
8962
8776
  const [connectToConnector, setConnectToConnector] = useState(undefined);
8777
+ const { switchChainAsync } = useSwitchChain();
8963
8778
  const { connect } = useConnect({
8964
8779
  mutation: {
8965
8780
  onError: (e) => {
@@ -9060,29 +8875,33 @@ function useWallets(hookOptions = {}) {
9060
8875
  throw new OpenfortError('Invalid recovery method', OpenfortErrorType.VALIDATION_ERROR);
9061
8876
  }
9062
8877
  }, [walletConfig, getEncryptionSession]);
9063
- const rawWallets = useMemo(() => {
8878
+ const userLinkedWalletConnectors = useMemo(() => {
9064
8879
  const userWallets = user
9065
8880
  ? user.linkedAccounts
9066
- .filter((a) => a.provider === UIAuthProvider.WALLET)
9067
- .map((a) => {
8881
+ .filter((linkedAccount) => linkedAccount.provider === UIAuthProvider.WALLET)
8882
+ .map((linkedAccount) => {
9068
8883
  // For connector wallets (e.g. Metamask, Rabby, etc.)
9069
- const wallet = availableWallets.find((c) => c.connector.id === a.walletClientType);
8884
+ const wallet = availableWallets.find((c) => c.connector.id === linkedAccount.walletClientType);
9070
8885
  return {
9071
8886
  accounts: [],
9072
- address: a.address,
9073
- connectorType: a.connectorType,
9074
- walletClientType: a.walletClientType,
9075
- id: (wallet === null || wallet === void 0 ? void 0 : wallet.id) || a.walletClientType || 'unknown',
8887
+ address: linkedAccount.address,
8888
+ connectorType: linkedAccount.connectorType,
8889
+ walletClientType: linkedAccount.walletClientType,
8890
+ id: (wallet === null || wallet === void 0 ? void 0 : wallet.id) || linkedAccount.walletClientType || 'unknown',
9076
8891
  isAvailable: !!wallet,
9077
8892
  connector: wallet === null || wallet === void 0 ? void 0 : wallet.connector,
9078
8893
  };
9079
8894
  })
9080
8895
  : [];
8896
+ return userWallets;
8897
+ }, [user === null || user === void 0 ? void 0 : user.linkedAccounts, embeddedAccounts]);
8898
+ const userEmbeddedWallets = useMemo(() => {
8899
+ const newRawWallets = [];
9081
8900
  embeddedAccounts === null || embeddedAccounts === void 0 ? void 0 : embeddedAccounts.forEach((embeddedAccount) => {
9082
8901
  // Remove duplicates (different chain ids)
9083
- if (userWallets.find((w) => w.address.toLowerCase() === embeddedAccount.address.toLowerCase()))
8902
+ if (newRawWallets.find((w) => w.address.toLowerCase() === embeddedAccount.address.toLowerCase()))
9084
8903
  return;
9085
- userWallets.push(parseEmbeddedAccount({
8904
+ newRawWallets.push(parseEmbeddedAccount({
9086
8905
  embeddedAccount,
9087
8906
  connector: openfortConnector,
9088
8907
  simpleAccounts: getSimpleAccounts({
@@ -9092,8 +8911,11 @@ function useWallets(hookOptions = {}) {
9092
8911
  chainId,
9093
8912
  }));
9094
8913
  });
9095
- return userWallets;
9096
- }, [user === null || user === void 0 ? void 0 : user.linkedAccounts, embeddedAccounts]);
8914
+ return newRawWallets;
8915
+ }, [chainId, embeddedAccounts, openfortConnector]);
8916
+ const rawWallets = useMemo(() => {
8917
+ return [...userLinkedWalletConnectors, ...userEmbeddedWallets];
8918
+ }, [userLinkedWalletConnectors, userEmbeddedWallets]);
9097
8919
  const wallets = useMemo(() => {
9098
8920
  // logger.log("Mapping wallets", { rawWallets, status, address, isConnected, connector: connector?.id });
9099
8921
  return rawWallets.map((w) => {
@@ -9104,8 +8926,9 @@ function useWallets(hookOptions = {}) {
9104
8926
  isActive: w.address.toLowerCase() === (address === null || address === void 0 ? void 0 : address.toLowerCase()) && isConnected && (connector === null || connector === void 0 ? void 0 : connector.id) === w.id,
9105
8927
  });
9106
8928
  });
9107
- }, [rawWallets.length, status.status, address, isConnected, connector === null || connector === void 0 ? void 0 : connector.id]);
8929
+ }, [rawWallets, status.status, address, isConnected, connector === null || connector === void 0 ? void 0 : connector.id]);
9108
8930
  const activeWallet = isConnected && connector ? wallets.find((w) => w.isActive) : undefined;
8931
+ const [shouldSwitchToChain, setShouldSwitchToChain] = useState(null);
9109
8932
  useEffect(() => {
9110
8933
  if (connectToConnector)
9111
8934
  connect({ connector: connectToConnector.connector });
@@ -9176,6 +8999,7 @@ function useWallets(hookOptions = {}) {
9176
8999
  hookOptions,
9177
9000
  });
9178
9001
  }
9002
+ let hasToSwitchChain = false;
9179
9003
  try {
9180
9004
  const embeddedAccounts = await queryClient.ensureQueryData({
9181
9005
  queryKey: ['openfortEmbeddedAccountsList'],
@@ -9191,7 +9015,7 @@ function useWallets(hookOptions = {}) {
9191
9015
  let embeddedAccount;
9192
9016
  if (walletAddress) {
9193
9017
  const addressToMatch = walletAddress.toLowerCase();
9194
- const accountToRecover = embeddedAccounts.find((w) => {
9018
+ let accountToRecover = embeddedAccounts.find((w) => {
9195
9019
  if ((walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.accountType) === AccountTypeEnum.EOA) {
9196
9020
  return w.address.toLowerCase() === addressToMatch;
9197
9021
  }
@@ -9200,23 +9024,23 @@ function useWallets(hookOptions = {}) {
9200
9024
  }
9201
9025
  });
9202
9026
  if (!accountToRecover) {
9203
- // TODO: Connect to wallet in the other chain and then switch chain
9204
- return onError({
9205
- error: new OpenfortError(`Embedded wallet not found for address ${walletAddress} and chainId ${chainId}`, OpenfortErrorType.WALLET_ERROR),
9206
- options: optionsObject,
9207
- hookOptions,
9027
+ logger.log(`No embedded wallet found for address ${walletAddress} in chain ${chainId}. Checking other chains.`);
9028
+ const accountToRecoverInDifferentChain = embeddedAccounts.find((w) => {
9029
+ return w.address.toLowerCase() === addressToMatch && !!w.chainId;
9208
9030
  });
9031
+ if (!accountToRecoverInDifferentChain || !accountToRecoverInDifferentChain.chainId) {
9032
+ throw new OpenfortError(`Embedded wallet not found for address ${walletAddress}`, OpenfortErrorType.WALLET_ERROR);
9033
+ }
9034
+ logger.log(`Found embedded wallet for address ${walletAddress} in different chain ${accountToRecoverInDifferentChain.chainId}.`);
9035
+ hasToSwitchChain = true;
9036
+ accountToRecover = accountToRecoverInDifferentChain;
9209
9037
  }
9210
9038
  logger.log('Found embedded wallet to recover', accountToRecover);
9211
9039
  if (((_b = optionsObject.recovery) === null || _b === void 0 ? void 0 : _b.recoveryMethod) &&
9212
9040
  accountToRecover.recoveryMethod &&
9213
9041
  optionsObject.recovery.recoveryMethod !== accountToRecover.recoveryMethod) {
9214
9042
  logger.log('Recovery method does not match', optionsObject.recovery.recoveryMethod, accountToRecover.recoveryMethod);
9215
- return onError({
9216
- error: new OpenfortError("The recovery method you entered is incorrect and does not match the wallet's recovery method", OpenfortErrorType.WALLET_ERROR),
9217
- options: optionsObject,
9218
- hookOptions,
9219
- });
9043
+ throw new OpenfortError("The recovery method you entered is incorrect and does not match the wallet's recovery method", OpenfortErrorType.WALLET_ERROR);
9220
9044
  }
9221
9045
  const recovery = {
9222
9046
  recoveryMethod: (_c = accountToRecover.recoveryMethod) !== null && _c !== void 0 ? _c : RecoveryMethod.AUTOMATIC,
@@ -9234,11 +9058,7 @@ function useWallets(hookOptions = {}) {
9234
9058
  if ((walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.accountType) === AccountTypeEnum.EOA) {
9235
9059
  accountToRecover = embeddedAccounts.find((w) => w.accountType === AccountTypeEnum.EOA);
9236
9060
  if (!accountToRecover) {
9237
- return onError({
9238
- error: new OpenfortError('No embedded wallet found with type EOA', OpenfortErrorType.WALLET_ERROR),
9239
- options: optionsObject,
9240
- hookOptions,
9241
- });
9061
+ throw new OpenfortError('No embedded wallet found with type EOA', OpenfortErrorType.WALLET_ERROR);
9242
9062
  }
9243
9063
  }
9244
9064
  else {
@@ -9246,11 +9066,7 @@ function useWallets(hookOptions = {}) {
9246
9066
  if (!accountToRecover) {
9247
9067
  // Here it should check if there is a wallet that can recover in another chain and recover it in the current chain (its a different account so its not supported yet)
9248
9068
  // TODO: Connect to wallet in the other chain and then switch chain
9249
- return onError({
9250
- error: new OpenfortError('No embedded wallet found for the current chain', OpenfortErrorType.WALLET_ERROR),
9251
- options: optionsObject,
9252
- hookOptions,
9253
- });
9069
+ throw new OpenfortError('No embedded wallet found for the current chain', OpenfortErrorType.WALLET_ERROR);
9254
9070
  }
9255
9071
  }
9256
9072
  logger.log('Found embedded wallet to recover (without walletAddress)', accountToRecover);
@@ -9266,11 +9082,7 @@ function useWallets(hookOptions = {}) {
9266
9082
  walletAddress = accountToRecover.address;
9267
9083
  }
9268
9084
  if (!embeddedAccount) {
9269
- return onError({
9270
- error: new OpenfortError('Failed to recover embedded wallet', OpenfortErrorType.WALLET_ERROR),
9271
- options: optionsObject,
9272
- hookOptions,
9273
- });
9085
+ throw new OpenfortError('Failed to recover embedded wallet', OpenfortErrorType.WALLET_ERROR);
9274
9086
  }
9275
9087
  setStatus({
9276
9088
  status: 'success',
@@ -9321,6 +9133,11 @@ function useWallets(hookOptions = {}) {
9321
9133
  hookOptions,
9322
9134
  });
9323
9135
  }
9136
+ finally {
9137
+ if (hasToSwitchChain) {
9138
+ setShouldSwitchToChain(chainId);
9139
+ }
9140
+ }
9324
9141
  }
9325
9142
  else {
9326
9143
  setStatus({
@@ -9334,6 +9151,19 @@ function useWallets(hookOptions = {}) {
9334
9151
  }
9335
9152
  return {};
9336
9153
  }, [wallets, setOpen, setRoute, setConnector, disconnectAsync, address, client, walletConfig, chainId, hookOptions]);
9154
+ useEffect(() => {
9155
+ (async () => {
9156
+ if (shouldSwitchToChain) {
9157
+ logger.log(`Switching to chain ${shouldSwitchToChain}.`);
9158
+ // const a = await client.embeddedWallet.getEthereumProvider()
9159
+ // const res = await switchChain(a, { id: shouldSwitchToChain })
9160
+ const res = await switchChainAsync({ chainId: shouldSwitchToChain });
9161
+ logger.log('Switched to chain', res);
9162
+ updateEmbeddedAccounts();
9163
+ setShouldSwitchToChain(null);
9164
+ }
9165
+ })();
9166
+ }, [shouldSwitchToChain]);
9337
9167
  const queryClient = useQueryClient();
9338
9168
  const createWallet = useCallback(async ({ recovery, ...options } = {}) => {
9339
9169
  setStatus({
@@ -9343,18 +9173,10 @@ function useWallets(hookOptions = {}) {
9343
9173
  try {
9344
9174
  const accessToken = await client.getAccessToken();
9345
9175
  if (!accessToken) {
9346
- return onError({
9347
- error: new OpenfortError('Openfort access token not found', OpenfortErrorType.WALLET_ERROR),
9348
- hookOptions,
9349
- options,
9350
- });
9176
+ throw new OpenfortError('Openfort access token not found', OpenfortErrorType.WALLET_ERROR);
9351
9177
  }
9352
9178
  if (!walletConfig) {
9353
- return onError({
9354
- error: new OpenfortError('Embedded signer not enabled', OpenfortErrorType.WALLET_ERROR),
9355
- hookOptions,
9356
- options,
9357
- });
9179
+ throw new OpenfortError('Embedded signer not enabled', OpenfortErrorType.WALLET_ERROR);
9358
9180
  }
9359
9181
  const recoveryParams = await parseWalletRecovery(recovery);
9360
9182
  const embeddedAccount = await client.embeddedWallet.create({
@@ -9385,7 +9207,9 @@ function useWallets(hookOptions = {}) {
9385
9207
  }
9386
9208
  catch (e) {
9387
9209
  const errorObj = e instanceof Error ? e : new Error('Failed to create wallet');
9388
- const error = new OpenfortError('Failed to create wallet', OpenfortErrorType.WALLET_ERROR, { error: errorObj });
9210
+ const error = e instanceof OpenfortError
9211
+ ? e
9212
+ : new OpenfortError('Failed to create wallet', OpenfortErrorType.WALLET_ERROR, { error: errorObj });
9389
9213
  setStatus({
9390
9214
  status: 'error',
9391
9215
  error,
@@ -11638,7 +11462,7 @@ const LoadWallets = () => {
11638
11462
  return (jsx(PageContent, { onBack: !user ? 'back' : null, children: jsx(Loader, { header: "Setting up wallet", isError: isError, description: isError ? errorMessage : 'Setting up wallets' }) }));
11639
11463
  };
11640
11464
 
11641
- const IconContainer$2 = styled(motion.div) `
11465
+ const IconContainer$1 = styled(motion.div) `
11642
11466
  transition: all 220ms cubic-bezier(0.175, 0.885, 0.32, 1.1);
11643
11467
  display: flex;
11644
11468
  align-items: center;
@@ -11696,7 +11520,7 @@ const IconContainer$2 = styled(motion.div) `
11696
11520
  }
11697
11521
  `}
11698
11522
  `;
11699
- const CopyToClipboardIcon = ({ copied, small }) => (jsx(IconContainer$2, { "$clipboard": copied, children: jsx(CopyToClipboardIcon$1, { style: {
11523
+ const CopyToClipboardIcon = ({ copied, small }) => (jsx(IconContainer$1, { "$clipboard": copied, children: jsx(CopyToClipboardIcon$1, { style: {
11700
11524
  transform: small ? 'scale(1)' : 'translateX(3px) scale(1.5)',
11701
11525
  opacity: small || copied ? 1 : 0.3,
11702
11526
  } }) }));
@@ -11819,10 +11643,8 @@ const MobileConnectors = () => {
11819
11643
  var _a;
11820
11644
  const context = useOpenfort();
11821
11645
  const locales = useLocales();
11822
- const { connect: { getUri }, } = useWeb3();
11823
- const wcUri = getUri();
11824
11646
  const { open: openW3M, isOpen: isOpenW3M } = useWalletConnectModal();
11825
- const wallets = useWallets$1();
11647
+ const wallets = useWagmiWallets();
11826
11648
  // filter out installed wallets
11827
11649
  const walletsIdsToDisplay = (_a = Object.keys(walletConfigs).filter((walletId) => {
11828
11650
  const wallet = walletConfigs[walletId];
@@ -11836,7 +11658,7 @@ const MobileConnectors = () => {
11836
11658
  context.setRoute(routes.CONNECT_WITH_MOBILE);
11837
11659
  context.setConnector({ id: walletId });
11838
11660
  };
11839
- return (jsx(PageContent, { width: 312, onBack: routes.PROVIDERS, children: jsxs(Container$2, { children: [jsx(ModalContent, { style: { paddingBottom: 0 }, children: jsx(ScrollArea, { height: 340, children: jsxs(WalletList, { "$disabled": !wcUri, children: [walletsIdsToDisplay
11661
+ return (jsx(PageContent, { width: 312, onBack: routes.PROVIDERS, children: jsxs(Container$2, { children: [jsx(ModalContent, { style: { paddingBottom: 0 }, children: jsx(ScrollArea, { height: 340, children: jsxs(WalletList, { children: [walletsIdsToDisplay
11840
11662
  .sort(
11841
11663
  // sort by name
11842
11664
  (a, b) => {
@@ -11868,7 +11690,7 @@ const MobileConnectors = () => {
11868
11690
  justifyContent: 'center',
11869
11691
  gap: 14,
11870
11692
  paddingTop: 8,
11871
- }, children: jsx(CopyToClipboard, { variant: "button", string: wcUri, children: locales.copyToClipboard }) }))] }) }));
11693
+ }, children: jsx(CopyToClipboard, { variant: "button", children: locales.copyToClipboard }) }))] }) }));
11872
11694
  };
11873
11695
 
11874
11696
  const Introduction = () => {
@@ -12501,7 +12323,7 @@ const PoweredByFooter = ({ showDisclaimer }) => {
12501
12323
  const { uiConfig: options } = useOpenfort();
12502
12324
  return (jsxs(Container, { children: [showDisclaimer && (jsx(Disclaimer, { children: (options === null || options === void 0 ? void 0 : options.disclaimer) ? (options.disclaimer) : (jsxs("div", { children: ["By logging in, you agree to our", ' ', jsx("a", { href: (_a = options === null || options === void 0 ? void 0 : options.termsOfServiceUrl) !== null && _a !== void 0 ? _a : 'https://www.openfort.io/terms', target: "_blank", rel: "noopener noreferrer", children: "Terms of Service" }), ' ', "&", ' ', jsx("a", { href: (_b = options === null || options === void 0 ? void 0 : options.privacyPolicyUrl) !== null && _b !== void 0 ? _b : 'https://www.openfort.io/privacy', target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" }), "."] })) })), jsxs(TextButton, { onClick: () => {
12503
12325
  window.open('https://www.openfort.io/', '_blank');
12504
- }, children: [jsx("span", { children: "Powered by" }), jsx(IconContainer$1, { children: jsx(Logos.Openfort, {}) }), jsx("span", { children: "Openfort" })] })] }));
12326
+ }, children: [jsx("span", { children: "Powered by" }), jsx(IconContainer, { children: jsx(Logos.Openfort, {}) }), jsx("span", { children: "Openfort" })] })] }));
12505
12327
  };
12506
12328
  const Disclaimer = styled(motion.div) `
12507
12329
  padding: 8px 50px 0px 50px;
@@ -12524,7 +12346,7 @@ const Disclaimer = styled(motion.div) `
12524
12346
  }
12525
12347
  }
12526
12348
  `;
12527
- const IconContainer$1 = styled.div `
12349
+ const IconContainer = styled.div `
12528
12350
  width: 20px;
12529
12351
  height: 20px;
12530
12352
  margin-left: 5px;
@@ -12729,7 +12551,7 @@ const ProvidersHeader = styled(motion.h3) `
12729
12551
 
12730
12552
  const WalletIcon = ({ provider }) => {
12731
12553
  var _a;
12732
- const wallets = useWallets$1();
12554
+ const wallets = useWagmiWallets();
12733
12555
  const wallet = useMemo(() => {
12734
12556
  return wallets.find((w) => { var _a; return ((_a = w.id) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === provider.walletClientType; });
12735
12557
  }, [provider]);
@@ -12941,11 +12763,9 @@ const RecoverPasswordWallet = ({ wallet, onBack, logoutOnBack, }) => {
12941
12763
  if (recoveryError)
12942
12764
  triggerResize();
12943
12765
  }, [recoveryError]);
12944
- const ensFallbackConfig = useEnsFallbackConfig();
12945
12766
  const { data: ensName } = useEnsName({
12946
12767
  chainId: 1,
12947
12768
  address: wallet.address,
12948
- config: ensFallbackConfig,
12949
12769
  });
12950
12770
  return (jsxs(PageContent, { onBack: onBack, logoutOnBack: logoutOnBack, children: [jsx(FloatingGraphic, { height: "130px", logoCenter: {
12951
12771
  logo: jsx(KeyIcon, {}),
@@ -13752,113 +13572,67 @@ const ConnectWithOAuth = () => {
13752
13572
  } }) }));
13753
13573
  };
13754
13574
 
13755
- const IconContainer = styled(motion.div) `
13756
- position: relative;
13757
- display: flex;
13758
- align-items: center;
13759
- justify-content: center;
13760
- width: 47px;
13761
- height: 52px;
13762
- min-width: 47px;
13763
- min-height: 52px;
13764
- svg {
13765
- display: block;
13766
- max-width: 100%;
13767
- height: auto;
13768
- }
13769
- `;
13770
- const ScanIconWithLogos = ({ logo }) => {
13771
- const logoList = [
13772
- jsx(Logos.MetaMask, { background: true }),
13773
- jsx(Logos.Coinbase, { background: true }),
13774
- jsx(Logos.Crypto, {}),
13775
- jsx(Logos.ImToken, {}),
13776
- jsx(Logos.Argent, {}),
13777
- jsx(Logos.Trust, {}),
13778
- ];
13779
- return (jsx(IconContainer, { children: jsxs("svg", { "aria-hidden": "true", width: "47", height: "52", viewBox: "0 0 47 52", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsxs("g", { mask: "url(#gradient-mask)", children: [jsx("path", { d: "M7 14.5C7 11.4624 9.46243 9 12.5 9H31.5C34.5376 9 37 11.4624 37 14.5V47H7V14.5Z", fill: "var(--ck-graphic-scaniconwithlogos-04)" }), logo ? (jsx("foreignObject", { x: "13", y: "21", width: "18", height: "18", rx: "5", children: jsx("div", { style: { overflow: 'hidden', borderRadius: 5 }, children: logo }) })) : (jsxs(Fragment, { children: [jsx("foreignObject", { x: "12", y: "15", width: "9", height: "9", rx: "2.5", children: jsx("div", { style: { overflow: 'hidden', borderRadius: 2.5 }, children: logoList[0] }) }), jsx("foreignObject", { x: "23", y: "15", width: "9", height: "9", rx: "2.5", children: jsx("div", { style: { overflow: 'hidden', borderRadius: 2.5 }, children: logoList[1] }) }), jsx("foreignObject", { x: "12", y: "26", width: "9", height: "9", rx: "2.5", children: jsx("div", { style: { overflow: 'hidden', borderRadius: 2.5 }, children: jsx("div", { style: { overflow: 'hidden', borderRadius: 2.5 }, children: logoList[2] }) }) }), jsx("foreignObject", { x: "23", y: "26", width: "9", height: "9", rx: "2.5", children: jsx("div", { style: { overflow: 'hidden', borderRadius: 2.5 }, children: logoList[3] }) }), jsx("foreignObject", { x: "12", y: "37", width: "9", height: "9", rx: "2.5", children: jsx("div", { style: { overflow: 'hidden', borderRadius: 2.5 }, children: logoList[4] }) }), jsx("foreignObject", { x: "23", y: "37", width: "9", height: "9", rx: "2.5", children: jsx("div", { style: { overflow: 'hidden', borderRadius: 2.5 }, children: logoList[5] }) })] })), jsx("path", { d: "M36 47V13.7143C36 11.1107 33.8893 9 31.2857 9H12.7143C10.1107 9 8 11.1107 8 13.7143V47", stroke: "url(#paint0_linear_924_12568)", strokeWidth: "2" }), jsx("path", { d: "M15 10H29C29 11.1046 28.1046 12 27 12H17C15.8954 12 15 11.1046 15 10Z", fill: "var(--ck-graphic-scaniconwithlogos-01)" }), jsx("rect", { x: "1", y: "47", width: "43", height: "5", fill: "var(--ck-tooltip-background)" }), jsx("rect", { x: "22", y: "1", width: "24", height: "24", rx: "12", fill: "var(--ck-graphic-scaniconwithlogos-03)", stroke: "var(--ck-tooltip-background)", strokeWidth: "2" }), jsx("rect", { x: "34.5", y: "10", width: "2.5", height: "2.5", rx: "0.75", fill: "#373737" }), jsx("rect", { x: "31", y: "10", width: "2.5", height: "2.5", rx: "0.75", fill: "#373737" }), jsx("rect", { x: "31", y: "13.5", width: "2.5", height: "2.5", rx: "0.75", fill: "#373737" }), jsx("rect", { x: "34.5", y: "13.5", width: "2.5", height: "2.5", rx: "0.75", fill: "#373737" }), jsx("path", { d: "M28.5 10.5V9C28.5 8.17157 29.1716 7.5 30 7.5H31.5", stroke: "#373737", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M36.5 7.5L38 7.5C38.8284 7.5 39.5 8.17157 39.5 9L39.5 10.5", stroke: "#373737", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M39.5 15.5L39.5 17C39.5 17.8284 38.8284 18.5 38 18.5L36.5 18.5", stroke: "#373737", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M31.5 18.5L30 18.5C29.1716 18.5 28.5 17.8284 28.5 17L28.5 15.5", stroke: "#373737", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] }), jsxs("defs", { children: [jsxs("linearGradient", { id: "paint0_linear_924_12568", x1: "22", y1: "8.2549", x2: "22", y2: "47", gradientUnits: "userSpaceOnUse", children: [jsx("stop", { stopColor: "var(--ck-graphic-scaniconwithlogos-01)" }), jsx("stop", { offset: "1", stopColor: "var(--ck-graphic-scaniconwithlogos-02)" })] }), jsxs("linearGradient", { id: "linear-gradient-mask", x1: "47", y1: "42", x2: "47", y2: "47", gradientUnits: "userSpaceOnUse", children: [jsx("stop", { stopColor: "white" }), jsx("stop", { offset: "1", stopColor: "black", stopOpacity: "0" })] }), jsx("mask", { id: "gradient-mask", children: jsx("rect", { x: "0", y: "0", width: "47", height: "52", fill: "url(#linear-gradient-mask)" }) })] })] }) }));
13780
- };
13781
-
13782
- const ConnectWithQRCode = ({ switchConnectMethod }) => {
13783
- var _a, _b, _c, _d;
13784
- const { connector, setRoute, uiConfig } = useOpenfort();
13785
- const id = connector.id;
13575
+ const ConnectWithSiwe = () => {
13576
+ const { isConnected, address } = useAccount();
13577
+ const { connector, setRoute } = useOpenfort();
13786
13578
  const wallet = useWallet(connector.id);
13787
- const { open: openW3M, isOpen: isOpenW3M } = useWalletConnectModal();
13788
- const { connect: { getUri }, } = useWeb3();
13789
- const wcUri = getUri(id);
13790
- const uri = wcUri ? ((_b = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.getWalletConnectDeeplink) === null || _a === void 0 ? void 0 : _a.call(wallet, wcUri)) !== null && _b !== void 0 ? _b : wcUri) : undefined;
13791
- const locales = useLocales({
13792
- CONNECTORNAME: wallet === null || wallet === void 0 ? void 0 : wallet.name,
13793
- });
13794
- const connectWithSiwe = useConnectWithSiwe();
13795
- const { isConnected } = useAccount();
13796
- const { setOpen } = useOpenfort();
13797
- const { disconnect } = useDisconnect();
13798
- const [isFirstFrame, setIsFirstFrame] = React.useState(true);
13579
+ const [error, setError] = useState(undefined);
13580
+ const siwe = useConnectWithSiwe();
13581
+ const [description, setDescription] = useState(undefined);
13582
+ const connectWithSiwe = () => {
13583
+ setDescription('Requesting signature to verify wallet...');
13584
+ siwe({
13585
+ walletClientType: connector.id,
13586
+ onConnect: () => {
13587
+ setRoute(routes.PROFILE);
13588
+ },
13589
+ onError: (error) => {
13590
+ setError(error || 'Connection failed');
13591
+ setDescription(undefined);
13592
+ },
13593
+ });
13594
+ };
13799
13595
  useEffect(() => {
13800
- // When the component is first rendered, we disconnect the user if they are connected
13801
- if (isFirstFrame) {
13802
- setIsFirstFrame(false);
13803
- if (isConnected) {
13804
- disconnect();
13805
- }
13596
+ if (isConnected) {
13597
+ connectWithSiwe();
13806
13598
  }
13807
- else {
13808
- // When connected with WalletConnect, we connect with SIWE
13809
- if (isConnected) {
13810
- connectWithSiwe({
13811
- // connectorType: 'walletConnect',
13812
- // walletClientType: 'walletConnect',
13813
- onError: (error) => {
13814
- logger.log(error);
13815
- disconnect();
13816
- },
13817
- onConnect: () => {
13818
- setOpen(false);
13819
- },
13820
- });
13821
- }
13599
+ }, [isConnected]);
13600
+ const { data: ensName } = useEnsName({
13601
+ chainId: 1,
13602
+ address: address,
13603
+ });
13604
+ return (jsxs(PageContent, { children: [jsxs(ModalBody, { style: { textAlign: 'center' }, children: ["Connected with", jsx(CopyToClipboard, { string: address, children: ensName !== null && ensName !== void 0 ? ensName : truncateEthAddress(address) })] }), jsx(Loader, { header: 'Sign in to your wallet', icon: wallet === null || wallet === void 0 ? void 0 : wallet.icon, isError: !!error, description: error !== null && error !== void 0 ? error : description, onRetry: () => connectWithSiwe() })] }));
13605
+ };
13606
+ const ConnectWithWalletConnect = () => {
13607
+ const { connector } = useOpenfort();
13608
+ const wallet = useWallet(connector.id);
13609
+ const [error, setError] = useState(undefined);
13610
+ const { open: openWalletConnectModal } = useWalletConnectModal();
13611
+ useEffect(() => {
13612
+ openWCModal();
13613
+ }, []);
13614
+ const openWCModal = async () => {
13615
+ setError(undefined);
13616
+ const { error } = await openWalletConnectModal();
13617
+ if (error) {
13618
+ setError(error);
13822
13619
  }
13620
+ };
13621
+ return (jsx(PageContent, { children: jsx(Loader, { header: error ? 'Error connecting wallet.' : `Connecting...`, icon: wallet === null || wallet === void 0 ? void 0 : wallet.icon, isError: !!error, description: error, onRetry: () => openWCModal() }) }));
13622
+ };
13623
+ const ConnectWithQRCode = () => {
13624
+ const { connector, triggerResize } = useOpenfort();
13625
+ const { isConnected } = useAccount();
13626
+ useEffect(() => {
13627
+ triggerResize();
13823
13628
  }, [isConnected]);
13629
+ const wallet = useWallet(connector.id);
13824
13630
  if (!wallet)
13825
- return jsxs(Fragment, { children: ["Wallet not found ", connector.id] });
13826
- const downloads = wallet === null || wallet === void 0 ? void 0 : wallet.downloadUrls;
13827
- const extensions = {
13828
- chrome: downloads === null || downloads === void 0 ? void 0 : downloads.chrome,
13829
- firefox: downloads === null || downloads === void 0 ? void 0 : downloads.firefox,
13830
- brave: downloads === null || downloads === void 0 ? void 0 : downloads.brave,
13831
- edge: downloads === null || downloads === void 0 ? void 0 : downloads.edge,
13832
- safari: downloads === null || downloads === void 0 ? void 0 : downloads.safari,
13833
- };
13834
- detectBrowser();
13835
- const hasApps = downloads && Object.keys(downloads).length !== 0;
13836
- extensions
13837
- ? {
13838
- name: Object.keys(extensions)[0],
13839
- label: ((_c = Object.keys(extensions)[0]) === null || _c === void 0 ? void 0 : _c.charAt(0).toUpperCase()) + ((_d = Object.keys(extensions)[0]) === null || _d === void 0 ? void 0 : _d.slice(1)), // Capitalise first letter, but this might be better suited as a lookup table
13840
- url: extensions[Object.keys(extensions)[0]],
13841
- }
13842
- : undefined;
13843
- const showAdditionalOptions = isWalletConnectConnector(id);
13844
- return (jsxs(PageContent, { children: [jsxs(ModalContent, { style: { paddingBottom: 8, gap: 14 }, children: [jsx(CustomQRCode, { value: uri, image: wallet === null || wallet === void 0 ? void 0 : wallet.icon, tooltipMessage: isWalletConnectConnector(id) ? (jsxs(Fragment, { children: [jsx(ScanIconWithLogos, {}), jsx("span", { children: locales.scanScreen_tooltip_walletConnect })] })) : (jsxs(Fragment, { children: [jsx(ScanIconWithLogos, { logo: wallet === null || wallet === void 0 ? void 0 : wallet.icon }), jsx("span", { children: locales.scanScreen_tooltip_default })] })) }), showAdditionalOptions ? jsx(OrDivider, {}) : hasApps && jsx(OrDivider, { children: locales.dontHaveTheApp })] }), showAdditionalOptions && ( // for walletConnect
13845
- jsxs("div", { style: {
13846
- display: 'flex',
13847
- alignItems: 'center',
13848
- justifyContent: 'center',
13849
- gap: 14,
13850
- }, children: [uiConfig.walletConnectCTA !== 'modal' && (jsx(CopyToClipboard, { variant: "button", string: uri, children: uiConfig.walletConnectCTA === 'link' ? locales.copyToClipboard : locales.copyCode })), uiConfig.walletConnectCTA !== 'link' && (jsx(Button, { icon: jsx(ExternalLinkIcon, {}), onClick: openW3M, disabled: isOpenW3M, waiting: isOpenW3M, children: uiConfig.walletConnectCTA === 'modal' ? locales.useWalletConnectModal : locales.useModal }))] })), isFamilyAccountsConnector(wallet.id) && (jsxs(Fragment, { children: [jsx(OrDivider, {}), jsx(Button, { onClick: () => switchConnectMethod(id), children: locales.loginWithEmailOrPhone })] })), hasApps && (jsx(Button, { onClick: () => {
13851
- setRoute(routes.DOWNLOAD);
13852
- },
13853
- /*
13854
- icon={
13855
- <div style={{ background: connectorInfo?.icon }}>
13856
- {connectorInfo?.logos.default}
13857
- </div>
13858
- }
13859
- roundedIcon
13860
- */
13861
- download: true, children: locales.getWalletName }))] }));
13631
+ return jsx(Loader, { header: `Connector not found: ${connector.id}`, isError: true });
13632
+ if (isConnected) {
13633
+ return jsx(ConnectWithSiwe, {});
13634
+ }
13635
+ return jsx(ConnectWithWalletConnect, {});
13862
13636
  };
13863
13637
 
13864
13638
  const states$1 = {
@@ -13893,11 +13667,7 @@ const ConnectUsing = () => {
13893
13667
  return jsx(ConnectWithOAuth, {});
13894
13668
  if (!wallet)
13895
13669
  return jsxs(Alert, { children: ["Connector not found ", context.connector.id] });
13896
- return (jsxs(AnimatePresence, { children: [status === states$1.QRCODE && (jsx(motion.div, { initial: 'initial', animate: 'animate', exit: 'exit', variants: contentVariants$1, children: jsx(ConnectWithQRCode, { switchConnectMethod: (_id) => {
13897
- //if (id) setId(id);
13898
- setStatus(states$1.INJECTOR);
13899
- setTimeout(context.triggerResize, 10); // delay required here for modal to resize
13900
- } }) }, states$1.QRCODE)), status === states$1.INJECTOR && (jsx(motion.div, { initial: 'initial', animate: 'animate', exit: 'exit', variants: contentVariants$1, children: jsx(ConnectWithInjector, { switchConnectMethod: (_id) => {
13670
+ return (jsxs(AnimatePresence, { children: [status === states$1.QRCODE && (jsx(motion.div, { initial: 'initial', animate: 'animate', exit: 'exit', variants: contentVariants$1, children: jsx(ConnectWithQRCode, {}) }, states$1.QRCODE)), status === states$1.INJECTOR && (jsx(motion.div, { initial: 'initial', animate: 'animate', exit: 'exit', variants: contentVariants$1, children: jsx(ConnectWithInjector, { switchConnectMethod: (_id) => {
13901
13671
  //if (id) setId(id);
13902
13672
  setStatus(states$1.QRCODE);
13903
13673
  setTimeout(context.triggerResize, 10); // delay required here for modal to resize
@@ -13946,21 +13716,13 @@ const ConnectWithMobile = () => {
13946
13716
  const { isConnected } = useAccount();
13947
13717
  const [status, setStatus] = useState(isConnected ? states.INIT : states.CONNECTING);
13948
13718
  const [description, setDescription] = useState(undefined);
13949
- const { connect: { getUri }, } = useWeb3();
13950
- const wcUri = getUri();
13951
13719
  const [hasReturned, setHasReturned] = useState(false);
13952
13720
  const siwe = useConnectWithSiwe();
13953
- const openApp = (url) => {
13721
+ const openApp = () => {
13954
13722
  var _a;
13955
- const uri = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.getWalletConnectDeeplink) === null || _a === void 0 ? void 0 : _a.call(wallet, url !== null && url !== void 0 ? url : '');
13956
- logger.log('Opening wallet app with uri', { uri, url, wallet, walletId, walletConfigs, connectorId: connector.id });
13723
+ const uri = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.getWalletConnectDeeplink) === null || _a === void 0 ? void 0 : _a.call(wallet, '');
13957
13724
  if (uri) {
13958
- if (url) {
13959
- window.location.href = uri;
13960
- }
13961
- else {
13962
- window.location.href = uri.replace('?uri=', '');
13963
- }
13725
+ window.location.href = uri.replace('?uri=', '');
13964
13726
  }
13965
13727
  else {
13966
13728
  setStatus(states.ERROR);
@@ -13987,7 +13749,6 @@ const ConnectWithMobile = () => {
13987
13749
  useEffect(() => {
13988
13750
  switch (status) {
13989
13751
  case states.INIT:
13990
- openApp(wcUri);
13991
13752
  break;
13992
13753
  case states.CONNECTING:
13993
13754
  setDescription('Requesting signature to verify wallet...');
@@ -14010,7 +13771,7 @@ const ConnectWithMobile = () => {
14010
13771
  } }), isConnected ? (jsx(Button, { onClick: () => {
14011
13772
  openApp();
14012
13773
  }, children: "Sign in App" })) : (jsx(Button, { onClick: () => {
14013
- openApp(wcUri);
13774
+ openApp();
14014
13775
  }, children: "Sign in App" })), jsx(DownloadFooter, { children: jsxs(FitText, { children: ["Don't have ", (_a = wallet.name) !== null && _a !== void 0 ? _a : connector.id.split(',')[0], " installed?", ' ', jsx("a", { style: { marginLeft: 5 }, href: isAndroid() ? (_b = wallet === null || wallet === void 0 ? void 0 : wallet.downloadUrls) === null || _b === void 0 ? void 0 : _b.android : (_c = wallet === null || wallet === void 0 ? void 0 : wallet.downloadUrls) === null || _c === void 0 ? void 0 : _c.ios, target: "_blank", rel: "noreferrer", children: "GET" })] }) })] }));
14015
13776
  };
14016
13777
 
@@ -14140,6 +13901,34 @@ const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customTheme
14140
13901
  return (jsx(ConnectKitThemeProvider, { theme: theme, customTheme: customTheme, mode: mode, children: jsx(Modal, { open: context.open, pages: pages, pageId: route, onClose: closeable ? hide : undefined }) }));
14141
13902
  };
14142
13903
 
13904
+ const Web3Context = createContext({
13905
+ connect: {
13906
+ getUri: () => '',
13907
+ },
13908
+ dapp: {
13909
+ chains: [],
13910
+ },
13911
+ account: undefined,
13912
+ });
13913
+ const Web3ContextProvider = ({ children }) => {
13914
+ const { address: currentAddress, chain } = useAccount();
13915
+ const chainIsSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
13916
+ const chains = useChains();
13917
+ const value = {
13918
+ dapp: {
13919
+ chains,
13920
+ },
13921
+ account: currentAddress
13922
+ ? {
13923
+ chain,
13924
+ chainIsSupported,
13925
+ address: currentAddress,
13926
+ }
13927
+ : undefined,
13928
+ };
13929
+ return jsx(Web3Context.Provider, { value: value, children: children });
13930
+ };
13931
+
14143
13932
  /**
14144
13933
  * Provides Openfort configuration and context to descendant components.
14145
13934
  *
@@ -14168,7 +13957,7 @@ const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customTheme
14168
13957
  * }
14169
13958
  * ```
14170
13959
  */
14171
- const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMode = false, publishableKey, walletConfig, overrides, thirdPartyAuth, }) => {
13960
+ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMode, publishableKey, walletConfig, overrides, thirdPartyAuth, }) => {
14172
13961
  var _a, _b, _c, _d, _e;
14173
13962
  // OpenfortProvider must be within a WagmiProvider
14174
13963
  if (!React.useContext(WagmiContext)) {
@@ -14179,9 +13968,35 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
14179
13968
  if (React.useContext(Openfortcontext)) {
14180
13969
  throw new Error('Multiple, nested usages of OpenfortProvider detected. Please use only one.');
14181
13970
  }
14182
- useMemo(() => {
14183
- logger.enabled = !!debugMode;
14184
- }, []);
13971
+ const debugModeOptions = useMemo(() => {
13972
+ const getDebugMode = () => {
13973
+ var _a, _b, _c;
13974
+ if (typeof debugMode === 'undefined') {
13975
+ return {
13976
+ shieldDebugMode: false,
13977
+ openfortCoreDebugMode: false,
13978
+ openfortReactDebugMode: false,
13979
+ };
13980
+ }
13981
+ else if (typeof debugMode === 'boolean') {
13982
+ return {
13983
+ shieldDebugMode: debugMode,
13984
+ openfortCoreDebugMode: debugMode,
13985
+ openfortReactDebugMode: debugMode,
13986
+ };
13987
+ }
13988
+ else {
13989
+ return {
13990
+ shieldDebugMode: (_a = debugMode.shieldDebugMode) !== null && _a !== void 0 ? _a : false,
13991
+ openfortCoreDebugMode: (_b = debugMode.openfortCoreDebugMode) !== null && _b !== void 0 ? _b : false,
13992
+ openfortReactDebugMode: (_c = debugMode.openfortReactDebugMode) !== null && _c !== void 0 ? _c : false,
13993
+ };
13994
+ }
13995
+ };
13996
+ const debugModeOptions = getDebugMode();
13997
+ logger.enabled = debugModeOptions.openfortReactDebugMode;
13998
+ return debugModeOptions;
13999
+ }, [debugMode]);
14185
14000
  const injectedConnector = useConnector('injected');
14186
14001
  const allowAutomaticRecovery = !!((walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.createEncryptedSessionEndpoint) || (walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.getEncryptionSession));
14187
14002
  // Default config options
@@ -14323,7 +14138,7 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
14323
14138
  // Other configuration
14324
14139
  uiConfig: safeUiConfig,
14325
14140
  errorMessage,
14326
- debugMode,
14141
+ debugMode: debugModeOptions,
14327
14142
  emailInput,
14328
14143
  setEmailInput,
14329
14144
  resize,
@@ -14332,14 +14147,20 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
14332
14147
  overrides,
14333
14148
  thirdPartyAuth,
14334
14149
  };
14335
- return createElement(Openfortcontext.Provider, { value }, jsx(Web3ContextProvider, { enabled: open, children: jsxs(CoreOpenfortProvider, { baseConfiguration: {
14336
- publishableKey,
14337
- }, shieldConfiguration: walletConfig
14338
- ? {
14339
- shieldPublishableKey: walletConfig.shieldPublishableKey,
14340
- debug: debugMode,
14341
- }
14342
- : undefined, overrides: overrides, thirdPartyAuth: thirdPartyAuth, onConnect: onConnect, onDisconnect: onDisconnect, children: [children, jsx(ConnectModal, { lang: ckLang, theme: ckTheme, mode: (_e = safeUiConfig.mode) !== null && _e !== void 0 ? _e : ckMode, customTheme: ckCustomTheme })] }) }));
14150
+ return createElement(Openfortcontext.Provider, { value }, jsx(Web3ContextProvider, { children: jsxs(CoreOpenfortProvider, { openfortConfig: {
14151
+ baseConfiguration: {
14152
+ publishableKey,
14153
+ },
14154
+ shieldConfiguration: walletConfig
14155
+ ? {
14156
+ shieldPublishableKey: walletConfig.shieldPublishableKey,
14157
+ debug: debugModeOptions.shieldDebugMode,
14158
+ }
14159
+ : undefined,
14160
+ debug: debugModeOptions.openfortCoreDebugMode,
14161
+ overrides,
14162
+ thirdPartyAuth,
14163
+ }, onConnect: onConnect, onDisconnect: onDisconnect, children: [children, jsx(ConnectModal, { lang: ckLang, theme: ckTheme, mode: (_e = safeUiConfig.mode) !== null && _e !== void 0 ? _e : ckMode, customTheme: ckCustomTheme })] }) }));
14343
14164
  };
14344
14165
 
14345
14166
  /**
@@ -14737,7 +14558,7 @@ const useAuthCallback = ({ enabled = true, // Automatically handle OAuth and ema
14737
14558
  const useWalletAuth = (hookOptions = {}) => {
14738
14559
  const { updateUser } = useOpenfortCore();
14739
14560
  const siwe = useConnectWithSiwe();
14740
- const availableWallets = useWallets$1(); // TODO: Use this to get the wallet client type
14561
+ const availableWallets = useWagmiWallets(); // TODO: Use this to get the wallet client type
14741
14562
  const { disconnect } = useDisconnect();
14742
14563
  const [walletConnectingTo, setWalletConnectingTo] = useState(null);
14743
14564
  const [shouldConnectWithSiwe, setShouldConnectWithSiwe] = useState(false);