@openfort/react 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -8
- package/build/components/{OpenfortKit → Openfort}/OpenfortKit.d.ts +6 -6
- package/build/components/{OpenfortKit → Openfort}/context.d.ts +2 -2
- package/build/components/{OpenfortKit → Openfort}/types.d.ts +4 -4
- package/build/components/Pages/Providers/index.d.ts +1 -1
- package/build/hooks/openfort/auth/status.d.ts +3 -3
- package/build/hooks/openfort/auth/useAuthCallback.d.ts +5 -5
- package/build/hooks/openfort/auth/useCreateWalletPostAuth.d.ts +1 -1
- package/build/hooks/openfort/auth/useEmailAuth.d.ts +3 -3
- package/build/hooks/openfort/auth/useGuestAuth.d.ts +3 -3
- package/build/hooks/openfort/auth/useOAuth.d.ts +4 -4
- package/build/hooks/openfort/auth/useSignOut.d.ts +2 -2
- package/build/hooks/openfort/auth/useWalletAuth.d.ts +4 -4
- package/build/hooks/openfort/hookConsistency.d.ts +3 -3
- package/build/hooks/openfort/useProviders.d.ts +1 -1
- package/build/hooks/openfort/useStatus.d.ts +6 -9
- package/build/hooks/openfort/useUser.d.ts +1 -0
- package/build/hooks/openfort/useWallet.d.ts +1 -0
- package/build/hooks/openfort/useWallets.d.ts +20 -9
- package/build/index.d.ts +5 -4
- package/build/index.es.js +356 -245
- package/build/index.es.js.map +1 -1
- package/build/openfort/OpenfortProvider.d.ts +2 -2
- package/build/openfort/useOpenfort.d.ts +1 -1
- package/build/types.d.ts +10 -9
- package/build/version.d.ts +1 -1
- package/package.json +3 -3
- package/build/openfort/OpenfortProvider_old.d.ts +0 -0
- /package/build/components/{OpenfortKit → Openfort}/useOpenfortKit.d.ts +0 -0
package/build/index.es.js
CHANGED
|
@@ -5,7 +5,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
5
5
|
import React, { createContext, useEffect, useState, useMemo, useRef, useCallback, createElement, useLayoutEffect } from 'react';
|
|
6
6
|
import { detect } from 'detect-browser';
|
|
7
7
|
import { Buffer } from 'buffer';
|
|
8
|
-
import { Openfort as Openfort$1, RecoveryMethod, EmbeddedState, AuthActionRequiredActions, OAuthProvider, ShieldAuthType, MissingRecoveryPasswordError } from '@openfort/openfort-js';
|
|
8
|
+
import { Openfort as Openfort$1, RecoveryMethod, EmbeddedState, AuthActionRequiredActions, OAuthProvider, ShieldAuthType, MissingRecoveryPasswordError, AccountTypeEnum, ChainTypeEnum } from '@openfort/openfort-js';
|
|
9
9
|
export { RecoveryMethod } from '@openfort/openfort-js';
|
|
10
10
|
import { polygonAmoy } from 'viem/chains';
|
|
11
11
|
import { motion, AnimatePresence, MotionConfig } from 'framer-motion';
|
|
@@ -20,17 +20,18 @@ import { normalize } from 'viem/ens';
|
|
|
20
20
|
import { AxiosError } from 'axios';
|
|
21
21
|
import { createSiweMessage } from 'viem/siwe';
|
|
22
22
|
import { signMessage } from '@wagmi/core';
|
|
23
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
23
|
+
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
24
24
|
|
|
25
|
-
const OPENFORTKIT_VERSION = '0.0.
|
|
25
|
+
const OPENFORTKIT_VERSION = '0.0.2';
|
|
26
26
|
|
|
27
|
-
var
|
|
28
|
-
(function (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
var OpenfortErrorType;
|
|
28
|
+
(function (OpenfortErrorType) {
|
|
29
|
+
OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
30
|
+
OpenfortErrorType["WALLET_ERROR"] = "WALLET_ERROR";
|
|
31
|
+
})(OpenfortErrorType || (OpenfortErrorType = {}));
|
|
32
|
+
class OpenfortError extends Error {
|
|
32
33
|
constructor(message, type, data) {
|
|
33
|
-
if ((data === null || data === void 0 ? void 0 : data.error) instanceof
|
|
34
|
+
if ((data === null || data === void 0 ? void 0 : data.error) instanceof OpenfortError) {
|
|
34
35
|
super(data.error.message);
|
|
35
36
|
this.data = data.error.data;
|
|
36
37
|
this.type = data.error.type;
|
|
@@ -45,7 +46,7 @@ class OpenfortKitError extends Error {
|
|
|
45
46
|
}
|
|
46
47
|
this.type = type;
|
|
47
48
|
this.data = data || {};
|
|
48
|
-
this.name = '
|
|
49
|
+
this.name = 'OpenfortError';
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -108,7 +109,7 @@ const defaultConfig = ({ appName = 'OpenfortKit', appIcon, appDescription, appUr
|
|
|
108
109
|
walletConnectProjectId,
|
|
109
110
|
coinbaseWalletPreference,
|
|
110
111
|
});
|
|
111
|
-
console.log("OPENFORTKIT CHAINS", chains, transports);
|
|
112
|
+
// console.log("OPENFORTKIT CHAINS", chains, transports);
|
|
112
113
|
const config = {
|
|
113
114
|
...props,
|
|
114
115
|
chains,
|
|
@@ -918,10 +919,10 @@ function useConnect({ ...props } = {}) {
|
|
|
918
919
|
|
|
919
920
|
const Context$1 = createContext(null);
|
|
920
921
|
|
|
921
|
-
const
|
|
922
|
+
const useOpenfortCore = () => {
|
|
922
923
|
const context = React.useContext(Context$1);
|
|
923
924
|
if (!context)
|
|
924
|
-
throw Error('useOpenfortContext Hook must be inside
|
|
925
|
+
throw Error('useOpenfortContext Hook must be inside CoreOpenfortProvider.');
|
|
925
926
|
return context;
|
|
926
927
|
};
|
|
927
928
|
|
|
@@ -932,7 +933,7 @@ function useIsMounted() {
|
|
|
932
933
|
}
|
|
933
934
|
|
|
934
935
|
const useConnectCallback = ({ onConnect, onDisconnect, }) => {
|
|
935
|
-
const { user } =
|
|
936
|
+
const { user } = useOpenfortCore();
|
|
936
937
|
const { address, connector } = useAccount();
|
|
937
938
|
const hasAddress = !!address;
|
|
938
939
|
const [isConnected, setIsConnected] = useState(false);
|
|
@@ -990,7 +991,7 @@ const ConnectCallback = ({ onConnect, onDisconnect }) => {
|
|
|
990
991
|
});
|
|
991
992
|
return null;
|
|
992
993
|
};
|
|
993
|
-
const
|
|
994
|
+
const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ...openfortProps }) => {
|
|
994
995
|
const log = debugMode ? console.log : () => { };
|
|
995
996
|
const { connectors, connect, reset } = useConnect();
|
|
996
997
|
const { address } = useAccount();
|
|
@@ -1002,7 +1003,7 @@ const OpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ...ope
|
|
|
1002
1003
|
const openfort = useMemo(() => {
|
|
1003
1004
|
log('Creating Openfort instance.');
|
|
1004
1005
|
if (!openfortProps.baseConfiguration.publishableKey)
|
|
1005
|
-
throw Error('
|
|
1006
|
+
throw Error('CoreOpenfortProvider requires a publishableKey to be set in the baseConfiguration.');
|
|
1006
1007
|
const newClient = createOpenfortClient(openfortProps);
|
|
1007
1008
|
return newClient;
|
|
1008
1009
|
}, []);
|
|
@@ -4477,7 +4478,7 @@ function usePrevious(value, initial) {
|
|
|
4477
4478
|
return ref.current.previous;
|
|
4478
4479
|
}
|
|
4479
4480
|
|
|
4480
|
-
const useWallet = (id) => {
|
|
4481
|
+
const useWallet$1 = (id) => {
|
|
4481
4482
|
const wallets = useWallets$1();
|
|
4482
4483
|
const wallet = wallets.find((c) => c.id === id);
|
|
4483
4484
|
if (!wallet)
|
|
@@ -4774,7 +4775,7 @@ const Modal = ({ open, pages, pageId, positionInside, inline, demo, onClose, onB
|
|
|
4774
4775
|
const context = useOpenfortKit();
|
|
4775
4776
|
const themeContext = useThemeContext();
|
|
4776
4777
|
const mobile = isMobile();
|
|
4777
|
-
const wallet = useWallet((_a = context.connector) === null || _a === void 0 ? void 0 : _a.id);
|
|
4778
|
+
const wallet = useWallet$1((_a = context.connector) === null || _a === void 0 ? void 0 : _a.id);
|
|
4778
4779
|
const walletInfo = {
|
|
4779
4780
|
name: wallet === null || wallet === void 0 ? void 0 : wallet.name,
|
|
4780
4781
|
shortName: (_b = wallet === null || wallet === void 0 ? void 0 : wallet.shortName) !== null && _b !== void 0 ? _b : wallet === null || wallet === void 0 ? void 0 : wallet.name,
|
|
@@ -7265,7 +7266,7 @@ CustomQRCode.displayName = 'CustomQRCode';
|
|
|
7265
7266
|
const DownloadApp = () => {
|
|
7266
7267
|
var _a, _b, _c;
|
|
7267
7268
|
const context = useOpenfortKit();
|
|
7268
|
-
const wallet = useWallet(context.connector.id);
|
|
7269
|
+
const wallet = useWallet$1(context.connector.id);
|
|
7269
7270
|
const locales = useLocales({
|
|
7270
7271
|
CONNECTORNAME: wallet === null || wallet === void 0 ? void 0 : wallet.name,
|
|
7271
7272
|
});
|
|
@@ -9199,7 +9200,7 @@ var Wallet = ({ ...props }) => {
|
|
|
9199
9200
|
};
|
|
9200
9201
|
|
|
9201
9202
|
function useProviders() {
|
|
9202
|
-
const { user } =
|
|
9203
|
+
const { user } = useOpenfortCore();
|
|
9203
9204
|
const { uiConfig: options } = useOpenfortKit();
|
|
9204
9205
|
const allProviders = (options === null || options === void 0 ? void 0 : options.authProviders) || [];
|
|
9205
9206
|
const providers = allProviders.filter(p => p !== AuthProvider.GUEST) || [];
|
|
@@ -9314,7 +9315,7 @@ const AddLinkedProviderButton = () => {
|
|
|
9314
9315
|
return (jsx(LinkedProviderButton, { disabled: unlinkedProviders.length === 0, onClick: () => setRoute(routes.PROVIDERS), children: "+" }));
|
|
9315
9316
|
};
|
|
9316
9317
|
const LinkedProviders = () => {
|
|
9317
|
-
const { user } =
|
|
9318
|
+
const { user } = useOpenfortCore();
|
|
9318
9319
|
if (!user || !user.linkedAccounts) {
|
|
9319
9320
|
return (jsx("div", { children: jsx("p", { children: "No linked providers" }) }));
|
|
9320
9321
|
}
|
|
@@ -9338,7 +9339,7 @@ const Profile = ({ closeModal }) => {
|
|
|
9338
9339
|
//watch: true,
|
|
9339
9340
|
});
|
|
9340
9341
|
const [shouldDisconnect, setShouldDisconnect] = useState(false);
|
|
9341
|
-
const { logout, user } =
|
|
9342
|
+
const { logout, user } = useOpenfortCore();
|
|
9342
9343
|
useEffect(() => {
|
|
9343
9344
|
// if (!isConnected) context.setOpen(false);
|
|
9344
9345
|
}, [isConnected]);
|
|
@@ -9747,7 +9748,7 @@ const createSIWEMessage = (address, nonce, chainId) => createSiweMessage({
|
|
|
9747
9748
|
});
|
|
9748
9749
|
|
|
9749
9750
|
function useConnectWithSiwe() {
|
|
9750
|
-
const { client, user, updateUser } =
|
|
9751
|
+
const { client, user, updateUser } = useOpenfortCore();
|
|
9751
9752
|
const { log } = useOpenfortKit();
|
|
9752
9753
|
const { address } = useAccount();
|
|
9753
9754
|
const chainId = useChainId();
|
|
@@ -9797,7 +9798,7 @@ function useConnectWithSiwe() {
|
|
|
9797
9798
|
onError && onError("Failed to connect with SIWE");
|
|
9798
9799
|
}
|
|
9799
9800
|
}
|
|
9800
|
-
}, [client, user, updateUser, log]);
|
|
9801
|
+
}, [client, user, updateUser, log, address, chainId, config, connector]);
|
|
9801
9802
|
return connectWithSiwe;
|
|
9802
9803
|
}
|
|
9803
9804
|
|
|
@@ -9841,7 +9842,7 @@ const contentVariants$1 = {
|
|
|
9841
9842
|
};
|
|
9842
9843
|
const ConnectWithInjector = ({ switchConnectMethod, forceState }) => {
|
|
9843
9844
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9844
|
-
const openfort =
|
|
9845
|
+
const openfort = useOpenfortCore();
|
|
9845
9846
|
const { log, setOpen } = useOpenfortKit();
|
|
9846
9847
|
const { isConnected } = useAccount();
|
|
9847
9848
|
const { disconnect } = useDisconnect();
|
|
@@ -9927,7 +9928,7 @@ const ConnectWithInjector = ({ switchConnectMethod, forceState }) => {
|
|
|
9927
9928
|
});
|
|
9928
9929
|
const { triggerResize, connector: c } = useOpenfortKit();
|
|
9929
9930
|
const id = c.id;
|
|
9930
|
-
const wallet = useWallet(id);
|
|
9931
|
+
const wallet = useWallet$1(id);
|
|
9931
9932
|
const walletInfo = {
|
|
9932
9933
|
name: wallet === null || wallet === void 0 ? void 0 : wallet.name,
|
|
9933
9934
|
shortName: (_a = wallet === null || wallet === void 0 ? void 0 : wallet.shortName) !== null && _a !== void 0 ? _a : wallet === null || wallet === void 0 ? void 0 : wallet.name,
|
|
@@ -10055,7 +10056,7 @@ const ConnectWithQRCode = ({ switchConnectMethod }) => {
|
|
|
10055
10056
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10056
10057
|
const context = useOpenfortKit();
|
|
10057
10058
|
const id = context.connector.id;
|
|
10058
|
-
const wallet = useWallet(context.connector.id);
|
|
10059
|
+
const wallet = useWallet$1(context.connector.id);
|
|
10059
10060
|
const { open: openW3M, isOpen: isOpenW3M } = useWalletConnectModal();
|
|
10060
10061
|
const { connect: { getUri }, } = useWeb3();
|
|
10061
10062
|
const wcUri = getUri(id);
|
|
@@ -10179,11 +10180,23 @@ const Loader = ({ reason, isLoading = true, icon }) => {
|
|
|
10179
10180
|
useEffect(() => {
|
|
10180
10181
|
return () => triggerResize();
|
|
10181
10182
|
}, []);
|
|
10183
|
+
const renderLogo = () => {
|
|
10184
|
+
if (icon) {
|
|
10185
|
+
return icon;
|
|
10186
|
+
}
|
|
10187
|
+
if (options === null || options === void 0 ? void 0 : options.logo) {
|
|
10188
|
+
if (typeof options.logo === 'string') {
|
|
10189
|
+
return jsx("img", { src: options.logo, alt: "Logo", style: { width: '100%' } });
|
|
10190
|
+
}
|
|
10191
|
+
return options.logo;
|
|
10192
|
+
}
|
|
10193
|
+
return jsx(Logos.Openfort, {});
|
|
10194
|
+
};
|
|
10182
10195
|
return (jsxs(Fragment, { children: [jsx(ConnectingContainer, { children: jsx(ConnectingAnimation, { "$success": !isLoading, children: jsx(SquircleSpinner, { logo: jsx("div", { style: {
|
|
10183
10196
|
padding: '12px',
|
|
10184
10197
|
position: 'relative',
|
|
10185
10198
|
width: '100%',
|
|
10186
|
-
}, children:
|
|
10199
|
+
}, children: renderLogo() }), connecting: isLoading }) }) }), jsx(TextWrapper, { children: isLoading ? (jsxs(Fragment, { children: [jsx(ModalH1, { children: "Loading, please wait" }), jsx(ModalBody, { children: reason })] })) : (jsxs(ModalH1, { "$valid": true, children: [jsx(TickIcon, {}), " ", reason] })) })] }));
|
|
10187
10200
|
};
|
|
10188
10201
|
|
|
10189
10202
|
const states$1 = {
|
|
@@ -10193,7 +10206,7 @@ const states$1 = {
|
|
|
10193
10206
|
};
|
|
10194
10207
|
const ConnectWithOAuth = ({}) => {
|
|
10195
10208
|
const { connector, setRoute, log } = useOpenfortKit();
|
|
10196
|
-
const { client, user } =
|
|
10209
|
+
const { client, user } = useOpenfortCore();
|
|
10197
10210
|
const [status, setStatus] = useState(states$1.INIT);
|
|
10198
10211
|
useEffect(() => {
|
|
10199
10212
|
(async () => {
|
|
@@ -10290,7 +10303,7 @@ const states = {
|
|
|
10290
10303
|
};
|
|
10291
10304
|
const ConnectUsing = () => {
|
|
10292
10305
|
const context = useOpenfortKit();
|
|
10293
|
-
const wallet = useWallet(context.connector.id);
|
|
10306
|
+
const wallet = useWallet$1(context.connector.id);
|
|
10294
10307
|
// If cannot be scanned, display injector flow, which if extension is not installed will show CTA to install it
|
|
10295
10308
|
const isQrCode = !(wallet === null || wallet === void 0 ? void 0 : wallet.isInstalled) && (wallet === null || wallet === void 0 ? void 0 : wallet.getWalletConnectDeeplink);
|
|
10296
10309
|
// For OAuth connectors, we don't need to show the injector flow
|
|
@@ -10455,7 +10468,7 @@ const EmailLogin = () => {
|
|
|
10455
10468
|
const [email, setEmail] = React.useState("");
|
|
10456
10469
|
const [password, setPassword] = React.useState("");
|
|
10457
10470
|
const { setRoute, log } = useOpenfortKit();
|
|
10458
|
-
const { client } =
|
|
10471
|
+
const { client } = useOpenfortCore();
|
|
10459
10472
|
const [loginLoading, setLoginLoading] = React.useState(false);
|
|
10460
10473
|
const [loginError, setLoginError] = React.useState(false);
|
|
10461
10474
|
const handleSubmit = async () => {
|
|
@@ -10498,7 +10511,7 @@ const EmailSignup = () => {
|
|
|
10498
10511
|
const [password, setPassword] = React.useState("");
|
|
10499
10512
|
const [username, setUsername] = React.useState("");
|
|
10500
10513
|
const { setRoute, triggerResize, log, uiConfig: options } = useOpenfortKit();
|
|
10501
|
-
const { client } =
|
|
10514
|
+
const { client } = useOpenfortCore();
|
|
10502
10515
|
const [signupLoading, setSignupLoading] = React.useState(false);
|
|
10503
10516
|
const [signupError, setSignupError] = React.useState(false);
|
|
10504
10517
|
const handleSubmit = async () => {
|
|
@@ -10544,7 +10557,7 @@ const EmailSignup = () => {
|
|
|
10544
10557
|
};
|
|
10545
10558
|
|
|
10546
10559
|
const EmailVerification = () => {
|
|
10547
|
-
const { client } =
|
|
10560
|
+
const { client } = useOpenfortCore();
|
|
10548
10561
|
const { setRoute, log } = useOpenfortKit();
|
|
10549
10562
|
const [loading, setLoading] = useState(true);
|
|
10550
10563
|
const [shouldSendEmailVerification, setShouldSendEmailVerification] = useState(false);
|
|
@@ -10637,7 +10650,7 @@ const EmailVerification = () => {
|
|
|
10637
10650
|
const RequestEmail = () => {
|
|
10638
10651
|
const [email, setEmail] = React.useState("");
|
|
10639
10652
|
const { log, triggerResize } = useOpenfortKit();
|
|
10640
|
-
const { client } =
|
|
10653
|
+
const { client } = useOpenfortCore();
|
|
10641
10654
|
const [loading, setLoading] = React.useState(false);
|
|
10642
10655
|
const [message, setMessage] = React.useState("");
|
|
10643
10656
|
const [error, setError] = React.useState("");
|
|
@@ -10694,7 +10707,7 @@ const ResetPassword = () => {
|
|
|
10694
10707
|
const url = new URL(fixedUrl);
|
|
10695
10708
|
const [password, setPassword] = React.useState("");
|
|
10696
10709
|
const { setRoute, triggerResize, log } = useOpenfortKit();
|
|
10697
|
-
const { client, updateUser } =
|
|
10710
|
+
const { client, updateUser } = useOpenfortCore();
|
|
10698
10711
|
const [loading, setLoading] = React.useState(false);
|
|
10699
10712
|
const email = url.searchParams.get("email");
|
|
10700
10713
|
const handleSubmit = async () => {
|
|
@@ -10769,7 +10782,7 @@ const LinkEmail = () => {
|
|
|
10769
10782
|
const [email, setEmail] = React.useState("");
|
|
10770
10783
|
const [password, setPassword] = React.useState("");
|
|
10771
10784
|
const { setRoute, triggerResize, log } = useOpenfortKit();
|
|
10772
|
-
const { client, updateUser } =
|
|
10785
|
+
const { client, updateUser } = useOpenfortCore();
|
|
10773
10786
|
const [loginLoading, setLoginLoading] = React.useState(false);
|
|
10774
10787
|
const [loginError, setLoginError] = React.useState(false);
|
|
10775
10788
|
const handleSubmit = async () => {
|
|
@@ -10807,7 +10820,7 @@ const LinkEmail = () => {
|
|
|
10807
10820
|
|
|
10808
10821
|
const Loading = () => {
|
|
10809
10822
|
const { setRoute, walletConfig } = useOpenfortKit();
|
|
10810
|
-
const { isLoading, user, needsRecovery } =
|
|
10823
|
+
const { isLoading, user, needsRecovery } = useOpenfortCore();
|
|
10811
10824
|
const { address } = useAccount();
|
|
10812
10825
|
const [isFirstFrame, setIsFirstFrame] = React.useState(true);
|
|
10813
10826
|
const [retryCount, setRetryCount] = React.useState(0);
|
|
@@ -10851,7 +10864,7 @@ const ProviderButton = ({ children, icon, onClick }) => {
|
|
|
10851
10864
|
return (jsx(ProvidersButton, { children: jsxs(Button, { onClick: onClick, children: [jsx(ProviderLabel, { children: children }), jsx(ProviderIcon$1, { children: icon })] }) }));
|
|
10852
10865
|
};
|
|
10853
10866
|
const GuestButton = () => {
|
|
10854
|
-
const { signUpGuest } =
|
|
10867
|
+
const { signUpGuest } = useOpenfortCore();
|
|
10855
10868
|
const { setRoute } = useOpenfortKit();
|
|
10856
10869
|
const handleClick = () => {
|
|
10857
10870
|
signUpGuest();
|
|
@@ -10865,7 +10878,7 @@ const WalletButton = () => {
|
|
|
10865
10878
|
};
|
|
10866
10879
|
const EmailButton = () => {
|
|
10867
10880
|
const { setRoute } = useOpenfortKit();
|
|
10868
|
-
const { user } =
|
|
10881
|
+
const { user } = useOpenfortCore();
|
|
10869
10882
|
return jsx(ProviderButton, { onClick: () => setRoute(user ? routes.LINK_EMAIL : routes.EMAIL_LOGIN), icon: jsx(EmailIcon, {}), children: "Email" });
|
|
10870
10883
|
};
|
|
10871
10884
|
const AuthProviderButton = ({ provider, title = provider + " login", icon }) => {
|
|
@@ -10896,7 +10909,7 @@ const ProviderButtonSwitch = ({ provider }) => {
|
|
|
10896
10909
|
};
|
|
10897
10910
|
// This accounts for the case where the user has an address but no user, which can happen if the user has not signed up yet, but logged in with a wallet
|
|
10898
10911
|
const AddressButNoUserCase = () => {
|
|
10899
|
-
const { updateUser } =
|
|
10912
|
+
const { updateUser } = useOpenfortCore();
|
|
10900
10913
|
const { disconnect } = useDisconnect();
|
|
10901
10914
|
useEffect(() => {
|
|
10902
10915
|
updateUser()
|
|
@@ -10916,7 +10929,7 @@ const SocialProvidersButton = () => {
|
|
|
10916
10929
|
};
|
|
10917
10930
|
const Providers = () => {
|
|
10918
10931
|
const maxProviders = 4;
|
|
10919
|
-
const { user } =
|
|
10932
|
+
const { user } = useOpenfortCore();
|
|
10920
10933
|
const { address } = useAccount();
|
|
10921
10934
|
const { allProviders, availableProviders } = useProviders();
|
|
10922
10935
|
if (address && !user) {
|
|
@@ -10937,19 +10950,38 @@ const mapStatus = (status) => {
|
|
|
10937
10950
|
};
|
|
10938
10951
|
};
|
|
10939
10952
|
|
|
10940
|
-
const
|
|
10953
|
+
const onSuccess = ({ hookOptions, options, data, }) => {
|
|
10954
|
+
var _a, _b, _c, _d;
|
|
10955
|
+
(_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onSuccess) === null || _a === void 0 ? void 0 : _a.call(hookOptions, data);
|
|
10956
|
+
(_b = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onSettled) === null || _b === void 0 ? void 0 : _b.call(hookOptions, data, null);
|
|
10957
|
+
(_c = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _c === void 0 ? void 0 : _c.call(options, data);
|
|
10958
|
+
(_d = options === null || options === void 0 ? void 0 : options.onSettled) === null || _d === void 0 ? void 0 : _d.call(options, data, null);
|
|
10959
|
+
return data;
|
|
10960
|
+
};
|
|
10961
|
+
const onError = ({ hookOptions, options, error, }) => {
|
|
10962
|
+
var _a, _b, _c, _d;
|
|
10963
|
+
(_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onError) === null || _a === void 0 ? void 0 : _a.call(hookOptions, error);
|
|
10964
|
+
(_b = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onSettled) === null || _b === void 0 ? void 0 : _b.call(hookOptions, null, error);
|
|
10965
|
+
(_c = options === null || options === void 0 ? void 0 : options.onError) === null || _c === void 0 ? void 0 : _c.call(options, error);
|
|
10966
|
+
(_d = options === null || options === void 0 ? void 0 : options.onSettled) === null || _d === void 0 ? void 0 : _d.call(options, null, error);
|
|
10967
|
+
if ((hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.throwOnError) || (options === null || options === void 0 ? void 0 : options.throwOnError))
|
|
10968
|
+
throw error;
|
|
10969
|
+
return { error };
|
|
10970
|
+
};
|
|
10971
|
+
|
|
10972
|
+
const createOpenfortWallet = ({ address, isActive, }) => ({
|
|
10941
10973
|
connectorType: "embedded",
|
|
10942
10974
|
walletClientType: "openfort",
|
|
10943
|
-
address
|
|
10975
|
+
address,
|
|
10944
10976
|
id: embeddedWalletId,
|
|
10945
10977
|
isAvailable: true,
|
|
10946
|
-
isActive
|
|
10978
|
+
isActive,
|
|
10947
10979
|
});
|
|
10948
|
-
function useWallets() {
|
|
10949
|
-
const { user, embeddedState, client } =
|
|
10950
|
-
const { walletConfig, log, setOpen, setRoute, setConnector, uiConfig
|
|
10980
|
+
function useWallets(hookOptions = {}) {
|
|
10981
|
+
const { user, embeddedState, client } = useOpenfortCore();
|
|
10982
|
+
const { walletConfig, log, setOpen, setRoute, setConnector, uiConfig } = useOpenfortKit();
|
|
10951
10983
|
const { connector, isConnected, address } = useAccount();
|
|
10952
|
-
const
|
|
10984
|
+
const chainId = useChainId();
|
|
10953
10985
|
const deviceWallets = useWallets$1(); // TODO: Map wallets object to be the same as wallets
|
|
10954
10986
|
const { disconnect } = useDisconnect();
|
|
10955
10987
|
const [status, setStatus] = useState({
|
|
@@ -10958,20 +10990,25 @@ function useWallets() {
|
|
|
10958
10990
|
const [connectToConnector, setConnectToConnector] = useState(undefined);
|
|
10959
10991
|
const { connect } = useConnect$1({
|
|
10960
10992
|
mutation: {
|
|
10961
|
-
onError: (
|
|
10962
|
-
console.error("Error connecting ---",
|
|
10993
|
+
onError: (e) => {
|
|
10994
|
+
console.error("Error connecting ---", e);
|
|
10995
|
+
const error = new OpenfortError("Failed to connect with wallet: ", OpenfortErrorType.AUTHENTICATION_ERROR, e);
|
|
10963
10996
|
setStatus({
|
|
10964
10997
|
status: 'error',
|
|
10965
|
-
error
|
|
10998
|
+
error,
|
|
10999
|
+
});
|
|
11000
|
+
onError({
|
|
11001
|
+
error,
|
|
11002
|
+
options: hookOptions,
|
|
10966
11003
|
});
|
|
10967
11004
|
},
|
|
10968
11005
|
onSuccess: (data) => {
|
|
10969
11006
|
setConnectToConnector(undefined);
|
|
10970
|
-
|
|
11007
|
+
log("Connected with wallet", data, connectToConnector);
|
|
10971
11008
|
if ((connectToConnector === null || connectToConnector === void 0 ? void 0 : connectToConnector.address) && !data.accounts.some((a) => a === connectToConnector.address)) {
|
|
10972
11009
|
setStatus({
|
|
10973
11010
|
status: 'error',
|
|
10974
|
-
error: new
|
|
11011
|
+
error: new OpenfortError("Failed to connect with wallet: Address mismatch", OpenfortErrorType.AUTHENTICATION_ERROR),
|
|
10975
11012
|
});
|
|
10976
11013
|
disconnect();
|
|
10977
11014
|
return;
|
|
@@ -10984,8 +11021,32 @@ function useWallets() {
|
|
|
10984
11021
|
});
|
|
10985
11022
|
const usesEmbeddedWallet = user && walletConfig;
|
|
10986
11023
|
const isEmbedded = embeddedState === EmbeddedState.READY;
|
|
11024
|
+
const { data: embeddedWallets, refetch } = useQuery({
|
|
11025
|
+
queryKey: ['openfortEmbeddedWalletList'],
|
|
11026
|
+
queryFn: () => !!user ? client.embeddedWallet.list() : Promise.resolve([]),
|
|
11027
|
+
});
|
|
11028
|
+
useEffect(() => {
|
|
11029
|
+
log("Refetching embedded wallets");
|
|
11030
|
+
refetch();
|
|
11031
|
+
}, [!!user, refetch]);
|
|
11032
|
+
const getEncryptionSession = useCallback(async () => {
|
|
11033
|
+
if (!walletConfig || !walletConfig.createEncryptedSessionEndpoint) {
|
|
11034
|
+
throw new Error("No createEncryptedSessionEndpoint set in walletConfig");
|
|
11035
|
+
}
|
|
11036
|
+
const resp = await fetch(walletConfig.createEncryptedSessionEndpoint, {
|
|
11037
|
+
method: "POST",
|
|
11038
|
+
headers: {
|
|
11039
|
+
"Content-Type": "application/json",
|
|
11040
|
+
},
|
|
11041
|
+
});
|
|
11042
|
+
if (!resp.ok) {
|
|
11043
|
+
throw new Error("Failed to create encryption session");
|
|
11044
|
+
}
|
|
11045
|
+
const respJSON = await resp.json();
|
|
11046
|
+
return respJSON.session;
|
|
11047
|
+
}, [walletConfig]);
|
|
10987
11048
|
const wallets = useMemo(() => {
|
|
10988
|
-
const
|
|
11049
|
+
const userWallets = user ? user.linkedAccounts
|
|
10989
11050
|
.filter((a) => a.provider === AuthProvider.WALLET)
|
|
10990
11051
|
.map((a) => {
|
|
10991
11052
|
const wallet = deviceWallets.find((c) => c.connector.id === a.walletClientType);
|
|
@@ -10998,16 +11059,14 @@ function useWallets() {
|
|
|
10998
11059
|
isActive: (connector === null || connector === void 0 ? void 0 : connector.id) === a.walletClientType && address === a.address,
|
|
10999
11060
|
};
|
|
11000
11061
|
}) : [];
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
isEmbedded,
|
|
11006
|
-
address
|
|
11062
|
+
embeddedWallets === null || embeddedWallets === void 0 ? void 0 : embeddedWallets.forEach((wallet) => {
|
|
11063
|
+
userWallets.push(createOpenfortWallet({
|
|
11064
|
+
address: wallet.address,
|
|
11065
|
+
isActive: wallet.address === address,
|
|
11007
11066
|
}));
|
|
11008
|
-
}
|
|
11009
|
-
return
|
|
11010
|
-
}, [user, address, connector === null || connector === void 0 ? void 0 : connector.id]);
|
|
11067
|
+
});
|
|
11068
|
+
return userWallets;
|
|
11069
|
+
}, [user, address, connector === null || connector === void 0 ? void 0 : connector.id, embeddedWallets]);
|
|
11011
11070
|
const activeWallet = isConnected && connector ? wallets.find((w) => w.isActive) : undefined;
|
|
11012
11071
|
useEffect(() => {
|
|
11013
11072
|
if (connectToConnector)
|
|
@@ -11022,7 +11081,7 @@ function useWallets() {
|
|
|
11022
11081
|
const wallet = deviceWallets.find(c => c.id === optionsObject.connector);
|
|
11023
11082
|
if (!wallet) {
|
|
11024
11083
|
log("Connector not found", connector);
|
|
11025
|
-
return { error: "Connector not found" };
|
|
11084
|
+
return { error: new OpenfortError("Connector not found", OpenfortErrorType.WALLET_ERROR) };
|
|
11026
11085
|
}
|
|
11027
11086
|
log("Connecting to", wallet.connector);
|
|
11028
11087
|
connector = wallet.connector;
|
|
@@ -11032,7 +11091,7 @@ function useWallets() {
|
|
|
11032
11091
|
}
|
|
11033
11092
|
if (!connector) {
|
|
11034
11093
|
log("Connector not found", deviceWallets, optionsObject.connector);
|
|
11035
|
-
return { error: "Connector not found" };
|
|
11094
|
+
return { error: new OpenfortError("Connector not found", OpenfortErrorType.WALLET_ERROR) };
|
|
11036
11095
|
}
|
|
11037
11096
|
if ((activeWallet === null || activeWallet === void 0 ? void 0 : activeWallet.id) === connector.id && address === optionsObject.address) {
|
|
11038
11097
|
log(`Already connected to ${connector.id} with address ${address}, skipping connection`);
|
|
@@ -11058,7 +11117,11 @@ function useWallets() {
|
|
|
11058
11117
|
const walletToConnect = wallets.find((w) => w.id == connector.id);
|
|
11059
11118
|
if (!walletToConnect) {
|
|
11060
11119
|
log("Wallet not found", connector);
|
|
11061
|
-
return {
|
|
11120
|
+
return onError({
|
|
11121
|
+
error: new OpenfortError("Wallet not found", OpenfortErrorType.AUTHENTICATION_ERROR),
|
|
11122
|
+
options: optionsObject,
|
|
11123
|
+
hookOptions
|
|
11124
|
+
});
|
|
11062
11125
|
}
|
|
11063
11126
|
log("Connecting to wallet", walletToConnect);
|
|
11064
11127
|
if (connector.id === embeddedWalletId) {
|
|
@@ -11077,38 +11140,18 @@ function useWallets() {
|
|
|
11077
11140
|
function isOpenfortWallet(opts) {
|
|
11078
11141
|
return opts.connector === embeddedWalletId;
|
|
11079
11142
|
}
|
|
11080
|
-
|
|
11081
|
-
console.log("Setting active wallet", { options: optionsObject, chainId });
|
|
11143
|
+
log("Setting active wallet", { options: optionsObject, chainId });
|
|
11082
11144
|
if (isOpenfortWallet(optionsObject)) {
|
|
11083
|
-
const getEncryptionSession = async () => {
|
|
11084
|
-
if (!walletConfig || !walletConfig.createEncryptedSessionEndpoint) {
|
|
11085
|
-
throw new Error("No createEncryptedSessionEndpoint set in walletConfig");
|
|
11086
|
-
}
|
|
11087
|
-
const resp = await fetch(walletConfig.createEncryptedSessionEndpoint, {
|
|
11088
|
-
method: "POST",
|
|
11089
|
-
headers: {
|
|
11090
|
-
"Content-Type": "application/json",
|
|
11091
|
-
},
|
|
11092
|
-
});
|
|
11093
|
-
if (!resp.ok) {
|
|
11094
|
-
throw new Error("Failed to create encryption session");
|
|
11095
|
-
}
|
|
11096
|
-
const respJSON = await resp.json();
|
|
11097
|
-
return respJSON.session;
|
|
11098
|
-
};
|
|
11099
11145
|
setStatus({
|
|
11100
11146
|
status: 'loading',
|
|
11101
11147
|
});
|
|
11102
11148
|
const { password } = optionsObject;
|
|
11103
|
-
// -----
|
|
11104
|
-
//
|
|
11105
|
-
// HERE WOULD GO THE LOGIC TO CONNECT TO WALLET A OR B
|
|
11106
|
-
//
|
|
11107
|
-
// -----
|
|
11108
11149
|
if (!walletConfig) {
|
|
11109
|
-
return {
|
|
11110
|
-
error: "Embedded signer not enabled",
|
|
11111
|
-
|
|
11150
|
+
return onError({
|
|
11151
|
+
error: new OpenfortError("Embedded signer not enabled", OpenfortErrorType.WALLET_ERROR),
|
|
11152
|
+
options: optionsObject,
|
|
11153
|
+
hookOptions
|
|
11154
|
+
});
|
|
11112
11155
|
}
|
|
11113
11156
|
log(`Handling recovery with Openfort: password=${password}, chainId=${chainId}`);
|
|
11114
11157
|
try {
|
|
@@ -11116,70 +11159,91 @@ function useWallets() {
|
|
|
11116
11159
|
if (!accessToken) {
|
|
11117
11160
|
throw new Error("Openfort access token not found");
|
|
11118
11161
|
}
|
|
11119
|
-
|
|
11120
|
-
|
|
11121
|
-
|
|
11122
|
-
|
|
11123
|
-
|
|
11124
|
-
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
|
|
11133
|
-
|
|
11162
|
+
const shieldAuthentication = password ? {
|
|
11163
|
+
auth: ShieldAuthType.OPENFORT,
|
|
11164
|
+
token: accessToken,
|
|
11165
|
+
} : {
|
|
11166
|
+
auth: ShieldAuthType.OPENFORT,
|
|
11167
|
+
token: accessToken,
|
|
11168
|
+
encryptionSession: walletConfig.getEncryptionSession ?
|
|
11169
|
+
await walletConfig.getEncryptionSession() :
|
|
11170
|
+
await getEncryptionSession(),
|
|
11171
|
+
};
|
|
11172
|
+
const recoveryParams = password ? {
|
|
11173
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11174
|
+
password,
|
|
11175
|
+
} : {
|
|
11176
|
+
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
11177
|
+
};
|
|
11178
|
+
log("Recovery params", recoveryParams, optionsObject.address);
|
|
11179
|
+
if (optionsObject.address) {
|
|
11180
|
+
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;
|
|
11181
|
+
if (!walletId) {
|
|
11182
|
+
return onError({
|
|
11183
|
+
error: new OpenfortError("Embedded wallet not found for address", OpenfortErrorType.WALLET_ERROR),
|
|
11184
|
+
options: optionsObject,
|
|
11185
|
+
hookOptions
|
|
11186
|
+
});
|
|
11187
|
+
}
|
|
11188
|
+
await client.embeddedWallet.recover({
|
|
11189
|
+
account: walletId,
|
|
11190
|
+
shieldAuthentication,
|
|
11191
|
+
recoveryParams,
|
|
11134
11192
|
});
|
|
11135
11193
|
}
|
|
11136
11194
|
else {
|
|
11137
|
-
if (!
|
|
11138
|
-
|
|
11139
|
-
}
|
|
11140
|
-
const shieldAuth = {
|
|
11141
|
-
auth: ShieldAuthType.OPENFORT,
|
|
11142
|
-
token: accessToken,
|
|
11143
|
-
};
|
|
11144
|
-
await client.embeddedWallet.configure({
|
|
11145
|
-
chainId,
|
|
11146
|
-
recoveryParams: {
|
|
11147
|
-
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11195
|
+
if (!embeddedWallets || embeddedWallets.length === 0) {
|
|
11196
|
+
await createWallet({
|
|
11148
11197
|
password,
|
|
11149
|
-
}
|
|
11150
|
-
|
|
11151
|
-
|
|
11198
|
+
});
|
|
11199
|
+
}
|
|
11200
|
+
else {
|
|
11201
|
+
await client.embeddedWallet.recover({
|
|
11202
|
+
account: embeddedWallets[0].id,
|
|
11203
|
+
shieldAuthentication,
|
|
11204
|
+
recoveryParams,
|
|
11205
|
+
});
|
|
11206
|
+
}
|
|
11152
11207
|
}
|
|
11153
11208
|
setStatus({
|
|
11154
11209
|
status: 'success',
|
|
11155
11210
|
});
|
|
11156
|
-
return {
|
|
11157
|
-
|
|
11158
|
-
|
|
11159
|
-
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11211
|
+
return onSuccess({
|
|
11212
|
+
data: {
|
|
11213
|
+
wallet: createOpenfortWallet({
|
|
11214
|
+
address: optionsObject.address,
|
|
11215
|
+
isActive: true,
|
|
11216
|
+
}),
|
|
11217
|
+
},
|
|
11218
|
+
options: optionsObject,
|
|
11219
|
+
hookOptions,
|
|
11220
|
+
});
|
|
11163
11221
|
}
|
|
11164
11222
|
catch (err) {
|
|
11165
11223
|
log('Error handling recovery with Openfort:', err);
|
|
11166
11224
|
if (err instanceof MissingRecoveryPasswordError) {
|
|
11167
|
-
return {
|
|
11168
|
-
error: "Missing recovery password",
|
|
11169
|
-
|
|
11225
|
+
return onError({
|
|
11226
|
+
error: new OpenfortError("Missing recovery password", OpenfortErrorType.WALLET_ERROR),
|
|
11227
|
+
options: optionsObject,
|
|
11228
|
+
hookOptions
|
|
11229
|
+
});
|
|
11170
11230
|
}
|
|
11171
11231
|
if (typeof err === 'string') {
|
|
11172
|
-
return {
|
|
11173
|
-
error: err,
|
|
11174
|
-
|
|
11232
|
+
return onError({
|
|
11233
|
+
error: new OpenfortError(err, OpenfortErrorType.WALLET_ERROR),
|
|
11234
|
+
options: optionsObject,
|
|
11235
|
+
hookOptions
|
|
11236
|
+
});
|
|
11175
11237
|
}
|
|
11176
11238
|
// setStatus({
|
|
11177
11239
|
// status: 'error',
|
|
11178
11240
|
// error: new Error("Failed to connect with embedded wallet: " + err),
|
|
11179
11241
|
// });
|
|
11180
|
-
return {
|
|
11181
|
-
error: "The recovery phrase you entered is incorrect.",
|
|
11182
|
-
|
|
11242
|
+
return onError({
|
|
11243
|
+
error: new OpenfortError("The recovery phrase you entered is incorrect.", OpenfortErrorType.WALLET_ERROR),
|
|
11244
|
+
options: optionsObject,
|
|
11245
|
+
hookOptions
|
|
11246
|
+
});
|
|
11183
11247
|
}
|
|
11184
11248
|
}
|
|
11185
11249
|
else {
|
|
@@ -11193,15 +11257,68 @@ function useWallets() {
|
|
|
11193
11257
|
}
|
|
11194
11258
|
return {};
|
|
11195
11259
|
}, [wallets, setOpen, setRoute, setConnector, disconnect, log, isConnected, address, usesEmbeddedWallet, isEmbedded]);
|
|
11196
|
-
useCallback(() => {
|
|
11197
|
-
|
|
11198
|
-
|
|
11260
|
+
const createWallet = useCallback(async ({ password, ...options } = {}) => {
|
|
11261
|
+
var _a;
|
|
11262
|
+
setStatus({
|
|
11263
|
+
status: 'loading',
|
|
11264
|
+
});
|
|
11265
|
+
const accessToken = await client.getAccessToken();
|
|
11266
|
+
if (!accessToken) {
|
|
11267
|
+
return onError({
|
|
11268
|
+
error: new OpenfortError("Openfort access token not found", OpenfortErrorType.WALLET_ERROR),
|
|
11269
|
+
hookOptions,
|
|
11270
|
+
options,
|
|
11271
|
+
});
|
|
11272
|
+
}
|
|
11273
|
+
if (!walletConfig) {
|
|
11274
|
+
return onError({
|
|
11275
|
+
error: new OpenfortError("Embedded signer not enabled", OpenfortErrorType.WALLET_ERROR),
|
|
11276
|
+
hookOptions,
|
|
11277
|
+
options,
|
|
11278
|
+
});
|
|
11279
|
+
}
|
|
11280
|
+
const shieldAuthentication = password ? {
|
|
11281
|
+
auth: ShieldAuthType.OPENFORT,
|
|
11282
|
+
token: accessToken,
|
|
11283
|
+
} : {
|
|
11284
|
+
auth: ShieldAuthType.OPENFORT,
|
|
11285
|
+
token: accessToken,
|
|
11286
|
+
encryptionSession: walletConfig.getEncryptionSession ?
|
|
11287
|
+
await walletConfig.getEncryptionSession() :
|
|
11288
|
+
await getEncryptionSession(),
|
|
11289
|
+
};
|
|
11290
|
+
const recoveryParams = password ? {
|
|
11291
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11292
|
+
password,
|
|
11293
|
+
} : {
|
|
11294
|
+
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
11295
|
+
};
|
|
11296
|
+
const wallet = await client.embeddedWallet.create({
|
|
11297
|
+
chainId: (_a = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.initialChainId) !== null && _a !== void 0 ? _a : chainId,
|
|
11298
|
+
accountType: AccountTypeEnum.SMART_ACCOUNT,
|
|
11299
|
+
chainType: ChainTypeEnum.EVM,
|
|
11300
|
+
recoveryParams,
|
|
11301
|
+
shieldAuthentication
|
|
11302
|
+
});
|
|
11303
|
+
setStatus({
|
|
11304
|
+
status: 'success',
|
|
11305
|
+
});
|
|
11306
|
+
refetch();
|
|
11307
|
+
return onSuccess({
|
|
11308
|
+
data: {
|
|
11309
|
+
wallet: createOpenfortWallet({
|
|
11310
|
+
address: wallet.address,
|
|
11311
|
+
isActive: true,
|
|
11312
|
+
})
|
|
11313
|
+
}
|
|
11314
|
+
});
|
|
11315
|
+
}, [refetch, client, uiConfig, chainId]);
|
|
11199
11316
|
return {
|
|
11200
11317
|
wallets,
|
|
11201
11318
|
availableWallets: deviceWallets,
|
|
11202
11319
|
activeWallet,
|
|
11203
11320
|
setActiveWallet,
|
|
11204
|
-
|
|
11321
|
+
createWallet,
|
|
11205
11322
|
...mapStatus(status),
|
|
11206
11323
|
exportPrivateKey: client.embeddedWallet.exportPrivateKey,
|
|
11207
11324
|
};
|
|
@@ -11223,7 +11340,7 @@ const Recover = () => {
|
|
|
11223
11340
|
});
|
|
11224
11341
|
setLoading(false);
|
|
11225
11342
|
if (error) {
|
|
11226
|
-
setRecoveryError(error || "There was an error recovering your account");
|
|
11343
|
+
setRecoveryError(error.message || "There was an error recovering your account");
|
|
11227
11344
|
}
|
|
11228
11345
|
else {
|
|
11229
11346
|
log("Recovery success");
|
|
@@ -11239,7 +11356,7 @@ const Recover = () => {
|
|
|
11239
11356
|
}, children: [jsx(Input, { value: recoveryPhrase, onChange: (e) => setRecoveryPhrase(e.target.value), type: "password", placeholder: "Enter your password", autoComplete: "off" }), recoveryError && (jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, children: jsx(ModalBody, { style: { height: 24, marginTop: 12 }, "$error": true, children: jsx(FitText, { children: recoveryError }) }) }, recoveryError)), jsx(Button, { onClick: handleSubmit, waiting: loading, disabled: loading, children: "Enter" })] })] }));
|
|
11240
11357
|
};
|
|
11241
11358
|
const AutomaticRecovery = () => {
|
|
11242
|
-
const { needsRecovery } =
|
|
11359
|
+
const { needsRecovery } = useOpenfortCore();
|
|
11243
11360
|
const { setActiveWallet } = useWallets();
|
|
11244
11361
|
const { log } = useOpenfortKit();
|
|
11245
11362
|
const [hasRecoveryMethod, setHasRecoveryMethod] = React.useState(false);
|
|
@@ -11250,7 +11367,8 @@ const AutomaticRecovery = () => {
|
|
|
11250
11367
|
const response = await setActiveWallet({
|
|
11251
11368
|
connector: embeddedWalletId,
|
|
11252
11369
|
});
|
|
11253
|
-
|
|
11370
|
+
// TODO: Handle error properly
|
|
11371
|
+
if (response.error && response.error.message === "Missing recovery password") {
|
|
11254
11372
|
setHasRecoveryMethod(true);
|
|
11255
11373
|
}
|
|
11256
11374
|
}
|
|
@@ -11272,7 +11390,7 @@ const Connected = () => {
|
|
|
11272
11390
|
return (jsx(PageContent, { children: jsx(Loader, { isLoading: false, reason: "Connected" }) }));
|
|
11273
11391
|
};
|
|
11274
11392
|
const CreateEmbeddedSigner = () => {
|
|
11275
|
-
const { needsRecovery, user } =
|
|
11393
|
+
const { needsRecovery, user } = useOpenfortCore();
|
|
11276
11394
|
const { triggerResize, uiConfig, walletConfig, setRoute } = useOpenfortKit();
|
|
11277
11395
|
const [loading, setLoading] = React.useState(true);
|
|
11278
11396
|
const [embeddedSignerLoading, setEmbeddedSignerLoading] = React.useState(true);
|
|
@@ -11326,7 +11444,7 @@ const customThemeDefault = {};
|
|
|
11326
11444
|
const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customThemeDefault, lang = 'en-US' }) => {
|
|
11327
11445
|
var _a;
|
|
11328
11446
|
const context = useOpenfortKit();
|
|
11329
|
-
const { logout, user } =
|
|
11447
|
+
const { logout, user } = useOpenfortCore();
|
|
11330
11448
|
const { isConnected, chain } = useAccount();
|
|
11331
11449
|
const chainIsSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
|
|
11332
11450
|
//if chain is unsupported we enforce a "switch chain" prompt
|
|
@@ -11455,30 +11573,30 @@ const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customTheme
|
|
|
11455
11573
|
};
|
|
11456
11574
|
|
|
11457
11575
|
/**
|
|
11458
|
-
*
|
|
11576
|
+
* OpenfortProvider component provides context and configuration for OpenfortKit.
|
|
11459
11577
|
* It must be used within a WagmiProvider.
|
|
11460
11578
|
*
|
|
11461
11579
|
* @param {React.ReactNode} children - The child components to be wrapped by the provider.
|
|
11462
11580
|
* @param {string} [theme='auto'] - The theme to be used, default is 'auto'.
|
|
11463
11581
|
* @param {string} [mode='auto'] - The mode to be used, default is 'auto'.
|
|
11464
11582
|
* @param {CustomTheme} [customTheme] - Custom theme configuration.
|
|
11465
|
-
* @param {
|
|
11583
|
+
* @param {ConnectUIOptions} [options] - Additional configuration options.
|
|
11466
11584
|
* @param {Function} [onConnect] - Callback function to be called on connect.
|
|
11467
11585
|
* @param {Function} [onDisconnect] - Callback function to be called on disconnect.
|
|
11468
11586
|
* @param {boolean} [debugMode=false] - Enable or disable debug mode, default is false.
|
|
11469
11587
|
* @param {OpenfortOptions} [openfortOptions] - Options for Openfort integration.
|
|
11470
11588
|
* @throws Will throw an error if used outside of a WagmiProvider or if nested usages are detected.
|
|
11471
11589
|
*/
|
|
11472
|
-
const
|
|
11590
|
+
const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMode = false, publishableKey, walletConfig, }) => {
|
|
11473
11591
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11474
|
-
//
|
|
11592
|
+
// OpenfortProvider must be within a WagmiProvider
|
|
11475
11593
|
if (!React.useContext(WagmiContext)) {
|
|
11476
|
-
throw Error('
|
|
11594
|
+
throw Error('OpenfortProvider must be within a WagmiProvider');
|
|
11477
11595
|
}
|
|
11478
|
-
// Only allow for mounting
|
|
11596
|
+
// Only allow for mounting OpenfortProvider once, so we avoid weird global
|
|
11479
11597
|
// state collisions.
|
|
11480
11598
|
if (React.useContext(OpenfortKitContext)) {
|
|
11481
|
-
throw new Error('Multiple, nested usages of
|
|
11599
|
+
throw new Error('Multiple, nested usages of OpenfortProvider detected. Please use only one.');
|
|
11482
11600
|
}
|
|
11483
11601
|
const chains = useChains();
|
|
11484
11602
|
const injectedConnector = useConnector('injected');
|
|
@@ -11596,7 +11714,7 @@ const OpenfortKitProvider = ({ children, uiConfig, onConnect, onDisconnect, debu
|
|
|
11596
11714
|
triggerResize: () => onResize((prev) => prev + 1),
|
|
11597
11715
|
walletConfig,
|
|
11598
11716
|
};
|
|
11599
|
-
return createElement(OpenfortKitContext.Provider, { value }, jsx(Fragment, { children: jsx(Web3ContextProvider, { enabled: open, children: jsxs(
|
|
11717
|
+
return createElement(OpenfortKitContext.Provider, { value }, jsx(Fragment, { children: jsx(Web3ContextProvider, { enabled: open, children: jsxs(CoreOpenfortProvider, { baseConfiguration: {
|
|
11600
11718
|
publishableKey,
|
|
11601
11719
|
}, shieldConfiguration: walletConfig ? {
|
|
11602
11720
|
shieldPublishableKey: walletConfig.shieldPublishableKey,
|
|
@@ -11855,7 +11973,7 @@ const allRoutes = [
|
|
|
11855
11973
|
];
|
|
11856
11974
|
function useUI() {
|
|
11857
11975
|
const { open, setOpen, setRoute, log } = useOpenfortKit();
|
|
11858
|
-
const { isLoading, user, needsRecovery } =
|
|
11976
|
+
const { isLoading, user, needsRecovery } = useOpenfortCore();
|
|
11859
11977
|
const { isConnected } = useAccount();
|
|
11860
11978
|
function defaultOpen() {
|
|
11861
11979
|
setOpen(true);
|
|
@@ -12014,7 +12132,7 @@ const ConnectButtonRenderer = ({ children, }) => {
|
|
|
12014
12132
|
};
|
|
12015
12133
|
ConnectButtonRenderer.displayName = 'OpenfortKitButton.Custom';
|
|
12016
12134
|
const ConnectedLabel = ({ separator }) => {
|
|
12017
|
-
const { user, isLoading } =
|
|
12135
|
+
const { user, isLoading } = useOpenfortCore();
|
|
12018
12136
|
const { address } = useAccount();
|
|
12019
12137
|
if (address && (user || isLoading))
|
|
12020
12138
|
return truncateEthAddress(address, separator);
|
|
@@ -12026,7 +12144,7 @@ const ConnectedLabel = ({ separator }) => {
|
|
|
12026
12144
|
};
|
|
12027
12145
|
function OpenfortKitButtonInner({ label, showAvatar, separator, }) {
|
|
12028
12146
|
const locales = useLocales({});
|
|
12029
|
-
const { user } =
|
|
12147
|
+
const { user } = useOpenfortCore();
|
|
12030
12148
|
const { address, chain } = useAccount();
|
|
12031
12149
|
const isChainSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
|
|
12032
12150
|
const ensFallbackConfig = useEnsFallbackConfig();
|
|
@@ -12117,44 +12235,41 @@ OpenfortKitButton.Custom = ConnectButtonRenderer;
|
|
|
12117
12235
|
|
|
12118
12236
|
var OpenfortKitStatus;
|
|
12119
12237
|
(function (OpenfortKitStatus) {
|
|
12120
|
-
OpenfortKitStatus[OpenfortKitStatus["
|
|
12121
|
-
OpenfortKitStatus[OpenfortKitStatus["
|
|
12122
|
-
OpenfortKitStatus[OpenfortKitStatus["
|
|
12123
|
-
OpenfortKitStatus[OpenfortKitStatus["
|
|
12124
|
-
OpenfortKitStatus[OpenfortKitStatus["CONNECTED_WITHOUT_USER"] = 4] = "CONNECTED_WITHOUT_USER";
|
|
12238
|
+
OpenfortKitStatus[OpenfortKitStatus["DISCONNECTED"] = 0] = "DISCONNECTED";
|
|
12239
|
+
OpenfortKitStatus[OpenfortKitStatus["NEEDS_RECOVERY"] = 1] = "NEEDS_RECOVERY";
|
|
12240
|
+
OpenfortKitStatus[OpenfortKitStatus["LOADING"] = 2] = "LOADING";
|
|
12241
|
+
OpenfortKitStatus[OpenfortKitStatus["CONNECTED"] = 3] = "CONNECTED";
|
|
12125
12242
|
})(OpenfortKitStatus || (OpenfortKitStatus = {}));
|
|
12126
12243
|
function useStatus() {
|
|
12127
|
-
const {
|
|
12128
|
-
const { isConnected } = useAccount();
|
|
12244
|
+
const { embeddedState } = useOpenfortCore();
|
|
12245
|
+
const { isConnected, isConnecting } = useAccount();
|
|
12129
12246
|
const getStatus = () => {
|
|
12130
|
-
if (
|
|
12247
|
+
if (embeddedState === EmbeddedState.READY)
|
|
12248
|
+
return OpenfortKitStatus.CONNECTED;
|
|
12249
|
+
if (embeddedState === EmbeddedState.NONE)
|
|
12131
12250
|
return OpenfortKitStatus.LOADING;
|
|
12132
|
-
if (needsRecovery)
|
|
12133
|
-
|
|
12134
|
-
if (!user) {
|
|
12251
|
+
// if (needsRecovery) return OpenfortKitStatus.NEEDS_RECOVERY;
|
|
12252
|
+
if (embeddedState === EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED) {
|
|
12135
12253
|
if (isConnected)
|
|
12136
|
-
return OpenfortKitStatus.
|
|
12254
|
+
return OpenfortKitStatus.CONNECTED;
|
|
12137
12255
|
else
|
|
12138
|
-
return OpenfortKitStatus.
|
|
12256
|
+
return OpenfortKitStatus.NEEDS_RECOVERY;
|
|
12139
12257
|
}
|
|
12140
|
-
|
|
12141
|
-
return OpenfortKitStatus.NEEDS_RECOVERY;
|
|
12142
|
-
return OpenfortKitStatus.CONNECTED;
|
|
12258
|
+
return OpenfortKitStatus.DISCONNECTED;
|
|
12143
12259
|
};
|
|
12144
12260
|
const status = getStatus();
|
|
12145
12261
|
return {
|
|
12146
|
-
status,
|
|
12147
12262
|
isLoading: status === OpenfortKitStatus.LOADING,
|
|
12148
|
-
hasUser: !!user,
|
|
12149
12263
|
isConnected: status === OpenfortKitStatus.CONNECTED,
|
|
12150
12264
|
isDisconnected: status === OpenfortKitStatus.DISCONNECTED,
|
|
12151
|
-
|
|
12152
|
-
|
|
12265
|
+
isConnecting: isConnecting || embeddedState === EmbeddedState.CREATING_ACCOUNT,
|
|
12266
|
+
isAuthenticated: embeddedState !== EmbeddedState.NONE && embeddedState !== EmbeddedState.UNAUTHENTICATED,
|
|
12153
12267
|
};
|
|
12154
12268
|
}
|
|
12155
12269
|
|
|
12156
12270
|
function useUser() {
|
|
12157
|
-
const { user, client } =
|
|
12271
|
+
const { user, client } = useOpenfortCore();
|
|
12272
|
+
const { isAuthenticated } = useStatus();
|
|
12158
12273
|
const getAccessTokenAndUpdate = useCallback(async () => {
|
|
12159
12274
|
await client.validateAndRefreshToken();
|
|
12160
12275
|
const token = await client.getAccessToken();
|
|
@@ -12162,11 +12277,17 @@ function useUser() {
|
|
|
12162
12277
|
}, [client]);
|
|
12163
12278
|
return {
|
|
12164
12279
|
user,
|
|
12280
|
+
isAuthenticated,
|
|
12165
12281
|
getAccessToken: getAccessTokenAndUpdate,
|
|
12166
12282
|
validateAndRefreshToken: async () => await client.validateAndRefreshToken(),
|
|
12167
12283
|
};
|
|
12168
12284
|
}
|
|
12169
12285
|
|
|
12286
|
+
function useWallet() {
|
|
12287
|
+
const { activeWallet } = useWallets();
|
|
12288
|
+
return activeWallet;
|
|
12289
|
+
}
|
|
12290
|
+
|
|
12170
12291
|
const buildCallbackUrl = ({ email, callbackUrl, provider, }) => {
|
|
12171
12292
|
if (callbackUrl && !callbackUrl.startsWith("http")) {
|
|
12172
12293
|
callbackUrl = `${window.location.origin}${callbackUrl.startsWith("/") ? "" : "/"}${callbackUrl}`;
|
|
@@ -12179,25 +12300,6 @@ const buildCallbackUrl = ({ email, callbackUrl, provider, }) => {
|
|
|
12179
12300
|
return redirectUrl.toString();
|
|
12180
12301
|
};
|
|
12181
12302
|
|
|
12182
|
-
const onSuccess = ({ hookOptions, options, data, }) => {
|
|
12183
|
-
var _a, _b, _c, _d;
|
|
12184
|
-
(_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onSuccess) === null || _a === void 0 ? void 0 : _a.call(hookOptions, data);
|
|
12185
|
-
(_b = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onSettled) === null || _b === void 0 ? void 0 : _b.call(hookOptions, data, null);
|
|
12186
|
-
(_c = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _c === void 0 ? void 0 : _c.call(options, data);
|
|
12187
|
-
(_d = options === null || options === void 0 ? void 0 : options.onSettled) === null || _d === void 0 ? void 0 : _d.call(options, data, null);
|
|
12188
|
-
return data;
|
|
12189
|
-
};
|
|
12190
|
-
const onError = ({ hookOptions, options, error, }) => {
|
|
12191
|
-
var _a, _b, _c, _d;
|
|
12192
|
-
(_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onError) === null || _a === void 0 ? void 0 : _a.call(hookOptions, error);
|
|
12193
|
-
(_b = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onSettled) === null || _b === void 0 ? void 0 : _b.call(hookOptions, null, error);
|
|
12194
|
-
(_c = options === null || options === void 0 ? void 0 : options.onError) === null || _c === void 0 ? void 0 : _c.call(options, error);
|
|
12195
|
-
(_d = options === null || options === void 0 ? void 0 : options.onSettled) === null || _d === void 0 ? void 0 : _d.call(options, null, error);
|
|
12196
|
-
if ((hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.throwOnError) || (options === null || options === void 0 ? void 0 : options.throwOnError))
|
|
12197
|
-
throw error;
|
|
12198
|
-
return { error };
|
|
12199
|
-
};
|
|
12200
|
-
|
|
12201
12303
|
// this hook is used to create a wallet after the user has authenticated
|
|
12202
12304
|
const useCreateWalletPostAuth = () => {
|
|
12203
12305
|
const { setActiveWallet } = useWallets();
|
|
@@ -12216,7 +12318,7 @@ const useCreateWalletPostAuth = () => {
|
|
|
12216
12318
|
|
|
12217
12319
|
const useEmailAuth = (hookOptions = {}) => {
|
|
12218
12320
|
const { log } = useOpenfortKit();
|
|
12219
|
-
const { client, updateUser } =
|
|
12321
|
+
const { client, updateUser } = useOpenfortCore();
|
|
12220
12322
|
const [requiresEmailVerification, setRequiresEmailVerification] = useState(false);
|
|
12221
12323
|
const [status, setStatus] = useState({
|
|
12222
12324
|
status: "idle",
|
|
@@ -12273,7 +12375,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12273
12375
|
}
|
|
12274
12376
|
}
|
|
12275
12377
|
catch (e) {
|
|
12276
|
-
const error = new
|
|
12378
|
+
const error = new OpenfortError("Failed to login with email and password", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12277
12379
|
setStatus({
|
|
12278
12380
|
status: 'error',
|
|
12279
12381
|
error: error
|
|
@@ -12311,7 +12413,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12311
12413
|
});
|
|
12312
12414
|
}
|
|
12313
12415
|
catch (e) {
|
|
12314
|
-
const error = new
|
|
12416
|
+
const error = new OpenfortError("Failed to reset password", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12315
12417
|
setStatus({
|
|
12316
12418
|
status: 'error',
|
|
12317
12419
|
error
|
|
@@ -12345,7 +12447,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12345
12447
|
});
|
|
12346
12448
|
}
|
|
12347
12449
|
catch (e) {
|
|
12348
|
-
const error = new
|
|
12450
|
+
const error = new OpenfortError("Failed to reset password", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12349
12451
|
setStatus({
|
|
12350
12452
|
status: 'error',
|
|
12351
12453
|
error
|
|
@@ -12403,7 +12505,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12403
12505
|
}
|
|
12404
12506
|
}
|
|
12405
12507
|
catch (e) {
|
|
12406
|
-
const error = new
|
|
12508
|
+
const error = new OpenfortError("Failed to login with email and password", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12407
12509
|
setStatus({
|
|
12408
12510
|
status: 'error',
|
|
12409
12511
|
error
|
|
@@ -12422,7 +12524,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12422
12524
|
const authToken = await client.getAccessToken();
|
|
12423
12525
|
if (!authToken) {
|
|
12424
12526
|
log("No token found");
|
|
12425
|
-
const error = new
|
|
12527
|
+
const error = new OpenfortError("No token found", OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
12426
12528
|
setStatus({
|
|
12427
12529
|
status: 'error',
|
|
12428
12530
|
error
|
|
@@ -12468,7 +12570,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12468
12570
|
}
|
|
12469
12571
|
}
|
|
12470
12572
|
catch (e) {
|
|
12471
|
-
const error = new
|
|
12573
|
+
const error = new OpenfortError("Failed to link email", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12472
12574
|
setStatus({
|
|
12473
12575
|
status: 'error',
|
|
12474
12576
|
error: error
|
|
@@ -12499,7 +12601,7 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12499
12601
|
const [status, setStatus] = useState({
|
|
12500
12602
|
status: "idle",
|
|
12501
12603
|
});
|
|
12502
|
-
const { client, updateUser } =
|
|
12604
|
+
const { client, updateUser } = useOpenfortCore();
|
|
12503
12605
|
const [provider, setProvider] = useState(null);
|
|
12504
12606
|
const [email, setEmail] = useState(null);
|
|
12505
12607
|
const { tryUseWallet } = useCreateWalletPostAuth();
|
|
@@ -12523,7 +12625,7 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12523
12625
|
});
|
|
12524
12626
|
}
|
|
12525
12627
|
catch (e) {
|
|
12526
|
-
const error = new
|
|
12628
|
+
const error = new OpenfortError("Failed to verify email", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12527
12629
|
setStatus({
|
|
12528
12630
|
status: 'error',
|
|
12529
12631
|
error,
|
|
@@ -12559,7 +12661,7 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12559
12661
|
});
|
|
12560
12662
|
}
|
|
12561
12663
|
catch (e) {
|
|
12562
|
-
const error = new
|
|
12664
|
+
const error = new OpenfortError("Failed to store credentials", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12563
12665
|
setStatus({
|
|
12564
12666
|
status: 'error',
|
|
12565
12667
|
error,
|
|
@@ -12594,7 +12696,7 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12594
12696
|
onError({
|
|
12595
12697
|
hookOptions,
|
|
12596
12698
|
options: {},
|
|
12597
|
-
error: new
|
|
12699
|
+
error: new OpenfortError("No state or email found in URL", OpenfortErrorType.AUTHENTICATION_ERROR),
|
|
12598
12700
|
});
|
|
12599
12701
|
return;
|
|
12600
12702
|
}
|
|
@@ -12620,7 +12722,7 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12620
12722
|
onError({
|
|
12621
12723
|
hookOptions,
|
|
12622
12724
|
options: {},
|
|
12623
|
-
error: new
|
|
12725
|
+
error: new OpenfortError("Missing player id or access token or refresh token", OpenfortErrorType.AUTHENTICATION_ERROR),
|
|
12624
12726
|
});
|
|
12625
12727
|
return;
|
|
12626
12728
|
}
|
|
@@ -12649,7 +12751,7 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12649
12751
|
};
|
|
12650
12752
|
|
|
12651
12753
|
const useGuestAuth = (hookOptions = {}) => {
|
|
12652
|
-
const { client, updateUser } =
|
|
12754
|
+
const { client, updateUser } = useOpenfortCore();
|
|
12653
12755
|
const [status, setStatus] = useState({
|
|
12654
12756
|
status: "idle",
|
|
12655
12757
|
});
|
|
@@ -12674,15 +12776,15 @@ const useGuestAuth = (hookOptions = {}) => {
|
|
|
12674
12776
|
return { user, wallet };
|
|
12675
12777
|
}
|
|
12676
12778
|
catch (error) {
|
|
12677
|
-
const
|
|
12779
|
+
const openfortError = new OpenfortError("Failed to signup guest", OpenfortErrorType.AUTHENTICATION_ERROR, { error });
|
|
12678
12780
|
setStatus({
|
|
12679
12781
|
status: 'error',
|
|
12680
|
-
error:
|
|
12782
|
+
error: openfortError,
|
|
12681
12783
|
});
|
|
12682
12784
|
return onError({
|
|
12683
12785
|
hookOptions,
|
|
12684
12786
|
options,
|
|
12685
|
-
error:
|
|
12787
|
+
error: openfortError,
|
|
12686
12788
|
});
|
|
12687
12789
|
}
|
|
12688
12790
|
}, [client, setStatus, updateUser, hookOptions]);
|
|
@@ -12693,12 +12795,14 @@ const useGuestAuth = (hookOptions = {}) => {
|
|
|
12693
12795
|
};
|
|
12694
12796
|
|
|
12695
12797
|
const useWalletAuth = (hookOptions = {}) => {
|
|
12696
|
-
const { updateUser } =
|
|
12798
|
+
const { updateUser } = useOpenfortCore();
|
|
12697
12799
|
const { log } = useOpenfortKit();
|
|
12698
12800
|
const siwe = useConnectWithSiwe();
|
|
12699
12801
|
const availableWallets = useWallets$1(); // TODO: Use this to get the wallet client type
|
|
12700
12802
|
const { disconnect } = useDisconnect();
|
|
12701
12803
|
const [walletConnectingTo, setWalletConnectingTo] = useState(null);
|
|
12804
|
+
const [shouldConnectWithSiwe, setShouldConnectWithSiwe] = useState(false);
|
|
12805
|
+
useAccount();
|
|
12702
12806
|
const [status, setStatus] = useState({
|
|
12703
12807
|
status: "idle",
|
|
12704
12808
|
});
|
|
@@ -12716,32 +12820,39 @@ const useWalletAuth = (hookOptions = {}) => {
|
|
|
12716
12820
|
const { connectAsync } = useConnect({
|
|
12717
12821
|
mutation: {
|
|
12718
12822
|
onError: (e) => {
|
|
12719
|
-
const error = new
|
|
12823
|
+
const error = new OpenfortError("Failed to connect with wallet", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12720
12824
|
handleError(error);
|
|
12721
12825
|
},
|
|
12722
12826
|
onSuccess: () => {
|
|
12723
|
-
|
|
12724
|
-
onError: (e) => {
|
|
12725
|
-
log("Error connecting with SIWE", e);
|
|
12726
|
-
disconnect();
|
|
12727
|
-
const error = new OpenfortKitError("Failed to connect with siwe", OpenfortKitErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12728
|
-
handleError(error);
|
|
12729
|
-
},
|
|
12730
|
-
onConnect: () => {
|
|
12731
|
-
log("Successfully connected with SIWE");
|
|
12732
|
-
setStatus({
|
|
12733
|
-
status: 'success',
|
|
12734
|
-
});
|
|
12735
|
-
updateUser();
|
|
12736
|
-
onSuccess({
|
|
12737
|
-
hookOptions,
|
|
12738
|
-
data: {},
|
|
12739
|
-
});
|
|
12740
|
-
},
|
|
12741
|
-
});
|
|
12827
|
+
setShouldConnectWithSiwe(true);
|
|
12742
12828
|
}
|
|
12743
12829
|
}
|
|
12744
12830
|
});
|
|
12831
|
+
useEffect(() => {
|
|
12832
|
+
// Ensure it has been connected with a wallet before connecting with SIWE
|
|
12833
|
+
if (!shouldConnectWithSiwe)
|
|
12834
|
+
return;
|
|
12835
|
+
setShouldConnectWithSiwe(false);
|
|
12836
|
+
siwe({
|
|
12837
|
+
onError: (e) => {
|
|
12838
|
+
log("Error connecting with SIWE", e);
|
|
12839
|
+
disconnect();
|
|
12840
|
+
const error = new OpenfortError("Failed to connect with siwe", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12841
|
+
handleError(error);
|
|
12842
|
+
},
|
|
12843
|
+
onConnect: () => {
|
|
12844
|
+
log("Successfully connected with SIWE");
|
|
12845
|
+
setStatus({
|
|
12846
|
+
status: 'success',
|
|
12847
|
+
});
|
|
12848
|
+
updateUser();
|
|
12849
|
+
onSuccess({
|
|
12850
|
+
hookOptions,
|
|
12851
|
+
data: {},
|
|
12852
|
+
});
|
|
12853
|
+
},
|
|
12854
|
+
});
|
|
12855
|
+
}, [shouldConnectWithSiwe, siwe, updateUser, log]);
|
|
12745
12856
|
// const generateSiweMessage = useCallback(
|
|
12746
12857
|
// async (args) => {
|
|
12747
12858
|
// try {
|
|
@@ -12827,7 +12938,7 @@ const useWalletAuth = (hookOptions = {}) => {
|
|
|
12827
12938
|
}
|
|
12828
12939
|
if (!connector) {
|
|
12829
12940
|
log("Connector not found", connector);
|
|
12830
|
-
return handleError(new
|
|
12941
|
+
return handleError(new OpenfortError("Connector not found", OpenfortErrorType.AUTHENTICATION_ERROR));
|
|
12831
12942
|
}
|
|
12832
12943
|
setWalletConnectingTo(connector.id);
|
|
12833
12944
|
const hasDisconnected = new Promise((resolve) => {
|
|
@@ -12837,7 +12948,7 @@ const useWalletAuth = (hookOptions = {}) => {
|
|
|
12837
12948
|
},
|
|
12838
12949
|
onError: (e) => {
|
|
12839
12950
|
console.error("Error disconnecting", e);
|
|
12840
|
-
const error = new
|
|
12951
|
+
const error = new OpenfortError("Failed to disconnect", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12841
12952
|
handleError(error);
|
|
12842
12953
|
resolve();
|
|
12843
12954
|
},
|
|
@@ -12848,11 +12959,11 @@ const useWalletAuth = (hookOptions = {}) => {
|
|
|
12848
12959
|
await connectAsync({
|
|
12849
12960
|
connector,
|
|
12850
12961
|
});
|
|
12851
|
-
|
|
12962
|
+
log("Connected to wallet!!!", connector.id);
|
|
12852
12963
|
}
|
|
12853
12964
|
catch (error) {
|
|
12854
12965
|
console.error("Error connecting", error);
|
|
12855
|
-
handleError(new
|
|
12966
|
+
handleError(new OpenfortError("Failed to connect", OpenfortErrorType.AUTHENTICATION_ERROR, { error }));
|
|
12856
12967
|
}
|
|
12857
12968
|
}, [siwe, disconnect, updateUser, availableWallets, log, setStatus, hookOptions]);
|
|
12858
12969
|
return {
|
|
@@ -12882,7 +12993,7 @@ function getOAuthProvider(provider) {
|
|
|
12882
12993
|
return providerToAuthProvider[provider];
|
|
12883
12994
|
}
|
|
12884
12995
|
const useOAuth = (hookOptions = {}) => {
|
|
12885
|
-
const { client, updateUser } =
|
|
12996
|
+
const { client, updateUser } = useOpenfortCore();
|
|
12886
12997
|
const [status, setStatus] = useState({
|
|
12887
12998
|
status: "idle",
|
|
12888
12999
|
});
|
|
@@ -12909,7 +13020,7 @@ const useOAuth = (hookOptions = {}) => {
|
|
|
12909
13020
|
});
|
|
12910
13021
|
}
|
|
12911
13022
|
catch (e) {
|
|
12912
|
-
const error = new
|
|
13023
|
+
const error = new OpenfortError("Failed to login with OAuth", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12913
13024
|
setStatus({
|
|
12914
13025
|
status: 'error',
|
|
12915
13026
|
error
|
|
@@ -12930,7 +13041,7 @@ const useOAuth = (hookOptions = {}) => {
|
|
|
12930
13041
|
});
|
|
12931
13042
|
const authToken = await client.getAccessToken();
|
|
12932
13043
|
if (!authToken) {
|
|
12933
|
-
throw new
|
|
13044
|
+
throw new OpenfortError("No auth token found", OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
12934
13045
|
}
|
|
12935
13046
|
await client.auth.initLinkOAuth({
|
|
12936
13047
|
authToken,
|
|
@@ -12949,7 +13060,7 @@ const useOAuth = (hookOptions = {}) => {
|
|
|
12949
13060
|
});
|
|
12950
13061
|
}
|
|
12951
13062
|
catch (e) {
|
|
12952
|
-
const error = new
|
|
13063
|
+
const error = new OpenfortError("Failed to link OAuth", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12953
13064
|
setStatus({
|
|
12954
13065
|
status: 'error',
|
|
12955
13066
|
error
|
|
@@ -12969,7 +13080,7 @@ const useOAuth = (hookOptions = {}) => {
|
|
|
12969
13080
|
};
|
|
12970
13081
|
|
|
12971
13082
|
function useSignOut(hookOptions = {}) {
|
|
12972
|
-
const { client, updateUser, user } =
|
|
13083
|
+
const { client, updateUser, user } = useOpenfortCore();
|
|
12973
13084
|
const [status, setStatus] = useState({
|
|
12974
13085
|
status: "idle",
|
|
12975
13086
|
});
|
|
@@ -12996,7 +13107,7 @@ function useSignOut(hookOptions = {}) {
|
|
|
12996
13107
|
catch (error) {
|
|
12997
13108
|
setStatus({
|
|
12998
13109
|
status: 'error',
|
|
12999
|
-
error: new
|
|
13110
|
+
error: new OpenfortError('Failed to sign out', OpenfortErrorType.AUTHENTICATION_ERROR, { error }),
|
|
13000
13111
|
});
|
|
13001
13112
|
throw error;
|
|
13002
13113
|
}
|
|
@@ -13007,5 +13118,5 @@ function useSignOut(hookOptions = {}) {
|
|
|
13007
13118
|
};
|
|
13008
13119
|
}
|
|
13009
13120
|
|
|
13010
|
-
export { AuthProvider, Avatar, Chain as ChainIcon, OPENFORTKIT_VERSION,
|
|
13121
|
+
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 };
|
|
13011
13122
|
//# sourceMappingURL=index.es.js.map
|