shogun-button-react 6.3.5 → 6.3.6
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.
|
@@ -21,6 +21,8 @@ type ShogunContextType = {
|
|
|
21
21
|
put: (path: string, data: any) => Promise<void>;
|
|
22
22
|
get: (path: string) => any;
|
|
23
23
|
remove: (path: string) => Promise<void>;
|
|
24
|
+
completePendingSignup: () => void;
|
|
25
|
+
hasPendingSignup: boolean;
|
|
24
26
|
};
|
|
25
27
|
export declare const useShogun: () => ShogunContextType;
|
|
26
28
|
type ShogunButtonProviderProps = {
|
|
@@ -25,6 +25,8 @@ const defaultShogunContext = {
|
|
|
25
25
|
put: async () => { },
|
|
26
26
|
get: () => null,
|
|
27
27
|
remove: async () => { },
|
|
28
|
+
completePendingSignup: () => { },
|
|
29
|
+
hasPendingSignup: false,
|
|
28
30
|
};
|
|
29
31
|
// Create context using React's createContext directly
|
|
30
32
|
const ShogunContext = createContext(defaultShogunContext);
|
|
@@ -36,6 +38,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
36
38
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
|
37
39
|
const [userPub, setUserPub] = useState(null);
|
|
38
40
|
const [username, setUsername] = useState(null);
|
|
41
|
+
const [pendingSignupData, setPendingSignupData] = useState(null);
|
|
39
42
|
// Effetto per gestire l'inizializzazione e pulizia
|
|
40
43
|
useEffect(() => {
|
|
41
44
|
var _a, _b;
|
|
@@ -324,12 +327,18 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
324
327
|
setIsLoggedIn(true);
|
|
325
328
|
setUserPub(userPub);
|
|
326
329
|
setUsername(displayName);
|
|
327
|
-
|
|
330
|
+
const signupPayload = {
|
|
328
331
|
userPub: userPub,
|
|
329
332
|
username: displayName,
|
|
330
|
-
seedPhrase: result.seedPhrase,
|
|
333
|
+
seedPhrase: result.seedPhrase,
|
|
331
334
|
authMethod: authMethod,
|
|
332
|
-
}
|
|
335
|
+
};
|
|
336
|
+
if (authMethod === "zkproof" && onSignupSuccess) {
|
|
337
|
+
setPendingSignupData(signupPayload);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
onSignupSuccess === null || onSignupSuccess === void 0 ? void 0 : onSignupSuccess(signupPayload);
|
|
341
|
+
}
|
|
333
342
|
}
|
|
334
343
|
else {
|
|
335
344
|
onError === null || onError === void 0 ? void 0 : onError(result.error);
|
|
@@ -349,6 +358,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
349
358
|
setIsLoggedIn(false);
|
|
350
359
|
setUserPub(null);
|
|
351
360
|
setUsername(null);
|
|
361
|
+
setPendingSignupData(null);
|
|
352
362
|
};
|
|
353
363
|
// Implementazione del metodo setProvider
|
|
354
364
|
const setProvider = (provider) => {
|
|
@@ -462,6 +472,13 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
462
472
|
const gunPlugin = null;
|
|
463
473
|
// Plugin hooks removed - GunAdvancedPlugin no longer available
|
|
464
474
|
const pluginHooks = {};
|
|
475
|
+
const completePendingSignup = React.useCallback(() => {
|
|
476
|
+
if (pendingSignupData) {
|
|
477
|
+
const dataToEmit = pendingSignupData;
|
|
478
|
+
setPendingSignupData(null);
|
|
479
|
+
onSignupSuccess === null || onSignupSuccess === void 0 ? void 0 : onSignupSuccess(dataToEmit);
|
|
480
|
+
}
|
|
481
|
+
}, [pendingSignupData, onSignupSuccess]);
|
|
465
482
|
// Create a properly typed context value
|
|
466
483
|
const contextValue = React.useMemo(() => ({
|
|
467
484
|
core,
|
|
@@ -479,6 +496,8 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
479
496
|
importGunPair,
|
|
480
497
|
setProvider,
|
|
481
498
|
gunPlugin,
|
|
499
|
+
completePendingSignup,
|
|
500
|
+
hasPendingSignup: Boolean(pendingSignupData),
|
|
482
501
|
put: async (path, data) => {
|
|
483
502
|
if (isShogunCore(core)) {
|
|
484
503
|
if (!core.gun)
|
|
@@ -537,6 +556,8 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
537
556
|
importGunPair,
|
|
538
557
|
gunPlugin,
|
|
539
558
|
pluginHooks,
|
|
559
|
+
pendingSignupData,
|
|
560
|
+
completePendingSignup,
|
|
540
561
|
]);
|
|
541
562
|
// Provide the context value to children
|
|
542
563
|
return (React.createElement(ShogunContext.Provider, { value: contextValue }, children));
|
|
@@ -586,7 +607,7 @@ const ExportIcon = () => (React.createElement("svg", { xmlns: "http://www.w3.org
|
|
|
586
607
|
// Component for Shogun login button
|
|
587
608
|
export const ShogunButton = (() => {
|
|
588
609
|
const Button = () => {
|
|
589
|
-
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, hasPlugin, } = useShogun();
|
|
610
|
+
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, hasPlugin, completePendingSignup, hasPendingSignup, } = useShogun();
|
|
590
611
|
// Form states
|
|
591
612
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
|
592
613
|
const [formUsername, setFormUsername] = useState("");
|
|
@@ -611,6 +632,7 @@ export const ShogunButton = (() => {
|
|
|
611
632
|
const [zkGeneratedTrapdoor, setZkGeneratedTrapdoor] = useState("");
|
|
612
633
|
const [webauthnSeedPhrase, setWebauthnSeedPhrase] = useState("");
|
|
613
634
|
const dropdownRef = useRef(null);
|
|
635
|
+
const [pendingZkConfirmation, setPendingZkConfirmation] = useState(false);
|
|
614
636
|
// Handle click outside to close dropdown
|
|
615
637
|
useEffect(() => {
|
|
616
638
|
const handleClickOutside = (event) => {
|
|
@@ -785,6 +807,7 @@ export const ShogunButton = (() => {
|
|
|
785
807
|
// Show the trapdoor to the user - CRITICAL for account recovery!
|
|
786
808
|
setZkGeneratedTrapdoor(result.seedPhrase);
|
|
787
809
|
setAuthView("zkproof-signup-result");
|
|
810
|
+
setPendingZkConfirmation(true);
|
|
788
811
|
}
|
|
789
812
|
else if (result && !result.success) {
|
|
790
813
|
throw new Error(result.error || "ZK-Proof signup failed");
|
|
@@ -909,6 +932,7 @@ export const ShogunButton = (() => {
|
|
|
909
932
|
setZkTrapdoor("");
|
|
910
933
|
setZkGeneratedTrapdoor("");
|
|
911
934
|
setWebauthnSeedPhrase("");
|
|
935
|
+
setPendingZkConfirmation(false);
|
|
912
936
|
};
|
|
913
937
|
const openModal = () => {
|
|
914
938
|
resetForm();
|
|
@@ -916,6 +940,17 @@ export const ShogunButton = (() => {
|
|
|
916
940
|
setModalIsOpen(true);
|
|
917
941
|
};
|
|
918
942
|
const closeModal = () => {
|
|
943
|
+
if (pendingZkConfirmation || hasPendingSignup) {
|
|
944
|
+
setError("Please save your trapdoor and confirm before leaving this screen.");
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
setModalIsOpen(false);
|
|
948
|
+
};
|
|
949
|
+
const finalizeZkProofSignup = () => {
|
|
950
|
+
completePendingSignup();
|
|
951
|
+
setError("");
|
|
952
|
+
setPendingZkConfirmation(false);
|
|
953
|
+
setAuthView("options");
|
|
919
954
|
setModalIsOpen(false);
|
|
920
955
|
};
|
|
921
956
|
const toggleMode = () => {
|
|
@@ -1186,7 +1221,7 @@ export const ShogunButton = (() => {
|
|
|
1186
1221
|
border: "1px solid #22c55e",
|
|
1187
1222
|
textAlign: "center",
|
|
1188
1223
|
} }, "\u2705 You're now logged in with WebAuthn!"),
|
|
1189
|
-
React.createElement("button", { type: "button", className: "shogun-submit-button", style: { marginTop: "16px" }, onClick:
|
|
1224
|
+
React.createElement("button", { type: "button", className: "shogun-submit-button", style: { marginTop: "16px" }, onClick: finalizeZkProofSignup }, "Close and Start Using App")));
|
|
1190
1225
|
const renderZkProofSignupResult = () => (React.createElement("div", { className: "shogun-auth-form" },
|
|
1191
1226
|
React.createElement("h3", null, "ZK-Proof Account Created!"),
|
|
1192
1227
|
React.createElement("div", { style: {
|
|
@@ -1232,7 +1267,7 @@ export const ShogunButton = (() => {
|
|
|
1232
1267
|
border: "1px solid #22c55e",
|
|
1233
1268
|
textAlign: "center",
|
|
1234
1269
|
} }, "\u2705 You're now logged in anonymously!"),
|
|
1235
|
-
React.createElement("button", { type: "button", className: "shogun-submit-button", style: { marginTop: "16px" }, onClick:
|
|
1270
|
+
React.createElement("button", { type: "button", className: "shogun-submit-button", style: { marginTop: "16px" }, onClick: finalizeZkProofSignup }, "Close and Start Using App")));
|
|
1236
1271
|
const renderImportForm = () => (React.createElement("div", { className: "shogun-auth-form" },
|
|
1237
1272
|
React.createElement("h3", null, "Import Gun Pair"),
|
|
1238
1273
|
React.createElement("div", { style: {
|
|
@@ -1292,7 +1327,13 @@ export const ShogunButton = (() => {
|
|
|
1292
1327
|
React.createElement("button", { className: "shogun-connect-button", onClick: openModal },
|
|
1293
1328
|
React.createElement(WalletIcon, null),
|
|
1294
1329
|
React.createElement("span", null, "Login / Sign Up")),
|
|
1295
|
-
modalIsOpen && (React.createElement("div", { className: "shogun-modal-overlay", onClick:
|
|
1330
|
+
modalIsOpen && (React.createElement("div", { className: "shogun-modal-overlay", onClick: () => {
|
|
1331
|
+
if (pendingZkConfirmation || hasPendingSignup) {
|
|
1332
|
+
setError("Please copy your trapdoor and press Continue before closing.");
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
closeModal();
|
|
1336
|
+
} },
|
|
1296
1337
|
React.createElement("div", { className: "shogun-modal", onClick: (e) => e.stopPropagation() },
|
|
1297
1338
|
React.createElement("div", { className: "shogun-modal-header" },
|
|
1298
1339
|
React.createElement("h2", null, authView === "recover"
|
|
@@ -1312,7 +1353,7 @@ export const ShogunButton = (() => {
|
|
|
1312
1353
|
: formMode === "login"
|
|
1313
1354
|
? "Login"
|
|
1314
1355
|
: "Sign Up"),
|
|
1315
|
-
React.createElement("button", { className: "shogun-close-button", onClick: closeModal, "aria-label": "Close" },
|
|
1356
|
+
React.createElement("button", { className: "shogun-close-button", onClick: closeModal, "aria-label": "Close", disabled: pendingZkConfirmation || hasPendingSignup },
|
|
1316
1357
|
React.createElement(CloseIcon, null))),
|
|
1317
1358
|
React.createElement("div", { className: "shogun-modal-content" },
|
|
1318
1359
|
error && React.createElement("div", { className: "shogun-error-message" }, error),
|