@openfort/react 0.0.2 → 0.0.4
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 +18 -26
- package/build/components/ConnectButton/index.d.ts +3 -3
- package/build/components/Openfort/{OpenfortKit.d.ts → OpenfortProvider.d.ts} +1 -1
- package/build/components/Openfort/context.d.ts +1 -1
- package/build/components/Openfort/types.d.ts +2 -2
- package/build/components/Openfort/useOpenfort.d.ts +1 -0
- package/build/hooks/openfort/auth/useAuthCallback.d.ts +14 -29
- package/build/hooks/openfort/auth/useCreateWalletPostAuth.d.ts +12 -1
- package/build/hooks/openfort/auth/useEmailAuth.d.ts +13 -3
- package/build/hooks/openfort/auth/useGuestAuth.d.ts +2 -1
- package/build/hooks/openfort/auth/useOAuth.d.ts +20 -6
- package/build/hooks/openfort/useStatus.d.ts +1 -1
- package/build/hooks/openfort/useWallets.d.ts +16 -5
- package/build/index.d.ts +5 -5
- package/build/index.es.js +443 -343
- package/build/index.es.js.map +1 -1
- package/build/openfort/context.d.ts +1 -1
- package/build/openfort/useOpenfort.d.ts +1 -1
- package/build/styles/styled/index.d.ts +1 -1
- package/build/styles/types.d.ts +1 -1
- package/build/types.d.ts +1 -1
- package/build/version.d.ts +1 -1
- package/package.json +3 -3
- package/build/components/Openfort/useOpenfortKit.d.ts +0 -1
- /package/build/openfort/{OpenfortProvider.d.ts → CoreOpenfortProvider.d.ts} +0 -0
package/build/index.es.js
CHANGED
|
@@ -22,7 +22,7 @@ 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
|
|
25
|
+
const OPENFORT_VERSION = '0.0.4';
|
|
26
26
|
|
|
27
27
|
var OpenfortErrorType;
|
|
28
28
|
(function (OpenfortErrorType) {
|
|
@@ -94,7 +94,7 @@ const defaultConnectors = ({ app, walletConnectProjectId, coinbaseWalletPreferen
|
|
|
94
94
|
// OLD_TODO: Move these to a provider rather than global variable
|
|
95
95
|
let globalAppName;
|
|
96
96
|
const getAppName = () => globalAppName;
|
|
97
|
-
const defaultConfig = ({ appName = '
|
|
97
|
+
const defaultConfig = ({ appName = 'Openfort', appIcon, appDescription, appUrl, walletConnectProjectId, coinbaseWalletPreference, chains = [mainnet, polygon, optimism, arbitrum], client, ...props }) => {
|
|
98
98
|
var _a, _b;
|
|
99
99
|
globalAppName = appName;
|
|
100
100
|
// OLD_TODO: nice to have, automate transports based on chains, but for now just provide public if not provided
|
|
@@ -109,7 +109,7 @@ const defaultConfig = ({ appName = 'OpenfortKit', appIcon, appDescription, appUr
|
|
|
109
109
|
walletConnectProjectId,
|
|
110
110
|
coinbaseWalletPreference,
|
|
111
111
|
});
|
|
112
|
-
// console.log("
|
|
112
|
+
// console.log("OPENFORT CHAINS", chains, transports);
|
|
113
113
|
const config = {
|
|
114
114
|
...props,
|
|
115
115
|
chains,
|
|
@@ -788,7 +788,7 @@ const socialProviders = [
|
|
|
788
788
|
AuthProvider.FACEBOOK,
|
|
789
789
|
];
|
|
790
790
|
|
|
791
|
-
const
|
|
791
|
+
const Openfortcontext = createContext(null);
|
|
792
792
|
|
|
793
793
|
function useChainIsSupported(chainId) {
|
|
794
794
|
const { chains } = useConfig();
|
|
@@ -868,10 +868,10 @@ function useThemeFont(theme) {
|
|
|
868
868
|
useGoogleFont(font !== null && font !== void 0 ? font : '');
|
|
869
869
|
}
|
|
870
870
|
|
|
871
|
-
const
|
|
872
|
-
const context = React.useContext(
|
|
871
|
+
const useOpenfort = () => {
|
|
872
|
+
const context = React.useContext(Openfortcontext);
|
|
873
873
|
if (!context)
|
|
874
|
-
throw Error('
|
|
874
|
+
throw Error('Openfort Hook must be inside a Provider.');
|
|
875
875
|
return context;
|
|
876
876
|
};
|
|
877
877
|
|
|
@@ -880,7 +880,7 @@ const useOpenfortKit = () => {
|
|
|
880
880
|
* additional functionality.
|
|
881
881
|
*/
|
|
882
882
|
function useConnect({ ...props } = {}) {
|
|
883
|
-
const context =
|
|
883
|
+
const context = useOpenfort();
|
|
884
884
|
const { connect, connectAsync, connectors, ...rest } = useConnect$1({
|
|
885
885
|
...props,
|
|
886
886
|
mutation: {
|
|
@@ -997,7 +997,7 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
|
|
|
997
997
|
const { address } = useAccount();
|
|
998
998
|
const [user, setUser] = useState(null);
|
|
999
999
|
const { disconnect } = useDisconnect();
|
|
1000
|
-
const { walletConfig } =
|
|
1000
|
+
const { walletConfig } = useOpenfort();
|
|
1001
1001
|
const automaticRecovery = walletConfig && walletConfig.recoveryMethod === RecoveryMethod.AUTOMATIC;
|
|
1002
1002
|
// ---- Openfort instance ----
|
|
1003
1003
|
const openfort = useMemo(() => {
|
|
@@ -1207,7 +1207,7 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
|
|
|
1207
1207
|
* 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
1208
|
*
|
|
1209
1209
|
* 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-
|
|
1210
|
+
* https://github.com/openfort-xyz/openfort-react/discussions/new
|
|
1211
1211
|
*
|
|
1212
1212
|
*/
|
|
1213
1213
|
var styled = typeof styled$1.div === 'function' ? styled$1 : styled$1['default'];
|
|
@@ -2343,7 +2343,7 @@ const ResetContainer = styled(motion.div) `
|
|
|
2343
2343
|
|
|
2344
2344
|
const Portal = (props) => {
|
|
2345
2345
|
props = {
|
|
2346
|
-
selector: '
|
|
2346
|
+
selector: '__OPENFORT__',
|
|
2347
2347
|
...props,
|
|
2348
2348
|
};
|
|
2349
2349
|
const { selector, children } = props;
|
|
@@ -2355,7 +2355,7 @@ const Portal = (props) => {
|
|
|
2355
2355
|
if (!ref.current) {
|
|
2356
2356
|
const div = document.createElement('div');
|
|
2357
2357
|
div.setAttribute('id', selector);
|
|
2358
|
-
div.setAttribute('data-
|
|
2358
|
+
div.setAttribute('data-openfort-react', `${OPENFORT_VERSION}`);
|
|
2359
2359
|
document.body.appendChild(div);
|
|
2360
2360
|
ref.current = div;
|
|
2361
2361
|
}
|
|
@@ -3026,7 +3026,7 @@ styled(motion.div) `
|
|
|
3026
3026
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
3027
3027
|
function useLockBodyScroll(initialLocked) {
|
|
3028
3028
|
const [locked, setLocked] = useState(initialLocked);
|
|
3029
|
-
const context =
|
|
3029
|
+
const context = useOpenfort();
|
|
3030
3030
|
useIsomorphicLayoutEffect(() => {
|
|
3031
3031
|
var _a;
|
|
3032
3032
|
if (!locked)
|
|
@@ -4410,7 +4410,7 @@ export const keys = {
|
|
|
4410
4410
|
|
|
4411
4411
|
function useLocales(replacements) {
|
|
4412
4412
|
var _a, _b;
|
|
4413
|
-
const context =
|
|
4413
|
+
const context = useOpenfort();
|
|
4414
4414
|
const language = (_b = (_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.language) !== null && _b !== void 0 ? _b : 'en-US';
|
|
4415
4415
|
const translations = useMemo(() => {
|
|
4416
4416
|
return getLocale(language);
|
|
@@ -4487,7 +4487,7 @@ const useWallet$1 = (id) => {
|
|
|
4487
4487
|
};
|
|
4488
4488
|
const useWallets$1 = () => {
|
|
4489
4489
|
const connectors = useConnectors();
|
|
4490
|
-
const context =
|
|
4490
|
+
const context = useOpenfort();
|
|
4491
4491
|
const wallets = connectors.map((connector) => {
|
|
4492
4492
|
var _a, _b;
|
|
4493
4493
|
// use overrides
|
|
@@ -4772,7 +4772,7 @@ const contentVariants$2 = {
|
|
|
4772
4772
|
};
|
|
4773
4773
|
const Modal = ({ open, pages, pageId, positionInside, inline, demo, onClose, onBack, onInfo, }) => {
|
|
4774
4774
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
4775
|
-
const context =
|
|
4775
|
+
const context = useOpenfort();
|
|
4776
4776
|
const themeContext = useThemeContext();
|
|
4777
4777
|
const mobile = isMobile();
|
|
4778
4778
|
const wallet = useWallet$1((_a = context.connector) === null || _a === void 0 ? void 0 : _a.id);
|
|
@@ -5681,7 +5681,7 @@ const About = () => {
|
|
|
5681
5681
|
const locales = useLocales({
|
|
5682
5682
|
//CONNECTORNAME: connector.name,
|
|
5683
5683
|
});
|
|
5684
|
-
const context =
|
|
5684
|
+
const context = useOpenfort();
|
|
5685
5685
|
const ctaUrl = (_b = (_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.ethereumOnboardingUrl) !== null && _b !== void 0 ? _b : locales.aboutScreen_ctaUrl;
|
|
5686
5686
|
const [ready, setReady] = useState(true);
|
|
5687
5687
|
const [slider, setSlider] = useState(0);
|
|
@@ -6376,7 +6376,7 @@ const ConnectorsContainer = styled.div `
|
|
|
6376
6376
|
function useWalletConnectUri({ enabled } = {
|
|
6377
6377
|
enabled: true,
|
|
6378
6378
|
}) {
|
|
6379
|
-
const { log } =
|
|
6379
|
+
const { log } = useOpenfort();
|
|
6380
6380
|
const [uri, setUri] = useState(undefined);
|
|
6381
6381
|
const connector = useWalletConnectConnector();
|
|
6382
6382
|
const { isConnected } = useAccount();
|
|
@@ -6790,7 +6790,7 @@ const useLastConnector = () => {
|
|
|
6790
6790
|
|
|
6791
6791
|
const ConnectorList = () => {
|
|
6792
6792
|
var _a;
|
|
6793
|
-
const context =
|
|
6793
|
+
const context = useOpenfort();
|
|
6794
6794
|
const isMobile = useIsMobile();
|
|
6795
6795
|
const wallets = useWallets$1();
|
|
6796
6796
|
const { lastConnectorId } = useLastConnector();
|
|
@@ -6802,14 +6802,14 @@ const ConnectorList = () => {
|
|
|
6802
6802
|
...wallets.filter((wallet) => lastConnectorId === wallet.connector.id && wallet.id !== embeddedWalletId),
|
|
6803
6803
|
...wallets.filter((wallet) => lastConnectorId !== wallet.connector.id && wallet.id !== embeddedWalletId),
|
|
6804
6804
|
];
|
|
6805
|
-
return (jsxs(ScrollArea, { mobileDirection: 'horizontal', children: [walletsToDisplay.length === 0 && (jsx(Alert, { error: true, children: "No connectors found in
|
|
6805
|
+
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
6806
|
};
|
|
6807
6807
|
const ConnectorItem = ({ wallet, isRecent, }) => {
|
|
6808
6808
|
var _a, _b, _c, _d;
|
|
6809
6809
|
const { connect: { getUri }, } = useWeb3();
|
|
6810
6810
|
const uri = getUri();
|
|
6811
6811
|
const isMobile = useIsMobile();
|
|
6812
|
-
const context =
|
|
6812
|
+
const context = useOpenfort();
|
|
6813
6813
|
const { connect } = useConnect();
|
|
6814
6814
|
/*
|
|
6815
6815
|
const [ready, setReady] = useState(false);
|
|
@@ -6851,7 +6851,7 @@ const ConnectorItem = ({ wallet, isRecent, }) => {
|
|
|
6851
6851
|
|
|
6852
6852
|
const Wallets = () => {
|
|
6853
6853
|
var _a, _b;
|
|
6854
|
-
const context =
|
|
6854
|
+
const context = useOpenfort();
|
|
6855
6855
|
const locales = useLocales({});
|
|
6856
6856
|
const isMobile = useIsMobile();
|
|
6857
6857
|
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 +7084,7 @@ const TooltipTail = styled(motion.div) `
|
|
|
7084
7084
|
|
|
7085
7085
|
const Tooltip = ({ children, message, open, xOffset = 0, yOffset = 0, delay, }) => {
|
|
7086
7086
|
var _a;
|
|
7087
|
-
const context =
|
|
7087
|
+
const context = useOpenfort();
|
|
7088
7088
|
const themeContext = useThemeContext();
|
|
7089
7089
|
if ((_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.hideTooltips)
|
|
7090
7090
|
return jsx(Fragment, { children: children });
|
|
@@ -7265,7 +7265,7 @@ CustomQRCode.displayName = 'CustomQRCode';
|
|
|
7265
7265
|
|
|
7266
7266
|
const DownloadApp = () => {
|
|
7267
7267
|
var _a, _b, _c;
|
|
7268
|
-
const context =
|
|
7268
|
+
const context = useOpenfort();
|
|
7269
7269
|
const wallet = useWallet$1(context.connector.id);
|
|
7270
7270
|
const locales = useLocales({
|
|
7271
7271
|
CONNECTORNAME: wallet === null || wallet === void 0 ? void 0 : wallet.name,
|
|
@@ -7346,7 +7346,7 @@ const WalletList = styled.div `
|
|
|
7346
7346
|
const Container$6 = styled.div ``;
|
|
7347
7347
|
|
|
7348
7348
|
function useWalletConnectModal() {
|
|
7349
|
-
const { log } =
|
|
7349
|
+
const { log } = useOpenfort();
|
|
7350
7350
|
const { connectAsync, connectors } = useConnect();
|
|
7351
7351
|
const [isOpen, setIsOpen] = useState(false);
|
|
7352
7352
|
return {
|
|
@@ -7506,7 +7506,7 @@ const CopyToClipboard = ({ string, children, variant }) => {
|
|
|
7506
7506
|
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
7507
|
const MobileConnectors = () => {
|
|
7508
7508
|
var _a, _b;
|
|
7509
|
-
const context =
|
|
7509
|
+
const context = useOpenfort();
|
|
7510
7510
|
const locales = useLocales();
|
|
7511
7511
|
const { connect: { getUri }, } = useWeb3();
|
|
7512
7512
|
const wcUri = getUri();
|
|
@@ -7733,7 +7733,7 @@ var wave = (jsxs("svg", { "aria-hidden": "true", width: "298", height: "188", vi
|
|
|
7733
7733
|
|
|
7734
7734
|
const Introduction = () => {
|
|
7735
7735
|
var _a, _b;
|
|
7736
|
-
const context =
|
|
7736
|
+
const context = useOpenfort();
|
|
7737
7737
|
const locales = useLocales({});
|
|
7738
7738
|
const ctaUrl = (_b = (_a = context.uiConfig) === null || _a === void 0 ? void 0 : _a.walletOnboardingUrl) !== null && _b !== void 0 ? _b : locales.onboardingScreen_ctaUrl;
|
|
7739
7739
|
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 +7885,7 @@ function useEnsFallbackConfig() {
|
|
|
7885
7885
|
const Avatar = ({ address, name, size = 96, radius = 96 }) => {
|
|
7886
7886
|
var _a, _b, _c;
|
|
7887
7887
|
const isMounted = useIsMounted();
|
|
7888
|
-
const context =
|
|
7888
|
+
const context = useOpenfort();
|
|
7889
7889
|
const imageRef = useRef(null);
|
|
7890
7890
|
const [loaded, setLoaded] = useState(true);
|
|
7891
7891
|
const ensFallbackConfig = useEnsFallbackConfig();
|
|
@@ -8708,7 +8708,7 @@ const ChainSelectList = ({ variant, }) => {
|
|
|
8708
8708
|
switchChain({ chainId });
|
|
8709
8709
|
}
|
|
8710
8710
|
};
|
|
8711
|
-
const { triggerResize } =
|
|
8711
|
+
const { triggerResize } = useOpenfort();
|
|
8712
8712
|
return (jsxs(SwitchNetworksContainer, { style: { marginBottom: switchChain !== undefined ? -8 : 0 }, children: [jsx(ChainButtonContainer, { children: jsx(ChainButtons, { children: chains.map((x) => {
|
|
8713
8713
|
var _a;
|
|
8714
8714
|
const c = chainConfigs.find((ch) => ch.id === x.id);
|
|
@@ -8831,7 +8831,7 @@ const DropdownHeading = styled(motion.div) `
|
|
|
8831
8831
|
|
|
8832
8832
|
const ChainSelectDropdown = ({ children, open, onClose, offsetX = 0, offsetY = 8 }) => {
|
|
8833
8833
|
var _a, _b, _c, _d;
|
|
8834
|
-
const context =
|
|
8834
|
+
const context = useOpenfort();
|
|
8835
8835
|
const themeContext = useThemeContext();
|
|
8836
8836
|
const locales = useLocales();
|
|
8837
8837
|
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
|
@@ -9077,7 +9077,7 @@ const SwitchChainButton = styled(motion.button) `
|
|
|
9077
9077
|
`;
|
|
9078
9078
|
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
9079
|
const ChainSelector = () => {
|
|
9080
|
-
const context =
|
|
9080
|
+
const context = useOpenfort();
|
|
9081
9081
|
const [isOpen, setIsOpen] = useState(false);
|
|
9082
9082
|
const { chain } = useAccount();
|
|
9083
9083
|
const { chains } = useSwitchChain();
|
|
@@ -9102,7 +9102,7 @@ const ChainSelector = () => {
|
|
|
9102
9102
|
|
|
9103
9103
|
const PoweredByFooter = ({ showDisclaimer }) => {
|
|
9104
9104
|
var _a, _b;
|
|
9105
|
-
const { uiConfig: options } =
|
|
9105
|
+
const { uiConfig: options } = useOpenfort();
|
|
9106
9106
|
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
9107
|
window.open("https://www.openfort.xyz/", "_blank");
|
|
9108
9108
|
}, children: [jsx("span", { children: "Powered by" }), jsx(IconContainer$2, { children: jsx(Logos.Openfort, {}) }), jsx("span", { children: "Openfort" })] })] }));
|
|
@@ -9201,7 +9201,7 @@ var Wallet = ({ ...props }) => {
|
|
|
9201
9201
|
|
|
9202
9202
|
function useProviders() {
|
|
9203
9203
|
const { user } = useOpenfortCore();
|
|
9204
|
-
const { uiConfig: options } =
|
|
9204
|
+
const { uiConfig: options } = useOpenfort();
|
|
9205
9205
|
const allProviders = (options === null || options === void 0 ? void 0 : options.authProviders) || [];
|
|
9206
9206
|
const providers = allProviders.filter(p => p !== AuthProvider.GUEST) || [];
|
|
9207
9207
|
const linkedProviders = user ? providers.filter(p => { var _a; return (_a = user.linkedAccounts) === null || _a === void 0 ? void 0 : _a.find(a => a.provider === p); }) : [];
|
|
@@ -9310,7 +9310,7 @@ const LinkedProvider = ({ provider }) => {
|
|
|
9310
9310
|
return (jsx(LinkedProviderButton, { disabled: true, children: jsx(ProviderIcon$1, { children: jsx(ProviderIcon, { provider: provider }) }) }));
|
|
9311
9311
|
};
|
|
9312
9312
|
const AddLinkedProviderButton = () => {
|
|
9313
|
-
const { setRoute } =
|
|
9313
|
+
const { setRoute } = useOpenfort();
|
|
9314
9314
|
const { availableProviders: unlinkedProviders } = useProviders();
|
|
9315
9315
|
return (jsx(LinkedProviderButton, { disabled: unlinkedProviders.length === 0, onClick: () => setRoute(routes.PROVIDERS), children: "+" }));
|
|
9316
9316
|
};
|
|
@@ -9324,7 +9324,7 @@ const LinkedProviders = () => {
|
|
|
9324
9324
|
|
|
9325
9325
|
const Profile = ({ closeModal }) => {
|
|
9326
9326
|
var _a, _b, _c, _d;
|
|
9327
|
-
const context =
|
|
9327
|
+
const context = useOpenfort();
|
|
9328
9328
|
const themeContext = useThemeContext();
|
|
9329
9329
|
const locales = useLocales();
|
|
9330
9330
|
const { address, isConnected, connector, chain } = useAccount();
|
|
@@ -9749,11 +9749,10 @@ const createSIWEMessage = (address, nonce, chainId) => createSiweMessage({
|
|
|
9749
9749
|
|
|
9750
9750
|
function useConnectWithSiwe() {
|
|
9751
9751
|
const { client, user, updateUser } = useOpenfortCore();
|
|
9752
|
-
const { log } =
|
|
9753
|
-
const { address } = useAccount();
|
|
9752
|
+
const { log } = useOpenfort();
|
|
9753
|
+
const { address, connector } = useAccount();
|
|
9754
9754
|
const chainId = useChainId();
|
|
9755
9755
|
const config = useConfig();
|
|
9756
|
-
const { connector } = useAccount();
|
|
9757
9756
|
const connectWithSiwe = useCallback(async ({ onError, onConnect, }) => {
|
|
9758
9757
|
const connectorType = connector === null || connector === void 0 ? void 0 : connector.type;
|
|
9759
9758
|
const walletClientType = connector === null || connector === void 0 ? void 0 : connector.id;
|
|
@@ -9843,7 +9842,7 @@ const contentVariants$1 = {
|
|
|
9843
9842
|
const ConnectWithInjector = ({ switchConnectMethod, forceState }) => {
|
|
9844
9843
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9845
9844
|
const openfort = useOpenfortCore();
|
|
9846
|
-
const { log, setOpen } =
|
|
9845
|
+
const { log, setOpen } = useOpenfort();
|
|
9847
9846
|
const { isConnected } = useAccount();
|
|
9848
9847
|
const { disconnect } = useDisconnect();
|
|
9849
9848
|
const connectWithSiwe = useConnectWithSiwe();
|
|
@@ -9926,7 +9925,7 @@ const ConnectWithInjector = ({ switchConnectMethod, forceState }) => {
|
|
|
9926
9925
|
},
|
|
9927
9926
|
},
|
|
9928
9927
|
});
|
|
9929
|
-
const { triggerResize, connector: c } =
|
|
9928
|
+
const { triggerResize, connector: c } = useOpenfort();
|
|
9930
9929
|
const id = c.id;
|
|
9931
9930
|
const wallet = useWallet$1(id);
|
|
9932
9931
|
const walletInfo = {
|
|
@@ -10054,7 +10053,7 @@ const ScanIconWithLogos = ({ logo }) => {
|
|
|
10054
10053
|
|
|
10055
10054
|
const ConnectWithQRCode = ({ switchConnectMethod }) => {
|
|
10056
10055
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10057
|
-
const context =
|
|
10056
|
+
const context = useOpenfort();
|
|
10058
10057
|
const id = context.connector.id;
|
|
10059
10058
|
const wallet = useWallet$1(context.connector.id);
|
|
10060
10059
|
const { open: openW3M, isOpen: isOpenW3M } = useWalletConnectModal();
|
|
@@ -10080,7 +10079,7 @@ const ConnectWithQRCode = ({ switchConnectMethod }) => {
|
|
|
10080
10079
|
const hasApps = downloads && Object.keys(downloads).length !== 0;
|
|
10081
10080
|
const connectWithSiwe = useConnectWithSiwe();
|
|
10082
10081
|
const { isConnected } = useAccount();
|
|
10083
|
-
const { log, setOpen } =
|
|
10082
|
+
const { log, setOpen } = useOpenfort();
|
|
10084
10083
|
const { disconnect } = useDisconnect();
|
|
10085
10084
|
const [isFirstFrame, setIsFirstFrame] = React.useState(true);
|
|
10086
10085
|
useEffect(() => {
|
|
@@ -10175,8 +10174,8 @@ const ConnectingAnimation = styled(motion.div) `
|
|
|
10175
10174
|
`}
|
|
10176
10175
|
`;
|
|
10177
10176
|
const Loader = ({ reason, isLoading = true, icon }) => {
|
|
10178
|
-
const { uiConfig: options } =
|
|
10179
|
-
const { triggerResize } =
|
|
10177
|
+
const { uiConfig: options } = useOpenfort();
|
|
10178
|
+
const { triggerResize } = useOpenfort();
|
|
10180
10179
|
useEffect(() => {
|
|
10181
10180
|
return () => triggerResize();
|
|
10182
10181
|
}, []);
|
|
@@ -10205,7 +10204,7 @@ const states$1 = {
|
|
|
10205
10204
|
CONNECTING: "connecting",
|
|
10206
10205
|
};
|
|
10207
10206
|
const ConnectWithOAuth = ({}) => {
|
|
10208
|
-
const { connector, setRoute, log } =
|
|
10207
|
+
const { connector, setRoute, log } = useOpenfort();
|
|
10209
10208
|
const { client, user } = useOpenfortCore();
|
|
10210
10209
|
const [status, setStatus] = useState(states$1.INIT);
|
|
10211
10210
|
useEffect(() => {
|
|
@@ -10302,7 +10301,7 @@ const states = {
|
|
|
10302
10301
|
INJECTOR: 'injector',
|
|
10303
10302
|
};
|
|
10304
10303
|
const ConnectUsing = () => {
|
|
10305
|
-
const context =
|
|
10304
|
+
const context = useOpenfort();
|
|
10306
10305
|
const wallet = useWallet$1(context.connector.id);
|
|
10307
10306
|
// If cannot be scanned, display injector flow, which if extension is not installed will show CTA to install it
|
|
10308
10307
|
const isQrCode = !(wallet === null || wallet === void 0 ? void 0 : wallet.isInstalled) && (wallet === null || wallet === void 0 ? void 0 : wallet.getWalletConnectDeeplink);
|
|
@@ -10467,7 +10466,7 @@ const textVariants$2 = {
|
|
|
10467
10466
|
const EmailLogin = () => {
|
|
10468
10467
|
const [email, setEmail] = React.useState("");
|
|
10469
10468
|
const [password, setPassword] = React.useState("");
|
|
10470
|
-
const { setRoute, log } =
|
|
10469
|
+
const { setRoute, log } = useOpenfort();
|
|
10471
10470
|
const { client } = useOpenfortCore();
|
|
10472
10471
|
const [loginLoading, setLoginLoading] = React.useState(false);
|
|
10473
10472
|
const [loginError, setLoginError] = React.useState(false);
|
|
@@ -10510,7 +10509,7 @@ const EmailSignup = () => {
|
|
|
10510
10509
|
const [email, setEmail] = React.useState("");
|
|
10511
10510
|
const [password, setPassword] = React.useState("");
|
|
10512
10511
|
const [username, setUsername] = React.useState("");
|
|
10513
|
-
const { setRoute, triggerResize, log, uiConfig: options } =
|
|
10512
|
+
const { setRoute, triggerResize, log, uiConfig: options } = useOpenfort();
|
|
10514
10513
|
const { client } = useOpenfortCore();
|
|
10515
10514
|
const [signupLoading, setSignupLoading] = React.useState(false);
|
|
10516
10515
|
const [signupError, setSignupError] = React.useState(false);
|
|
@@ -10558,7 +10557,7 @@ const EmailSignup = () => {
|
|
|
10558
10557
|
|
|
10559
10558
|
const EmailVerification = () => {
|
|
10560
10559
|
const { client } = useOpenfortCore();
|
|
10561
|
-
const { setRoute, log } =
|
|
10560
|
+
const { setRoute, log } = useOpenfort();
|
|
10562
10561
|
const [loading, setLoading] = useState(true);
|
|
10563
10562
|
const [shouldSendEmailVerification, setShouldSendEmailVerification] = useState(false);
|
|
10564
10563
|
const emailInStorage = useMemo(() => localStorage.getItem(emailToVerifyLocalStorageKey), []);
|
|
@@ -10649,7 +10648,7 @@ const EmailVerification = () => {
|
|
|
10649
10648
|
// TODO: Localize
|
|
10650
10649
|
const RequestEmail = () => {
|
|
10651
10650
|
const [email, setEmail] = React.useState("");
|
|
10652
|
-
const { log, triggerResize } =
|
|
10651
|
+
const { log, triggerResize } = useOpenfort();
|
|
10653
10652
|
const { client } = useOpenfortCore();
|
|
10654
10653
|
const [loading, setLoading] = React.useState(false);
|
|
10655
10654
|
const [message, setMessage] = React.useState("");
|
|
@@ -10706,7 +10705,7 @@ const ResetPassword = () => {
|
|
|
10706
10705
|
const fixedUrl = window.location.href.replace("?state=", "&state="); // redirectUrl is not working with query params
|
|
10707
10706
|
const url = new URL(fixedUrl);
|
|
10708
10707
|
const [password, setPassword] = React.useState("");
|
|
10709
|
-
const { setRoute, triggerResize, log } =
|
|
10708
|
+
const { setRoute, triggerResize, log } = useOpenfort();
|
|
10710
10709
|
const { client, updateUser } = useOpenfortCore();
|
|
10711
10710
|
const [loading, setLoading] = React.useState(false);
|
|
10712
10711
|
const email = url.searchParams.get("email");
|
|
@@ -10781,7 +10780,7 @@ const textVariants$1 = {
|
|
|
10781
10780
|
const LinkEmail = () => {
|
|
10782
10781
|
const [email, setEmail] = React.useState("");
|
|
10783
10782
|
const [password, setPassword] = React.useState("");
|
|
10784
|
-
const { setRoute, triggerResize, log } =
|
|
10783
|
+
const { setRoute, triggerResize, log } = useOpenfort();
|
|
10785
10784
|
const { client, updateUser } = useOpenfortCore();
|
|
10786
10785
|
const [loginLoading, setLoginLoading] = React.useState(false);
|
|
10787
10786
|
const [loginError, setLoginError] = React.useState(false);
|
|
@@ -10819,7 +10818,7 @@ const LinkEmail = () => {
|
|
|
10819
10818
|
};
|
|
10820
10819
|
|
|
10821
10820
|
const Loading = () => {
|
|
10822
|
-
const { setRoute, walletConfig } =
|
|
10821
|
+
const { setRoute, walletConfig } = useOpenfort();
|
|
10823
10822
|
const { isLoading, user, needsRecovery } = useOpenfortCore();
|
|
10824
10823
|
const { address } = useAccount();
|
|
10825
10824
|
const [isFirstFrame, setIsFirstFrame] = React.useState(true);
|
|
@@ -10865,7 +10864,7 @@ const ProviderButton = ({ children, icon, onClick }) => {
|
|
|
10865
10864
|
};
|
|
10866
10865
|
const GuestButton = () => {
|
|
10867
10866
|
const { signUpGuest } = useOpenfortCore();
|
|
10868
|
-
const { setRoute } =
|
|
10867
|
+
const { setRoute } = useOpenfort();
|
|
10869
10868
|
const handleClick = () => {
|
|
10870
10869
|
signUpGuest();
|
|
10871
10870
|
setRoute(routes.RECOVER);
|
|
@@ -10873,16 +10872,16 @@ const GuestButton = () => {
|
|
|
10873
10872
|
return (jsx(ProviderButton, { onClick: handleClick, icon: jsx(GuestIcon, {}), children: "Guest" }));
|
|
10874
10873
|
};
|
|
10875
10874
|
const WalletButton = () => {
|
|
10876
|
-
const { setRoute } =
|
|
10875
|
+
const { setRoute } = useOpenfort();
|
|
10877
10876
|
return jsx(ProviderButton, { onClick: () => setRoute(routes.CONNECTORS), icon: jsx(Logos.OtherWallets, {}), children: "Wallet" });
|
|
10878
10877
|
};
|
|
10879
10878
|
const EmailButton = () => {
|
|
10880
|
-
const { setRoute } =
|
|
10879
|
+
const { setRoute } = useOpenfort();
|
|
10881
10880
|
const { user } = useOpenfortCore();
|
|
10882
10881
|
return jsx(ProviderButton, { onClick: () => setRoute(user ? routes.LINK_EMAIL : routes.EMAIL_LOGIN), icon: jsx(EmailIcon, {}), children: "Email" });
|
|
10883
10882
|
};
|
|
10884
10883
|
const AuthProviderButton = ({ provider, title = provider + " login", icon }) => {
|
|
10885
|
-
const { setRoute, setConnector } =
|
|
10884
|
+
const { setRoute, setConnector } = useOpenfort();
|
|
10886
10885
|
const handleClick = () => {
|
|
10887
10886
|
setRoute(routes.CONNECT);
|
|
10888
10887
|
setConnector({ id: provider, type: "oauth" });
|
|
@@ -10924,7 +10923,7 @@ const AddressButNoUserCase = () => {
|
|
|
10924
10923
|
return (jsx(PageContent, { children: jsx(Loader, { reason: "Updating user" }) }));
|
|
10925
10924
|
};
|
|
10926
10925
|
const SocialProvidersButton = () => {
|
|
10927
|
-
const { setRoute } =
|
|
10926
|
+
const { setRoute } = useOpenfort();
|
|
10928
10927
|
return (jsx(ProviderButton, { onClick: () => setRoute(routes.SOCIAL_PROVIDERS), icon: jsx(OtherSocials, {}), children: "Other socials" }));
|
|
10929
10928
|
};
|
|
10930
10929
|
const Providers = () => {
|
|
@@ -10941,15 +10940,6 @@ const Providers = () => {
|
|
|
10941
10940
|
return (jsxs(PageContent, { children: [(filteredProviders).map((auth) => (jsx(ProviderButtonSwitch, { provider: auth }, auth))), hasExcessProviders && jsx(SocialProvidersButton, {}), jsx(PoweredByFooter, { showDisclaimer: true })] }));
|
|
10942
10941
|
};
|
|
10943
10942
|
|
|
10944
|
-
const mapStatus = (status) => {
|
|
10945
|
-
return {
|
|
10946
|
-
isLoading: status.status === 'loading',
|
|
10947
|
-
isError: status.status === 'error',
|
|
10948
|
-
isSuccess: status.status === 'success',
|
|
10949
|
-
error: status.error
|
|
10950
|
-
};
|
|
10951
|
-
};
|
|
10952
|
-
|
|
10953
10943
|
const onSuccess = ({ hookOptions, options, data, }) => {
|
|
10954
10944
|
var _a, _b, _c, _d;
|
|
10955
10945
|
(_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.onSuccess) === null || _a === void 0 ? void 0 : _a.call(hookOptions, data);
|
|
@@ -10969,21 +10959,29 @@ const onError = ({ hookOptions, options, error, }) => {
|
|
|
10969
10959
|
return { error };
|
|
10970
10960
|
};
|
|
10971
10961
|
|
|
10972
|
-
const createOpenfortWallet = ({ address,
|
|
10962
|
+
const createOpenfortWallet = ({ address, }) => ({
|
|
10973
10963
|
connectorType: "embedded",
|
|
10974
10964
|
walletClientType: "openfort",
|
|
10975
10965
|
address,
|
|
10976
10966
|
id: embeddedWalletId,
|
|
10977
10967
|
isAvailable: true,
|
|
10978
|
-
isActive,
|
|
10979
10968
|
});
|
|
10969
|
+
const mapWalletStatus = (status) => {
|
|
10970
|
+
return {
|
|
10971
|
+
error: status.error,
|
|
10972
|
+
isError: status.status === 'error',
|
|
10973
|
+
isSuccess: status.status === 'success',
|
|
10974
|
+
isCreating: status.status === 'creating',
|
|
10975
|
+
isConnecting: status.status === 'connecting',
|
|
10976
|
+
};
|
|
10977
|
+
};
|
|
10980
10978
|
function useWallets(hookOptions = {}) {
|
|
10981
10979
|
const { user, embeddedState, client } = useOpenfortCore();
|
|
10982
|
-
const { walletConfig, log, setOpen, setRoute, setConnector, uiConfig } =
|
|
10980
|
+
const { walletConfig, log, setOpen, setRoute, setConnector, uiConfig } = useOpenfort();
|
|
10983
10981
|
const { connector, isConnected, address } = useAccount();
|
|
10984
10982
|
const chainId = useChainId();
|
|
10985
10983
|
const deviceWallets = useWallets$1(); // TODO: Map wallets object to be the same as wallets
|
|
10986
|
-
const { disconnect } = useDisconnect();
|
|
10984
|
+
const { disconnect, disconnectAsync } = useDisconnect();
|
|
10987
10985
|
const [status, setStatus] = useState({
|
|
10988
10986
|
status: "idle",
|
|
10989
10987
|
});
|
|
@@ -11019,8 +11017,6 @@ function useWallets(hookOptions = {}) {
|
|
|
11019
11017
|
}
|
|
11020
11018
|
}
|
|
11021
11019
|
});
|
|
11022
|
-
const usesEmbeddedWallet = user && walletConfig;
|
|
11023
|
-
const isEmbedded = embeddedState === EmbeddedState.READY;
|
|
11024
11020
|
const { data: embeddedWallets, refetch } = useQuery({
|
|
11025
11021
|
queryKey: ['openfortEmbeddedWalletList'],
|
|
11026
11022
|
queryFn: () => !!user ? client.embeddedWallet.list() : Promise.resolve([]),
|
|
@@ -11045,7 +11041,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11045
11041
|
const respJSON = await resp.json();
|
|
11046
11042
|
return respJSON.session;
|
|
11047
11043
|
}, [walletConfig]);
|
|
11048
|
-
const
|
|
11044
|
+
const rawWallets = useMemo(() => {
|
|
11049
11045
|
const userWallets = user ? user.linkedAccounts
|
|
11050
11046
|
.filter((a) => a.provider === AuthProvider.WALLET)
|
|
11051
11047
|
.map((a) => {
|
|
@@ -11056,17 +11052,28 @@ function useWallets(hookOptions = {}) {
|
|
|
11056
11052
|
walletClientType: a.walletClientType,
|
|
11057
11053
|
id: (wallet === null || wallet === void 0 ? void 0 : wallet.id) || a.walletClientType || "unknown",
|
|
11058
11054
|
isAvailable: !!wallet,
|
|
11059
|
-
isActive: (connector === null || connector === void 0 ? void 0 : connector.id) === a.walletClientType && address === a.address,
|
|
11060
11055
|
};
|
|
11061
11056
|
}) : [];
|
|
11062
11057
|
embeddedWallets === null || embeddedWallets === void 0 ? void 0 : embeddedWallets.forEach((wallet) => {
|
|
11058
|
+
// Remove duplicates (different chain ids)
|
|
11059
|
+
if (userWallets.find(w => w.address === (wallet.address)))
|
|
11060
|
+
return;
|
|
11063
11061
|
userWallets.push(createOpenfortWallet({
|
|
11064
11062
|
address: wallet.address,
|
|
11065
|
-
isActive: wallet.address === address,
|
|
11066
11063
|
}));
|
|
11067
11064
|
});
|
|
11068
11065
|
return userWallets;
|
|
11069
|
-
}, [user
|
|
11066
|
+
}, [user === null || user === void 0 ? void 0 : user.linkedAccounts, embeddedWallets]);
|
|
11067
|
+
const wallets = useMemo(() => {
|
|
11068
|
+
if (!isConnected || !address)
|
|
11069
|
+
return rawWallets;
|
|
11070
|
+
console.log("Mapping wallets", { rawWallets, status, address, isConnected, connector });
|
|
11071
|
+
return rawWallets.map((w) => ({
|
|
11072
|
+
...w,
|
|
11073
|
+
isConnecting: status.status === 'connecting' && status.address === w.address,
|
|
11074
|
+
isActive: w.address === address && isConnected && (connector === null || connector === void 0 ? void 0 : connector.id) === w.id,
|
|
11075
|
+
}));
|
|
11076
|
+
}, [rawWallets, status, address, isConnected, connector]);
|
|
11070
11077
|
const activeWallet = isConnected && connector ? wallets.find((w) => w.isActive) : undefined;
|
|
11071
11078
|
useEffect(() => {
|
|
11072
11079
|
if (connectToConnector)
|
|
@@ -11087,7 +11094,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11087
11094
|
connector = wallet.connector;
|
|
11088
11095
|
}
|
|
11089
11096
|
else {
|
|
11090
|
-
connector = connector;
|
|
11097
|
+
connector = optionsObject.connector;
|
|
11091
11098
|
}
|
|
11092
11099
|
if (!connector) {
|
|
11093
11100
|
log("Connector not found", deviceWallets, optionsObject.connector);
|
|
@@ -11097,22 +11104,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11097
11104
|
log(`Already connected to ${connector.id} with address ${address}, skipping connection`);
|
|
11098
11105
|
return { wallet: activeWallet };
|
|
11099
11106
|
}
|
|
11100
|
-
|
|
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;
|
|
11107
|
+
await disconnectAsync();
|
|
11116
11108
|
if (showUI) {
|
|
11117
11109
|
const walletToConnect = wallets.find((w) => w.id == connector.id);
|
|
11118
11110
|
if (!walletToConnect) {
|
|
@@ -11143,7 +11135,8 @@ function useWallets(hookOptions = {}) {
|
|
|
11143
11135
|
log("Setting active wallet", { options: optionsObject, chainId });
|
|
11144
11136
|
if (isOpenfortWallet(optionsObject)) {
|
|
11145
11137
|
setStatus({
|
|
11146
|
-
status: '
|
|
11138
|
+
status: 'connecting',
|
|
11139
|
+
address: optionsObject.address,
|
|
11147
11140
|
});
|
|
11148
11141
|
const { password } = optionsObject;
|
|
11149
11142
|
if (!walletConfig) {
|
|
@@ -11153,12 +11146,13 @@ function useWallets(hookOptions = {}) {
|
|
|
11153
11146
|
hookOptions
|
|
11154
11147
|
});
|
|
11155
11148
|
}
|
|
11156
|
-
log(`Handling recovery with Openfort:
|
|
11149
|
+
log(`Handling recovery with Openfort: ${password ? "with password" : "without password"}, chainId=${chainId}`);
|
|
11157
11150
|
try {
|
|
11158
11151
|
const accessToken = await client.getAccessToken();
|
|
11159
11152
|
if (!accessToken) {
|
|
11160
11153
|
throw new Error("Openfort access token not found");
|
|
11161
11154
|
}
|
|
11155
|
+
log("Access token");
|
|
11162
11156
|
const shieldAuthentication = password ? {
|
|
11163
11157
|
auth: ShieldAuthType.OPENFORT,
|
|
11164
11158
|
token: accessToken,
|
|
@@ -11169,13 +11163,17 @@ function useWallets(hookOptions = {}) {
|
|
|
11169
11163
|
await walletConfig.getEncryptionSession() :
|
|
11170
11164
|
await getEncryptionSession(),
|
|
11171
11165
|
};
|
|
11166
|
+
log("Shield authentication");
|
|
11172
11167
|
const recoveryParams = password ? {
|
|
11173
11168
|
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11174
11169
|
password,
|
|
11175
11170
|
} : {
|
|
11176
11171
|
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
11177
11172
|
};
|
|
11178
|
-
|
|
11173
|
+
// Ensure that the embedded wallet is listed
|
|
11174
|
+
const embeddedWallets = await client.embeddedWallet.list();
|
|
11175
|
+
log("Recovery params", optionsObject.address);
|
|
11176
|
+
log("Embedded wallets", embeddedWallets, chainId);
|
|
11179
11177
|
if (optionsObject.address) {
|
|
11180
11178
|
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
11179
|
if (!walletId) {
|
|
@@ -11192,18 +11190,19 @@ function useWallets(hookOptions = {}) {
|
|
|
11192
11190
|
});
|
|
11193
11191
|
}
|
|
11194
11192
|
else {
|
|
11195
|
-
if
|
|
11196
|
-
|
|
11197
|
-
password,
|
|
11198
|
-
});
|
|
11199
|
-
}
|
|
11200
|
-
else {
|
|
11193
|
+
// Check if the embedded wallet is already created in the current chain
|
|
11194
|
+
if (embeddedWallets.some((w) => w.chainId === chainId)) {
|
|
11201
11195
|
await client.embeddedWallet.recover({
|
|
11202
11196
|
account: embeddedWallets[0].id,
|
|
11203
11197
|
shieldAuthentication,
|
|
11204
11198
|
recoveryParams,
|
|
11205
11199
|
});
|
|
11206
11200
|
}
|
|
11201
|
+
else {
|
|
11202
|
+
await createWallet({
|
|
11203
|
+
password,
|
|
11204
|
+
});
|
|
11205
|
+
}
|
|
11207
11206
|
}
|
|
11208
11207
|
setStatus({
|
|
11209
11208
|
status: 'success',
|
|
@@ -11212,7 +11211,6 @@ function useWallets(hookOptions = {}) {
|
|
|
11212
11211
|
data: {
|
|
11213
11212
|
wallet: createOpenfortWallet({
|
|
11214
11213
|
address: optionsObject.address,
|
|
11215
|
-
isActive: true,
|
|
11216
11214
|
}),
|
|
11217
11215
|
},
|
|
11218
11216
|
options: optionsObject,
|
|
@@ -11248,7 +11246,8 @@ function useWallets(hookOptions = {}) {
|
|
|
11248
11246
|
}
|
|
11249
11247
|
else {
|
|
11250
11248
|
setStatus({
|
|
11251
|
-
status: '
|
|
11249
|
+
status: 'connecting',
|
|
11250
|
+
address: optionsObject.address,
|
|
11252
11251
|
});
|
|
11253
11252
|
setConnectToConnector({
|
|
11254
11253
|
address: optionsObject.address,
|
|
@@ -11256,12 +11255,13 @@ function useWallets(hookOptions = {}) {
|
|
|
11256
11255
|
});
|
|
11257
11256
|
}
|
|
11258
11257
|
return {};
|
|
11259
|
-
}, [wallets, setOpen, setRoute, setConnector,
|
|
11258
|
+
}, [wallets, setOpen, setRoute, setConnector, disconnectAsync, log, address, client, walletConfig, chainId, refetch, hookOptions]);
|
|
11260
11259
|
const createWallet = useCallback(async ({ password, ...options } = {}) => {
|
|
11261
11260
|
var _a;
|
|
11262
11261
|
setStatus({
|
|
11263
|
-
status: '
|
|
11262
|
+
status: 'creating',
|
|
11264
11263
|
});
|
|
11264
|
+
log("Creating wallet", { password: !!password, options });
|
|
11265
11265
|
const accessToken = await client.getAccessToken();
|
|
11266
11266
|
if (!accessToken) {
|
|
11267
11267
|
return onError({
|
|
@@ -11277,10 +11277,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11277
11277
|
options,
|
|
11278
11278
|
});
|
|
11279
11279
|
}
|
|
11280
|
-
const shieldAuthentication =
|
|
11281
|
-
auth: ShieldAuthType.OPENFORT,
|
|
11282
|
-
token: accessToken,
|
|
11283
|
-
} : {
|
|
11280
|
+
const shieldAuthentication = {
|
|
11284
11281
|
auth: ShieldAuthType.OPENFORT,
|
|
11285
11282
|
token: accessToken,
|
|
11286
11283
|
encryptionSession: walletConfig.getEncryptionSession ?
|
|
@@ -11308,18 +11305,57 @@ function useWallets(hookOptions = {}) {
|
|
|
11308
11305
|
data: {
|
|
11309
11306
|
wallet: createOpenfortWallet({
|
|
11310
11307
|
address: wallet.address,
|
|
11311
|
-
isActive: true,
|
|
11312
11308
|
})
|
|
11313
11309
|
}
|
|
11314
11310
|
});
|
|
11315
11311
|
}, [refetch, client, uiConfig, chainId]);
|
|
11312
|
+
const setRecovery = useCallback(async (params) => {
|
|
11313
|
+
try {
|
|
11314
|
+
setStatus({
|
|
11315
|
+
status: 'loading',
|
|
11316
|
+
});
|
|
11317
|
+
// Set embedded wallet recovery method
|
|
11318
|
+
if (params.recoveryMethod === 'password') {
|
|
11319
|
+
await client.embeddedWallet.setEmbeddedRecovery({
|
|
11320
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11321
|
+
recoveryPassword: params.recoveryPassword
|
|
11322
|
+
});
|
|
11323
|
+
}
|
|
11324
|
+
else {
|
|
11325
|
+
await client.embeddedWallet.setEmbeddedRecovery({
|
|
11326
|
+
recoveryMethod: RecoveryMethod.AUTOMATIC
|
|
11327
|
+
});
|
|
11328
|
+
}
|
|
11329
|
+
// Get the updated embedded account
|
|
11330
|
+
const embeddedAccount = await client.embeddedWallet.get();
|
|
11331
|
+
setStatus({ status: 'success' });
|
|
11332
|
+
return onSuccess({
|
|
11333
|
+
hookOptions,
|
|
11334
|
+
options: params,
|
|
11335
|
+
data: {
|
|
11336
|
+
wallet: createOpenfortWallet({
|
|
11337
|
+
address: embeddedAccount.address,
|
|
11338
|
+
}),
|
|
11339
|
+
}
|
|
11340
|
+
});
|
|
11341
|
+
}
|
|
11342
|
+
catch (error) {
|
|
11343
|
+
const errorObj = error instanceof Error ? error : new Error('Failed to set wallet recovery');
|
|
11344
|
+
return onError({
|
|
11345
|
+
hookOptions,
|
|
11346
|
+
options: params,
|
|
11347
|
+
error: new OpenfortError('Failed to set wallet recovery', OpenfortErrorType.WALLET_ERROR, { error: errorObj }),
|
|
11348
|
+
});
|
|
11349
|
+
}
|
|
11350
|
+
}, [client, setStatus, hookOptions]);
|
|
11316
11351
|
return {
|
|
11317
11352
|
wallets,
|
|
11318
11353
|
availableWallets: deviceWallets,
|
|
11319
11354
|
activeWallet,
|
|
11320
|
-
|
|
11355
|
+
setRecovery,
|
|
11321
11356
|
createWallet,
|
|
11322
|
-
|
|
11357
|
+
setActiveWallet,
|
|
11358
|
+
...mapWalletStatus(status),
|
|
11323
11359
|
exportPrivateKey: client.embeddedWallet.exportPrivateKey,
|
|
11324
11360
|
};
|
|
11325
11361
|
}
|
|
@@ -11328,7 +11364,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11328
11364
|
const Recover = () => {
|
|
11329
11365
|
const [recoveryPhrase, setRecoveryPhrase] = React.useState("");
|
|
11330
11366
|
const [recoveryError, setRecoveryError] = React.useState(false);
|
|
11331
|
-
const { triggerResize, uiConfig: options, log } =
|
|
11367
|
+
const { triggerResize, uiConfig: options, log } = useOpenfort();
|
|
11332
11368
|
useChainId();
|
|
11333
11369
|
const [loading, setLoading] = React.useState(false);
|
|
11334
11370
|
const { setActiveWallet } = useWallets();
|
|
@@ -11358,7 +11394,7 @@ const Recover = () => {
|
|
|
11358
11394
|
const AutomaticRecovery = () => {
|
|
11359
11395
|
const { needsRecovery } = useOpenfortCore();
|
|
11360
11396
|
const { setActiveWallet } = useWallets();
|
|
11361
|
-
const { log } =
|
|
11397
|
+
const { log } = useOpenfort();
|
|
11362
11398
|
const [hasRecoveryMethod, setHasRecoveryMethod] = React.useState(false);
|
|
11363
11399
|
useEffect(() => {
|
|
11364
11400
|
(async () => {
|
|
@@ -11380,7 +11416,7 @@ const AutomaticRecovery = () => {
|
|
|
11380
11416
|
return (jsx(PageContent, { children: jsx(Loader, { reason: "Setting up signer" }) }));
|
|
11381
11417
|
};
|
|
11382
11418
|
const Connected = () => {
|
|
11383
|
-
const { setOpen } =
|
|
11419
|
+
const { setOpen } = useOpenfort();
|
|
11384
11420
|
// hide on connect
|
|
11385
11421
|
useEffect(() => {
|
|
11386
11422
|
setTimeout(() => {
|
|
@@ -11391,7 +11427,7 @@ const Connected = () => {
|
|
|
11391
11427
|
};
|
|
11392
11428
|
const CreateEmbeddedSigner = () => {
|
|
11393
11429
|
const { needsRecovery, user } = useOpenfortCore();
|
|
11394
|
-
const { triggerResize, uiConfig, walletConfig, setRoute } =
|
|
11430
|
+
const { triggerResize, uiConfig, walletConfig, setRoute } = useOpenfort();
|
|
11395
11431
|
const [loading, setLoading] = React.useState(true);
|
|
11396
11432
|
const [embeddedSignerLoading, setEmbeddedSignerLoading] = React.useState(true);
|
|
11397
11433
|
const { isConnected } = useAccount();
|
|
@@ -11443,7 +11479,7 @@ const SocialProviders = () => {
|
|
|
11443
11479
|
const customThemeDefault = {};
|
|
11444
11480
|
const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customThemeDefault, lang = 'en-US' }) => {
|
|
11445
11481
|
var _a;
|
|
11446
|
-
const context =
|
|
11482
|
+
const context = useOpenfort();
|
|
11447
11483
|
const { logout, user } = useOpenfortCore();
|
|
11448
11484
|
const { isConnected, chain } = useAccount();
|
|
11449
11485
|
const chainIsSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
|
|
@@ -11573,7 +11609,7 @@ const ConnectModal = ({ mode = 'auto', theme = 'auto', customTheme = customTheme
|
|
|
11573
11609
|
};
|
|
11574
11610
|
|
|
11575
11611
|
/**
|
|
11576
|
-
* OpenfortProvider component provides context and configuration for
|
|
11612
|
+
* OpenfortProvider component provides context and configuration for Openfort.
|
|
11577
11613
|
* It must be used within a WagmiProvider.
|
|
11578
11614
|
*
|
|
11579
11615
|
* @param {React.ReactNode} children - The child components to be wrapped by the provider.
|
|
@@ -11595,7 +11631,7 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
|
|
|
11595
11631
|
}
|
|
11596
11632
|
// Only allow for mounting OpenfortProvider once, so we avoid weird global
|
|
11597
11633
|
// state collisions.
|
|
11598
|
-
if (React.useContext(
|
|
11634
|
+
if (React.useContext(Openfortcontext)) {
|
|
11599
11635
|
throw new Error('Multiple, nested usages of OpenfortProvider detected. Please use only one.');
|
|
11600
11636
|
}
|
|
11601
11637
|
const chains = useChains();
|
|
@@ -11714,12 +11750,13 @@ const OpenfortProvider = ({ children, uiConfig, onConnect, onDisconnect, debugMo
|
|
|
11714
11750
|
triggerResize: () => onResize((prev) => prev + 1),
|
|
11715
11751
|
walletConfig,
|
|
11716
11752
|
};
|
|
11717
|
-
return createElement(
|
|
11753
|
+
return createElement(Openfortcontext.Provider, { value }, jsx(Fragment, { children: jsx(Web3ContextProvider, { enabled: open, children: jsxs(CoreOpenfortProvider, { baseConfiguration: {
|
|
11718
11754
|
publishableKey,
|
|
11719
11755
|
}, shieldConfiguration: walletConfig ? {
|
|
11720
11756
|
shieldPublishableKey: walletConfig.shieldPublishableKey,
|
|
11721
11757
|
shieldEncryptionKey: walletConfig.recoveryMethod === RecoveryMethod.PASSWORD ? walletConfig.shieldEncryptionKey : undefined,
|
|
11722
|
-
|
|
11758
|
+
debug: debugMode,
|
|
11759
|
+
} : undefined, overrides: opts.overrides, 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 })] }) }) }));
|
|
11723
11760
|
};
|
|
11724
11761
|
|
|
11725
11762
|
const Container$1 = styled(motion.div) `
|
|
@@ -11972,7 +12009,7 @@ const allRoutes = [
|
|
|
11972
12009
|
...safeRoutes.disconnected,
|
|
11973
12010
|
];
|
|
11974
12011
|
function useUI() {
|
|
11975
|
-
const { open, setOpen, setRoute, log } =
|
|
12012
|
+
const { open, setOpen, setRoute, log } = useOpenfort();
|
|
11976
12013
|
const { isLoading, user, needsRecovery } = useOpenfortCore();
|
|
11977
12014
|
const { isConnected } = useAccount();
|
|
11978
12015
|
function defaultOpen() {
|
|
@@ -12097,7 +12134,7 @@ const textVariants = {
|
|
|
12097
12134
|
};
|
|
12098
12135
|
const ConnectButtonRenderer = ({ children, }) => {
|
|
12099
12136
|
const isMounted = useIsMounted();
|
|
12100
|
-
const context =
|
|
12137
|
+
const context = useOpenfort();
|
|
12101
12138
|
const { open, close, isOpen } = useUI();
|
|
12102
12139
|
const { address, isConnected, chain } = useAccount();
|
|
12103
12140
|
const isChainSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
|
|
@@ -12130,7 +12167,7 @@ const ConnectButtonRenderer = ({ children, }) => {
|
|
|
12130
12167
|
ensName: ensName === null || ensName === void 0 ? void 0 : ensName.toString(),
|
|
12131
12168
|
}) }));
|
|
12132
12169
|
};
|
|
12133
|
-
ConnectButtonRenderer.displayName = '
|
|
12170
|
+
ConnectButtonRenderer.displayName = 'OpenfortButton.Custom';
|
|
12134
12171
|
const ConnectedLabel = ({ separator }) => {
|
|
12135
12172
|
const { user, isLoading } = useOpenfortCore();
|
|
12136
12173
|
const { address } = useAccount();
|
|
@@ -12142,7 +12179,7 @@ const ConnectedLabel = ({ separator }) => {
|
|
|
12142
12179
|
return truncateUserId(user.id, separator);
|
|
12143
12180
|
return "Loading...";
|
|
12144
12181
|
};
|
|
12145
|
-
function
|
|
12182
|
+
function OpenfortButtonInner({ label, showAvatar, separator, }) {
|
|
12146
12183
|
const locales = useLocales({});
|
|
12147
12184
|
const { user } = useOpenfortCore();
|
|
12148
12185
|
const { address, chain } = useAccount();
|
|
@@ -12167,7 +12204,7 @@ function OpenfortKitButtonInner({ label, showAvatar, separator, }) {
|
|
|
12167
12204
|
//padding: '0 5px',
|
|
12168
12205
|
}, children: label ? label : defaultLabel }, "connectWalletText")) }));
|
|
12169
12206
|
}
|
|
12170
|
-
function
|
|
12207
|
+
function OpenfortButton({
|
|
12171
12208
|
// Options
|
|
12172
12209
|
label, showBalance = false, showAvatar = true,
|
|
12173
12210
|
// Theming
|
|
@@ -12176,7 +12213,7 @@ theme, mode, customTheme,
|
|
|
12176
12213
|
onClick, }) {
|
|
12177
12214
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
12178
12215
|
const isMounted = useIsMounted();
|
|
12179
|
-
const context =
|
|
12216
|
+
const context = useOpenfort();
|
|
12180
12217
|
const { address, chain } = useAccount();
|
|
12181
12218
|
const chainIsSupported = useChainIsSupported(chain === null || chain === void 0 ? void 0 : chain.id);
|
|
12182
12219
|
const { open } = useUI();
|
|
@@ -12229,39 +12266,39 @@ onClick, }) {
|
|
|
12229
12266
|
}
|
|
12230
12267
|
: {
|
|
12231
12268
|
overflow: 'hidden',
|
|
12232
|
-
}, children: jsx(
|
|
12269
|
+
}, children: jsx(OpenfortButtonInner, { separator: separator, showAvatar: showAvatar, label: label }) })] }) }));
|
|
12233
12270
|
}
|
|
12234
|
-
|
|
12235
|
-
|
|
12236
|
-
var
|
|
12237
|
-
(function (
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
|
|
12242
|
-
})(
|
|
12271
|
+
OpenfortButton.Custom = ConnectButtonRenderer;
|
|
12272
|
+
|
|
12273
|
+
var OpenfortStatus;
|
|
12274
|
+
(function (OpenfortStatus) {
|
|
12275
|
+
OpenfortStatus[OpenfortStatus["DISCONNECTED"] = 0] = "DISCONNECTED";
|
|
12276
|
+
OpenfortStatus[OpenfortStatus["NEEDS_RECOVERY"] = 1] = "NEEDS_RECOVERY";
|
|
12277
|
+
OpenfortStatus[OpenfortStatus["LOADING"] = 2] = "LOADING";
|
|
12278
|
+
OpenfortStatus[OpenfortStatus["CONNECTED"] = 3] = "CONNECTED";
|
|
12279
|
+
})(OpenfortStatus || (OpenfortStatus = {}));
|
|
12243
12280
|
function useStatus() {
|
|
12244
12281
|
const { embeddedState } = useOpenfortCore();
|
|
12245
12282
|
const { isConnected, isConnecting } = useAccount();
|
|
12246
12283
|
const getStatus = () => {
|
|
12247
12284
|
if (embeddedState === EmbeddedState.READY)
|
|
12248
|
-
return
|
|
12285
|
+
return OpenfortStatus.CONNECTED;
|
|
12249
12286
|
if (embeddedState === EmbeddedState.NONE)
|
|
12250
|
-
return
|
|
12251
|
-
// if (needsRecovery) return
|
|
12287
|
+
return OpenfortStatus.LOADING;
|
|
12288
|
+
// if (needsRecovery) return OpenfortStatus.NEEDS_RECOVERY;
|
|
12252
12289
|
if (embeddedState === EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED) {
|
|
12253
12290
|
if (isConnected)
|
|
12254
|
-
return
|
|
12291
|
+
return OpenfortStatus.CONNECTED;
|
|
12255
12292
|
else
|
|
12256
|
-
return
|
|
12293
|
+
return OpenfortStatus.NEEDS_RECOVERY;
|
|
12257
12294
|
}
|
|
12258
|
-
return
|
|
12295
|
+
return OpenfortStatus.DISCONNECTED;
|
|
12259
12296
|
};
|
|
12260
12297
|
const status = getStatus();
|
|
12261
12298
|
return {
|
|
12262
|
-
isLoading: status ===
|
|
12263
|
-
isConnected: status ===
|
|
12264
|
-
isDisconnected: status ===
|
|
12299
|
+
isLoading: status === OpenfortStatus.LOADING,
|
|
12300
|
+
isConnected: status === OpenfortStatus.CONNECTED,
|
|
12301
|
+
isDisconnected: status === OpenfortStatus.DISCONNECTED,
|
|
12265
12302
|
isConnecting: isConnecting || embeddedState === EmbeddedState.CREATING_ACCOUNT,
|
|
12266
12303
|
isAuthenticated: embeddedState !== EmbeddedState.NONE && embeddedState !== EmbeddedState.UNAUTHENTICATED,
|
|
12267
12304
|
};
|
|
@@ -12300,24 +12337,84 @@ const buildCallbackUrl = ({ email, callbackUrl, provider, }) => {
|
|
|
12300
12337
|
return redirectUrl.toString();
|
|
12301
12338
|
};
|
|
12302
12339
|
|
|
12340
|
+
const mapStatus = (status) => {
|
|
12341
|
+
return {
|
|
12342
|
+
isLoading: status.status === 'loading',
|
|
12343
|
+
isError: status.status === 'error',
|
|
12344
|
+
isSuccess: status.status === 'success',
|
|
12345
|
+
error: status.error
|
|
12346
|
+
};
|
|
12347
|
+
};
|
|
12348
|
+
|
|
12349
|
+
function useSignOut(hookOptions = {}) {
|
|
12350
|
+
const { client, updateUser, user } = useOpenfortCore();
|
|
12351
|
+
const [status, setStatus] = useState({
|
|
12352
|
+
status: "idle",
|
|
12353
|
+
});
|
|
12354
|
+
const { disconnect } = useDisconnect();
|
|
12355
|
+
const signOut = useCallback(async (options = {}) => {
|
|
12356
|
+
if (!user)
|
|
12357
|
+
return;
|
|
12358
|
+
setStatus({
|
|
12359
|
+
status: 'loading',
|
|
12360
|
+
});
|
|
12361
|
+
try {
|
|
12362
|
+
await client.auth.logout();
|
|
12363
|
+
disconnect();
|
|
12364
|
+
updateUser();
|
|
12365
|
+
setStatus({
|
|
12366
|
+
status: 'success',
|
|
12367
|
+
});
|
|
12368
|
+
return onSuccess({
|
|
12369
|
+
hookOptions,
|
|
12370
|
+
options,
|
|
12371
|
+
data: {},
|
|
12372
|
+
});
|
|
12373
|
+
}
|
|
12374
|
+
catch (e) {
|
|
12375
|
+
const error = new OpenfortError('Failed to sign out', OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12376
|
+
setStatus({
|
|
12377
|
+
status: 'error',
|
|
12378
|
+
error,
|
|
12379
|
+
});
|
|
12380
|
+
return onError({
|
|
12381
|
+
hookOptions,
|
|
12382
|
+
options,
|
|
12383
|
+
error,
|
|
12384
|
+
});
|
|
12385
|
+
}
|
|
12386
|
+
}, [client, user, disconnect, updateUser, setStatus, hookOptions]);
|
|
12387
|
+
return {
|
|
12388
|
+
...mapStatus(status),
|
|
12389
|
+
signOut,
|
|
12390
|
+
};
|
|
12391
|
+
}
|
|
12392
|
+
|
|
12303
12393
|
// this hook is used to create a wallet after the user has authenticated
|
|
12304
12394
|
const useCreateWalletPostAuth = () => {
|
|
12305
12395
|
const { setActiveWallet } = useWallets();
|
|
12306
|
-
const { walletConfig } =
|
|
12307
|
-
const
|
|
12308
|
-
|
|
12396
|
+
const { walletConfig } = useOpenfort();
|
|
12397
|
+
const { signOut } = useSignOut();
|
|
12398
|
+
const tryUseWallet = useCallback(async ({ logoutOnError: signOutOnError = true, automaticRecovery = true }) => {
|
|
12399
|
+
if (!walletConfig || walletConfig.recoveryMethod !== RecoveryMethod.AUTOMATIC || !automaticRecovery) {
|
|
12309
12400
|
return {};
|
|
12310
|
-
|
|
12401
|
+
}
|
|
12402
|
+
const wallet = await setActiveWallet({
|
|
12311
12403
|
connector: embeddedWalletId,
|
|
12312
12404
|
});
|
|
12313
|
-
|
|
12405
|
+
if (wallet.error && signOutOnError) {
|
|
12406
|
+
// If there was an error and we should log out, we can call the logout function
|
|
12407
|
+
await signOut();
|
|
12408
|
+
}
|
|
12409
|
+
return wallet;
|
|
12410
|
+
}, [walletConfig, setActiveWallet, signOut]);
|
|
12314
12411
|
return {
|
|
12315
12412
|
tryUseWallet,
|
|
12316
12413
|
};
|
|
12317
12414
|
};
|
|
12318
12415
|
|
|
12319
12416
|
const useEmailAuth = (hookOptions = {}) => {
|
|
12320
|
-
const { log } =
|
|
12417
|
+
const { log } = useOpenfort();
|
|
12321
12418
|
const { client, updateUser } = useOpenfortCore();
|
|
12322
12419
|
const [requiresEmailVerification, setRequiresEmailVerification] = useState(false);
|
|
12323
12420
|
const [status, setStatus] = useState({
|
|
@@ -12361,7 +12458,10 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12361
12458
|
});
|
|
12362
12459
|
}
|
|
12363
12460
|
else {
|
|
12364
|
-
const { wallet } = await tryUseWallet(
|
|
12461
|
+
const { wallet } = await tryUseWallet({
|
|
12462
|
+
logoutOnError: options.logoutOnError || hookOptions.logoutOnError,
|
|
12463
|
+
automaticRecovery: options.automaticRecovery || hookOptions.automaticRecovery,
|
|
12464
|
+
});
|
|
12365
12465
|
setStatus({
|
|
12366
12466
|
status: 'success',
|
|
12367
12467
|
});
|
|
@@ -12491,7 +12591,10 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12491
12591
|
});
|
|
12492
12592
|
}
|
|
12493
12593
|
else {
|
|
12494
|
-
const { wallet } = await tryUseWallet(
|
|
12594
|
+
const { wallet } = await tryUseWallet({
|
|
12595
|
+
logoutOnError: options.logoutOnError || hookOptions.logoutOnError,
|
|
12596
|
+
automaticRecovery: options.automaticRecovery || hookOptions.automaticRecovery,
|
|
12597
|
+
});
|
|
12495
12598
|
setStatus({
|
|
12496
12599
|
status: 'success',
|
|
12497
12600
|
});
|
|
@@ -12582,38 +12685,14 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12582
12685
|
});
|
|
12583
12686
|
}
|
|
12584
12687
|
}, [client, setStatus, updateUser, log, hookOptions]);
|
|
12585
|
-
|
|
12586
|
-
signInEmail,
|
|
12587
|
-
signUpEmail,
|
|
12588
|
-
linkEmail,
|
|
12589
|
-
requestResetPassword,
|
|
12590
|
-
resetPassword,
|
|
12591
|
-
reset,
|
|
12592
|
-
...mapStatus(status),
|
|
12593
|
-
requiresEmailVerification,
|
|
12594
|
-
isAwaitingInput: status.status === 'awaiting-input',
|
|
12595
|
-
};
|
|
12596
|
-
};
|
|
12597
|
-
|
|
12598
|
-
const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically handle OAuth and email callback
|
|
12599
|
-
...hookOptions } = {}) => {
|
|
12600
|
-
const { log } = useOpenfortKit();
|
|
12601
|
-
const [status, setStatus] = useState({
|
|
12602
|
-
status: "idle",
|
|
12603
|
-
});
|
|
12604
|
-
const { client, updateUser } = useOpenfortCore();
|
|
12605
|
-
const [provider, setProvider] = useState(null);
|
|
12606
|
-
const [email, setEmail] = useState(null);
|
|
12607
|
-
const { tryUseWallet } = useCreateWalletPostAuth();
|
|
12608
|
-
const verifyEmail = useCallback(async ({ email, state, ...options }) => {
|
|
12688
|
+
const verifyEmail = useCallback(async (options) => {
|
|
12609
12689
|
setStatus({
|
|
12610
12690
|
status: 'loading',
|
|
12611
12691
|
});
|
|
12612
|
-
setEmail(email);
|
|
12613
12692
|
try {
|
|
12614
12693
|
await client.auth.verifyEmail({
|
|
12615
|
-
email,
|
|
12616
|
-
state,
|
|
12694
|
+
email: options.email,
|
|
12695
|
+
state: options.state,
|
|
12617
12696
|
});
|
|
12618
12697
|
setStatus({
|
|
12619
12698
|
status: 'success',
|
|
@@ -12621,7 +12700,9 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12621
12700
|
return onSuccess({
|
|
12622
12701
|
hookOptions,
|
|
12623
12702
|
options,
|
|
12624
|
-
data: {
|
|
12703
|
+
data: {
|
|
12704
|
+
email: options.email,
|
|
12705
|
+
},
|
|
12625
12706
|
});
|
|
12626
12707
|
}
|
|
12627
12708
|
catch (e) {
|
|
@@ -12631,14 +12712,42 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12631
12712
|
error,
|
|
12632
12713
|
});
|
|
12633
12714
|
log("Error verifying email", e);
|
|
12634
|
-
onError({
|
|
12715
|
+
return onError({
|
|
12635
12716
|
hookOptions,
|
|
12636
12717
|
options,
|
|
12637
12718
|
error,
|
|
12638
12719
|
});
|
|
12639
|
-
return { error, type: "verifyEmail" };
|
|
12640
12720
|
}
|
|
12641
12721
|
}, [client, log, hookOptions]);
|
|
12722
|
+
return {
|
|
12723
|
+
signInEmail,
|
|
12724
|
+
signUpEmail,
|
|
12725
|
+
verifyEmail,
|
|
12726
|
+
linkEmail,
|
|
12727
|
+
requestResetPassword,
|
|
12728
|
+
resetPassword,
|
|
12729
|
+
reset,
|
|
12730
|
+
...mapStatus(status),
|
|
12731
|
+
requiresEmailVerification,
|
|
12732
|
+
isAwaitingInput: status.status === 'awaiting-input',
|
|
12733
|
+
};
|
|
12734
|
+
};
|
|
12735
|
+
|
|
12736
|
+
({
|
|
12737
|
+
// [OAuthProvider.APPLE]: AuthProvider.,
|
|
12738
|
+
// [OAuthProvider.DISCORD]: AuthProvider.,
|
|
12739
|
+
// [OAuthProvider.EPIC_GAMES]: AuthProvider.,
|
|
12740
|
+
[AuthProvider.FACEBOOK]: OAuthProvider.FACEBOOK,
|
|
12741
|
+
[AuthProvider.GOOGLE]: OAuthProvider.GOOGLE,
|
|
12742
|
+
// [OAuthProvider.LINE]: AuthProvider.,
|
|
12743
|
+
[AuthProvider.TWITTER]: OAuthProvider.TWITTER,
|
|
12744
|
+
});
|
|
12745
|
+
const useOAuth = (hookOptions = {}) => {
|
|
12746
|
+
const { client, updateUser } = useOpenfortCore();
|
|
12747
|
+
const [status, setStatus] = useState({
|
|
12748
|
+
status: "idle",
|
|
12749
|
+
});
|
|
12750
|
+
const { tryUseWallet } = useCreateWalletPostAuth();
|
|
12642
12751
|
const storeCredentials = useCallback(async ({ player, accessToken, refreshToken, ...options }) => {
|
|
12643
12752
|
setStatus({
|
|
12644
12753
|
status: 'loading',
|
|
@@ -12653,7 +12762,10 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12653
12762
|
status: 'success',
|
|
12654
12763
|
});
|
|
12655
12764
|
const user = await updateUser() || undefined;
|
|
12656
|
-
const { wallet } = await tryUseWallet(
|
|
12765
|
+
const { wallet } = await tryUseWallet({
|
|
12766
|
+
logoutOnError: options.logoutOnError || hookOptions.logoutOnError,
|
|
12767
|
+
automaticRecovery: options.automaticRecovery || hookOptions.automaticRecovery,
|
|
12768
|
+
});
|
|
12657
12769
|
return onSuccess({
|
|
12658
12770
|
data: { user, wallet, type: "storeCredentials" },
|
|
12659
12771
|
hookOptions,
|
|
@@ -12666,17 +12778,105 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12666
12778
|
status: 'error',
|
|
12667
12779
|
error,
|
|
12668
12780
|
});
|
|
12669
|
-
|
|
12670
|
-
onError({
|
|
12781
|
+
return onError({
|
|
12671
12782
|
hookOptions,
|
|
12672
12783
|
options,
|
|
12673
12784
|
error,
|
|
12674
12785
|
});
|
|
12675
|
-
return { error, type: "storeCredentials" };
|
|
12676
12786
|
}
|
|
12677
|
-
}, [client,
|
|
12787
|
+
}, [client, hookOptions]);
|
|
12788
|
+
const initOAuth = useCallback(async (options) => {
|
|
12789
|
+
var _a;
|
|
12790
|
+
const authProvider = options.provider;
|
|
12791
|
+
try {
|
|
12792
|
+
setStatus({
|
|
12793
|
+
status: 'loading',
|
|
12794
|
+
});
|
|
12795
|
+
await client.auth.initOAuth({
|
|
12796
|
+
provider: authProvider,
|
|
12797
|
+
options: {
|
|
12798
|
+
redirectTo: buildCallbackUrl({
|
|
12799
|
+
provider: authProvider,
|
|
12800
|
+
callbackUrl: (_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.redirectTo) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.redirectTo,
|
|
12801
|
+
})
|
|
12802
|
+
},
|
|
12803
|
+
});
|
|
12804
|
+
return onSuccess({
|
|
12805
|
+
data: {},
|
|
12806
|
+
hookOptions,
|
|
12807
|
+
options,
|
|
12808
|
+
});
|
|
12809
|
+
}
|
|
12810
|
+
catch (e) {
|
|
12811
|
+
const error = new OpenfortError("Failed to login with OAuth", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12812
|
+
setStatus({
|
|
12813
|
+
status: 'error',
|
|
12814
|
+
error
|
|
12815
|
+
});
|
|
12816
|
+
return onError({
|
|
12817
|
+
hookOptions,
|
|
12818
|
+
options,
|
|
12819
|
+
error,
|
|
12820
|
+
});
|
|
12821
|
+
}
|
|
12822
|
+
}, [client, setStatus, updateUser, hookOptions]);
|
|
12823
|
+
const linkOauth = useCallback(async (options) => {
|
|
12824
|
+
var _a;
|
|
12825
|
+
const authProvider = options.provider;
|
|
12826
|
+
try {
|
|
12827
|
+
setStatus({
|
|
12828
|
+
status: 'loading',
|
|
12829
|
+
});
|
|
12830
|
+
const authToken = await client.getAccessToken();
|
|
12831
|
+
if (!authToken) {
|
|
12832
|
+
throw new OpenfortError("No auth token found", OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
12833
|
+
}
|
|
12834
|
+
await client.auth.initLinkOAuth({
|
|
12835
|
+
authToken,
|
|
12836
|
+
provider: authProvider,
|
|
12837
|
+
options: {
|
|
12838
|
+
redirectTo: buildCallbackUrl({
|
|
12839
|
+
provider: authProvider,
|
|
12840
|
+
callbackUrl: (_a = options === null || options === void 0 ? void 0 : options.redirectTo) !== null && _a !== void 0 ? _a : hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.redirectTo,
|
|
12841
|
+
})
|
|
12842
|
+
},
|
|
12843
|
+
});
|
|
12844
|
+
return onSuccess({
|
|
12845
|
+
data: {},
|
|
12846
|
+
hookOptions,
|
|
12847
|
+
options,
|
|
12848
|
+
});
|
|
12849
|
+
}
|
|
12850
|
+
catch (e) {
|
|
12851
|
+
const error = new OpenfortError("Failed to link OAuth", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
12852
|
+
setStatus({
|
|
12853
|
+
status: 'error',
|
|
12854
|
+
error
|
|
12855
|
+
});
|
|
12856
|
+
return onError({
|
|
12857
|
+
hookOptions,
|
|
12858
|
+
options,
|
|
12859
|
+
error,
|
|
12860
|
+
});
|
|
12861
|
+
}
|
|
12862
|
+
}, [client, setStatus, updateUser, hookOptions]);
|
|
12863
|
+
return {
|
|
12864
|
+
initOAuth,
|
|
12865
|
+
linkOauth,
|
|
12866
|
+
storeCredentials,
|
|
12867
|
+
...mapStatus(status),
|
|
12868
|
+
};
|
|
12869
|
+
};
|
|
12870
|
+
|
|
12871
|
+
const useAuthCallback = ({ enabled = true, // Automatically handle OAuth and email callback
|
|
12872
|
+
...hookOptions } = {}) => {
|
|
12873
|
+
const { log } = useOpenfort();
|
|
12874
|
+
const [provider, setProvider] = useState(null);
|
|
12875
|
+
const [email, setEmail] = useState(null);
|
|
12876
|
+
const { verifyEmail, isSuccess: isEmailSuccess, isLoading: isEmailLoading, isError: isEmailError, error: emailError, } = useEmailAuth();
|
|
12877
|
+
const { storeCredentials, isSuccess: isOAuthSuccess, isLoading: isOAuthLoading, isError: isOAuthError, error: oAuthError, } = useOAuth();
|
|
12678
12878
|
useEffect(() => {
|
|
12679
|
-
if (!
|
|
12879
|
+
if (!enabled)
|
|
12680
12880
|
return;
|
|
12681
12881
|
(async () => {
|
|
12682
12882
|
// redirectUrl is not working with query params OF-1013
|
|
@@ -12705,7 +12905,26 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12705
12905
|
window.history.replaceState({}, document.title, url.toString());
|
|
12706
12906
|
};
|
|
12707
12907
|
log("EmailVerification", state, email);
|
|
12708
|
-
|
|
12908
|
+
const options = {
|
|
12909
|
+
onSuccess: (data) => {
|
|
12910
|
+
var _a;
|
|
12911
|
+
(_a = hookOptions.onSuccess) === null || _a === void 0 ? void 0 : _a.call(hookOptions, {
|
|
12912
|
+
...data,
|
|
12913
|
+
type: "verifyEmail",
|
|
12914
|
+
});
|
|
12915
|
+
},
|
|
12916
|
+
onSettled: (data, error) => {
|
|
12917
|
+
var _a;
|
|
12918
|
+
(_a = hookOptions.onSettled) === null || _a === void 0 ? void 0 : _a.call(hookOptions, {
|
|
12919
|
+
...data,
|
|
12920
|
+
type: "verifyEmail",
|
|
12921
|
+
}, error);
|
|
12922
|
+
},
|
|
12923
|
+
onError: hookOptions.onError,
|
|
12924
|
+
throwOnError: hookOptions.throwOnError,
|
|
12925
|
+
};
|
|
12926
|
+
await verifyEmail({ email, state, ...options });
|
|
12927
|
+
setEmail(email);
|
|
12709
12928
|
removeParams();
|
|
12710
12929
|
}
|
|
12711
12930
|
else {
|
|
@@ -12736,7 +12955,25 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12736
12955
|
window.history.replaceState({}, document.title, url.toString());
|
|
12737
12956
|
};
|
|
12738
12957
|
log("callback", { player, accessToken, refreshToken });
|
|
12739
|
-
|
|
12958
|
+
const options = {
|
|
12959
|
+
onSuccess: (data) => {
|
|
12960
|
+
var _a;
|
|
12961
|
+
(_a = hookOptions.onSuccess) === null || _a === void 0 ? void 0 : _a.call(hookOptions, {
|
|
12962
|
+
...data,
|
|
12963
|
+
type: "storeCredentials",
|
|
12964
|
+
});
|
|
12965
|
+
},
|
|
12966
|
+
onSettled: (data, error) => {
|
|
12967
|
+
var _a;
|
|
12968
|
+
(_a = hookOptions.onSettled) === null || _a === void 0 ? void 0 : _a.call(hookOptions, {
|
|
12969
|
+
...data,
|
|
12970
|
+
type: "storeCredentials",
|
|
12971
|
+
}, error);
|
|
12972
|
+
},
|
|
12973
|
+
onError: hookOptions.onError,
|
|
12974
|
+
throwOnError: hookOptions.throwOnError,
|
|
12975
|
+
};
|
|
12976
|
+
await storeCredentials({ player, accessToken, refreshToken, ...options });
|
|
12740
12977
|
removeParams();
|
|
12741
12978
|
}
|
|
12742
12979
|
})();
|
|
@@ -12746,7 +12983,10 @@ const useAuthCallback = ({ automaticallyHandleCallback = true, // Automatically
|
|
|
12746
12983
|
provider,
|
|
12747
12984
|
verifyEmail,
|
|
12748
12985
|
storeCredentials,
|
|
12749
|
-
|
|
12986
|
+
isLoading: isEmailLoading || isOAuthLoading,
|
|
12987
|
+
isError: isEmailError || isOAuthError,
|
|
12988
|
+
isSuccess: isEmailSuccess || isOAuthSuccess,
|
|
12989
|
+
error: emailError || oAuthError,
|
|
12750
12990
|
};
|
|
12751
12991
|
};
|
|
12752
12992
|
|
|
@@ -12764,16 +13004,18 @@ const useGuestAuth = (hookOptions = {}) => {
|
|
|
12764
13004
|
const result = await client.auth.signUpGuest();
|
|
12765
13005
|
const user = result.player;
|
|
12766
13006
|
await updateUser(user);
|
|
12767
|
-
const { wallet } = await tryUseWallet(
|
|
13007
|
+
const { wallet } = await tryUseWallet({
|
|
13008
|
+
logoutOnError: options.logoutOnError || hookOptions.logoutOnError,
|
|
13009
|
+
automaticRecovery: options.automaticRecovery || hookOptions.automaticRecovery,
|
|
13010
|
+
});
|
|
12768
13011
|
setStatus({
|
|
12769
13012
|
status: 'success',
|
|
12770
13013
|
});
|
|
12771
|
-
onSuccess({
|
|
13014
|
+
return onSuccess({
|
|
12772
13015
|
hookOptions,
|
|
12773
13016
|
options,
|
|
12774
|
-
data: user,
|
|
13017
|
+
data: { user, wallet },
|
|
12775
13018
|
});
|
|
12776
|
-
return { user, wallet };
|
|
12777
13019
|
}
|
|
12778
13020
|
catch (error) {
|
|
12779
13021
|
const openfortError = new OpenfortError("Failed to signup guest", OpenfortErrorType.AUTHENTICATION_ERROR, { error });
|
|
@@ -12796,13 +13038,12 @@ const useGuestAuth = (hookOptions = {}) => {
|
|
|
12796
13038
|
|
|
12797
13039
|
const useWalletAuth = (hookOptions = {}) => {
|
|
12798
13040
|
const { updateUser } = useOpenfortCore();
|
|
12799
|
-
const { log } =
|
|
13041
|
+
const { log } = useOpenfort();
|
|
12800
13042
|
const siwe = useConnectWithSiwe();
|
|
12801
13043
|
const availableWallets = useWallets$1(); // TODO: Use this to get the wallet client type
|
|
12802
13044
|
const { disconnect } = useDisconnect();
|
|
12803
13045
|
const [walletConnectingTo, setWalletConnectingTo] = useState(null);
|
|
12804
13046
|
const [shouldConnectWithSiwe, setShouldConnectWithSiwe] = useState(false);
|
|
12805
|
-
useAccount();
|
|
12806
13047
|
const [status, setStatus] = useState({
|
|
12807
13048
|
status: "idle",
|
|
12808
13049
|
});
|
|
@@ -12977,146 +13218,5 @@ const useWalletAuth = (hookOptions = {}) => {
|
|
|
12977
13218
|
};
|
|
12978
13219
|
};
|
|
12979
13220
|
|
|
12980
|
-
|
|
12981
|
-
// [OAuthProvider.APPLE]: AuthProvider.,
|
|
12982
|
-
// [OAuthProvider.DISCORD]: AuthProvider.,
|
|
12983
|
-
// [OAuthProvider.EPIC_GAMES]: AuthProvider.,
|
|
12984
|
-
[AuthProvider.FACEBOOK]: OAuthProvider.FACEBOOK,
|
|
12985
|
-
[AuthProvider.GOOGLE]: OAuthProvider.GOOGLE,
|
|
12986
|
-
// [OAuthProvider.LINE]: AuthProvider.,
|
|
12987
|
-
[AuthProvider.TWITTER]: OAuthProvider.TWITTER,
|
|
12988
|
-
};
|
|
12989
|
-
function getOAuthProvider(provider) {
|
|
12990
|
-
if (!providerToAuthProvider[provider]) {
|
|
12991
|
-
throw new Error(`Unsupported OAuth provider: ${provider}`);
|
|
12992
|
-
}
|
|
12993
|
-
return providerToAuthProvider[provider];
|
|
12994
|
-
}
|
|
12995
|
-
const useOAuth = (hookOptions = {}) => {
|
|
12996
|
-
const { client, updateUser } = useOpenfortCore();
|
|
12997
|
-
const [status, setStatus] = useState({
|
|
12998
|
-
status: "idle",
|
|
12999
|
-
});
|
|
13000
|
-
const initOAuth = useCallback(async (options) => {
|
|
13001
|
-
var _a;
|
|
13002
|
-
const authProvider = options.provider;
|
|
13003
|
-
try {
|
|
13004
|
-
setStatus({
|
|
13005
|
-
status: 'loading',
|
|
13006
|
-
});
|
|
13007
|
-
await client.auth.initOAuth({
|
|
13008
|
-
provider: getOAuthProvider(authProvider),
|
|
13009
|
-
options: {
|
|
13010
|
-
redirectTo: buildCallbackUrl({
|
|
13011
|
-
provider: authProvider,
|
|
13012
|
-
callbackUrl: (_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.redirectTo) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.redirectTo,
|
|
13013
|
-
})
|
|
13014
|
-
},
|
|
13015
|
-
});
|
|
13016
|
-
return onSuccess({
|
|
13017
|
-
data: {},
|
|
13018
|
-
hookOptions,
|
|
13019
|
-
options,
|
|
13020
|
-
});
|
|
13021
|
-
}
|
|
13022
|
-
catch (e) {
|
|
13023
|
-
const error = new OpenfortError("Failed to login with OAuth", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
13024
|
-
setStatus({
|
|
13025
|
-
status: 'error',
|
|
13026
|
-
error
|
|
13027
|
-
});
|
|
13028
|
-
return onError({
|
|
13029
|
-
hookOptions,
|
|
13030
|
-
options,
|
|
13031
|
-
error,
|
|
13032
|
-
});
|
|
13033
|
-
}
|
|
13034
|
-
}, [client, setStatus, updateUser, hookOptions]);
|
|
13035
|
-
const linkOauth = useCallback(async (options) => {
|
|
13036
|
-
var _a;
|
|
13037
|
-
const authProvider = options.provider;
|
|
13038
|
-
try {
|
|
13039
|
-
setStatus({
|
|
13040
|
-
status: 'loading',
|
|
13041
|
-
});
|
|
13042
|
-
const authToken = await client.getAccessToken();
|
|
13043
|
-
if (!authToken) {
|
|
13044
|
-
throw new OpenfortError("No auth token found", OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
13045
|
-
}
|
|
13046
|
-
await client.auth.initLinkOAuth({
|
|
13047
|
-
authToken,
|
|
13048
|
-
provider: getOAuthProvider(authProvider),
|
|
13049
|
-
options: {
|
|
13050
|
-
redirectTo: buildCallbackUrl({
|
|
13051
|
-
provider: authProvider,
|
|
13052
|
-
callbackUrl: (_a = options === null || options === void 0 ? void 0 : options.redirectTo) !== null && _a !== void 0 ? _a : hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.redirectTo,
|
|
13053
|
-
})
|
|
13054
|
-
},
|
|
13055
|
-
});
|
|
13056
|
-
return onSuccess({
|
|
13057
|
-
data: {},
|
|
13058
|
-
hookOptions,
|
|
13059
|
-
options,
|
|
13060
|
-
});
|
|
13061
|
-
}
|
|
13062
|
-
catch (e) {
|
|
13063
|
-
const error = new OpenfortError("Failed to link OAuth", OpenfortErrorType.AUTHENTICATION_ERROR, { error: e });
|
|
13064
|
-
setStatus({
|
|
13065
|
-
status: 'error',
|
|
13066
|
-
error
|
|
13067
|
-
});
|
|
13068
|
-
return onError({
|
|
13069
|
-
hookOptions,
|
|
13070
|
-
options,
|
|
13071
|
-
error,
|
|
13072
|
-
});
|
|
13073
|
-
}
|
|
13074
|
-
}, [client, setStatus, updateUser, hookOptions]);
|
|
13075
|
-
return {
|
|
13076
|
-
initOAuth,
|
|
13077
|
-
linkOauth,
|
|
13078
|
-
...mapStatus(status),
|
|
13079
|
-
};
|
|
13080
|
-
};
|
|
13081
|
-
|
|
13082
|
-
function useSignOut(hookOptions = {}) {
|
|
13083
|
-
const { client, updateUser, user } = useOpenfortCore();
|
|
13084
|
-
const [status, setStatus] = useState({
|
|
13085
|
-
status: "idle",
|
|
13086
|
-
});
|
|
13087
|
-
const { disconnect } = useDisconnect();
|
|
13088
|
-
const signOut = useCallback(async (options = {}) => {
|
|
13089
|
-
if (!user)
|
|
13090
|
-
return;
|
|
13091
|
-
setStatus({
|
|
13092
|
-
status: 'loading',
|
|
13093
|
-
});
|
|
13094
|
-
try {
|
|
13095
|
-
await client.auth.logout();
|
|
13096
|
-
disconnect();
|
|
13097
|
-
updateUser();
|
|
13098
|
-
setStatus({
|
|
13099
|
-
status: 'success',
|
|
13100
|
-
});
|
|
13101
|
-
return onSuccess({
|
|
13102
|
-
hookOptions,
|
|
13103
|
-
options,
|
|
13104
|
-
data: {},
|
|
13105
|
-
});
|
|
13106
|
-
}
|
|
13107
|
-
catch (error) {
|
|
13108
|
-
setStatus({
|
|
13109
|
-
status: 'error',
|
|
13110
|
-
error: new OpenfortError('Failed to sign out', OpenfortErrorType.AUTHENTICATION_ERROR, { error }),
|
|
13111
|
-
});
|
|
13112
|
-
throw error;
|
|
13113
|
-
}
|
|
13114
|
-
}, [client, user, disconnect, updateUser, setStatus, hookOptions]);
|
|
13115
|
-
return {
|
|
13116
|
-
...mapStatus(status),
|
|
13117
|
-
signOut,
|
|
13118
|
-
};
|
|
13119
|
-
}
|
|
13120
|
-
|
|
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 };
|
|
13221
|
+
export { AuthProvider, Avatar, Chain as ChainIcon, OPENFORT_VERSION, OpenfortButton, OpenfortError, OpenfortErrorType, OpenfortProvider, OpenfortStatus, Openfortcontext, 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 };
|
|
13122
13222
|
//# sourceMappingURL=index.es.js.map
|