@openfort/react 0.0.3 → 0.0.5

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,12 +1,12 @@
1
+ import { Openfort as Openfort$1, RecoveryMethod, EmbeddedState, AuthActionRequiredActions, OAuthProvider, MissingRecoveryPasswordError, AccountTypeEnum, ChainTypeEnum } from '@openfort/openfort-js';
2
+ export { RecoveryMethod, ThirdPartyOAuthProvider } from '@openfort/openfort-js';
1
3
  import { http, useConfig, useConnectors as useConnectors$1, useConnect as useConnect$1, useAccount, useDisconnect, useSwitchChain, createConfig, useEnsAddress, useEnsName, useEnsAvatar, useBalance, useChainId, WagmiContext, useBlockNumber } from 'wagmi';
2
4
  import { mainnet, polygon, optimism, arbitrum, sepolia } from 'wagmi/chains';
3
5
  import { safe, injected, coinbaseWallet, walletConnect } from '@wagmi/connectors';
4
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import React, { createContext, useEffect, useState, useMemo, useRef, useCallback, createElement, useLayoutEffect } from 'react';
7
+ import React, { useEffect, createContext, useState, useMemo, useRef, useCallback, createElement, useLayoutEffect } from 'react';
6
8
  import { detect } from 'detect-browser';
7
9
  import { Buffer } from 'buffer';
8
- import { Openfort as Openfort$1, RecoveryMethod, EmbeddedState, AuthActionRequiredActions, OAuthProvider, ShieldAuthType, MissingRecoveryPasswordError, AccountTypeEnum, ChainTypeEnum } from '@openfort/openfort-js';
9
- export { RecoveryMethod } from '@openfort/openfort-js';
10
10
  import { polygonAmoy } from 'viem/chains';
11
11
  import { motion, AnimatePresence, MotionConfig } from 'framer-motion';
12
12
  import styled$1, { css, keyframes } from 'styled-components';
@@ -22,12 +22,13 @@ import { createSiweMessage } from 'viem/siwe';
22
22
  import { signMessage } from '@wagmi/core';
23
23
  import { useQuery, useQueryClient } from '@tanstack/react-query';
24
24
 
25
- const OPENFORTKIT_VERSION = '0.0.3';
25
+ const OPENFORT_VERSION = '0.0.5';
26
26
 
27
27
  var OpenfortErrorType;
28
28
  (function (OpenfortErrorType) {
29
29
  OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
30
30
  OpenfortErrorType["WALLET_ERROR"] = "WALLET_ERROR";
31
+ OpenfortErrorType["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
31
32
  })(OpenfortErrorType || (OpenfortErrorType = {}));
32
33
  class OpenfortError extends Error {
33
34
  constructor(message, type, data) {
@@ -94,7 +95,7 @@ const defaultConnectors = ({ app, walletConnectProjectId, coinbaseWalletPreferen
94
95
  // OLD_TODO: Move these to a provider rather than global variable
95
96
  let globalAppName;
96
97
  const getAppName = () => globalAppName;
97
- const defaultConfig = ({ appName = 'OpenfortKit', appIcon, appDescription, appUrl, walletConnectProjectId, coinbaseWalletPreference, chains = [mainnet, polygon, optimism, arbitrum], client, ...props }) => {
98
+ const defaultConfig = ({ appName = 'Openfort', appIcon, appDescription, appUrl, walletConnectProjectId, coinbaseWalletPreference, chains = [mainnet, polygon, optimism, arbitrum], client, ...props }) => {
98
99
  var _a, _b;
99
100
  globalAppName = appName;
100
101
  // OLD_TODO: nice to have, automate transports based on chains, but for now just provide public if not provided
@@ -109,7 +110,7 @@ const defaultConfig = ({ appName = 'OpenfortKit', appIcon, appDescription, appUr
109
110
  walletConnectProjectId,
110
111
  coinbaseWalletPreference,
111
112
  });
112
- // console.log("OPENFORTKIT CHAINS", chains, transports);
113
+ // console.log("OPENFORT CHAINS", chains, transports);
113
114
  const config = {
114
115
  ...props,
115
116
  chains,
@@ -788,8 +789,6 @@ const socialProviders = [
788
789
  AuthProvider.FACEBOOK,
789
790
  ];
790
791
 
791
- const OpenfortKitContext = createContext(null);
792
-
793
792
  function useChainIsSupported(chainId) {
794
793
  const { chains } = useConfig();
795
794
  if (!chainId)
@@ -868,10 +867,12 @@ function useThemeFont(theme) {
868
867
  useGoogleFont(font !== null && font !== void 0 ? font : '');
869
868
  }
870
869
 
871
- const useOpenfortKit = () => {
872
- const context = React.useContext(OpenfortKitContext);
870
+ const Openfortcontext = createContext(null);
871
+
872
+ const useOpenfort = () => {
873
+ const context = React.useContext(Openfortcontext);
873
874
  if (!context)
874
- throw Error('OpenfortKit Hook must be inside a Provider.');
875
+ throw Error('Openfort Hook must be inside a Provider.');
875
876
  return context;
876
877
  };
877
878
 
@@ -880,7 +881,7 @@ const useOpenfortKit = () => {
880
881
  * additional functionality.
881
882
  */
882
883
  function useConnect({ ...props } = {}) {
883
- const context = useOpenfortKit();
884
+ const context = useOpenfort();
884
885
  const { connect, connectAsync, connectors, ...rest } = useConnect$1({
885
886
  ...props,
886
887
  mutation: {
@@ -974,14 +975,8 @@ const useConnectCallback = ({ onConnect, onDisconnect, }) => {
974
975
  *
975
976
  * const token = await client.getAccessToken();
976
977
  */
977
- function createOpenfortClient({ baseConfiguration, overrides, shieldConfiguration, }) {
978
- return new Openfort$1({
979
- baseConfiguration,
980
- overrides: {
981
- ...overrides,
982
- },
983
- shieldConfiguration
984
- });
978
+ function createOpenfortClient(config) {
979
+ return new Openfort$1(config);
985
980
  }
986
981
 
987
982
  const ConnectCallback = ({ onConnect, onDisconnect }) => {
@@ -997,11 +992,11 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
997
992
  const { address } = useAccount();
998
993
  const [user, setUser] = useState(null);
999
994
  const { disconnect } = useDisconnect();
1000
- const { walletConfig } = useOpenfortKit();
995
+ const { walletConfig } = useOpenfort();
1001
996
  const automaticRecovery = walletConfig && walletConfig.recoveryMethod === RecoveryMethod.AUTOMATIC;
1002
997
  // ---- Openfort instance ----
1003
998
  const openfort = useMemo(() => {
1004
- log('Creating Openfort instance.');
999
+ log('Creating Openfort instance.', openfortProps);
1005
1000
  if (!openfortProps.baseConfiguration.publishableKey)
1006
1001
  throw Error('CoreOpenfortProvider requires a publishableKey to be set in the baseConfiguration.');
1007
1002
  const newClient = createOpenfortClient(openfortProps);
@@ -1054,6 +1049,7 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
1054
1049
  var _a, _b;
1055
1050
  if (!openfort)
1056
1051
  return null;
1052
+ log("Updating user", { user, logoutOnError });
1057
1053
  if (user) {
1058
1054
  setUser(user);
1059
1055
  return user;
@@ -1113,11 +1109,20 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
1113
1109
  setIsConnectedWithEmbeddedSigner(false);
1114
1110
  break;
1115
1111
  case EmbeddedState.READY:
1116
- if (!user)
1117
- updateUser(undefined, true);
1118
- // We cannot stop polling here because there is a bug on openfort-js
1119
- // that makes the embedded state to be stuck on CREATING_ACCOUNT
1120
- // stopPollingEmbeddedState();
1112
+ (async () => {
1113
+ for (let i = 0; i < 5; i++) {
1114
+ log("Trying to update user...", i);
1115
+ try {
1116
+ const user = await updateUser(undefined, true);
1117
+ if (user)
1118
+ break;
1119
+ }
1120
+ catch (err) {
1121
+ console.error("Error updating user, retrying...", err);
1122
+ }
1123
+ await new Promise((resolve) => setTimeout(resolve, 250));
1124
+ }
1125
+ })();
1121
1126
  break;
1122
1127
  default:
1123
1128
  throw new Error(`Unknown embedded state: ${embeddedState}`);
@@ -1207,7 +1212,7 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
1207
1212
  * When using rollup with styled-components to build into an ES module, styled components decides to move all of it’s DOM elements into "styled.default" rather than just within "styled"
1208
1213
  *
1209
1214
  * We're unsure as to why this issue occurs, if you have any ideas or a better solution please let us know by opening a discussion on our GitHub repo:
1210
- * https://github.com/openfort-xyz/openfort-kit/discussions/new
1215
+ * https://github.com/openfort-xyz/openfort-react/discussions/new
1211
1216
  *
1212
1217
  */
1213
1218
  var styled = typeof styled$1.div === 'function' ? styled$1 : styled$1['default'];
@@ -2343,7 +2348,7 @@ const ResetContainer = styled(motion.div) `
2343
2348
 
2344
2349
  const Portal = (props) => {
2345
2350
  props = {
2346
- selector: '__CONNECTKIT__',
2351
+ selector: '__OPENFORT__',
2347
2352
  ...props,
2348
2353
  };
2349
2354
  const { selector, children } = props;
@@ -2355,7 +2360,7 @@ const Portal = (props) => {
2355
2360
  if (!ref.current) {
2356
2361
  const div = document.createElement('div');
2357
2362
  div.setAttribute('id', selector);
2358
- div.setAttribute('data-openfortkit', `${OPENFORTKIT_VERSION}`);
2363
+ div.setAttribute('data-openfort-react', `${OPENFORT_VERSION}`);
2359
2364
  document.body.appendChild(div);
2360
2365
  ref.current = div;
2361
2366
  }
@@ -3026,7 +3031,7 @@ styled(motion.div) `
3026
3031
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
3027
3032
  function useLockBodyScroll(initialLocked) {
3028
3033
  const [locked, setLocked] = useState(initialLocked);
3029
- const context = useOpenfortKit();
3034
+ const context = useOpenfort();
3030
3035
  useIsomorphicLayoutEffect(() => {
3031
3036
  var _a;
3032
3037
  if (!locked)
@@ -4410,7 +4415,7 @@ export const keys = {
4410
4415
 
4411
4416
  function useLocales(replacements) {
4412
4417
  var _a, _b;
4413
- const context = useOpenfortKit();
4418
+ const context = useOpenfort();
4414
4419
  const language = (_b = (_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.language) !== null && _b !== void 0 ? _b : 'en-US';
4415
4420
  const translations = useMemo(() => {
4416
4421
  return getLocale(language);
@@ -4487,7 +4492,7 @@ const useWallet$1 = (id) => {
4487
4492
  };
4488
4493
  const useWallets$1 = () => {
4489
4494
  const connectors = useConnectors();
4490
- const context = useOpenfortKit();
4495
+ const context = useOpenfort();
4491
4496
  const wallets = connectors.map((connector) => {
4492
4497
  var _a, _b;
4493
4498
  // use overrides
@@ -4772,7 +4777,7 @@ const contentVariants$2 = {
4772
4777
  };
4773
4778
  const Modal = ({ open, pages, pageId, positionInside, inline, demo, onClose, onBack, onInfo, }) => {
4774
4779
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
4775
- const context = useOpenfortKit();
4780
+ const context = useOpenfort();
4776
4781
  const themeContext = useThemeContext();
4777
4782
  const mobile = isMobile();
4778
4783
  const wallet = useWallet$1((_a = context.connector) === null || _a === void 0 ? void 0 : _a.id);
@@ -5681,7 +5686,7 @@ const About = () => {
5681
5686
  const locales = useLocales({
5682
5687
  //CONNECTORNAME: connector.name,
5683
5688
  });
5684
- const context = useOpenfortKit();
5689
+ const context = useOpenfort();
5685
5690
  const ctaUrl = (_b = (_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.ethereumOnboardingUrl) !== null && _b !== void 0 ? _b : locales.aboutScreen_ctaUrl;
5686
5691
  const [ready, setReady] = useState(true);
5687
5692
  const [slider, setSlider] = useState(0);
@@ -6376,7 +6381,7 @@ const ConnectorsContainer = styled.div `
6376
6381
  function useWalletConnectUri({ enabled } = {
6377
6382
  enabled: true,
6378
6383
  }) {
6379
- const { log } = useOpenfortKit();
6384
+ const { log } = useOpenfort();
6380
6385
  const [uri, setUri] = useState(undefined);
6381
6386
  const connector = useWalletConnectConnector();
6382
6387
  const { isConnected } = useAccount();
@@ -6790,7 +6795,7 @@ const useLastConnector = () => {
6790
6795
 
6791
6796
  const ConnectorList = () => {
6792
6797
  var _a;
6793
- const context = useOpenfortKit();
6798
+ const context = useOpenfort();
6794
6799
  const isMobile = useIsMobile();
6795
6800
  const wallets = useWallets$1();
6796
6801
  const { lastConnectorId } = useLastConnector();
@@ -6802,14 +6807,14 @@ const ConnectorList = () => {
6802
6807
  ...wallets.filter((wallet) => lastConnectorId === wallet.connector.id && wallet.id !== embeddedWalletId),
6803
6808
  ...wallets.filter((wallet) => lastConnectorId !== wallet.connector.id && wallet.id !== embeddedWalletId),
6804
6809
  ];
6805
- return (jsxs(ScrollArea, { mobileDirection: 'horizontal', children: [walletsToDisplay.length === 0 && (jsx(Alert, { error: true, children: "No connectors found in OpenfortKit config." })), walletsToDisplay.length > 0 && (jsx(ConnectorsContainer, { "$mobile": isMobile, "$totalResults": walletsToDisplay.length, children: walletsToDisplay.map((wallet) => jsx(ConnectorItem, { wallet: wallet, isRecent: wallet.id === lastConnectorId }, wallet.id)) }))] }));
6810
+ return (jsxs(ScrollArea, { mobileDirection: 'horizontal', children: [walletsToDisplay.length === 0 && (jsx(Alert, { error: true, children: "No connectors found in Openfort config." })), walletsToDisplay.length > 0 && (jsx(ConnectorsContainer, { "$mobile": isMobile, "$totalResults": walletsToDisplay.length, children: walletsToDisplay.map((wallet) => jsx(ConnectorItem, { wallet: wallet, isRecent: wallet.id === lastConnectorId }, wallet.id)) }))] }));
6806
6811
  };
6807
6812
  const ConnectorItem = ({ wallet, isRecent, }) => {
6808
6813
  var _a, _b, _c, _d;
6809
6814
  const { connect: { getUri }, } = useWeb3();
6810
6815
  const uri = getUri();
6811
6816
  const isMobile = useIsMobile();
6812
- const context = useOpenfortKit();
6817
+ const context = useOpenfort();
6813
6818
  const { connect } = useConnect();
6814
6819
  /*
6815
6820
  const [ready, setReady] = useState(false);
@@ -6851,7 +6856,7 @@ const ConnectorItem = ({ wallet, isRecent, }) => {
6851
6856
 
6852
6857
  const Wallets = () => {
6853
6858
  var _a, _b;
6854
- const context = useOpenfortKit();
6859
+ const context = useOpenfort();
6855
6860
  const locales = useLocales({});
6856
6861
  const isMobile = useIsMobile();
6857
6862
  return (jsxs(PageContent, { style: { width: 312 }, children: [jsx(ConnectorList, {}), isMobile ? (jsx(Fragment, { children: jsxs(InfoBox, { children: [jsxs(ModalContent, { style: { padding: 0, textAlign: 'left' }, children: [jsx(ModalH1, { "$small": true, children: locales.connectorsScreen_h1 }), jsx(ModalBody, { children: locales.connectorsScreen_p })] }), jsxs(InfoBoxButtons, { children: [!((_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.hideQuestionMarkCTA) && (jsx(Button, { variant: 'tertiary', onClick: () => context.setRoute(routes.ABOUT), children: locales.learnMore })), !((_b = context.uiConfig) === null || _b === void 0 ? void 0 : _b.hideNoWalletCTA) && (jsx(Button, { variant: 'tertiary', onClick: () => context.setRoute(routes.ONBOARDING), children: locales.getWallet }))] })] }) })) : (jsx(Fragment, {}))] }));
@@ -7084,7 +7089,7 @@ const TooltipTail = styled(motion.div) `
7084
7089
 
7085
7090
  const Tooltip = ({ children, message, open, xOffset = 0, yOffset = 0, delay, }) => {
7086
7091
  var _a;
7087
- const context = useOpenfortKit();
7092
+ const context = useOpenfort();
7088
7093
  const themeContext = useThemeContext();
7089
7094
  if ((_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.hideTooltips)
7090
7095
  return jsx(Fragment, { children: children });
@@ -7265,7 +7270,7 @@ CustomQRCode.displayName = 'CustomQRCode';
7265
7270
 
7266
7271
  const DownloadApp = () => {
7267
7272
  var _a, _b, _c;
7268
- const context = useOpenfortKit();
7273
+ const context = useOpenfort();
7269
7274
  const wallet = useWallet$1(context.connector.id);
7270
7275
  const locales = useLocales({
7271
7276
  CONNECTORNAME: wallet === null || wallet === void 0 ? void 0 : wallet.name,
@@ -7346,7 +7351,7 @@ const WalletList = styled.div `
7346
7351
  const Container$6 = styled.div ``;
7347
7352
 
7348
7353
  function useWalletConnectModal() {
7349
- const { log } = useOpenfortKit();
7354
+ const { log } = useOpenfort();
7350
7355
  const { connectAsync, connectors } = useConnect();
7351
7356
  const [isOpen, setIsOpen] = useState(false);
7352
7357
  return {
@@ -7506,7 +7511,7 @@ const CopyToClipboard = ({ string, children, variant }) => {
7506
7511
  const MoreIcon = (jsx("svg", { width: "60", height: "60", viewBox: "0 0 60 60", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M30 42V19M19 30.5H42", stroke: "var(--ck-body-color-muted)", strokeWidth: "3", strokeLinecap: "round" }) }));
7507
7512
  const MobileConnectors = () => {
7508
7513
  var _a, _b;
7509
- const context = useOpenfortKit();
7514
+ const context = useOpenfort();
7510
7515
  const locales = useLocales();
7511
7516
  const { connect: { getUri }, } = useWeb3();
7512
7517
  const wcUri = getUri();
@@ -7733,7 +7738,7 @@ var wave = (jsxs("svg", { "aria-hidden": "true", width: "298", height: "188", vi
7733
7738
 
7734
7739
  const Introduction = () => {
7735
7740
  var _a, _b;
7736
- const context = useOpenfortKit();
7741
+ const context = useOpenfort();
7737
7742
  const locales = useLocales({});
7738
7743
  const ctaUrl = (_b = (_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.walletOnboardingUrl) !== null && _b !== void 0 ? _b : locales.onboardingScreen_ctaUrl;
7739
7744
  return (jsxs(PageContent, { children: [jsxs(Graphic, { children: [jsxs(LogoGroup, { children: [jsx(Logo$2, { children: jsx(LogoPosition, { children: jsx(LogoInner, { children: jsx(FloatWrapper, { children: jsx(RotateWrapper, { children: jsx(LogoGraphic, { children: jsx(Logos.Coinbase, { background: true }) }) }) }) }) }) }), jsx(Logo$2, { children: jsx(LogoPosition, { children: jsx(LogoInner, { children: jsx(FloatWrapper, { children: jsx(RotateWrapper, { children: jsx(LogoGraphic, { children: jsx(Logos.MetaMask, { background: true }) }) }) }) }) }) }), jsx(Logo$2, { children: jsx(LogoPosition, { children: jsx(LogoInner, { children: jsx(FloatWrapper, { children: jsx(RotateWrapper, { children: jsx(LogoGraphic, { children: jsx(Logos.Trust, {}) }) }) }) }) }) }), jsx(Logo$2, { children: jsx(LogoPosition, { children: jsx(LogoInner, { children: jsx(FloatWrapper, { children: jsx(RotateWrapper, { children: jsx(LogoGraphic, { children: jsx(Logos.Argent, {}) }) }) }) }) }) }), jsx(Logo$2, { children: jsx(LogoPosition, { children: jsx(LogoInner, { children: jsx(FloatWrapper, { children: jsx(RotateWrapper, { children: jsx(LogoGraphic, { children: jsx(Logos.ImToken, {}) }) }) }) }) }) })] }), jsx(GraphicBackground, { children: wave })] }), jsxs(ModalContent, { style: { paddingBottom: 18 }, children: [jsx(ModalH1, { "$small": true, children: locales.onboardingScreen_h1 }), jsx(ModalBody, { children: locales.onboardingScreen_p })] }), jsx(Button, { href: ctaUrl, arrow: true, children: locales.onboardingScreen_ctaText })] }));
@@ -7885,7 +7890,7 @@ function useEnsFallbackConfig() {
7885
7890
  const Avatar = ({ address, name, size = 96, radius = 96 }) => {
7886
7891
  var _a, _b, _c;
7887
7892
  const isMounted = useIsMounted();
7888
- const context = useOpenfortKit();
7893
+ const context = useOpenfort();
7889
7894
  const imageRef = useRef(null);
7890
7895
  const [loaded, setLoaded] = useState(true);
7891
7896
  const ensFallbackConfig = useEnsFallbackConfig();
@@ -8708,7 +8713,7 @@ const ChainSelectList = ({ variant, }) => {
8708
8713
  switchChain({ chainId });
8709
8714
  }
8710
8715
  };
8711
- const { triggerResize } = useOpenfortKit();
8716
+ const { triggerResize } = useOpenfort();
8712
8717
  return (jsxs(SwitchNetworksContainer, { style: { marginBottom: switchChain !== undefined ? -8 : 0 }, children: [jsx(ChainButtonContainer, { children: jsx(ChainButtons, { children: chains.map((x) => {
8713
8718
  var _a;
8714
8719
  const c = chainConfigs.find((ch) => ch.id === x.id);
@@ -8831,7 +8836,7 @@ const DropdownHeading = styled(motion.div) `
8831
8836
 
8832
8837
  const ChainSelectDropdown = ({ children, open, onClose, offsetX = 0, offsetY = 8 }) => {
8833
8838
  var _a, _b, _c, _d;
8834
- const context = useOpenfortKit();
8839
+ const context = useOpenfort();
8835
8840
  const themeContext = useThemeContext();
8836
8841
  const locales = useLocales();
8837
8842
  const [offset, setOffset] = useState({ x: 0, y: 0 });
@@ -9077,7 +9082,7 @@ const SwitchChainButton = styled(motion.button) `
9077
9082
  `;
9078
9083
  const ChevronDown = ({ ...props }) => (jsx("svg", { "aria-hidden": "true", width: "11", height: "6", viewBox: "0 0 11 6", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: jsx("path", { d: "M1.5 1L5.5 5L9.5 1", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }));
9079
9084
  const ChainSelector = () => {
9080
- const context = useOpenfortKit();
9085
+ const context = useOpenfort();
9081
9086
  const [isOpen, setIsOpen] = useState(false);
9082
9087
  const { chain } = useAccount();
9083
9088
  const { chains } = useSwitchChain();
@@ -9102,7 +9107,7 @@ const ChainSelector = () => {
9102
9107
 
9103
9108
  const PoweredByFooter = ({ showDisclaimer }) => {
9104
9109
  var _a, _b;
9105
- const { uiConfig: options } = useOpenfortKit();
9110
+ const { uiConfig: options } = useOpenfort();
9106
9111
  return (jsxs(Container$3, { children: [showDisclaimer && (jsx(Disclaimer, { children: (options === null || options === void 0 ? void 0 : options.disclaimer) ? (jsx(Fragment, { children: 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.xyz/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.xyz/privacy", target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" }), "."] })) })), jsxs(TextButton, { onClick: () => {
9107
9112
  window.open("https://www.openfort.xyz/", "_blank");
9108
9113
  }, children: [jsx("span", { children: "Powered by" }), jsx(IconContainer$2, { children: jsx(Logos.Openfort, {}) }), jsx("span", { children: "Openfort" })] })] }));
@@ -9201,7 +9206,7 @@ var Wallet = ({ ...props }) => {
9201
9206
 
9202
9207
  function useProviders() {
9203
9208
  const { user } = useOpenfortCore();
9204
- const { uiConfig: options } = useOpenfortKit();
9209
+ const { uiConfig: options, thirdPartyAuth, setOpen } = useOpenfort();
9205
9210
  const allProviders = (options === null || options === void 0 ? void 0 : options.authProviders) || [];
9206
9211
  const providers = allProviders.filter(p => p !== AuthProvider.GUEST) || [];
9207
9212
  const linkedProviders = user ? providers.filter(p => { var _a; return (_a = user.linkedAccounts) === null || _a === void 0 ? void 0 : _a.find(a => a.provider === p); }) : [];
@@ -9213,6 +9218,12 @@ function useProviders() {
9213
9218
  return !((_a = user.linkedAccounts) === null || _a === void 0 ? void 0 : _a.find(a => a.provider === provider));
9214
9219
  })
9215
9220
  : providers;
9221
+ useEffect(() => {
9222
+ if (thirdPartyAuth) {
9223
+ setOpen(false);
9224
+ console.error(new OpenfortError('When using external third party auth providers, openfort Auth providers are not available. Either remove the `thirdPartyAuth` or authenticate your users using Auth hooks.', OpenfortErrorType.CONFIGURATION_ERROR));
9225
+ }
9226
+ }, []);
9216
9227
  return {
9217
9228
  availableProviders,
9218
9229
  linkedProviders,
@@ -9310,7 +9321,7 @@ const LinkedProvider = ({ provider }) => {
9310
9321
  return (jsx(LinkedProviderButton, { disabled: true, children: jsx(ProviderIcon$1, { children: jsx(ProviderIcon, { provider: provider }) }) }));
9311
9322
  };
9312
9323
  const AddLinkedProviderButton = () => {
9313
- const { setRoute } = useOpenfortKit();
9324
+ const { setRoute } = useOpenfort();
9314
9325
  const { availableProviders: unlinkedProviders } = useProviders();
9315
9326
  return (jsx(LinkedProviderButton, { disabled: unlinkedProviders.length === 0, onClick: () => setRoute(routes.PROVIDERS), children: "+" }));
9316
9327
  };
@@ -9324,7 +9335,7 @@ const LinkedProviders = () => {
9324
9335
 
9325
9336
  const Profile = ({ closeModal }) => {
9326
9337
  var _a, _b, _c, _d;
9327
- const context = useOpenfortKit();
9338
+ const context = useOpenfort();
9328
9339
  const themeContext = useThemeContext();
9329
9340
  const locales = useLocales();
9330
9341
  const { address, isConnected, connector, chain } = useAccount();
@@ -9749,11 +9760,10 @@ const createSIWEMessage = (address, nonce, chainId) => createSiweMessage({
9749
9760
 
9750
9761
  function useConnectWithSiwe() {
9751
9762
  const { client, user, updateUser } = useOpenfortCore();
9752
- const { log } = useOpenfortKit();
9753
- const { address } = useAccount();
9763
+ const { log } = useOpenfort();
9764
+ const { address, connector } = useAccount();
9754
9765
  const chainId = useChainId();
9755
9766
  const config = useConfig();
9756
- const { connector } = useAccount();
9757
9767
  const connectWithSiwe = useCallback(async ({ onError, onConnect, }) => {
9758
9768
  const connectorType = connector === null || connector === void 0 ? void 0 : connector.type;
9759
9769
  const walletClientType = connector === null || connector === void 0 ? void 0 : connector.id;
@@ -9843,7 +9853,7 @@ const contentVariants$1 = {
9843
9853
  const ConnectWithInjector = ({ switchConnectMethod, forceState }) => {
9844
9854
  var _a, _b, _c, _d, _e, _f, _g, _h;
9845
9855
  const openfort = useOpenfortCore();
9846
- const { log, setOpen } = useOpenfortKit();
9856
+ const { log, setOpen } = useOpenfort();
9847
9857
  const { isConnected } = useAccount();
9848
9858
  const { disconnect } = useDisconnect();
9849
9859
  const connectWithSiwe = useConnectWithSiwe();
@@ -9926,7 +9936,7 @@ const ConnectWithInjector = ({ switchConnectMethod, forceState }) => {
9926
9936
  },
9927
9937
  },
9928
9938
  });
9929
- const { triggerResize, connector: c } = useOpenfortKit();
9939
+ const { triggerResize, connector: c } = useOpenfort();
9930
9940
  const id = c.id;
9931
9941
  const wallet = useWallet$1(id);
9932
9942
  const walletInfo = {
@@ -10054,7 +10064,7 @@ const ScanIconWithLogos = ({ logo }) => {
10054
10064
 
10055
10065
  const ConnectWithQRCode = ({ switchConnectMethod }) => {
10056
10066
  var _a, _b, _c, _d, _e, _f, _g, _h;
10057
- const context = useOpenfortKit();
10067
+ const context = useOpenfort();
10058
10068
  const id = context.connector.id;
10059
10069
  const wallet = useWallet$1(context.connector.id);
10060
10070
  const { open: openW3M, isOpen: isOpenW3M } = useWalletConnectModal();
@@ -10080,7 +10090,7 @@ const ConnectWithQRCode = ({ switchConnectMethod }) => {
10080
10090
  const hasApps = downloads && Object.keys(downloads).length !== 0;
10081
10091
  const connectWithSiwe = useConnectWithSiwe();
10082
10092
  const { isConnected } = useAccount();
10083
- const { log, setOpen } = useOpenfortKit();
10093
+ const { log, setOpen } = useOpenfort();
10084
10094
  const { disconnect } = useDisconnect();
10085
10095
  const [isFirstFrame, setIsFirstFrame] = React.useState(true);
10086
10096
  useEffect(() => {
@@ -10175,8 +10185,8 @@ const ConnectingAnimation = styled(motion.div) `
10175
10185
  `}
10176
10186
  `;
10177
10187
  const Loader = ({ reason, isLoading = true, icon }) => {
10178
- const { uiConfig: options } = useOpenfortKit();
10179
- const { triggerResize } = useOpenfortKit();
10188
+ const { uiConfig: options } = useOpenfort();
10189
+ const { triggerResize } = useOpenfort();
10180
10190
  useEffect(() => {
10181
10191
  return () => triggerResize();
10182
10192
  }, []);
@@ -10205,7 +10215,7 @@ const states$1 = {
10205
10215
  CONNECTING: "connecting",
10206
10216
  };
10207
10217
  const ConnectWithOAuth = ({}) => {
10208
- const { connector, setRoute, log } = useOpenfortKit();
10218
+ const { connector, setRoute, log } = useOpenfort();
10209
10219
  const { client, user } = useOpenfortCore();
10210
10220
  const [status, setStatus] = useState(states$1.INIT);
10211
10221
  useEffect(() => {
@@ -10302,7 +10312,7 @@ const states = {
10302
10312
  INJECTOR: 'injector',
10303
10313
  };
10304
10314
  const ConnectUsing = () => {
10305
- const context = useOpenfortKit();
10315
+ const context = useOpenfort();
10306
10316
  const wallet = useWallet$1(context.connector.id);
10307
10317
  // If cannot be scanned, display injector flow, which if extension is not installed will show CTA to install it
10308
10318
  const isQrCode = !(wallet === null || wallet === void 0 ? void 0 : wallet.isInstalled) && (wallet === null || wallet === void 0 ? void 0 : wallet.getWalletConnectDeeplink);
@@ -10467,7 +10477,7 @@ const textVariants$2 = {
10467
10477
  const EmailLogin = () => {
10468
10478
  const [email, setEmail] = React.useState("");
10469
10479
  const [password, setPassword] = React.useState("");
10470
- const { setRoute, log } = useOpenfortKit();
10480
+ const { setRoute, log } = useOpenfort();
10471
10481
  const { client } = useOpenfortCore();
10472
10482
  const [loginLoading, setLoginLoading] = React.useState(false);
10473
10483
  const [loginError, setLoginError] = React.useState(false);
@@ -10481,14 +10491,14 @@ const EmailLogin = () => {
10481
10491
  setLoginLoading(false);
10482
10492
  setLoginError("Invalid email or password.");
10483
10493
  }).then((user) => {
10484
- // console.log("User", user);
10494
+ // log("User", user);
10485
10495
  if (!user) {
10486
10496
  setLoginLoading(false);
10487
10497
  setLoginError("Invalid email or password.");
10488
10498
  return;
10489
10499
  }
10490
10500
  if ("action" in user && user.action === AuthActionRequiredActions.ACTION_VERIFY_EMAIL) {
10491
- console.log("User needs to verify email");
10501
+ log("User needs to verify email");
10492
10502
  localStorage.setItem(emailToVerifyLocalStorageKey, email);
10493
10503
  setRoute(routes.EMAIL_VERIFICATION);
10494
10504
  }
@@ -10510,7 +10520,7 @@ const EmailSignup = () => {
10510
10520
  const [email, setEmail] = React.useState("");
10511
10521
  const [password, setPassword] = React.useState("");
10512
10522
  const [username, setUsername] = React.useState("");
10513
- const { setRoute, triggerResize, log, uiConfig: options } = useOpenfortKit();
10523
+ const { setRoute, triggerResize, log, uiConfig: options } = useOpenfort();
10514
10524
  const { client } = useOpenfortCore();
10515
10525
  const [signupLoading, setSignupLoading] = React.useState(false);
10516
10526
  const [signupError, setSignupError] = React.useState(false);
@@ -10558,7 +10568,7 @@ const EmailSignup = () => {
10558
10568
 
10559
10569
  const EmailVerification = () => {
10560
10570
  const { client } = useOpenfortCore();
10561
- const { setRoute, log } = useOpenfortKit();
10571
+ const { setRoute, log } = useOpenfort();
10562
10572
  const [loading, setLoading] = useState(true);
10563
10573
  const [shouldSendEmailVerification, setShouldSendEmailVerification] = useState(false);
10564
10574
  const emailInStorage = useMemo(() => localStorage.getItem(emailToVerifyLocalStorageKey), []);
@@ -10649,7 +10659,7 @@ const EmailVerification = () => {
10649
10659
  // TODO: Localize
10650
10660
  const RequestEmail = () => {
10651
10661
  const [email, setEmail] = React.useState("");
10652
- const { log, triggerResize } = useOpenfortKit();
10662
+ const { log, triggerResize } = useOpenfort();
10653
10663
  const { client } = useOpenfortCore();
10654
10664
  const [loading, setLoading] = React.useState(false);
10655
10665
  const [message, setMessage] = React.useState("");
@@ -10706,7 +10716,7 @@ const ResetPassword = () => {
10706
10716
  const fixedUrl = window.location.href.replace("?state=", "&state="); // redirectUrl is not working with query params
10707
10717
  const url = new URL(fixedUrl);
10708
10718
  const [password, setPassword] = React.useState("");
10709
- const { setRoute, triggerResize, log } = useOpenfortKit();
10719
+ const { setRoute, triggerResize, log } = useOpenfort();
10710
10720
  const { client, updateUser } = useOpenfortCore();
10711
10721
  const [loading, setLoading] = React.useState(false);
10712
10722
  const email = url.searchParams.get("email");
@@ -10781,7 +10791,7 @@ const textVariants$1 = {
10781
10791
  const LinkEmail = () => {
10782
10792
  const [email, setEmail] = React.useState("");
10783
10793
  const [password, setPassword] = React.useState("");
10784
- const { setRoute, triggerResize, log } = useOpenfortKit();
10794
+ const { setRoute, triggerResize, log } = useOpenfort();
10785
10795
  const { client, updateUser } = useOpenfortCore();
10786
10796
  const [loginLoading, setLoginLoading] = React.useState(false);
10787
10797
  const [loginError, setLoginError] = React.useState(false);
@@ -10819,7 +10829,7 @@ const LinkEmail = () => {
10819
10829
  };
10820
10830
 
10821
10831
  const Loading = () => {
10822
- const { setRoute, walletConfig } = useOpenfortKit();
10832
+ const { setRoute, walletConfig } = useOpenfort();
10823
10833
  const { isLoading, user, needsRecovery } = useOpenfortCore();
10824
10834
  const { address } = useAccount();
10825
10835
  const [isFirstFrame, setIsFirstFrame] = React.useState(true);
@@ -10865,7 +10875,7 @@ const ProviderButton = ({ children, icon, onClick }) => {
10865
10875
  };
10866
10876
  const GuestButton = () => {
10867
10877
  const { signUpGuest } = useOpenfortCore();
10868
- const { setRoute } = useOpenfortKit();
10878
+ const { setRoute } = useOpenfort();
10869
10879
  const handleClick = () => {
10870
10880
  signUpGuest();
10871
10881
  setRoute(routes.RECOVER);
@@ -10873,16 +10883,16 @@ const GuestButton = () => {
10873
10883
  return (jsx(ProviderButton, { onClick: handleClick, icon: jsx(GuestIcon, {}), children: "Guest" }));
10874
10884
  };
10875
10885
  const WalletButton = () => {
10876
- const { setRoute } = useOpenfortKit();
10886
+ const { setRoute } = useOpenfort();
10877
10887
  return jsx(ProviderButton, { onClick: () => setRoute(routes.CONNECTORS), icon: jsx(Logos.OtherWallets, {}), children: "Wallet" });
10878
10888
  };
10879
10889
  const EmailButton = () => {
10880
- const { setRoute } = useOpenfortKit();
10890
+ const { setRoute } = useOpenfort();
10881
10891
  const { user } = useOpenfortCore();
10882
10892
  return jsx(ProviderButton, { onClick: () => setRoute(user ? routes.LINK_EMAIL : routes.EMAIL_LOGIN), icon: jsx(EmailIcon, {}), children: "Email" });
10883
10893
  };
10884
10894
  const AuthProviderButton = ({ provider, title = provider + " login", icon }) => {
10885
- const { setRoute, setConnector } = useOpenfortKit();
10895
+ const { setRoute, setConnector } = useOpenfort();
10886
10896
  const handleClick = () => {
10887
10897
  setRoute(routes.CONNECT);
10888
10898
  setConnector({ id: provider, type: "oauth" });
@@ -10924,7 +10934,7 @@ const AddressButNoUserCase = () => {
10924
10934
  return (jsx(PageContent, { children: jsx(Loader, { reason: "Updating user" }) }));
10925
10935
  };
10926
10936
  const SocialProvidersButton = () => {
10927
- const { setRoute } = useOpenfortKit();
10937
+ const { setRoute } = useOpenfort();
10928
10938
  return (jsx(ProviderButton, { onClick: () => setRoute(routes.SOCIAL_PROVIDERS), icon: jsx(OtherSocials, {}), children: "Other socials" }));
10929
10939
  };
10930
10940
  const Providers = () => {
@@ -10960,6 +10970,56 @@ const onError = ({ hookOptions, options, error, }) => {
10960
10970
  return { error };
10961
10971
  };
10962
10972
 
10973
+ var OpenfortStatus;
10974
+ (function (OpenfortStatus) {
10975
+ OpenfortStatus[OpenfortStatus["DISCONNECTED"] = 0] = "DISCONNECTED";
10976
+ OpenfortStatus[OpenfortStatus["NEEDS_RECOVERY"] = 1] = "NEEDS_RECOVERY";
10977
+ OpenfortStatus[OpenfortStatus["LOADING"] = 2] = "LOADING";
10978
+ OpenfortStatus[OpenfortStatus["CONNECTED"] = 3] = "CONNECTED";
10979
+ })(OpenfortStatus || (OpenfortStatus = {}));
10980
+ function useStatus() {
10981
+ const { embeddedState } = useOpenfortCore();
10982
+ const { isConnected, isConnecting } = useAccount();
10983
+ const getStatus = () => {
10984
+ if (embeddedState === EmbeddedState.READY)
10985
+ return OpenfortStatus.CONNECTED;
10986
+ if (embeddedState === EmbeddedState.NONE)
10987
+ return OpenfortStatus.LOADING;
10988
+ // if (needsRecovery) return OpenfortStatus.NEEDS_RECOVERY;
10989
+ if (embeddedState === EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED) {
10990
+ if (isConnected)
10991
+ return OpenfortStatus.CONNECTED;
10992
+ else
10993
+ return OpenfortStatus.NEEDS_RECOVERY;
10994
+ }
10995
+ return OpenfortStatus.DISCONNECTED;
10996
+ };
10997
+ const status = getStatus();
10998
+ return {
10999
+ isLoading: status === OpenfortStatus.LOADING,
11000
+ isConnected: status === OpenfortStatus.CONNECTED,
11001
+ isDisconnected: status === OpenfortStatus.DISCONNECTED,
11002
+ isConnecting: isConnecting || embeddedState === EmbeddedState.CREATING_ACCOUNT,
11003
+ isAuthenticated: embeddedState !== EmbeddedState.NONE && embeddedState !== EmbeddedState.UNAUTHENTICATED,
11004
+ };
11005
+ }
11006
+
11007
+ function useUser() {
11008
+ const { user, client } = useOpenfortCore();
11009
+ const { isAuthenticated } = useStatus();
11010
+ const getAccessTokenAndUpdate = useCallback(async () => {
11011
+ await client.validateAndRefreshToken();
11012
+ const token = await client.getAccessToken();
11013
+ return token;
11014
+ }, [client]);
11015
+ return {
11016
+ user,
11017
+ isAuthenticated,
11018
+ getAccessToken: getAccessTokenAndUpdate,
11019
+ validateAndRefreshToken: async () => await client.validateAndRefreshToken(),
11020
+ };
11021
+ }
11022
+
10963
11023
  const createOpenfortWallet = ({ address, }) => ({
10964
11024
  connectorType: "embedded",
10965
11025
  walletClientType: "openfort",
@@ -10967,7 +11027,7 @@ const createOpenfortWallet = ({ address, }) => ({
10967
11027
  id: embeddedWalletId,
10968
11028
  isAvailable: true,
10969
11029
  });
10970
- const mapStatus$1 = (status) => {
11030
+ const mapWalletStatus = (status) => {
10971
11031
  return {
10972
11032
  error: status.error,
10973
11033
  isError: status.status === 'error',
@@ -10977,12 +11037,13 @@ const mapStatus$1 = (status) => {
10977
11037
  };
10978
11038
  };
10979
11039
  function useWallets(hookOptions = {}) {
10980
- const { user, embeddedState, client } = useOpenfortCore();
10981
- const { walletConfig, log, setOpen, setRoute, setConnector, uiConfig } = useOpenfortKit();
11040
+ const { client } = useOpenfortCore();
11041
+ const { user } = useUser();
11042
+ const { walletConfig, log, setOpen, setRoute, setConnector, uiConfig } = useOpenfort();
10982
11043
  const { connector, isConnected, address } = useAccount();
10983
11044
  const chainId = useChainId();
10984
11045
  const deviceWallets = useWallets$1(); // TODO: Map wallets object to be the same as wallets
10985
- const { disconnect } = useDisconnect();
11046
+ const { disconnect, disconnectAsync } = useDisconnect();
10986
11047
  const [status, setStatus] = useState({
10987
11048
  status: "idle",
10988
11049
  });
@@ -11018,16 +11079,16 @@ function useWallets(hookOptions = {}) {
11018
11079
  }
11019
11080
  }
11020
11081
  });
11021
- const usesEmbeddedWallet = user && walletConfig;
11022
- const isEmbedded = embeddedState === EmbeddedState.READY;
11023
- const { data: embeddedWallets, refetch } = useQuery({
11082
+ // will reset on logout
11083
+ const { data: embeddedWallets, refetch, isPending: isLoadingWallets } = useQuery({
11024
11084
  queryKey: ['openfortEmbeddedWalletList'],
11025
- queryFn: () => !!user ? client.embeddedWallet.list() : Promise.resolve([]),
11085
+ queryFn: () => client.embeddedWallet.list(),
11086
+ refetchOnMount: false,
11087
+ refetchOnWindowFocus: false,
11026
11088
  });
11027
- useEffect(() => {
11028
- log("Refetching embedded wallets");
11029
- refetch();
11030
- }, [!!user, refetch]);
11089
+ // useEffect(() => {
11090
+ // queryClient.resetQueries({ queryKey: ['openfortEmbeddedWalletList'] })
11091
+ // }, [!!user, refetch]);
11031
11092
  const getEncryptionSession = useCallback(async () => {
11032
11093
  if (!walletConfig || !walletConfig.createEncryptedSessionEndpoint) {
11033
11094
  throw new Error("No createEncryptedSessionEndpoint set in walletConfig");
@@ -11044,7 +11105,7 @@ function useWallets(hookOptions = {}) {
11044
11105
  const respJSON = await resp.json();
11045
11106
  return respJSON.session;
11046
11107
  }, [walletConfig]);
11047
- const wallets = useMemo(() => {
11108
+ const rawWallets = useMemo(() => {
11048
11109
  const userWallets = user ? user.linkedAccounts
11049
11110
  .filter((a) => a.provider === AuthProvider.WALLET)
11050
11111
  .map((a) => {
@@ -11067,6 +11128,15 @@ function useWallets(hookOptions = {}) {
11067
11128
  });
11068
11129
  return userWallets;
11069
11130
  }, [user === null || user === void 0 ? void 0 : user.linkedAccounts, embeddedWallets]);
11131
+ const wallets = useMemo(() => {
11132
+ // if (!isConnected || !address) return rawWallets;
11133
+ log("Mapping wallets", { rawWallets, status, address, isConnected, connector });
11134
+ return rawWallets.map((w) => ({
11135
+ ...w,
11136
+ isConnecting: status.status === 'connecting' && status.address === w.address,
11137
+ isActive: w.address === address && isConnected && (connector === null || connector === void 0 ? void 0 : connector.id) === w.id,
11138
+ }));
11139
+ }, [rawWallets, status, address, isConnected, connector]);
11070
11140
  const activeWallet = isConnected && connector ? wallets.find((w) => w.isActive) : undefined;
11071
11141
  useEffect(() => {
11072
11142
  if (connectToConnector)
@@ -11087,7 +11157,7 @@ function useWallets(hookOptions = {}) {
11087
11157
  connector = wallet.connector;
11088
11158
  }
11089
11159
  else {
11090
- connector = connector;
11160
+ connector = optionsObject.connector;
11091
11161
  }
11092
11162
  if (!connector) {
11093
11163
  log("Connector not found", deviceWallets, optionsObject.connector);
@@ -11097,22 +11167,7 @@ function useWallets(hookOptions = {}) {
11097
11167
  log(`Already connected to ${connector.id} with address ${address}, skipping connection`);
11098
11168
  return { wallet: activeWallet };
11099
11169
  }
11100
- const hasDisconnected = new Promise((resolve) => {
11101
- disconnect(undefined, {
11102
- onSuccess: () => {
11103
- resolve();
11104
- },
11105
- onError: (error) => {
11106
- console.error("Error disconnecting", error);
11107
- // setStatus({
11108
- // status: 'error',
11109
- // error: new Error("Failed to disconnect: " + error),
11110
- // });
11111
- resolve();
11112
- },
11113
- });
11114
- });
11115
- await hasDisconnected;
11170
+ await disconnectAsync();
11116
11171
  if (showUI) {
11117
11172
  const walletToConnect = wallets.find((w) => w.id == connector.id);
11118
11173
  if (!walletToConnect) {
@@ -11156,31 +11211,22 @@ function useWallets(hookOptions = {}) {
11156
11211
  }
11157
11212
  log(`Handling recovery with Openfort: ${password ? "with password" : "without password"}, chainId=${chainId}`);
11158
11213
  try {
11159
- const accessToken = await client.getAccessToken();
11160
- if (!accessToken) {
11161
- throw new Error("Openfort access token not found");
11162
- }
11163
- log("Access token");
11164
- const shieldAuthentication = password ? {
11165
- auth: ShieldAuthType.OPENFORT,
11166
- token: accessToken,
11167
- } : {
11168
- auth: ShieldAuthType.OPENFORT,
11169
- token: accessToken,
11170
- encryptionSession: walletConfig.getEncryptionSession ?
11171
- await walletConfig.getEncryptionSession() :
11172
- await getEncryptionSession(),
11173
- };
11174
- log("Shield authentication");
11175
11214
  const recoveryParams = password ? {
11176
11215
  recoveryMethod: RecoveryMethod.PASSWORD,
11177
11216
  password,
11178
11217
  } : {
11179
11218
  recoveryMethod: RecoveryMethod.AUTOMATIC,
11219
+ encryptionSession: walletConfig.getEncryptionSession ?
11220
+ await walletConfig.getEncryptionSession() :
11221
+ await getEncryptionSession()
11180
11222
  };
11223
+ // Ensure that the embedded wallet is listed
11224
+ const embeddedWallets = await client.embeddedWallet.list();
11181
11225
  log("Recovery params", optionsObject.address);
11182
- if (optionsObject.address) {
11183
- const walletId = (_a = embeddedWallets === null || embeddedWallets === void 0 ? void 0 : embeddedWallets.find((w) => w.address === optionsObject.address && w.chainId === chainId)) === null || _a === void 0 ? void 0 : _a.id;
11226
+ log("Embedded wallets", embeddedWallets, chainId);
11227
+ let walletAddress = optionsObject.address;
11228
+ if (walletAddress) {
11229
+ const walletId = (_a = embeddedWallets === null || embeddedWallets === void 0 ? void 0 : embeddedWallets.find((w) => w.address === walletAddress && w.chainId === chainId)) === null || _a === void 0 ? void 0 : _a.id;
11184
11230
  if (!walletId) {
11185
11231
  return onError({
11186
11232
  error: new OpenfortError("Embedded wallet not found for address", OpenfortErrorType.WALLET_ERROR),
@@ -11190,22 +11236,27 @@ function useWallets(hookOptions = {}) {
11190
11236
  }
11191
11237
  await client.embeddedWallet.recover({
11192
11238
  account: walletId,
11193
- shieldAuthentication,
11194
11239
  recoveryParams,
11195
11240
  });
11196
11241
  }
11197
11242
  else {
11198
- if (!embeddedWallets || embeddedWallets.length === 0) {
11199
- await createWallet({
11200
- password,
11243
+ // Check if the embedded wallet is already created in the current chain
11244
+ if (embeddedWallets.some((w) => w.chainId === chainId)) {
11245
+ const walletToRecover = embeddedWallets.find((w) => w.chainId === chainId);
11246
+ await client.embeddedWallet.recover({
11247
+ account: walletToRecover.id,
11248
+ recoveryParams,
11201
11249
  });
11250
+ walletAddress = walletToRecover.address;
11202
11251
  }
11203
11252
  else {
11204
- await client.embeddedWallet.recover({
11205
- account: embeddedWallets[0].id,
11206
- shieldAuthentication,
11207
- recoveryParams,
11253
+ const wallet = await createWallet({
11254
+ password,
11208
11255
  });
11256
+ if (!wallet.wallet) {
11257
+ return { error: wallet.error || new OpenfortError("Failed to create embedded wallet", OpenfortErrorType.WALLET_ERROR) };
11258
+ }
11259
+ walletAddress = wallet.wallet.address;
11209
11260
  }
11210
11261
  }
11211
11262
  setStatus({
@@ -11214,7 +11265,7 @@ function useWallets(hookOptions = {}) {
11214
11265
  return onSuccess({
11215
11266
  data: {
11216
11267
  wallet: createOpenfortWallet({
11217
- address: optionsObject.address,
11268
+ address: walletAddress,
11218
11269
  }),
11219
11270
  },
11220
11271
  options: optionsObject,
@@ -11224,25 +11275,36 @@ function useWallets(hookOptions = {}) {
11224
11275
  catch (err) {
11225
11276
  log('Error handling recovery with Openfort:', err);
11226
11277
  if (err instanceof MissingRecoveryPasswordError) {
11278
+ const error = new OpenfortError("Missing recovery password", OpenfortErrorType.WALLET_ERROR);
11279
+ setStatus({
11280
+ status: 'error',
11281
+ error,
11282
+ });
11227
11283
  return onError({
11228
- error: new OpenfortError("Missing recovery password", OpenfortErrorType.WALLET_ERROR),
11284
+ error,
11229
11285
  options: optionsObject,
11230
11286
  hookOptions
11231
11287
  });
11232
11288
  }
11233
11289
  if (typeof err === 'string') {
11290
+ const error = new OpenfortError(err, OpenfortErrorType.WALLET_ERROR);
11291
+ setStatus({
11292
+ status: 'error',
11293
+ error,
11294
+ });
11234
11295
  return onError({
11235
- error: new OpenfortError(err, OpenfortErrorType.WALLET_ERROR),
11296
+ error,
11236
11297
  options: optionsObject,
11237
11298
  hookOptions
11238
11299
  });
11239
11300
  }
11240
- // setStatus({
11241
- // status: 'error',
11242
- // error: new Error("Failed to connect with embedded wallet: " + err),
11243
- // });
11301
+ const error = new OpenfortError("The recovery phrase you entered is incorrect.", OpenfortErrorType.WALLET_ERROR);
11302
+ setStatus({
11303
+ status: 'error',
11304
+ error,
11305
+ });
11244
11306
  return onError({
11245
- error: new OpenfortError("The recovery phrase you entered is incorrect.", OpenfortErrorType.WALLET_ERROR),
11307
+ error,
11246
11308
  options: optionsObject,
11247
11309
  hookOptions
11248
11310
  });
@@ -11259,71 +11321,110 @@ function useWallets(hookOptions = {}) {
11259
11321
  });
11260
11322
  }
11261
11323
  return {};
11262
- }, [wallets, setOpen, setRoute, setConnector, disconnect, log, isConnected, address, usesEmbeddedWallet, isEmbedded]);
11324
+ }, [wallets, setOpen, setRoute, setConnector, disconnectAsync, log, address, client, walletConfig, chainId, refetch, hookOptions]);
11263
11325
  const createWallet = useCallback(async ({ password, ...options } = {}) => {
11264
11326
  var _a;
11265
11327
  setStatus({
11266
11328
  status: 'creating',
11267
11329
  });
11268
11330
  log("Creating wallet", { password: !!password, options });
11269
- const accessToken = await client.getAccessToken();
11270
- if (!accessToken) {
11331
+ try {
11332
+ const accessToken = await client.getAccessToken();
11333
+ if (!accessToken) {
11334
+ return onError({
11335
+ error: new OpenfortError("Openfort access token not found", OpenfortErrorType.WALLET_ERROR),
11336
+ hookOptions,
11337
+ options,
11338
+ });
11339
+ }
11340
+ if (!walletConfig) {
11341
+ return onError({
11342
+ error: new OpenfortError("Embedded signer not enabled", OpenfortErrorType.WALLET_ERROR),
11343
+ hookOptions,
11344
+ options,
11345
+ });
11346
+ }
11347
+ const recoveryParams = password ? {
11348
+ recoveryMethod: RecoveryMethod.PASSWORD,
11349
+ password,
11350
+ } : {
11351
+ recoveryMethod: RecoveryMethod.AUTOMATIC,
11352
+ encryptionSession: walletConfig.getEncryptionSession ?
11353
+ await walletConfig.getEncryptionSession() :
11354
+ await getEncryptionSession()
11355
+ };
11356
+ const wallet = await client.embeddedWallet.create({
11357
+ chainId: (_a = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.initialChainId) !== null && _a !== void 0 ? _a : chainId,
11358
+ accountType: (options === null || options === void 0 ? void 0 : options.accountType) || (walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.accountType) || AccountTypeEnum.SMART_ACCOUNT,
11359
+ chainType: ChainTypeEnum.EVM,
11360
+ recoveryParams,
11361
+ });
11362
+ setStatus({
11363
+ status: 'success',
11364
+ });
11365
+ refetch();
11366
+ return onSuccess({
11367
+ data: {
11368
+ wallet: createOpenfortWallet({
11369
+ address: wallet.address,
11370
+ })
11371
+ }
11372
+ });
11373
+ }
11374
+ catch (e) {
11375
+ const errorObj = e instanceof Error ? e : new Error('Failed to create wallet');
11376
+ const error = new OpenfortError('Failed to create wallet', OpenfortErrorType.WALLET_ERROR, { error: errorObj });
11377
+ setStatus({
11378
+ status: 'error',
11379
+ error,
11380
+ });
11271
11381
  return onError({
11272
- error: new OpenfortError("Openfort access token not found", OpenfortErrorType.WALLET_ERROR),
11382
+ error,
11273
11383
  hookOptions,
11274
11384
  options,
11275
11385
  });
11276
11386
  }
11277
- if (!walletConfig) {
11387
+ }, [refetch, client, uiConfig, chainId]);
11388
+ const setRecovery = useCallback(async (params) => {
11389
+ try {
11390
+ setStatus({
11391
+ status: 'loading',
11392
+ });
11393
+ // Set embedded wallet recovery method
11394
+ await client.embeddedWallet.setRecoveryMethod(params.previousRecovery, params.newRecovery);
11395
+ // Get the updated embedded account
11396
+ const embeddedAccount = await client.embeddedWallet.get();
11397
+ setStatus({ status: 'success' });
11398
+ return onSuccess({
11399
+ hookOptions,
11400
+ options: params,
11401
+ data: {
11402
+ wallet: createOpenfortWallet({
11403
+ address: embeddedAccount.address,
11404
+ }),
11405
+ }
11406
+ });
11407
+ }
11408
+ catch (error) {
11409
+ const errorObj = error instanceof Error ? error : new Error('Failed to set wallet recovery');
11278
11410
  return onError({
11279
- error: new OpenfortError("Embedded signer not enabled", OpenfortErrorType.WALLET_ERROR),
11280
11411
  hookOptions,
11281
- options,
11412
+ options: params,
11413
+ error: new OpenfortError('Failed to set wallet recovery', OpenfortErrorType.WALLET_ERROR, { error: errorObj }),
11282
11414
  });
11283
11415
  }
11284
- const shieldAuthentication = {
11285
- auth: ShieldAuthType.OPENFORT,
11286
- token: accessToken,
11287
- encryptionSession: walletConfig.getEncryptionSession ?
11288
- await walletConfig.getEncryptionSession() :
11289
- await getEncryptionSession(),
11290
- };
11291
- const recoveryParams = password ? {
11292
- recoveryMethod: RecoveryMethod.PASSWORD,
11293
- password,
11294
- } : {
11295
- recoveryMethod: RecoveryMethod.AUTOMATIC,
11296
- };
11297
- const wallet = await client.embeddedWallet.create({
11298
- chainId: (_a = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.initialChainId) !== null && _a !== void 0 ? _a : chainId,
11299
- accountType: AccountTypeEnum.SMART_ACCOUNT,
11300
- chainType: ChainTypeEnum.EVM,
11301
- recoveryParams,
11302
- shieldAuthentication
11303
- });
11304
- setStatus({
11305
- status: 'success',
11306
- });
11307
- refetch();
11308
- return onSuccess({
11309
- data: {
11310
- wallet: createOpenfortWallet({
11311
- address: wallet.address,
11312
- })
11313
- }
11314
- });
11315
- }, [refetch, client, uiConfig, chainId]);
11416
+ }, [client, setStatus, hookOptions]);
11316
11417
  return {
11317
- wallets: wallets.map((w) => ({
11318
- ...w,
11319
- isConnecting: status.status === 'connecting' && status.address === w.address,
11320
- isActive: w.address === address && isConnected && (connector === null || connector === void 0 ? void 0 : connector.id) === w.id,
11321
- })),
11418
+ hasWallet: wallets.length > 0,
11419
+ isLoadingWallets,
11420
+ wallets,
11322
11421
  availableWallets: deviceWallets,
11323
11422
  activeWallet,
11324
- setActiveWallet,
11423
+ setRecovery,
11424
+ reset: () => setStatus({ status: 'idle' }),
11325
11425
  createWallet,
11326
- ...mapStatus$1(status),
11426
+ setActiveWallet,
11427
+ ...mapWalletStatus(status),
11327
11428
  exportPrivateKey: client.embeddedWallet.exportPrivateKey,
11328
11429
  };
11329
11430
  }
@@ -11332,7 +11433,7 @@ function useWallets(hookOptions = {}) {
11332
11433
  const Recover = () => {
11333
11434
  const [recoveryPhrase, setRecoveryPhrase] = React.useState("");
11334
11435
  const [recoveryError, setRecoveryError] = React.useState(false);
11335
- const { triggerResize, uiConfig: options, log } = useOpenfortKit();
11436
+ const { triggerResize, uiConfig: options, log } = useOpenfort();
11336
11437
  useChainId();
11337
11438
  const [loading, setLoading] = React.useState(false);
11338
11439
  const { setActiveWallet } = useWallets();
@@ -11362,7 +11463,7 @@ const Recover = () => {
11362
11463
  const AutomaticRecovery = () => {
11363
11464
  const { needsRecovery } = useOpenfortCore();
11364
11465
  const { setActiveWallet } = useWallets();
11365
- const { log } = useOpenfortKit();
11466
+ const { log } = useOpenfort();
11366
11467
  const [hasRecoveryMethod, setHasRecoveryMethod] = React.useState(false);
11367
11468
  useEffect(() => {
11368
11469
  (async () => {
@@ -11384,7 +11485,7 @@ const AutomaticRecovery = () => {
11384
11485
  return (jsx(PageContent, { children: jsx(Loader, { reason: "Setting up signer" }) }));
11385
11486
  };
11386
11487
  const Connected = () => {
11387
- const { setOpen } = useOpenfortKit();
11488
+ const { setOpen } = useOpenfort();
11388
11489
  // hide on connect
11389
11490
  useEffect(() => {
11390
11491
  setTimeout(() => {
@@ -11395,7 +11496,7 @@ const Connected = () => {
11395
11496
  };
11396
11497
  const CreateEmbeddedSigner = () => {
11397
11498
  const { needsRecovery, user } = useOpenfortCore();
11398
- const { triggerResize, uiConfig, walletConfig, setRoute } = useOpenfortKit();
11499
+ const { triggerResize, uiConfig, walletConfig, setRoute } = useOpenfort();
11399
11500
  const [loading, setLoading] = React.useState(true);
11400
11501
  const [embeddedSignerLoading, setEmbeddedSignerLoading] = React.useState(true);
11401
11502
  const { isConnected } = useAccount();
@@ -11447,7 +11548,7 @@ const SocialProviders = () => {
11447
11548
  const customThemeDefault = {};
11448
11549
  const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customThemeDefault, lang = 'en-US' }) => {
11449
11550
  var _a;
11450
- const context = useOpenfortKit();
11551
+ const context = useOpenfort();
11451
11552
  const { logout, user } = useOpenfortCore();
11452
11553
  const { isConnected, chain } = useAccount();
11453
11554
  const chainIsSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
@@ -11577,7 +11678,7 @@ const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customTheme
11577
11678
  };
11578
11679
 
11579
11680
  /**
11580
- * OpenfortProvider component provides context and configuration for OpenfortKit.
11681
+ * OpenfortProvider component provides context and configuration for Openfort.
11581
11682
  * It must be used within a WagmiProvider.
11582
11683
  *
11583
11684
  * @param {React.ReactNode} children - The child components to be wrapped by the provider.
@@ -11591,15 +11692,15 @@ const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customTheme
11591
11692
  * @param {OpenfortOptions} [openfortOptions] - Options for Openfort integration.
11592
11693
  * @throws Will throw an error if used outside of a WagmiProvider or if nested usages are detected.
11593
11694
  */
11594
- const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMode = false, publishableKey, walletConfig, }) => {
11595
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
11695
+ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMode = false, publishableKey, walletConfig, overrides, thirdPartyAuth, }) => {
11696
+ var _a, _b, _c, _d, _e, _f, _g, _h;
11596
11697
  // OpenfortProvider must be within a WagmiProvider
11597
11698
  if (!React.useContext(WagmiContext)) {
11598
11699
  throw Error('OpenfortProvider must be within a WagmiProvider');
11599
11700
  }
11600
11701
  // Only allow for mounting OpenfortProvider once, so we avoid weird global
11601
11702
  // state collisions.
11602
- if (React.useContext(OpenfortKitContext)) {
11703
+ if (React.useContext(Openfortcontext)) {
11603
11704
  throw new Error('Multiple, nested usages of OpenfortProvider detected. Please use only one.');
11604
11705
  }
11605
11706
  const chains = useChains();
@@ -11632,7 +11733,7 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
11632
11733
  authProviders: [],
11633
11734
  };
11634
11735
  const opts = Object.assign({}, defaultOptions, uiConfig);
11635
- if (((_b = opts.authProviders) === null || _b === void 0 ? void 0 : _b.length) === 0) {
11736
+ if (!opts.authProviders || opts.authProviders.length === 0) {
11636
11737
  opts.authProviders = [
11637
11738
  AuthProvider.GUEST,
11638
11739
  AuthProvider.EMAIL,
@@ -11642,7 +11743,7 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
11642
11743
  if (typeof window !== 'undefined') {
11643
11744
  // Buffer Polyfill, needed for bundlers that don't provide Node polyfills (e.g CRA, Vite, etc.)
11644
11745
  if (opts.bufferPolyfill)
11645
- window.Buffer = (_c = window.Buffer) !== null && _c !== void 0 ? _c : Buffer;
11746
+ window.Buffer = (_b = window.Buffer) !== null && _b !== void 0 ? _b : Buffer;
11646
11747
  // Some bundlers may need `global` and `process.env` polyfills as well
11647
11748
  // Not implemented here to avoid unexpected behaviors, but leaving example here for future reference
11648
11749
  /*
@@ -11650,9 +11751,9 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
11650
11751
  * window.process = window.process ?? { env: {} };
11651
11752
  */
11652
11753
  }
11653
- const [ckTheme, setTheme] = useState((_e = (_d = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.theme) !== null && _d !== void 0 ? _d : defaultOptions.theme) !== null && _e !== void 0 ? _e : "auto");
11654
- const [ckMode, setMode] = useState((_g = (_f = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.mode) !== null && _f !== void 0 ? _f : defaultOptions.mode) !== null && _g !== void 0 ? _g : 'auto');
11655
- const [ckCustomTheme, setCustomTheme] = useState((_h = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.customTheme) !== null && _h !== void 0 ? _h : {});
11754
+ const [ckTheme, setTheme] = useState((_d = (_c = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.theme) !== null && _c !== void 0 ? _c : defaultOptions.theme) !== null && _d !== void 0 ? _d : "auto");
11755
+ const [ckMode, setMode] = useState((_f = (_e = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.mode) !== null && _e !== void 0 ? _e : defaultOptions.mode) !== null && _f !== void 0 ? _f : 'auto');
11756
+ const [ckCustomTheme, setCustomTheme] = useState((_g = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.customTheme) !== null && _g !== void 0 ? _g : {});
11656
11757
  const [ckLang, setLang] = useState('en-US');
11657
11758
  const [open, setOpen] = useState(false);
11658
11759
  const [connector, setConnector] = useState({
@@ -11701,6 +11802,7 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
11701
11802
  connector,
11702
11803
  setConnector,
11703
11804
  onConnect,
11805
+ onDisconnect,
11704
11806
  // Other configuration
11705
11807
  uiConfig: opts,
11706
11808
  errorMessage,
@@ -11717,14 +11819,16 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
11717
11819
  resize,
11718
11820
  triggerResize: () => onResize((prev) => prev + 1),
11719
11821
  walletConfig,
11822
+ overrides,
11823
+ thirdPartyAuth,
11720
11824
  };
11721
- return createElement(OpenfortKitContext.Provider, { value }, jsx(Fragment, { children: jsx(Web3ContextProvider, { enabled: open, children: jsxs(CoreOpenfortProvider, { baseConfiguration: {
11825
+ return createElement(Openfortcontext.Provider, { value }, jsx(Fragment, { children: jsx(Web3ContextProvider, { enabled: open, children: jsxs(CoreOpenfortProvider, { baseConfiguration: {
11722
11826
  publishableKey,
11723
11827
  }, shieldConfiguration: walletConfig ? {
11724
11828
  shieldPublishableKey: walletConfig.shieldPublishableKey,
11725
11829
  shieldEncryptionKey: walletConfig.recoveryMethod === RecoveryMethod.PASSWORD ? walletConfig.shieldEncryptionKey : undefined,
11726
11830
  debug: debugMode,
11727
- } : undefined, overrides: opts.openfortUrlOverrides, debugMode: debugMode, onConnect: onConnect, onDisconnect: onDisconnect, children: [children, jsx(ConnectModal, { lang: ckLang, theme: ckTheme, mode: (_j = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.mode) !== null && _j !== void 0 ? _j : ckMode, customTheme: ckCustomTheme })] }) }) }));
11831
+ } : undefined, overrides: overrides, thirdPartyAuth: thirdPartyAuth, debugMode: debugMode, onConnect: onConnect, onDisconnect: onDisconnect, children: [children, jsx(ConnectModal, { lang: ckLang, theme: ckTheme, mode: (_h = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.mode) !== null && _h !== void 0 ? _h : ckMode, customTheme: ckCustomTheme })] }) }) }));
11728
11832
  };
11729
11833
 
11730
11834
  const Container$1 = styled(motion.div) `
@@ -11977,7 +12081,7 @@ const allRoutes = [
11977
12081
  ...safeRoutes.disconnected,
11978
12082
  ];
11979
12083
  function useUI() {
11980
- const { open, setOpen, setRoute, log } = useOpenfortKit();
12084
+ const { open, setOpen, setRoute, log } = useOpenfort();
11981
12085
  const { isLoading, user, needsRecovery } = useOpenfortCore();
11982
12086
  const { isConnected } = useAccount();
11983
12087
  function defaultOpen() {
@@ -12102,7 +12206,7 @@ const textVariants = {
12102
12206
  };
12103
12207
  const ConnectButtonRenderer = ({ children, }) => {
12104
12208
  const isMounted = useIsMounted();
12105
- const context = useOpenfortKit();
12209
+ const context = useOpenfort();
12106
12210
  const { open, close, isOpen } = useUI();
12107
12211
  const { address, isConnected, chain } = useAccount();
12108
12212
  const isChainSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
@@ -12135,7 +12239,7 @@ const ConnectButtonRenderer = ({ children, }) => {
12135
12239
  ensName: ensName === null || ensName === void 0 ? void 0 : ensName.toString(),
12136
12240
  }) }));
12137
12241
  };
12138
- ConnectButtonRenderer.displayName = 'OpenfortKitButton.Custom';
12242
+ ConnectButtonRenderer.displayName = 'OpenfortButton.Custom';
12139
12243
  const ConnectedLabel = ({ separator }) => {
12140
12244
  const { user, isLoading } = useOpenfortCore();
12141
12245
  const { address } = useAccount();
@@ -12147,7 +12251,7 @@ const ConnectedLabel = ({ separator }) => {
12147
12251
  return truncateUserId(user.id, separator);
12148
12252
  return "Loading...";
12149
12253
  };
12150
- function OpenfortKitButtonInner({ label, showAvatar, separator, }) {
12254
+ function OpenfortButtonInner({ label, showAvatar, separator, }) {
12151
12255
  const locales = useLocales({});
12152
12256
  const { user } = useOpenfortCore();
12153
12257
  const { address, chain } = useAccount();
@@ -12172,7 +12276,7 @@ function OpenfortKitButtonInner({ label, showAvatar, separator, }) {
12172
12276
  //padding: '0 5px',
12173
12277
  }, children: label ? label : defaultLabel }, "connectWalletText")) }));
12174
12278
  }
12175
- function OpenfortKitButton({
12279
+ function OpenfortButton({
12176
12280
  // Options
12177
12281
  label, showBalance = false, showAvatar = true,
12178
12282
  // Theming
@@ -12181,7 +12285,7 @@ theme, mode, customTheme,
12181
12285
  onClick, }) {
12182
12286
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
12183
12287
  const isMounted = useIsMounted();
12184
- const context = useOpenfortKit();
12288
+ const context = useOpenfort();
12185
12289
  const { address, chain } = useAccount();
12186
12290
  const chainIsSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
12187
12291
  const { open } = useUI();
@@ -12234,59 +12338,9 @@ onClick, }) {
12234
12338
  }
12235
12339
  : {
12236
12340
  overflow: 'hidden',
12237
- }, children: jsx(OpenfortKitButtonInner, { separator: separator, showAvatar: showAvatar, label: label }) })] }) }));
12238
- }
12239
- OpenfortKitButton.Custom = ConnectButtonRenderer;
12240
-
12241
- var OpenfortKitStatus;
12242
- (function (OpenfortKitStatus) {
12243
- OpenfortKitStatus[OpenfortKitStatus["DISCONNECTED"] = 0] = "DISCONNECTED";
12244
- OpenfortKitStatus[OpenfortKitStatus["NEEDS_RECOVERY"] = 1] = "NEEDS_RECOVERY";
12245
- OpenfortKitStatus[OpenfortKitStatus["LOADING"] = 2] = "LOADING";
12246
- OpenfortKitStatus[OpenfortKitStatus["CONNECTED"] = 3] = "CONNECTED";
12247
- })(OpenfortKitStatus || (OpenfortKitStatus = {}));
12248
- function useStatus() {
12249
- const { embeddedState } = useOpenfortCore();
12250
- const { isConnected, isConnecting } = useAccount();
12251
- const getStatus = () => {
12252
- if (embeddedState === EmbeddedState.READY)
12253
- return OpenfortKitStatus.CONNECTED;
12254
- if (embeddedState === EmbeddedState.NONE)
12255
- return OpenfortKitStatus.LOADING;
12256
- // if (needsRecovery) return OpenfortKitStatus.NEEDS_RECOVERY;
12257
- if (embeddedState === EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED) {
12258
- if (isConnected)
12259
- return OpenfortKitStatus.CONNECTED;
12260
- else
12261
- return OpenfortKitStatus.NEEDS_RECOVERY;
12262
- }
12263
- return OpenfortKitStatus.DISCONNECTED;
12264
- };
12265
- const status = getStatus();
12266
- return {
12267
- isLoading: status === OpenfortKitStatus.LOADING,
12268
- isConnected: status === OpenfortKitStatus.CONNECTED,
12269
- isDisconnected: status === OpenfortKitStatus.DISCONNECTED,
12270
- isConnecting: isConnecting || embeddedState === EmbeddedState.CREATING_ACCOUNT,
12271
- isAuthenticated: embeddedState !== EmbeddedState.NONE && embeddedState !== EmbeddedState.UNAUTHENTICATED,
12272
- };
12273
- }
12274
-
12275
- function useUser() {
12276
- const { user, client } = useOpenfortCore();
12277
- const { isAuthenticated } = useStatus();
12278
- const getAccessTokenAndUpdate = useCallback(async () => {
12279
- await client.validateAndRefreshToken();
12280
- const token = await client.getAccessToken();
12281
- return token;
12282
- }, [client]);
12283
- return {
12284
- user,
12285
- isAuthenticated,
12286
- getAccessToken: getAccessTokenAndUpdate,
12287
- validateAndRefreshToken: async () => await client.validateAndRefreshToken(),
12288
- };
12341
+ }, children: jsx(OpenfortButtonInner, { separator: separator, showAvatar: showAvatar, label: label }) })] }) }));
12289
12342
  }
12343
+ OpenfortButton.Custom = ConnectButtonRenderer;
12290
12344
 
12291
12345
  function useWallet() {
12292
12346
  const { activeWallet } = useWallets();
@@ -12320,14 +12374,14 @@ function useSignOut(hookOptions = {}) {
12320
12374
  status: "idle",
12321
12375
  });
12322
12376
  const { disconnect } = useDisconnect();
12377
+ const queryClient = useQueryClient();
12323
12378
  const signOut = useCallback(async (options = {}) => {
12324
- if (!user)
12325
- return;
12326
12379
  setStatus({
12327
12380
  status: 'loading',
12328
12381
  });
12329
12382
  try {
12330
12383
  await client.auth.logout();
12384
+ queryClient.resetQueries({ queryKey: ['openfortEmbeddedWalletList'] });
12331
12385
  disconnect();
12332
12386
  updateUser();
12333
12387
  setStatus({
@@ -12339,12 +12393,17 @@ function useSignOut(hookOptions = {}) {
12339
12393
  data: {},
12340
12394
  });
12341
12395
  }
12342
- catch (error) {
12396
+ catch (e) {
12397
+ const error = new OpenfortError('Failed to sign out', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
12343
12398
  setStatus({
12344
12399
  status: 'error',
12345
- error: new OpenfortError('Failed to sign out', OpenfortErrorType.AUTHENTICATION_ERROR, { error }),
12400
+ error,
12401
+ });
12402
+ return onError({
12403
+ hookOptions,
12404
+ options,
12405
+ error,
12346
12406
  });
12347
- throw error;
12348
12407
  }
12349
12408
  }, [client, user, disconnect, updateUser, setStatus, hookOptions]);
12350
12409
  return {
@@ -12356,7 +12415,7 @@ function useSignOut(hookOptions = {}) {
12356
12415
  // this hook is used to create a wallet after the user has authenticated
12357
12416
  const useCreateWalletPostAuth = () => {
12358
12417
  const { setActiveWallet } = useWallets();
12359
- const { walletConfig } = useOpenfortKit();
12418
+ const { walletConfig } = useOpenfort();
12360
12419
  const { signOut } = useSignOut();
12361
12420
  const tryUseWallet = useCallback(async ({ logoutOnError: signOutOnError = true, automaticRecovery = true }) => {
12362
12421
  if (!walletConfig || walletConfig.recoveryMethod !== RecoveryMethod.AUTOMATIC || !automaticRecovery) {
@@ -12377,7 +12436,7 @@ const useCreateWalletPostAuth = () => {
12377
12436
  };
12378
12437
 
12379
12438
  const useEmailAuth = (hookOptions = {}) => {
12380
- const { log } = useOpenfortKit();
12439
+ const { log } = useOpenfort();
12381
12440
  const { client, updateUser } = useOpenfortCore();
12382
12441
  const [requiresEmailVerification, setRequiresEmailVerification] = useState(false);
12383
12442
  const [status, setStatus] = useState({
@@ -12648,14 +12707,14 @@ const useEmailAuth = (hookOptions = {}) => {
12648
12707
  });
12649
12708
  }
12650
12709
  }, [client, setStatus, updateUser, log, hookOptions]);
12651
- const verifyEmail = useCallback(async ({ email, state, ...options }) => {
12710
+ const verifyEmail = useCallback(async (options) => {
12652
12711
  setStatus({
12653
12712
  status: 'loading',
12654
12713
  });
12655
12714
  try {
12656
12715
  await client.auth.verifyEmail({
12657
- email,
12658
- state,
12716
+ email: options.email,
12717
+ state: options.state,
12659
12718
  });
12660
12719
  setStatus({
12661
12720
  status: 'success',
@@ -12664,7 +12723,7 @@ const useEmailAuth = (hookOptions = {}) => {
12664
12723
  hookOptions,
12665
12724
  options,
12666
12725
  data: {
12667
- email,
12726
+ email: options.email,
12668
12727
  },
12669
12728
  });
12670
12729
  }
@@ -12696,7 +12755,7 @@ const useEmailAuth = (hookOptions = {}) => {
12696
12755
  };
12697
12756
  };
12698
12757
 
12699
- const providerToAuthProvider = {
12758
+ ({
12700
12759
  // [OAuthProvider.APPLE]: AuthProvider.,
12701
12760
  // [OAuthProvider.DISCORD]: AuthProvider.,
12702
12761
  // [OAuthProvider.EPIC_GAMES]: AuthProvider.,
@@ -12704,13 +12763,7 @@ const providerToAuthProvider = {
12704
12763
  [AuthProvider.GOOGLE]: OAuthProvider.GOOGLE,
12705
12764
  // [OAuthProvider.LINE]: AuthProvider.,
12706
12765
  [AuthProvider.TWITTER]: OAuthProvider.TWITTER,
12707
- };
12708
- function getOAuthProvider(provider) {
12709
- if (!providerToAuthProvider[provider]) {
12710
- throw new Error(`Unsupported OAuth provider: ${provider}`);
12711
- }
12712
- return providerToAuthProvider[provider];
12713
- }
12766
+ });
12714
12767
  const useOAuth = (hookOptions = {}) => {
12715
12768
  const { client, updateUser } = useOpenfortCore();
12716
12769
  const [status, setStatus] = useState({
@@ -12762,7 +12815,7 @@ const useOAuth = (hookOptions = {}) => {
12762
12815
  status: 'loading',
12763
12816
  });
12764
12817
  await client.auth.initOAuth({
12765
- provider: getOAuthProvider(authProvider),
12818
+ provider: authProvider,
12766
12819
  options: {
12767
12820
  redirectTo: buildCallbackUrl({
12768
12821
  provider: authProvider,
@@ -12802,7 +12855,7 @@ const useOAuth = (hookOptions = {}) => {
12802
12855
  }
12803
12856
  await client.auth.initLinkOAuth({
12804
12857
  authToken,
12805
- provider: getOAuthProvider(authProvider),
12858
+ provider: authProvider,
12806
12859
  options: {
12807
12860
  redirectTo: buildCallbackUrl({
12808
12861
  provider: authProvider,
@@ -12839,7 +12892,7 @@ const useOAuth = (hookOptions = {}) => {
12839
12892
 
12840
12893
  const useAuthCallback = ({ enabled = true, // Automatically handle OAuth and email callback
12841
12894
  ...hookOptions } = {}) => {
12842
- const { log } = useOpenfortKit();
12895
+ const { log } = useOpenfort();
12843
12896
  const [provider, setProvider] = useState(null);
12844
12897
  const [email, setEmail] = useState(null);
12845
12898
  const { verifyEmail, isSuccess: isEmailSuccess, isLoading: isEmailLoading, isError: isEmailError, error: emailError, } = useEmailAuth();
@@ -12980,12 +13033,11 @@ const useGuestAuth = (hookOptions = {}) => {
12980
13033
  setStatus({
12981
13034
  status: 'success',
12982
13035
  });
12983
- onSuccess({
13036
+ return onSuccess({
12984
13037
  hookOptions,
12985
13038
  options,
12986
- data: user,
13039
+ data: { user, wallet },
12987
13040
  });
12988
- return { user, wallet };
12989
13041
  }
12990
13042
  catch (error) {
12991
13043
  const openfortError = new OpenfortError("Failed to signup guest", OpenfortErrorType.AUTHENTICATION_ERROR, { error });
@@ -13008,13 +13060,12 @@ const useGuestAuth = (hookOptions = {}) => {
13008
13060
 
13009
13061
  const useWalletAuth = (hookOptions = {}) => {
13010
13062
  const { updateUser } = useOpenfortCore();
13011
- const { log } = useOpenfortKit();
13063
+ const { log } = useOpenfort();
13012
13064
  const siwe = useConnectWithSiwe();
13013
13065
  const availableWallets = useWallets$1(); // TODO: Use this to get the wallet client type
13014
13066
  const { disconnect } = useDisconnect();
13015
13067
  const [walletConnectingTo, setWalletConnectingTo] = useState(null);
13016
13068
  const [shouldConnectWithSiwe, setShouldConnectWithSiwe] = useState(false);
13017
- useAccount();
13018
13069
  const [status, setStatus] = useState({
13019
13070
  status: "idle",
13020
13071
  });
@@ -13189,5 +13240,5 @@ const useWalletAuth = (hookOptions = {}) => {
13189
13240
  };
13190
13241
  };
13191
13242
 
13192
- export { AuthProvider, Avatar, Chain as ChainIcon, OPENFORTKIT_VERSION, OpenfortError, OpenfortErrorType, OpenfortKitButton, OpenfortKitContext, OpenfortKitStatus, OpenfortProvider, embeddedWalletId, defaultConfig as getDefaultConfig, defaultConnectors as getDefaultConnectors, useAuthCallback, useChainIsSupported, useChains, useConnectWithSiwe, useEmailAuth, useGuestAuth, useOAuth, useOpenfortCore as useOpenfort, useSignOut, useStatus, useUI, useUser, useWallet, useWalletAuth, useWallets, wallets };
13243
+ export { AuthProvider, Avatar, Chain as ChainIcon, OPENFORT_VERSION, OpenfortButton, OpenfortError, OpenfortErrorType, OpenfortProvider, OpenfortStatus, embeddedWalletId, defaultConfig as getDefaultConfig, defaultConnectors as getDefaultConnectors, useAuthCallback, useChainIsSupported, useChains, useConnectWithSiwe, useEmailAuth, useGuestAuth, useOAuth, useOpenfortCore as useOpenfort, useSignOut, useStatus, useUI, useUser, useWallet, useWalletAuth, useWallets, wallets };
13193
13244
  //# sourceMappingURL=index.es.js.map