@openfort/react 0.0.7 → 0.0.9
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 +3 -3
- package/build/assets/icons.d.ts +3 -0
- package/build/components/Common/Loading/index.d.ts +8 -3
- package/build/hooks/openfort/auth/useConnectToWalletPostAuth.d.ts +2 -2
- package/build/hooks/openfort/useWallets.d.ts +16 -12
- package/build/index.d.ts +1 -1
- package/build/index.es.js +388 -211
- package/build/index.es.js.map +1 -1
- package/build/openfort/CoreOpenfortProvider.d.ts +3 -1
- package/build/types.d.ts +2 -1
- package/build/version.d.ts +1 -1
- package/package.json +2 -2
package/build/index.es.js
CHANGED
|
@@ -7,7 +7,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
7
7
|
import React, { useEffect, createContext, useState, useMemo, useRef, useCallback, createElement, useLayoutEffect, useContext } from 'react';
|
|
8
8
|
import { detect } from 'detect-browser';
|
|
9
9
|
import { Buffer } from 'buffer';
|
|
10
|
-
import {
|
|
10
|
+
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
11
11
|
import { motion, AnimatePresence, MotionConfig } from 'framer-motion';
|
|
12
12
|
import styled$1, { css, keyframes } from 'styled-components';
|
|
13
13
|
import { createPortal } from 'react-dom';
|
|
@@ -22,13 +22,14 @@ import { createSiweMessage } from 'viem/siwe';
|
|
|
22
22
|
import { signMessage } from '@wagmi/core';
|
|
23
23
|
import calculateEntropy from 'fast-password-entropy';
|
|
24
24
|
|
|
25
|
-
const OPENFORT_VERSION = '0.0.
|
|
25
|
+
const OPENFORT_VERSION = '0.0.9';
|
|
26
26
|
|
|
27
27
|
var OpenfortErrorType;
|
|
28
28
|
(function (OpenfortErrorType) {
|
|
29
29
|
OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
30
30
|
OpenfortErrorType["WALLET_ERROR"] = "WALLET_ERROR";
|
|
31
31
|
OpenfortErrorType["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
|
|
32
|
+
OpenfortErrorType["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
32
33
|
})(OpenfortErrorType || (OpenfortErrorType = {}));
|
|
33
34
|
class OpenfortError extends Error {
|
|
34
35
|
constructor(message, type, data) {
|
|
@@ -986,19 +987,20 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
|
|
|
986
987
|
const { walletConfig } = useOpenfort();
|
|
987
988
|
// ---- Openfort instance ----
|
|
988
989
|
const openfort = useMemo(() => {
|
|
990
|
+
var _a;
|
|
989
991
|
log('Creating Openfort instance.', openfortProps);
|
|
990
992
|
if (!openfortProps.baseConfiguration.publishableKey)
|
|
991
993
|
throw Error('CoreOpenfortProvider requires a publishableKey to be set in the baseConfiguration.');
|
|
994
|
+
if (openfortProps.shieldConfiguration && !((_a = openfortProps.shieldConfiguration) === null || _a === void 0 ? void 0 : _a.passkeyRpId) && typeof window !== 'undefined') {
|
|
995
|
+
openfortProps.shieldConfiguration = {
|
|
996
|
+
passkeyRpId: window.location.hostname,
|
|
997
|
+
passkeyRpName: document.title || 'Openfort DApp',
|
|
998
|
+
...openfortProps.shieldConfiguration,
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
992
1001
|
const newClient = createOpenfortClient(openfortProps);
|
|
993
1002
|
return newClient;
|
|
994
1003
|
}, []);
|
|
995
|
-
// Create or use provided client
|
|
996
|
-
// const client = useMemo(() => {
|
|
997
|
-
// // return new Openfort(openfortProps)
|
|
998
|
-
// const newClient = createOpenfortClient(openfortProps);
|
|
999
|
-
// setDefaultClient(newClient);
|
|
1000
|
-
// return newClient;
|
|
1001
|
-
// }, [openfortProps]);
|
|
1002
1004
|
// ---- Embedded state ----
|
|
1003
1005
|
const [embeddedState, setEmbeddedState] = useState(EmbeddedState.NONE);
|
|
1004
1006
|
const pollingRef = useRef(null);
|
|
@@ -1087,6 +1089,13 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
|
|
|
1087
1089
|
openfort.embeddedWallet.getEthereumProvider(resolvePolicy());
|
|
1088
1090
|
}, [openfort, walletConfig, chainId]);
|
|
1089
1091
|
const [isConnectedWithEmbeddedSigner, setIsConnectedWithEmbeddedSigner] = useState(false);
|
|
1092
|
+
// will reset on logout
|
|
1093
|
+
const { data: embeddedAccounts, refetch: fetchEmbeddedAccounts, isPending: isLoadingAccounts } = useQuery({
|
|
1094
|
+
queryKey: ['openfortEmbeddedAccountsList'],
|
|
1095
|
+
queryFn: () => openfort.embeddedWallet.list(),
|
|
1096
|
+
refetchOnMount: false,
|
|
1097
|
+
refetchOnWindowFocus: false,
|
|
1098
|
+
});
|
|
1090
1099
|
useEffect(() => {
|
|
1091
1100
|
if (!openfort)
|
|
1092
1101
|
return;
|
|
@@ -1103,6 +1112,7 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
|
|
|
1103
1112
|
if (!user)
|
|
1104
1113
|
updateUser(undefined, true);
|
|
1105
1114
|
setIsConnectedWithEmbeddedSigner(false);
|
|
1115
|
+
fetchEmbeddedAccounts();
|
|
1106
1116
|
break;
|
|
1107
1117
|
case EmbeddedState.READY:
|
|
1108
1118
|
(async () => {
|
|
@@ -1148,7 +1158,7 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
|
|
|
1148
1158
|
log('Logging out...');
|
|
1149
1159
|
await openfort.auth.logout();
|
|
1150
1160
|
await disconnectAsync();
|
|
1151
|
-
queryClient.resetQueries({ queryKey: ['
|
|
1161
|
+
queryClient.resetQueries({ queryKey: ['openfortEmbeddedAccountsList'] });
|
|
1152
1162
|
reset();
|
|
1153
1163
|
startPollingEmbeddedState();
|
|
1154
1164
|
}, [openfort]);
|
|
@@ -1198,6 +1208,8 @@ const CoreOpenfortProvider = ({ children, debugMode, onConnect, onDisconnect, ..
|
|
|
1198
1208
|
needsRecovery,
|
|
1199
1209
|
user,
|
|
1200
1210
|
updateUser,
|
|
1211
|
+
embeddedAccounts,
|
|
1212
|
+
isLoadingAccounts,
|
|
1201
1213
|
client: openfort,
|
|
1202
1214
|
};
|
|
1203
1215
|
return createElement(Context$1.Provider, { value }, jsxs(Fragment, { children: [jsx(ConnectCallback, { onConnect: onConnect, onDisconnect: onDisconnect }), children] }));
|
|
@@ -1354,7 +1366,7 @@ var base = {
|
|
|
1354
1366
|
'--ck-body-disclaimer-link-hover-color': '#FFFFFF',
|
|
1355
1367
|
'--ck-modal-box-shadow': '0px 2px 4px rgba(0, 0, 0, 0.02)',
|
|
1356
1368
|
'--ck-copytoclipboard-stroke': '#555555',
|
|
1357
|
-
'--ck-tooltip-background': '#
|
|
1369
|
+
'--ck-tooltip-background': '#323232ff',
|
|
1358
1370
|
'--ck-tooltip-background-secondary': '#333333',
|
|
1359
1371
|
'--ck-tooltip-color': '#999999',
|
|
1360
1372
|
'--ck-tooltip-shadow': '0px 2px 10px rgba(0, 0, 0, 0.08)',
|
|
@@ -2047,6 +2059,8 @@ const themeGlobals = {
|
|
|
2047
2059
|
'--ck-chain-ethereum-01': '#25292E',
|
|
2048
2060
|
'--ck-chain-ethereum-02': '#fff',
|
|
2049
2061
|
'--ck-chain-ethereum-03': '#DFE0E0',
|
|
2062
|
+
'--ck-body-color-danger': '#FF4E4E',
|
|
2063
|
+
'--ck-body-color-valid': '#32D74B',
|
|
2050
2064
|
},
|
|
2051
2065
|
dark: {
|
|
2052
2066
|
'--ck-graphic-wave-stop-01': '#E8F17D',
|
|
@@ -2058,6 +2072,8 @@ const themeGlobals = {
|
|
|
2058
2072
|
'--ck-graphic-scaniconwithlogos-02': '#696969',
|
|
2059
2073
|
'--ck-graphic-scaniconwithlogos-03': '#F8D74A',
|
|
2060
2074
|
'--ck-graphic-scaniconwithlogos-04': '#3D3D3D',
|
|
2075
|
+
'--ck-body-color-danger': '#FF4E4E',
|
|
2076
|
+
'--ck-body-color-valid': '#32D74B',
|
|
2061
2077
|
//'--ck-chain-ethereum-01': '#fff',
|
|
2062
2078
|
//'--ck-chain-ethereum-02': '#000',
|
|
2063
2079
|
//'--ck-chain-ethereum-03': '#000',
|
|
@@ -3100,9 +3116,10 @@ const EmailIcon = ({ ...props }) => (jsxs("svg", { xmlns: "http://www.w3.org/200
|
|
|
3100
3116
|
const GuestIcon = ({ ...props }) => (jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 256 256", width: "256", height: "256", children: [jsx("rect", { width: "256", height: "256", fill: "none" }), jsx("circle", { cx: "128", cy: "96", r: "64", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" }), jsx("path", { d: "M32,216c19.37-33.47,54.55-56,96-56s76.63,22.53,96,56", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "16" })] }));
|
|
3101
3117
|
const EyeIcon = ({ ...props }) => (jsxs("svg", { width: "800", height: "800", fill: "none", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: [jsx("path", { d: "m15.001 12c0 1.6569-1.3431 3-3 3-1.6568 0-3-1.3431-3-3s1.3432-3 3-3c1.6569 0 3 1.3431 3 3z", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2 }), jsx("path", { d: "m12.001 5c-4.4777 0-8.2679 2.9429-9.5422 7 1.2743 4.0571 5.0646 7 9.5422 7 4.4776 0 8.2679-2.9429 9.5422-7-1.2743-4.0571-5.0646-7-9.5422-7z", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2 })] }));
|
|
3102
3118
|
const EyeOffIcon = ({ ...props }) => (jsx("svg", { width: "800", height: "800", fill: "none", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: jsx("path", { d: "m2.999 3 18 18m-11.156-11.086c-0.52264 0.53996-0.84428 1.2756-0.84428 2.0864 0 1.6569 1.3432 3 3 3 0.8225 0 1.5677-0.331 2.1096-0.867m-7.6096-7.4858c-1.8993 1.2532-3.346 3.1368-4.042 5.3528 1.2742 4.0571 5.0646 7 9.5422 7 1.9889 0 3.8422-0.5806 5.3996-1.5816m-6.3998-12.369c0.329-0.03266 0.6627-0.04939 1.0002-0.04939 4.4777 0 8.268 2.9429 9.5422 7-0.2807 0.894-0.6837 1.7338-1.1892 2.5", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2 }) }));
|
|
3103
|
-
const KeyIcon = ({ ...props }) => (jsx("svg", { transform: "matrix(1 0 0 1 0 0)", width: "
|
|
3104
|
-
const LockIcon = ({ ...props }) => (jsxs("svg", { fill: "none", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: [jsx("path", { d: "m9 16c0 0.5523-0.44772 1-1 1s-1-0.4477-1-1 0.44772-1 1-1 1 0.4477 1 1z", fill: "currentColor" }), jsx("path", { d: "m13 16c0 0.5523-0.4477 1-1 1s-1-0.4477-1-1 0.4477-1 1-1 1 0.4477 1 1z", fill: "currentColor" }), jsx("path", { d: "m17 16c0 0.5523-0.4477 1-1 1s-1-0.4477-1-1 0.4477-1 1-1 1 0.4477 1 1z", fill: "currentColor" }), jsx("path", { d: "m6 10v-2c0-0.34071 0.0284-0.67479 0.08296-1m11.917 3v-2c0-3.3137-2.6863-6-6-6-1.792 0-3.4006 0.78563-4.5 2.0313", stroke: "currentColor", strokeLinecap: "round", strokeWidth: 1.
|
|
3119
|
+
const KeyIcon = ({ ...props }) => (jsx("svg", { transform: "matrix(1 0 0 1 0 0)", width: "24", height: "24", fill: "none", stroke: "#000000", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: jsx("path", { d: "M15 15a6 6 0 1 0-5.743-4.257L9 11l-5.707 5.707a1 1 0 0 0-.293.707V20a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1 1 1 0 0 1 1-1 1 1 0 0 0 1-1 1 1 0 0 1 1-1h.586a1 1 0 0 0 .707-.293L13 15l.257-.257A5.999 5.999 0 0 0 15 15zm2-6a2 2 0 0 0-2-2", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.152 }) }));
|
|
3120
|
+
const LockIcon = ({ ...props }) => (jsxs("svg", { fill: "none", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: [jsx("path", { d: "m9 16c0 0.5523-0.44772 1-1 1s-1-0.4477-1-1 0.44772-1 1-1 1 0.4477 1 1z", fill: "currentColor" }), jsx("path", { d: "m13 16c0 0.5523-0.4477 1-1 1s-1-0.4477-1-1 0.4477-1 1-1 1 0.4477 1 1z", fill: "currentColor" }), jsx("path", { d: "m17 16c0 0.5523-0.4477 1-1 1s-1-0.4477-1-1 0.4477-1 1-1 1 0.4477 1 1z", fill: "currentColor" }), jsx("path", { d: "m6 10v-2c0-0.34071 0.0284-0.67479 0.08296-1m11.917 3v-2c0-3.3137-2.6863-6-6-6-1.792 0-3.4006 0.78563-4.5 2.0313", stroke: "currentColor", strokeLinecap: "round", strokeWidth: 1.152 }), jsx("path", { d: "m11 22h-3c-2.8284 0-4.2426 0-5.1213-0.8787s-0.87868-2.2929-0.87868-5.1213 0-4.2426 0.87868-5.1213 2.2929-0.8787 5.1213-0.8787h8c2.8284 0 4.2426 0 5.1213 0.8787s0.8787 2.2929 0.8787 5.1213 0 4.2426-0.8787 5.1213-2.2929 0.8787-5.1213 0.8787h-1", stroke: "currentColor", strokeLinecap: "round", strokeWidth: 1.152 })] }));
|
|
3105
3121
|
const ShieldIcon = ({ ...props }) => (jsx("svg", { fill: "none", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: jsx("path", { d: "m9 12 2 2 4-4m5 2c0 4.4611-5.46 7.6937-7.3586 8.683-0.2053 0.107-0.308 0.1605-0.4504 0.1882-0.111 0.0216-0.271 0.0216-0.382 0-0.1424-0.0277-0.2451-0.0812-0.4504-0.1882-1.8986-0.9893-7.3586-4.2219-7.3586-8.683v-3.7824c0-0.79951 0-1.1993 0.13076-1.5429 0.11551-0.30357 0.30322-0.57443 0.5469-0.78918 0.27584-0.24309 0.65014-0.38345 1.3987-0.66418l5.3618-2.0107c0.2079-0.07796 0.3118-0.11694 0.4188-0.1324 0.0948-0.0137 0.1912-0.0137 0.286 0 0.107 0.01546 0.2109 0.05444 0.4188 0.1324l5.3618 2.0107c0.7486 0.28073 1.1229 0.42109 1.3987 0.66418 0.2437 0.21475 0.4314 0.48561 0.5469 0.78918 0.1308 0.34363 0.1308 0.74338 0.1308 1.5429v3.7824z", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.2 }) }));
|
|
3122
|
+
const FingerPrintIcon = ({ ...props }) => (jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 256 256", ...props, children: [jsx("rect", { width: 256, height: 256, fill: "none" }), jsx("path", { d: "M50.69,184.92A127.52,127.52,0,0,0,64,128a63.85,63.85,0,0,1,24-50", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 10 }), jsx("path", { d: "M128,128a191.11,191.11,0,0,1-24,93", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 10 }), jsx("path", { d: "M96,128a32,32,0,0,1,64,0,223.12,223.12,0,0,1-21.28,95.41", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 10 }), jsx("path", { d: "M218.56,184A289.45,289.45,0,0,0,224,128a96,96,0,0,0-192,0,95.8,95.8,0,0,1-5.47,32", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 10 }), jsx("path", { d: "M92.81,160a158.92,158.92,0,0,1-18.12,47.84", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 10 }), jsx("path", { d: "M120,64.5a66,66,0,0,1,8-.49,64,64,0,0,1,64,64,259.86,259.86,0,0,1-2,32", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 10 }), jsx("path", { d: "M183.94,192q-2.28,8.88-5.18,17.5", fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 10 })] }));
|
|
3106
3123
|
|
|
3107
3124
|
const KEYCODE_TAB = 9;
|
|
3108
3125
|
function useFocusTrap() {
|
|
@@ -9312,7 +9329,7 @@ const ProviderIcon = ({ provider }) => {
|
|
|
9312
9329
|
case "facebook":
|
|
9313
9330
|
return providersLogos[provider.provider];
|
|
9314
9331
|
default:
|
|
9315
|
-
return jsx(FitText, { children: provider.provider.substring(0,
|
|
9332
|
+
return jsx(FitText, { children: provider.provider.substring(0, 4).toUpperCase() });
|
|
9316
9333
|
}
|
|
9317
9334
|
};
|
|
9318
9335
|
const LinkedProvider = ({ provider }) => {
|
|
@@ -9394,15 +9411,15 @@ const Content = styled(motion.div) `
|
|
|
9394
9411
|
gap: 12px;
|
|
9395
9412
|
}
|
|
9396
9413
|
`;
|
|
9397
|
-
const dist = 2;
|
|
9398
|
-
const shakeKeyframes = keyframes `
|
|
9414
|
+
const dist$1 = 2;
|
|
9415
|
+
const shakeKeyframes$1 = keyframes `
|
|
9399
9416
|
0%{ transform:none; }
|
|
9400
|
-
25%{ transform:translateX(${dist}px); }
|
|
9401
|
-
50%{ transform:translateX(-${dist}px); }
|
|
9402
|
-
75%{ transform:translateX(${dist}px); }
|
|
9417
|
+
25%{ transform:translateX(${dist$1}px); }
|
|
9418
|
+
50%{ transform:translateX(-${dist$1}px); }
|
|
9419
|
+
75%{ transform:translateX(${dist$1}px); }
|
|
9403
9420
|
100%{ transform:none; }
|
|
9404
9421
|
`;
|
|
9405
|
-
const outlineKeyframes = keyframes `
|
|
9422
|
+
const outlineKeyframes$1 = keyframes `
|
|
9406
9423
|
0%{ opacity:1; }
|
|
9407
9424
|
100%{ opacity:0; }
|
|
9408
9425
|
`;
|
|
@@ -9441,9 +9458,9 @@ const ConnectingAnimation$1 = styled(motion.div) `
|
|
|
9441
9458
|
}
|
|
9442
9459
|
${(props) => props.$shake &&
|
|
9443
9460
|
css `
|
|
9444
|
-
animation: ${shakeKeyframes} 220ms ease-out both;
|
|
9461
|
+
animation: ${shakeKeyframes$1} 220ms ease-out both;
|
|
9445
9462
|
&:before {
|
|
9446
|
-
animation: ${outlineKeyframes} 220ms ease-out 750ms both;
|
|
9463
|
+
animation: ${outlineKeyframes$1} 220ms ease-out 750ms both;
|
|
9447
9464
|
}
|
|
9448
9465
|
`}
|
|
9449
9466
|
`;
|
|
@@ -9451,8 +9468,8 @@ const RetryButton = styled(motion.button) `
|
|
|
9451
9468
|
z-index: 5;
|
|
9452
9469
|
appearance: none;
|
|
9453
9470
|
position: absolute;
|
|
9454
|
-
right:
|
|
9455
|
-
bottom:
|
|
9471
|
+
right: 10px;
|
|
9472
|
+
bottom: 10px;
|
|
9456
9473
|
padding: 0;
|
|
9457
9474
|
display: flex;
|
|
9458
9475
|
align-items: center;
|
|
@@ -9464,7 +9481,7 @@ const RetryButton = styled(motion.button) `
|
|
|
9464
9481
|
overflow: hidden;
|
|
9465
9482
|
background: none;
|
|
9466
9483
|
|
|
9467
|
-
color: var(--ck-body-background);
|
|
9484
|
+
color: var(--ck-body-background-secondary);
|
|
9468
9485
|
transition: color 200ms ease;
|
|
9469
9486
|
box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.15);
|
|
9470
9487
|
|
|
@@ -10153,6 +10170,7 @@ const TextWrapper = styled.div `
|
|
|
10153
10170
|
flex-direction: column;
|
|
10154
10171
|
gap: 12px;
|
|
10155
10172
|
padding: 0 8px 32px;
|
|
10173
|
+
text-align: center;
|
|
10156
10174
|
`;
|
|
10157
10175
|
const ConnectingContainer = styled(motion.div) `
|
|
10158
10176
|
display: flex;
|
|
@@ -10161,7 +10179,20 @@ justify-content: center;
|
|
|
10161
10179
|
margin: 10px auto 16px;
|
|
10162
10180
|
height: 120px;
|
|
10163
10181
|
`;
|
|
10182
|
+
const dist = 2;
|
|
10183
|
+
const shakeKeyframes = keyframes `
|
|
10184
|
+
0%{ transform:none; }
|
|
10185
|
+
25%{ transform:translateX(${dist}px); }
|
|
10186
|
+
50%{ transform:translateX(-${dist}px); }
|
|
10187
|
+
75%{ transform:translateX(${dist}px); }
|
|
10188
|
+
100%{ transform:none; }
|
|
10189
|
+
`;
|
|
10190
|
+
const outlineKeyframes = keyframes `
|
|
10191
|
+
0%{ opacity:0; }
|
|
10192
|
+
100%{ opacity:1; }
|
|
10193
|
+
`;
|
|
10164
10194
|
const ConnectingAnimation = styled(motion.div) `
|
|
10195
|
+
position: relative;
|
|
10165
10196
|
user-select: none;
|
|
10166
10197
|
position: relative;
|
|
10167
10198
|
--spinner-error-opacity: 0;
|
|
@@ -10170,18 +10201,26 @@ const ConnectingAnimation = styled(motion.div) `
|
|
|
10170
10201
|
position: absolute;
|
|
10171
10202
|
inset: 1px;
|
|
10172
10203
|
opacity: 0;
|
|
10173
|
-
background:
|
|
10204
|
+
background: ${(props) => props.$color};
|
|
10174
10205
|
}
|
|
10175
|
-
${(props) => props.$
|
|
10206
|
+
${(props) => !!props.$color &&
|
|
10176
10207
|
css `
|
|
10177
10208
|
&:before {
|
|
10178
10209
|
opacity: 1;
|
|
10179
10210
|
}
|
|
10180
10211
|
`}
|
|
10212
|
+
${(props) => props.$shake &&
|
|
10213
|
+
css `
|
|
10214
|
+
animation: ${shakeKeyframes} 220ms ease-out both;
|
|
10215
|
+
&:before {
|
|
10216
|
+
animation: ${outlineKeyframes} 220ms ease-out both;
|
|
10217
|
+
}
|
|
10218
|
+
`}
|
|
10181
10219
|
`;
|
|
10182
|
-
const Loader = ({
|
|
10220
|
+
const Loader = ({ header, description, icon, isError = false, isSuccess = false, isLoading = !isError && !isSuccess, onRetry, }) => {
|
|
10183
10221
|
const { uiConfig: options } = useOpenfort();
|
|
10184
10222
|
const { triggerResize } = useOpenfort();
|
|
10223
|
+
const locales = useLocales();
|
|
10185
10224
|
useEffect(() => {
|
|
10186
10225
|
return () => triggerResize();
|
|
10187
10226
|
}, []);
|
|
@@ -10197,11 +10236,11 @@ const Loader = ({ reason, isLoading = true, icon }) => {
|
|
|
10197
10236
|
}
|
|
10198
10237
|
return jsx(Logos.Openfort, {});
|
|
10199
10238
|
};
|
|
10200
|
-
return (jsxs(Fragment, { children: [jsx(ConnectingContainer, { children:
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10239
|
+
return (jsxs(Fragment, { children: [jsx(ConnectingContainer, { children: jsxs(ConnectingAnimation, { "$color": isSuccess ? 'var(--ck-body-color-valid)' : isError ? 'var(--ck-body-color-danger)' : undefined, "$shake": isError, children: [jsx(AnimatePresence, { children: (isError && onRetry) && (jsx(RetryButton, { "aria-label": "Retry", initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.8 }, whileTap: { scale: 0.9 }, transition: { duration: 0.1 }, onClick: onRetry, children: jsx(RetryIconContainer, { children: jsx(Tooltip, { open: isError, message: locales.tryAgainQuestion, xOffset: -6, children: jsx(RetryIconCircle, {}) }) }) })) }), jsx(SquircleSpinner, { logo: jsx("div", { style: {
|
|
10240
|
+
padding: '12px',
|
|
10241
|
+
position: 'relative',
|
|
10242
|
+
width: '100%',
|
|
10243
|
+
}, children: renderLogo() }), connecting: isLoading })] }) }), jsxs(TextWrapper, { children: [isLoading && (jsxs(Fragment, { children: [jsx(ModalH1, { children: "Loading, please wait" }), jsx(ModalBody, { children: description !== null && description !== void 0 ? description : header })] })), isSuccess && (jsxs(Fragment, { children: [jsxs(ModalH1, { "$valid": true, children: [jsx(TickIcon, {}), " ", header] }), jsx(ModalBody, { children: description })] })), isError && (jsxs(Fragment, { children: [jsx(ModalH1, { "$error": true, children: header }), jsx(ModalBody, { children: description })] }))] })] }));
|
|
10205
10244
|
};
|
|
10206
10245
|
|
|
10207
10246
|
const states$1 = {
|
|
@@ -10299,7 +10338,7 @@ const ConnectWithOAuth = ({}) => {
|
|
|
10299
10338
|
}
|
|
10300
10339
|
})();
|
|
10301
10340
|
}, [status]);
|
|
10302
|
-
return (jsx(PageContent, { children: jsx(Loader, {
|
|
10341
|
+
return (jsx(PageContent, { children: jsx(Loader, { header: `Connecting with ${connector.id}`, icon: providersLogos[connector.id] }) }));
|
|
10303
10342
|
};
|
|
10304
10343
|
|
|
10305
10344
|
const states = {
|
|
@@ -10650,7 +10689,7 @@ const EmailVerification = () => {
|
|
|
10650
10689
|
})();
|
|
10651
10690
|
}, []);
|
|
10652
10691
|
if (loading) {
|
|
10653
|
-
return (jsx(PageContent, { children: jsx(Loader, {
|
|
10692
|
+
return (jsx(PageContent, { children: jsx(Loader, { header: "Checking if account is verified" }) }));
|
|
10654
10693
|
}
|
|
10655
10694
|
return (jsxs(PageContent, { children: [jsx(FloatingGraphic, { height: "190px", logoCenter: {
|
|
10656
10695
|
logo: jsx(EmailIcon, {}),
|
|
@@ -10878,7 +10917,7 @@ const Loading = () => {
|
|
|
10878
10917
|
// UX: Wait a bit before showing the next page
|
|
10879
10918
|
setTimeout(() => setIsFirstFrame(false), 400);
|
|
10880
10919
|
}, []);
|
|
10881
|
-
return (jsx(PageContent, { children: jsx(Loader, {
|
|
10920
|
+
return (jsx(PageContent, { children: jsx(Loader, { header: "Redirecting" }) }));
|
|
10882
10921
|
};
|
|
10883
10922
|
|
|
10884
10923
|
const ProviderButton = ({ children, icon, onClick }) => {
|
|
@@ -10942,7 +10981,7 @@ const AddressButNoUserCase = () => {
|
|
|
10942
10981
|
console.error("Failed to update user");
|
|
10943
10982
|
});
|
|
10944
10983
|
}, []);
|
|
10945
|
-
return (jsx(PageContent, { children: jsx(Loader, {
|
|
10984
|
+
return (jsx(PageContent, { children: jsx(Loader, { header: "Updating user" }) }));
|
|
10946
10985
|
};
|
|
10947
10986
|
const SocialProvidersButton = () => {
|
|
10948
10987
|
const { setRoute } = useOpenfort();
|
|
@@ -11031,14 +11070,23 @@ function useUser() {
|
|
|
11031
11070
|
};
|
|
11032
11071
|
}
|
|
11033
11072
|
|
|
11034
|
-
const
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11073
|
+
const parseEmbeddedAccount = (embeddedAccount) => {
|
|
11074
|
+
var _a;
|
|
11075
|
+
return ({
|
|
11076
|
+
connectorType: "embedded",
|
|
11077
|
+
walletClientType: "openfort",
|
|
11078
|
+
address: embeddedAccount.address,
|
|
11079
|
+
id: embeddedWalletId,
|
|
11080
|
+
isAvailable: true,
|
|
11081
|
+
recoveryMethod: (_a = embeddedAccount.recoveryMethod) !== null && _a !== void 0 ? _a : RecoveryMethod.AUTOMATIC,
|
|
11082
|
+
accountId: embeddedAccount.id,
|
|
11083
|
+
accountType: embeddedAccount.accountType,
|
|
11084
|
+
ownerAddress: embeddedAccount.ownerAddress,
|
|
11085
|
+
implementationType: embeddedAccount.implementationType,
|
|
11086
|
+
salt: embeddedAccount.salt,
|
|
11087
|
+
createdAt: embeddedAccount.createdAt,
|
|
11088
|
+
});
|
|
11089
|
+
};
|
|
11042
11090
|
const mapWalletStatus = (status) => {
|
|
11043
11091
|
return {
|
|
11044
11092
|
error: status.error,
|
|
@@ -11049,7 +11097,7 @@ const mapWalletStatus = (status) => {
|
|
|
11049
11097
|
};
|
|
11050
11098
|
};
|
|
11051
11099
|
function useWallets(hookOptions = {}) {
|
|
11052
|
-
const { client } = useOpenfortCore();
|
|
11100
|
+
const { client, embeddedAccounts, isLoadingAccounts: isLoadingWallets } = useOpenfortCore();
|
|
11053
11101
|
const { user } = useUser();
|
|
11054
11102
|
const { walletConfig, log, setOpen, setRoute, setConnector, uiConfig } = useOpenfort();
|
|
11055
11103
|
const { connector, isConnected, address } = useAccount();
|
|
@@ -11091,13 +11139,6 @@ function useWallets(hookOptions = {}) {
|
|
|
11091
11139
|
}
|
|
11092
11140
|
}
|
|
11093
11141
|
});
|
|
11094
|
-
// will reset on logout
|
|
11095
|
-
const { data: embeddedWallets, refetch, isPending: isLoadingWallets } = useQuery({
|
|
11096
|
-
queryKey: ['openfortEmbeddedWalletList'],
|
|
11097
|
-
queryFn: () => client.embeddedWallet.list(),
|
|
11098
|
-
refetchOnMount: false,
|
|
11099
|
-
refetchOnWindowFocus: false,
|
|
11100
|
-
});
|
|
11101
11142
|
const getEncryptionSession = useCallback(async () => {
|
|
11102
11143
|
if (!walletConfig || !walletConfig.createEncryptedSessionEndpoint) {
|
|
11103
11144
|
throw new Error("No createEncryptedSessionEndpoint set in walletConfig");
|
|
@@ -11114,6 +11155,58 @@ function useWallets(hookOptions = {}) {
|
|
|
11114
11155
|
const respJSON = await resp.json();
|
|
11115
11156
|
return respJSON.session;
|
|
11116
11157
|
}, [walletConfig]);
|
|
11158
|
+
const parseWalletRecovery = useMemo(() => async function parseWalletRecovery(recovery, embeddedAccounts, walletAddress) {
|
|
11159
|
+
var _a, _b;
|
|
11160
|
+
switch (recovery === null || recovery === void 0 ? void 0 : recovery.recoveryMethod) {
|
|
11161
|
+
case undefined:
|
|
11162
|
+
case RecoveryMethod.AUTOMATIC:
|
|
11163
|
+
const accessToken = await client.getAccessToken();
|
|
11164
|
+
if (!accessToken) {
|
|
11165
|
+
throw new OpenfortError("Openfort access token not found", OpenfortErrorType.AUTHENTICATION_ERROR);
|
|
11166
|
+
}
|
|
11167
|
+
return {
|
|
11168
|
+
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
11169
|
+
encryptionSession: (walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.getEncryptionSession) ?
|
|
11170
|
+
await walletConfig.getEncryptionSession(accessToken) :
|
|
11171
|
+
await getEncryptionSession()
|
|
11172
|
+
};
|
|
11173
|
+
case RecoveryMethod.PASSWORD:
|
|
11174
|
+
if (!recovery.password) {
|
|
11175
|
+
throw new OpenfortError("Please enter your password", OpenfortErrorType.VALIDATION_ERROR);
|
|
11176
|
+
}
|
|
11177
|
+
return {
|
|
11178
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11179
|
+
password: recovery.password,
|
|
11180
|
+
};
|
|
11181
|
+
case RecoveryMethod.PASSKEY:
|
|
11182
|
+
if (!embeddedAccounts) {
|
|
11183
|
+
return {
|
|
11184
|
+
recoveryMethod: RecoveryMethod.PASSKEY,
|
|
11185
|
+
};
|
|
11186
|
+
}
|
|
11187
|
+
if (!walletAddress) {
|
|
11188
|
+
walletAddress = (_a = embeddedAccounts.find(w => w.recoveryMethod === RecoveryMethod.PASSKEY)) === null || _a === void 0 ? void 0 : _a.address;
|
|
11189
|
+
if (!walletAddress) {
|
|
11190
|
+
throw new OpenfortError("No wallet address provided and no embedded wallet with passkey recovery found", OpenfortErrorType.VALIDATION_ERROR);
|
|
11191
|
+
}
|
|
11192
|
+
}
|
|
11193
|
+
const details = (_b = embeddedAccounts.find(w => w.address === walletAddress && w.recoveryMethod === RecoveryMethod.PASSKEY)) === null || _b === void 0 ? void 0 : _b.recoveryMethodDetails;
|
|
11194
|
+
const passkeyId = details === null || details === void 0 ? void 0 : details.passkeyId;
|
|
11195
|
+
const passkeyEnv = details === null || details === void 0 ? void 0 : details.passkeyEnv;
|
|
11196
|
+
if (!passkeyId || !passkeyEnv) {
|
|
11197
|
+
throw new OpenfortError("No passkey details found for the wallet", OpenfortErrorType.VALIDATION_ERROR);
|
|
11198
|
+
}
|
|
11199
|
+
return {
|
|
11200
|
+
recoveryMethod: RecoveryMethod.PASSKEY,
|
|
11201
|
+
passkeyInfo: {
|
|
11202
|
+
passkeyId,
|
|
11203
|
+
passkeyEnv,
|
|
11204
|
+
},
|
|
11205
|
+
};
|
|
11206
|
+
default:
|
|
11207
|
+
throw new OpenfortError("Invalid recovery method", OpenfortErrorType.VALIDATION_ERROR);
|
|
11208
|
+
}
|
|
11209
|
+
}, [walletConfig, getEncryptionSession]);
|
|
11117
11210
|
const rawWallets = useMemo(() => {
|
|
11118
11211
|
const userWallets = user ? user.linkedAccounts
|
|
11119
11212
|
.filter((a) => a.provider === UIAuthProvider.WALLET)
|
|
@@ -11127,38 +11220,34 @@ function useWallets(hookOptions = {}) {
|
|
|
11127
11220
|
isAvailable: !!wallet,
|
|
11128
11221
|
};
|
|
11129
11222
|
}) : [];
|
|
11130
|
-
|
|
11223
|
+
embeddedAccounts === null || embeddedAccounts === void 0 ? void 0 : embeddedAccounts.forEach((embeddedAccount) => {
|
|
11131
11224
|
// Remove duplicates (different chain ids)
|
|
11132
|
-
if (userWallets.find(w => w.address === (
|
|
11225
|
+
if (userWallets.find(w => w.address === (embeddedAccount.address)))
|
|
11133
11226
|
return;
|
|
11134
|
-
userWallets.push(
|
|
11135
|
-
address: wallet.address,
|
|
11136
|
-
recoveryMethod: wallet.recoveryMethod,
|
|
11137
|
-
}));
|
|
11227
|
+
userWallets.push(parseEmbeddedAccount(embeddedAccount));
|
|
11138
11228
|
});
|
|
11139
11229
|
return userWallets;
|
|
11140
|
-
}, [user === null || user === void 0 ? void 0 : user.linkedAccounts,
|
|
11230
|
+
}, [user === null || user === void 0 ? void 0 : user.linkedAccounts, embeddedAccounts]);
|
|
11141
11231
|
const wallets = useMemo(() => {
|
|
11142
|
-
//
|
|
11143
|
-
log("Mapping wallets", { rawWallets, status, address, isConnected, connector });
|
|
11232
|
+
// log("Mapping wallets", { rawWallets, status, address, isConnected, connector: connector?.id });
|
|
11144
11233
|
return rawWallets.map((w) => ({
|
|
11145
11234
|
...w,
|
|
11146
11235
|
isConnecting: status.status === 'connecting' && status.address === w.address,
|
|
11147
11236
|
isActive: w.address === address && isConnected && (connector === null || connector === void 0 ? void 0 : connector.id) === w.id,
|
|
11148
11237
|
}));
|
|
11149
|
-
}, [rawWallets, status, address, isConnected, connector]);
|
|
11238
|
+
}, [rawWallets.length, status.status, address, isConnected, connector === null || connector === void 0 ? void 0 : connector.id]);
|
|
11150
11239
|
const activeWallet = isConnected && connector ? wallets.find((w) => w.isActive) : undefined;
|
|
11151
11240
|
useEffect(() => {
|
|
11152
11241
|
if (connectToConnector)
|
|
11153
11242
|
connect({ connector: connectToConnector.connector });
|
|
11154
11243
|
}, [connectToConnector]);
|
|
11155
11244
|
const setActiveWallet = useCallback(async (options) => {
|
|
11156
|
-
var _a;
|
|
11157
|
-
const optionsObject = typeof options === "string" ? {
|
|
11245
|
+
var _a, _b, _c, _d, _e;
|
|
11246
|
+
const optionsObject = typeof options === "string" ? { walletId: options } : options;
|
|
11158
11247
|
const { showUI } = optionsObject;
|
|
11159
11248
|
let connector = null;
|
|
11160
|
-
if (typeof optionsObject.
|
|
11161
|
-
const wallet = deviceWallets.find(c => c.id === optionsObject.
|
|
11249
|
+
if (typeof optionsObject.walletId === 'string') {
|
|
11250
|
+
const wallet = deviceWallets.find(c => c.id === optionsObject.walletId);
|
|
11162
11251
|
if (!wallet) {
|
|
11163
11252
|
log("Connector not found", connector);
|
|
11164
11253
|
return { error: new OpenfortError("Connector not found", OpenfortErrorType.WALLET_ERROR) };
|
|
@@ -11167,10 +11256,10 @@ function useWallets(hookOptions = {}) {
|
|
|
11167
11256
|
connector = wallet.connector;
|
|
11168
11257
|
}
|
|
11169
11258
|
else {
|
|
11170
|
-
connector = optionsObject.
|
|
11259
|
+
connector = optionsObject.walletId;
|
|
11171
11260
|
}
|
|
11172
11261
|
if (!connector) {
|
|
11173
|
-
log("Connector not found", deviceWallets, optionsObject.
|
|
11262
|
+
log("Connector not found", deviceWallets, optionsObject.walletId);
|
|
11174
11263
|
return { error: new OpenfortError("Connector not found", OpenfortErrorType.WALLET_ERROR) };
|
|
11175
11264
|
}
|
|
11176
11265
|
if ((activeWallet === null || activeWallet === void 0 ? void 0 : activeWallet.id) === connector.id && address === optionsObject.address) {
|
|
@@ -11203,7 +11292,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11203
11292
|
return {};
|
|
11204
11293
|
}
|
|
11205
11294
|
function isOpenfortWallet(opts) {
|
|
11206
|
-
return opts.
|
|
11295
|
+
return opts.walletId === embeddedWalletId;
|
|
11207
11296
|
}
|
|
11208
11297
|
log("Setting active wallet", { options: optionsObject, chainId });
|
|
11209
11298
|
if (isOpenfortWallet(optionsObject)) {
|
|
@@ -11211,7 +11300,6 @@ function useWallets(hookOptions = {}) {
|
|
|
11211
11300
|
status: 'connecting',
|
|
11212
11301
|
address: optionsObject.address,
|
|
11213
11302
|
});
|
|
11214
|
-
const { password } = optionsObject;
|
|
11215
11303
|
if (!walletConfig) {
|
|
11216
11304
|
return onError({
|
|
11217
11305
|
error: new OpenfortError("Embedded signer not enabled", OpenfortErrorType.WALLET_ERROR),
|
|
@@ -11219,56 +11307,64 @@ function useWallets(hookOptions = {}) {
|
|
|
11219
11307
|
hookOptions
|
|
11220
11308
|
});
|
|
11221
11309
|
}
|
|
11222
|
-
const accessToken = await client.getAccessToken();
|
|
11223
|
-
if (!accessToken) {
|
|
11224
|
-
return onError({
|
|
11225
|
-
error: new OpenfortError("Openfort access token not found", OpenfortErrorType.WALLET_ERROR),
|
|
11226
|
-
hookOptions,
|
|
11227
|
-
options: optionsObject,
|
|
11228
|
-
});
|
|
11229
|
-
}
|
|
11230
|
-
log(`Handling recovery with Openfort: ${password ? "with password" : "without password"}, chainId=${chainId}`);
|
|
11231
11310
|
try {
|
|
11232
|
-
const
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
}
|
|
11236
|
-
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
11237
|
-
encryptionSession: walletConfig.getEncryptionSession ?
|
|
11238
|
-
await walletConfig.getEncryptionSession(accessToken) :
|
|
11239
|
-
await getEncryptionSession()
|
|
11240
|
-
};
|
|
11241
|
-
// Ensure that the embedded wallet is listed
|
|
11242
|
-
const embeddedWallets = await client.embeddedWallet.list();
|
|
11243
|
-
log("Recovery params", optionsObject.address);
|
|
11244
|
-
log("Embedded wallets", embeddedWallets, chainId);
|
|
11311
|
+
const embeddedAccounts = await queryClient.ensureQueryData({
|
|
11312
|
+
queryKey: ['openfortEmbeddedAccountsList'],
|
|
11313
|
+
queryFn: () => client.embeddedWallet.list()
|
|
11314
|
+
});
|
|
11245
11315
|
let walletAddress = optionsObject.address;
|
|
11316
|
+
// Ensure that the embedded wallet is listed
|
|
11317
|
+
log("Embedded wallets", embeddedAccounts, chainId);
|
|
11318
|
+
let embeddedAccount;
|
|
11246
11319
|
if (walletAddress) {
|
|
11247
|
-
const
|
|
11248
|
-
if (!
|
|
11320
|
+
const accountToRecover = embeddedAccounts.find(w => w.address === walletAddress && w.chainId === chainId);
|
|
11321
|
+
if (!accountToRecover) {
|
|
11322
|
+
// TODO: Connect to wallet in the other chain and then switch chain
|
|
11323
|
+
return onError({
|
|
11324
|
+
error: new OpenfortError(`Embedded wallet not found for address ${walletAddress} and chainId ${chainId}`, OpenfortErrorType.WALLET_ERROR),
|
|
11325
|
+
options: optionsObject,
|
|
11326
|
+
hookOptions
|
|
11327
|
+
});
|
|
11328
|
+
}
|
|
11329
|
+
log("Found embedded wallet to recover", accountToRecover);
|
|
11330
|
+
if (((_a = optionsObject.recovery) === null || _a === void 0 ? void 0 : _a.recoveryMethod) && accountToRecover.recoveryMethod && optionsObject.recovery.recoveryMethod !== accountToRecover.recoveryMethod) {
|
|
11331
|
+
log("Recovery method does not match", optionsObject.recovery.recoveryMethod, accountToRecover.recoveryMethod);
|
|
11249
11332
|
return onError({
|
|
11250
|
-
error: new OpenfortError("
|
|
11333
|
+
error: new OpenfortError("The recovery phrase you entered is incorrect and does not match the wallet's recovery method", OpenfortErrorType.WALLET_ERROR),
|
|
11251
11334
|
options: optionsObject,
|
|
11252
11335
|
hookOptions
|
|
11253
11336
|
});
|
|
11254
11337
|
}
|
|
11255
|
-
|
|
11256
|
-
|
|
11338
|
+
const recovery = {
|
|
11339
|
+
recoveryMethod: (_b = accountToRecover.recoveryMethod) !== null && _b !== void 0 ? _b : RecoveryMethod.AUTOMATIC,
|
|
11340
|
+
password: (_c = optionsObject.recovery) === null || _c === void 0 ? void 0 : _c.password,
|
|
11341
|
+
};
|
|
11342
|
+
const recoveryParams = await parseWalletRecovery(recovery, embeddedAccounts, walletAddress);
|
|
11343
|
+
embeddedAccount = await client.embeddedWallet.recover({
|
|
11344
|
+
account: accountToRecover.id,
|
|
11257
11345
|
recoveryParams,
|
|
11258
11346
|
});
|
|
11259
11347
|
}
|
|
11260
11348
|
else {
|
|
11261
11349
|
// Check if the embedded wallet is already created in the current chain
|
|
11262
|
-
if (
|
|
11263
|
-
const
|
|
11264
|
-
|
|
11265
|
-
|
|
11350
|
+
if (embeddedAccounts.some((w) => w.chainId === chainId)) {
|
|
11351
|
+
const accountToRecover = embeddedAccounts.find((w) => w.chainId === chainId);
|
|
11352
|
+
log("Found embedded wallet to recover (without walletAddress)", accountToRecover);
|
|
11353
|
+
const recovery = {
|
|
11354
|
+
recoveryMethod: (_d = accountToRecover.recoveryMethod) !== null && _d !== void 0 ? _d : RecoveryMethod.AUTOMATIC,
|
|
11355
|
+
password: (_e = optionsObject.recovery) === null || _e === void 0 ? void 0 : _e.password,
|
|
11356
|
+
};
|
|
11357
|
+
const recoveryParams = await parseWalletRecovery(recovery, embeddedAccounts, walletAddress);
|
|
11358
|
+
embeddedAccount = await client.embeddedWallet.recover({
|
|
11359
|
+
account: accountToRecover.id,
|
|
11266
11360
|
recoveryParams,
|
|
11267
11361
|
});
|
|
11268
|
-
walletAddress =
|
|
11362
|
+
walletAddress = accountToRecover.address;
|
|
11269
11363
|
}
|
|
11270
11364
|
else {
|
|
11365
|
+
log("No embedded wallet found for the current chain");
|
|
11271
11366
|
// Here it should check if there is a wallet that can recover in another chain and recover it in the current chain (its a different account so its not supported yet)
|
|
11367
|
+
// TODO: Connect to wallet in the other chain and then switch chain
|
|
11272
11368
|
return onError({
|
|
11273
11369
|
error: new OpenfortError("No embedded wallet found for the current chain", OpenfortErrorType.WALLET_ERROR),
|
|
11274
11370
|
options: optionsObject,
|
|
@@ -11276,47 +11372,42 @@ function useWallets(hookOptions = {}) {
|
|
|
11276
11372
|
});
|
|
11277
11373
|
}
|
|
11278
11374
|
}
|
|
11375
|
+
if (!embeddedAccount) {
|
|
11376
|
+
return onError({
|
|
11377
|
+
error: new OpenfortError("Failed to recover embedded wallet", OpenfortErrorType.WALLET_ERROR),
|
|
11378
|
+
options: optionsObject,
|
|
11379
|
+
hookOptions
|
|
11380
|
+
});
|
|
11381
|
+
}
|
|
11279
11382
|
setStatus({
|
|
11280
11383
|
status: 'success',
|
|
11281
11384
|
});
|
|
11282
11385
|
return onSuccess({
|
|
11283
11386
|
data: {
|
|
11284
|
-
wallet:
|
|
11285
|
-
address: walletAddress,
|
|
11286
|
-
recoveryMethod: recoveryParams.recoveryMethod,
|
|
11287
|
-
}),
|
|
11387
|
+
wallet: parseEmbeddedAccount(embeddedAccount),
|
|
11288
11388
|
},
|
|
11289
11389
|
options: optionsObject,
|
|
11290
11390
|
hookOptions,
|
|
11291
11391
|
});
|
|
11292
11392
|
}
|
|
11293
11393
|
catch (err) {
|
|
11294
|
-
|
|
11394
|
+
let error;
|
|
11295
11395
|
if (err instanceof MissingRecoveryPasswordError) {
|
|
11296
|
-
|
|
11297
|
-
setStatus({
|
|
11298
|
-
status: 'error',
|
|
11299
|
-
error,
|
|
11300
|
-
});
|
|
11301
|
-
return onError({
|
|
11302
|
-
error,
|
|
11303
|
-
options: optionsObject,
|
|
11304
|
-
hookOptions
|
|
11305
|
-
});
|
|
11396
|
+
error = new OpenfortError("Missing recovery password", OpenfortErrorType.WALLET_ERROR);
|
|
11306
11397
|
}
|
|
11307
|
-
if (
|
|
11308
|
-
|
|
11309
|
-
|
|
11310
|
-
|
|
11311
|
-
|
|
11312
|
-
});
|
|
11313
|
-
return onError({
|
|
11314
|
-
error,
|
|
11315
|
-
options: optionsObject,
|
|
11316
|
-
hookOptions
|
|
11317
|
-
});
|
|
11398
|
+
else if (err instanceof OpenfortError) {
|
|
11399
|
+
error = err;
|
|
11400
|
+
}
|
|
11401
|
+
else if (typeof err === 'string') {
|
|
11402
|
+
error = new OpenfortError(err, OpenfortErrorType.WALLET_ERROR);
|
|
11318
11403
|
}
|
|
11319
|
-
|
|
11404
|
+
else {
|
|
11405
|
+
error = new OpenfortError("Failed to recover embedded wallet", OpenfortErrorType.WALLET_ERROR, { error: err });
|
|
11406
|
+
if (error.message === "Wrong recovery password for this embedded signer") {
|
|
11407
|
+
error.message = "Wrong password, Please try again.";
|
|
11408
|
+
}
|
|
11409
|
+
}
|
|
11410
|
+
log('Error handling recovery with Openfort:', error, err);
|
|
11320
11411
|
setStatus({
|
|
11321
11412
|
status: 'error',
|
|
11322
11413
|
error,
|
|
@@ -11324,7 +11415,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11324
11415
|
return onError({
|
|
11325
11416
|
error,
|
|
11326
11417
|
options: optionsObject,
|
|
11327
|
-
hookOptions
|
|
11418
|
+
hookOptions,
|
|
11328
11419
|
});
|
|
11329
11420
|
}
|
|
11330
11421
|
}
|
|
@@ -11339,13 +11430,14 @@ function useWallets(hookOptions = {}) {
|
|
|
11339
11430
|
});
|
|
11340
11431
|
}
|
|
11341
11432
|
return {};
|
|
11342
|
-
}, [wallets, setOpen, setRoute, setConnector, disconnectAsync, log, address, client, walletConfig, chainId,
|
|
11343
|
-
const
|
|
11433
|
+
}, [wallets, setOpen, setRoute, setConnector, disconnectAsync, log, address, client, walletConfig, chainId, hookOptions]);
|
|
11434
|
+
const queryClient = useQueryClient();
|
|
11435
|
+
const createWallet = useCallback(async ({ recovery, ...options } = {}) => {
|
|
11344
11436
|
var _a;
|
|
11345
11437
|
setStatus({
|
|
11346
11438
|
status: 'creating',
|
|
11347
11439
|
});
|
|
11348
|
-
log("Creating wallet", {
|
|
11440
|
+
log("Creating wallet", { recovery: (recovery === null || recovery === void 0 ? void 0 : recovery.recoveryMethod) || RecoveryMethod.AUTOMATIC, options });
|
|
11349
11441
|
try {
|
|
11350
11442
|
const accessToken = await client.getAccessToken();
|
|
11351
11443
|
if (!accessToken) {
|
|
@@ -11362,16 +11454,8 @@ function useWallets(hookOptions = {}) {
|
|
|
11362
11454
|
options,
|
|
11363
11455
|
});
|
|
11364
11456
|
}
|
|
11365
|
-
const recoveryParams =
|
|
11366
|
-
|
|
11367
|
-
password,
|
|
11368
|
-
} : {
|
|
11369
|
-
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
11370
|
-
encryptionSession: walletConfig.getEncryptionSession ?
|
|
11371
|
-
await walletConfig.getEncryptionSession(accessToken) :
|
|
11372
|
-
await getEncryptionSession()
|
|
11373
|
-
};
|
|
11374
|
-
const wallet = await client.embeddedWallet.create({
|
|
11457
|
+
const recoveryParams = await parseWalletRecovery(recovery);
|
|
11458
|
+
const embeddedAccount = await client.embeddedWallet.create({
|
|
11375
11459
|
chainId: (_a = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.initialChainId) !== null && _a !== void 0 ? _a : chainId,
|
|
11376
11460
|
accountType: (options === null || options === void 0 ? void 0 : options.accountType) || (walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.accountType) || AccountTypeEnum.SMART_ACCOUNT,
|
|
11377
11461
|
chainType: ChainTypeEnum.EVM,
|
|
@@ -11380,13 +11464,10 @@ function useWallets(hookOptions = {}) {
|
|
|
11380
11464
|
setStatus({
|
|
11381
11465
|
status: 'success',
|
|
11382
11466
|
});
|
|
11383
|
-
|
|
11467
|
+
queryClient.invalidateQueries({ queryKey: ['openfortEmbeddedAccountsList'] });
|
|
11384
11468
|
return onSuccess({
|
|
11385
11469
|
data: {
|
|
11386
|
-
wallet:
|
|
11387
|
-
address: wallet.address,
|
|
11388
|
-
recoveryMethod: wallet.recoveryMethod,
|
|
11389
|
-
})
|
|
11470
|
+
wallet: parseEmbeddedAccount(embeddedAccount)
|
|
11390
11471
|
}
|
|
11391
11472
|
});
|
|
11392
11473
|
}
|
|
@@ -11403,7 +11484,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11403
11484
|
options,
|
|
11404
11485
|
});
|
|
11405
11486
|
}
|
|
11406
|
-
}, [
|
|
11487
|
+
}, [client, uiConfig, chainId]);
|
|
11407
11488
|
const setRecovery = useCallback(async (params) => {
|
|
11408
11489
|
try {
|
|
11409
11490
|
setStatus({
|
|
@@ -11418,10 +11499,7 @@ function useWallets(hookOptions = {}) {
|
|
|
11418
11499
|
hookOptions,
|
|
11419
11500
|
options: params,
|
|
11420
11501
|
data: {
|
|
11421
|
-
wallet:
|
|
11422
|
-
address: embeddedAccount.address,
|
|
11423
|
-
recoveryMethod: embeddedAccount.recoveryMethod,
|
|
11424
|
-
}),
|
|
11502
|
+
wallet: parseEmbeddedAccount(embeddedAccount),
|
|
11425
11503
|
}
|
|
11426
11504
|
});
|
|
11427
11505
|
}
|
|
@@ -11642,8 +11720,11 @@ const RecoverPasswordWallet = ({ wallet }) => {
|
|
|
11642
11720
|
const handleSubmit = async () => {
|
|
11643
11721
|
setLoading(true);
|
|
11644
11722
|
const { error } = await setActiveWallet({
|
|
11645
|
-
|
|
11646
|
-
|
|
11723
|
+
walletId: embeddedWalletId,
|
|
11724
|
+
recovery: {
|
|
11725
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11726
|
+
password: recoveryPhrase,
|
|
11727
|
+
},
|
|
11647
11728
|
address: wallet.address,
|
|
11648
11729
|
});
|
|
11649
11730
|
setLoading(false);
|
|
@@ -11664,7 +11745,6 @@ const RecoverPasswordWallet = ({ wallet }) => {
|
|
|
11664
11745
|
address: wallet.address,
|
|
11665
11746
|
config: ensFallbackConfig,
|
|
11666
11747
|
});
|
|
11667
|
-
const separator = '....';
|
|
11668
11748
|
return (jsxs(PageContent, { children: [jsx(FloatingGraphic, { height: "130px", logoCenter: {
|
|
11669
11749
|
logo: jsx(KeyIcon, {}),
|
|
11670
11750
|
size: "1.2",
|
|
@@ -11674,11 +11754,46 @@ const RecoverPasswordWallet = ({ wallet }) => {
|
|
|
11674
11754
|
}, logoBottomRight: {
|
|
11675
11755
|
logo: jsx(LockIcon, {}),
|
|
11676
11756
|
size: "0.5",
|
|
11677
|
-
} }), jsx(ModalHeading, { children: "Recover wallet" }), jsxs(ModalBody, { style: { textAlign: "center" }, children: ["Please enter the recovery password to recover wallet", " ", jsx(CopyToClipboard, { string: wallet.address, children: ensName !== null && ensName !== void 0 ? ensName : truncateEthAddress(wallet.address
|
|
11757
|
+
} }), jsx(ModalHeading, { children: "Recover wallet" }), jsxs(ModalBody, { style: { textAlign: "center" }, children: ["Please enter the recovery password to recover wallet", " ", jsx(CopyToClipboard, { string: wallet.address, children: ensName !== null && ensName !== void 0 ? ensName : truncateEthAddress(wallet.address) })] }), jsxs("form", { onSubmit: (e) => {
|
|
11678
11758
|
e.preventDefault();
|
|
11679
11759
|
handleSubmit();
|
|
11680
11760
|
}, 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: "Recover wallet" })] })] }));
|
|
11681
11761
|
};
|
|
11762
|
+
const RecoverPasskeyWallet = ({ wallet }) => {
|
|
11763
|
+
const { triggerResize, uiConfig: options, log } = useOpenfort();
|
|
11764
|
+
const { setActiveWallet, error: recoveryError, isConnecting: loading } = useWallets();
|
|
11765
|
+
const [shouldRecoverWallet, setShouldRecoverWallet] = useState(false);
|
|
11766
|
+
const recoverWallet = async () => {
|
|
11767
|
+
setActiveWallet({
|
|
11768
|
+
walletId: embeddedWalletId,
|
|
11769
|
+
recovery: {
|
|
11770
|
+
recoveryMethod: RecoveryMethod.PASSKEY,
|
|
11771
|
+
},
|
|
11772
|
+
address: wallet.address,
|
|
11773
|
+
});
|
|
11774
|
+
};
|
|
11775
|
+
useEffect(() => {
|
|
11776
|
+
// To ensure the wallet is created only once
|
|
11777
|
+
if (shouldRecoverWallet) {
|
|
11778
|
+
recoverWallet();
|
|
11779
|
+
}
|
|
11780
|
+
}, [shouldRecoverWallet]);
|
|
11781
|
+
useEffect(() => {
|
|
11782
|
+
setShouldRecoverWallet(true);
|
|
11783
|
+
}, []);
|
|
11784
|
+
useEffect(() => {
|
|
11785
|
+
if (recoveryError)
|
|
11786
|
+
triggerResize();
|
|
11787
|
+
}, [recoveryError]);
|
|
11788
|
+
const ensFallbackConfig = useEnsFallbackConfig();
|
|
11789
|
+
const { data: ensName } = useEnsName({
|
|
11790
|
+
chainId: 1,
|
|
11791
|
+
address: wallet.address,
|
|
11792
|
+
config: ensFallbackConfig,
|
|
11793
|
+
});
|
|
11794
|
+
const walletDisplay = ensName !== null && ensName !== void 0 ? ensName : truncateEthAddress(wallet.address);
|
|
11795
|
+
return (jsxs(PageContent, { children: [jsx(BackButton, { onClick: (() => setShouldRecoverWallet(false)) }), jsx(Loader, { icon: jsx(FingerPrintIcon, {}), isError: !!recoveryError, header: recoveryError ? "Invalid passkey." : `Recovering wallet ${walletDisplay} with passkey...`, description: recoveryError ? "There was an error creating your passkey. Please try again." : undefined, onRetry: () => recoverWallet() })] }));
|
|
11796
|
+
};
|
|
11682
11797
|
const RecoverAutomaticWallet = ({ walletAddress }) => {
|
|
11683
11798
|
const { embeddedState } = useOpenfortCore();
|
|
11684
11799
|
const { setActiveWallet } = useWallets();
|
|
@@ -11689,7 +11804,7 @@ const RecoverAutomaticWallet = ({ walletAddress }) => {
|
|
|
11689
11804
|
if (embeddedState === EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED) {
|
|
11690
11805
|
log("Automatically recovering wallet", walletAddress);
|
|
11691
11806
|
const response = await setActiveWallet({
|
|
11692
|
-
|
|
11807
|
+
walletId: embeddedWalletId,
|
|
11693
11808
|
});
|
|
11694
11809
|
if (response.error) {
|
|
11695
11810
|
setError(response.error.message || "There was an error recovering your account");
|
|
@@ -11701,7 +11816,7 @@ const RecoverAutomaticWallet = ({ walletAddress }) => {
|
|
|
11701
11816
|
if (error) {
|
|
11702
11817
|
jsx(PageContent, { children: jsx(ModalBody, { style: { textAlign: "center" }, "$error": true, children: jsx(FitText, { children: error }) }) });
|
|
11703
11818
|
}
|
|
11704
|
-
return (jsx(PageContent, { children: jsx(Loader, {
|
|
11819
|
+
return (jsx(PageContent, { children: jsx(Loader, { header: `Recovering wallet...` }) }));
|
|
11705
11820
|
};
|
|
11706
11821
|
const CreateWalletAutomaticRecovery = () => {
|
|
11707
11822
|
const { embeddedState } = useOpenfortCore();
|
|
@@ -11725,7 +11840,7 @@ const CreateWalletAutomaticRecovery = () => {
|
|
|
11725
11840
|
setShouldCreateWallet(true);
|
|
11726
11841
|
}
|
|
11727
11842
|
}, [embeddedState]);
|
|
11728
|
-
return (jsx(PageContent, { children: jsx(Loader, {
|
|
11843
|
+
return (jsx(PageContent, { children: jsx(Loader, { header: "Creating wallet..." }) }));
|
|
11729
11844
|
};
|
|
11730
11845
|
const OtherMethod = ({ currentMethod, onChangeMethod }) => {
|
|
11731
11846
|
const { uiConfig } = useOpenfort();
|
|
@@ -11746,6 +11861,9 @@ const OtherMethod = ({ currentMethod, onChangeMethod }) => {
|
|
|
11746
11861
|
case RecoveryMethod.AUTOMATIC:
|
|
11747
11862
|
text = "Skip for now";
|
|
11748
11863
|
break;
|
|
11864
|
+
case RecoveryMethod.PASSKEY:
|
|
11865
|
+
text = "Use passkey recovery";
|
|
11866
|
+
break;
|
|
11749
11867
|
default:
|
|
11750
11868
|
text = method;
|
|
11751
11869
|
}
|
|
@@ -11755,6 +11873,40 @@ const OtherMethod = ({ currentMethod, onChangeMethod }) => {
|
|
|
11755
11873
|
}
|
|
11756
11874
|
return (jsx(OtherMethodButton, { onClick: () => onChangeMethod("other"), children: "Choose another recovery method" }));
|
|
11757
11875
|
};
|
|
11876
|
+
const CreateWalletPasskeyRecovery = ({ onChangeMethod }) => {
|
|
11877
|
+
const { triggerResize } = useOpenfort();
|
|
11878
|
+
const { createWallet, error: recoveryError } = useWallets();
|
|
11879
|
+
const [shouldCreateWallet, setShouldCreateWallet] = useState(false);
|
|
11880
|
+
const { log } = useOpenfort();
|
|
11881
|
+
const { embeddedState } = useOpenfortCore();
|
|
11882
|
+
useEffect(() => {
|
|
11883
|
+
// To ensure the wallet is created only once
|
|
11884
|
+
if (shouldCreateWallet) {
|
|
11885
|
+
(async () => {
|
|
11886
|
+
log("Creating wallet passkey recovery");
|
|
11887
|
+
const response = await createWallet({
|
|
11888
|
+
recovery: {
|
|
11889
|
+
recoveryMethod: RecoveryMethod.PASSKEY,
|
|
11890
|
+
}
|
|
11891
|
+
});
|
|
11892
|
+
if (response.error) {
|
|
11893
|
+
log("Error creating wallet", response.error);
|
|
11894
|
+
setShouldCreateWallet(false);
|
|
11895
|
+
}
|
|
11896
|
+
})();
|
|
11897
|
+
}
|
|
11898
|
+
}, [shouldCreateWallet]);
|
|
11899
|
+
useEffect(() => {
|
|
11900
|
+
if (embeddedState === EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED) {
|
|
11901
|
+
setShouldCreateWallet(true);
|
|
11902
|
+
}
|
|
11903
|
+
}, [embeddedState]);
|
|
11904
|
+
useEffect(() => {
|
|
11905
|
+
if (recoveryError)
|
|
11906
|
+
triggerResize();
|
|
11907
|
+
}, [recoveryError]);
|
|
11908
|
+
return (jsx(PageContent, { children: jsx(Loader, { icon: jsx(FingerPrintIcon, {}), isError: !!recoveryError, header: recoveryError ? "Invalid passkey." : "Creating wallet with passkey...", description: recoveryError ? "There was an error creating your passkey. Please try again." : undefined, onRetry: () => setShouldCreateWallet(true) }) }));
|
|
11909
|
+
};
|
|
11758
11910
|
const CreateWalletPasswordRecovery = ({ onChangeMethod }) => {
|
|
11759
11911
|
const [recoveryPhrase, setRecoveryPhrase] = useState("");
|
|
11760
11912
|
const [recoveryError, setRecoveryError] = useState(false);
|
|
@@ -11769,7 +11921,10 @@ const CreateWalletPasswordRecovery = ({ onChangeMethod }) => {
|
|
|
11769
11921
|
}
|
|
11770
11922
|
setLoading(true);
|
|
11771
11923
|
const { error } = await createWallet({
|
|
11772
|
-
|
|
11924
|
+
recovery: {
|
|
11925
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
11926
|
+
password: recoveryPhrase,
|
|
11927
|
+
},
|
|
11773
11928
|
});
|
|
11774
11929
|
setLoading(false);
|
|
11775
11930
|
if (error) {
|
|
@@ -11805,7 +11960,7 @@ const CreateWalletPasswordRecovery = ({ onChangeMethod }) => {
|
|
|
11805
11960
|
] }), 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: "Create wallet" })] }), jsx(OtherMethod, { currentMethod: RecoveryMethod.PASSWORD, onChangeMethod: onChangeMethod })] })] }));
|
|
11806
11961
|
};
|
|
11807
11962
|
const ChooseRecoveryMethod = ({ onChangeMethod }) => {
|
|
11808
|
-
return (jsxs(PageContent, { children: [jsx(ModalHeading, { children: "Choose a recovery method" }), jsx(Button, { onClick: () => onChangeMethod(RecoveryMethod.PASSWORD), children: "Password" }), jsx(Button, { onClick: () => onChangeMethod(RecoveryMethod.AUTOMATIC), children: "Automatic" }), jsx(Button, { onClick: () =>
|
|
11963
|
+
return (jsxs(PageContent, { children: [jsx(ModalHeading, { children: "Choose a recovery method" }), jsx(Button, { onClick: () => onChangeMethod(RecoveryMethod.PASSWORD), children: "Password" }), jsx(Button, { onClick: () => onChangeMethod(RecoveryMethod.AUTOMATIC), children: "Automatic" }), jsx(Button, { onClick: () => onChangeMethod(RecoveryMethod.PASSKEY), children: "Passkey" })] }));
|
|
11809
11964
|
};
|
|
11810
11965
|
const RecoverWallet = ({ wallet }) => {
|
|
11811
11966
|
switch (wallet.recoveryMethod) {
|
|
@@ -11813,34 +11968,66 @@ const RecoverWallet = ({ wallet }) => {
|
|
|
11813
11968
|
return jsx(RecoverPasswordWallet, { wallet: wallet });
|
|
11814
11969
|
case RecoveryMethod.AUTOMATIC:
|
|
11815
11970
|
return jsx(RecoverAutomaticWallet, { walletAddress: wallet.address });
|
|
11971
|
+
case RecoveryMethod.PASSKEY:
|
|
11972
|
+
return jsx(RecoverPasskeyWallet, { wallet: wallet });
|
|
11816
11973
|
default:
|
|
11817
11974
|
console.error("Unsupported recovery method: " + wallet.recoveryMethod + ", defaulting to automatic.");
|
|
11818
11975
|
return jsx(RecoverAutomaticWallet, { walletAddress: wallet.address });
|
|
11819
11976
|
}
|
|
11820
11977
|
};
|
|
11978
|
+
const WalletRecoveryIcon = ({ recovery }) => {
|
|
11979
|
+
switch (recovery) {
|
|
11980
|
+
case RecoveryMethod.PASSWORD:
|
|
11981
|
+
return jsx(KeyIcon, {});
|
|
11982
|
+
case RecoveryMethod.PASSKEY:
|
|
11983
|
+
return jsx(FingerPrintIcon, {});
|
|
11984
|
+
case RecoveryMethod.AUTOMATIC:
|
|
11985
|
+
return jsx(LockIcon, {});
|
|
11986
|
+
default:
|
|
11987
|
+
return null;
|
|
11988
|
+
}
|
|
11989
|
+
};
|
|
11990
|
+
const SelectWalletButton = ({ wallet, onSelect }) => {
|
|
11991
|
+
const ensFallbackConfig = useEnsFallbackConfig();
|
|
11992
|
+
const { data: ensName } = useEnsName({
|
|
11993
|
+
chainId: 1,
|
|
11994
|
+
address: wallet.address,
|
|
11995
|
+
config: ensFallbackConfig,
|
|
11996
|
+
});
|
|
11997
|
+
const walletDisplay = ensName !== null && ensName !== void 0 ? ensName : truncateEthAddress(wallet.address);
|
|
11998
|
+
// <Button
|
|
11999
|
+
// onClick={() => onSelect(wallet)}
|
|
12000
|
+
// >
|
|
12001
|
+
// {walletDisplay} - {wallet.recoveryMethod} recover
|
|
12002
|
+
// </Button>
|
|
12003
|
+
return (jsx(ProvidersButton, { children: jsxs(Button, { onClick: () => onSelect(wallet), children: [jsx(ProviderLabel, { children: walletDisplay }), jsx(ProviderIcon$1, { children: jsx(WalletRecoveryIcon, { recovery: wallet.recoveryMethod }) })] }) }));
|
|
12004
|
+
};
|
|
12005
|
+
const SelectWalletToRecover = ({ wallets }) => {
|
|
12006
|
+
const [selectedWallet, setSelectedWallet] = useState(null);
|
|
12007
|
+
if (selectedWallet) {
|
|
12008
|
+
return jsx(RecoverWallet, { wallet: selectedWallet });
|
|
12009
|
+
}
|
|
12010
|
+
return (jsxs(PageContent, { children: [jsx(ModalHeading, { children: "Select a wallet to recover" }), wallets.map((wallet) => (jsx(SelectWalletButton, { wallet: wallet, onSelect: setSelectedWallet }, wallet.id)))] }));
|
|
12011
|
+
};
|
|
11821
12012
|
const CreateWallet = () => {
|
|
11822
|
-
const { uiConfig } = useOpenfort();
|
|
12013
|
+
const { uiConfig, triggerResize } = useOpenfort();
|
|
11823
12014
|
const [userSelectedMethod, setUserSelectedMethod] = useState(null);
|
|
11824
|
-
|
|
11825
|
-
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
return jsx(CreateWalletAutomaticRecovery, {});
|
|
11830
|
-
case "other":
|
|
11831
|
-
return jsx(ChooseRecoveryMethod, { onChangeMethod: setUserSelectedMethod });
|
|
11832
|
-
default:
|
|
11833
|
-
throw new Error("Unsupported recovery method: " + userSelectedMethod);
|
|
11834
|
-
}
|
|
11835
|
-
}
|
|
11836
|
-
// Default recovery method configured
|
|
11837
|
-
switch (uiConfig.walletRecovery.defaultMethod) {
|
|
12015
|
+
useEffect(() => {
|
|
12016
|
+
triggerResize();
|
|
12017
|
+
}, [userSelectedMethod]);
|
|
12018
|
+
const method = userSelectedMethod !== null && userSelectedMethod !== void 0 ? userSelectedMethod : uiConfig.walletRecovery.defaultMethod;
|
|
12019
|
+
switch (method) {
|
|
11838
12020
|
case RecoveryMethod.PASSWORD:
|
|
11839
12021
|
return jsx(CreateWalletPasswordRecovery, { onChangeMethod: setUserSelectedMethod });
|
|
11840
12022
|
case RecoveryMethod.AUTOMATIC:
|
|
11841
12023
|
return jsx(CreateWalletAutomaticRecovery, {});
|
|
12024
|
+
case RecoveryMethod.PASSKEY:
|
|
12025
|
+
return jsx(CreateWalletPasskeyRecovery, { onChangeMethod: setUserSelectedMethod });
|
|
12026
|
+
case "other":
|
|
12027
|
+
return jsx(ChooseRecoveryMethod, { onChangeMethod: setUserSelectedMethod });
|
|
11842
12028
|
default:
|
|
11843
|
-
|
|
12029
|
+
console.error("Unsupported recovery method: " + userSelectedMethod + uiConfig.walletRecovery.defaultMethod);
|
|
12030
|
+
return null;
|
|
11844
12031
|
}
|
|
11845
12032
|
};
|
|
11846
12033
|
const Connected = () => {
|
|
@@ -11851,7 +12038,7 @@ const Connected = () => {
|
|
|
11851
12038
|
setOpen(false);
|
|
11852
12039
|
}, 1000);
|
|
11853
12040
|
}, []);
|
|
11854
|
-
return (jsx(PageContent, { children: jsx(Loader, { isLoading: false,
|
|
12041
|
+
return (jsx(PageContent, { children: jsx(Loader, { isLoading: false, isSuccess: true, header: "Connected" }) }));
|
|
11855
12042
|
};
|
|
11856
12043
|
const RecoverPage = () => {
|
|
11857
12044
|
const { needsRecovery, user } = useOpenfortCore();
|
|
@@ -11889,7 +12076,7 @@ const RecoverPage = () => {
|
|
|
11889
12076
|
// setLoading(false);
|
|
11890
12077
|
// }, [user])
|
|
11891
12078
|
if (embeddedSignerLoading) {
|
|
11892
|
-
return (jsx(PageContent, { children: jsx(Loader, {
|
|
12079
|
+
return (jsx(PageContent, { children: jsx(Loader, { header: "Setting up wallet" }) }));
|
|
11893
12080
|
}
|
|
11894
12081
|
if (isConnected && user) {
|
|
11895
12082
|
return jsx(Connected, {});
|
|
@@ -11902,20 +12089,10 @@ const RecoverPage = () => {
|
|
|
11902
12089
|
if (openfortWallets.length === 0) {
|
|
11903
12090
|
return (jsx(CreateWallet, {}));
|
|
11904
12091
|
}
|
|
11905
|
-
|
|
11906
|
-
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
// <PageContent>
|
|
11910
|
-
// <div style={{ flexDirection: "column", display: "flex", gap: 8 }}>
|
|
11911
|
-
// {wallets.map((wallet) => (
|
|
11912
|
-
// <div key={wallet.address}>
|
|
11913
|
-
// {wallet.address} - {wallet.recoveryMethod} recover
|
|
11914
|
-
// </div>
|
|
11915
|
-
// ))}
|
|
11916
|
-
// </div>
|
|
11917
|
-
// </PageContent>
|
|
11918
|
-
// )
|
|
12092
|
+
if (wallets.length === 1) {
|
|
12093
|
+
return (jsx(RecoverWallet, { wallet: openfortWallets[0] }));
|
|
12094
|
+
}
|
|
12095
|
+
return (jsx(SelectWalletToRecover, { wallets: openfortWallets }));
|
|
11919
12096
|
// if (walletConfig && walletConfig.recoveryMethod === RecoveryMethod.AUTOMATIC) {
|
|
11920
12097
|
// return <AutomaticRecovery />
|
|
11921
12098
|
// }
|
|
@@ -12817,14 +12994,12 @@ const useConnectToWalletPostAuth = () => {
|
|
|
12817
12994
|
const { walletConfig } = useOpenfort();
|
|
12818
12995
|
const { signOut } = useSignOut();
|
|
12819
12996
|
const queryClient = useQueryClient();
|
|
12820
|
-
const tryUseWallet = useCallback(async ({ logoutOnError: signOutOnError = true,
|
|
12821
|
-
|
|
12822
|
-
if ((!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.createEncryptedSessionEndpoint) && !(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.getEncryptionSession)) || !automaticRecovery) {
|
|
12997
|
+
const tryUseWallet = useCallback(async ({ logoutOnError: signOutOnError = true, recoverWalletAutomatically = true }) => {
|
|
12998
|
+
if ((!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.createEncryptedSessionEndpoint) && !(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.getEncryptionSession)) || !recoverWalletAutomatically) {
|
|
12823
12999
|
// If there is no encryption session, we cannot create a wallet
|
|
12824
13000
|
return {};
|
|
12825
13001
|
}
|
|
12826
|
-
const wallets = await queryClient.ensureQueryData({ queryKey: ['
|
|
12827
|
-
console.log("WALLETS", wallets);
|
|
13002
|
+
const wallets = await queryClient.ensureQueryData({ queryKey: ['openfortEmbeddedAccountsList'] });
|
|
12828
13003
|
let wallet;
|
|
12829
13004
|
if (wallets.length === 0) {
|
|
12830
13005
|
const createWalletResult = await createWallet();
|
|
@@ -12839,7 +13014,7 @@ const useConnectToWalletPostAuth = () => {
|
|
|
12839
13014
|
// Has a wallet with automatic recovery
|
|
12840
13015
|
if (wallets.some(w => w.recoveryMethod === RecoveryMethod.AUTOMATIC)) {
|
|
12841
13016
|
const setWalletResult = await setActiveWallet({
|
|
12842
|
-
|
|
13017
|
+
walletId: embeddedWalletId,
|
|
12843
13018
|
});
|
|
12844
13019
|
if (!setWalletResult.wallet || (setWalletResult.error && signOutOnError)) {
|
|
12845
13020
|
console.error("Error recovering wallet:", setWalletResult.error);
|
|
@@ -12870,7 +13045,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12870
13045
|
}, []);
|
|
12871
13046
|
const { tryUseWallet } = useConnectToWalletPostAuth();
|
|
12872
13047
|
const signInEmail = useCallback(async (options) => {
|
|
12873
|
-
var _a;
|
|
13048
|
+
var _a, _b, _c;
|
|
12874
13049
|
try {
|
|
12875
13050
|
setStatus({
|
|
12876
13051
|
status: 'loading',
|
|
@@ -12901,8 +13076,8 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
12901
13076
|
}
|
|
12902
13077
|
else {
|
|
12903
13078
|
const { wallet } = await tryUseWallet({
|
|
12904
|
-
logoutOnError: options.logoutOnError
|
|
12905
|
-
|
|
13079
|
+
logoutOnError: (_b = options.logoutOnError) !== null && _b !== void 0 ? _b : hookOptions.logoutOnError,
|
|
13080
|
+
recoverWalletAutomatically: (_c = options.recoverWalletAutomatically) !== null && _c !== void 0 ? _c : hookOptions.recoverWalletAutomatically,
|
|
12906
13081
|
});
|
|
12907
13082
|
setStatus({
|
|
12908
13083
|
status: 'success',
|
|
@@ -13002,7 +13177,7 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
13002
13177
|
}
|
|
13003
13178
|
}, [client, setStatus, updateUser, hookOptions]);
|
|
13004
13179
|
const signUpEmail = useCallback(async (options) => {
|
|
13005
|
-
var _a;
|
|
13180
|
+
var _a, _b, _c;
|
|
13006
13181
|
try {
|
|
13007
13182
|
setStatus({
|
|
13008
13183
|
status: 'loading',
|
|
@@ -13034,8 +13209,8 @@ const useEmailAuth = (hookOptions = {}) => {
|
|
|
13034
13209
|
}
|
|
13035
13210
|
else {
|
|
13036
13211
|
const { wallet } = await tryUseWallet({
|
|
13037
|
-
logoutOnError: options.logoutOnError
|
|
13038
|
-
|
|
13212
|
+
logoutOnError: (_b = options.logoutOnError) !== null && _b !== void 0 ? _b : hookOptions.logoutOnError,
|
|
13213
|
+
recoverWalletAutomatically: (_c = options.recoverWalletAutomatically) !== null && _c !== void 0 ? _c : hookOptions.recoverWalletAutomatically,
|
|
13039
13214
|
});
|
|
13040
13215
|
setStatus({
|
|
13041
13216
|
status: 'success',
|
|
@@ -13182,6 +13357,7 @@ const useOAuth = (hookOptions = {}) => {
|
|
|
13182
13357
|
});
|
|
13183
13358
|
const { tryUseWallet } = useConnectToWalletPostAuth();
|
|
13184
13359
|
const storeCredentials = useCallback(async ({ player, accessToken, refreshToken, ...options }) => {
|
|
13360
|
+
var _a, _b;
|
|
13185
13361
|
setStatus({
|
|
13186
13362
|
status: 'loading',
|
|
13187
13363
|
});
|
|
@@ -13196,8 +13372,8 @@ const useOAuth = (hookOptions = {}) => {
|
|
|
13196
13372
|
});
|
|
13197
13373
|
const user = await updateUser() || undefined;
|
|
13198
13374
|
const { wallet } = await tryUseWallet({
|
|
13199
|
-
logoutOnError: options.logoutOnError
|
|
13200
|
-
|
|
13375
|
+
logoutOnError: (_a = options.logoutOnError) !== null && _a !== void 0 ? _a : hookOptions.logoutOnError,
|
|
13376
|
+
recoverWalletAutomatically: (_b = options.recoverWalletAutomatically) !== null && _b !== void 0 ? _b : hookOptions.recoverWalletAutomatically,
|
|
13201
13377
|
});
|
|
13202
13378
|
return onSuccess({
|
|
13203
13379
|
data: { user, wallet, type: "storeCredentials" },
|
|
@@ -13430,6 +13606,7 @@ const useGuestAuth = (hookOptions = {}) => {
|
|
|
13430
13606
|
});
|
|
13431
13607
|
const { tryUseWallet } = useConnectToWalletPostAuth();
|
|
13432
13608
|
const signUpGuest = useCallback(async (options = {}) => {
|
|
13609
|
+
var _a, _b;
|
|
13433
13610
|
try {
|
|
13434
13611
|
setStatus({
|
|
13435
13612
|
status: 'loading',
|
|
@@ -13438,8 +13615,8 @@ const useGuestAuth = (hookOptions = {}) => {
|
|
|
13438
13615
|
const user = result.player;
|
|
13439
13616
|
await updateUser(user);
|
|
13440
13617
|
const { wallet } = await tryUseWallet({
|
|
13441
|
-
logoutOnError: options.logoutOnError
|
|
13442
|
-
|
|
13618
|
+
logoutOnError: (_a = options.logoutOnError) !== null && _a !== void 0 ? _a : hookOptions.logoutOnError,
|
|
13619
|
+
recoverWalletAutomatically: (_b = options.recoverWalletAutomatically) !== null && _b !== void 0 ? _b : hookOptions.recoverWalletAutomatically,
|
|
13443
13620
|
});
|
|
13444
13621
|
setStatus({
|
|
13445
13622
|
status: 'success',
|