shogun-button-react 6.3.7 → 6.4.0
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/dist/components/ShogunButton.js +17 -99
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +0 -2
- package/package.json +2 -2
|
@@ -38,7 +38,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
38
38
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
|
39
39
|
const [userPub, setUserPub] = useState(null);
|
|
40
40
|
const [username, setUsername] = useState(null);
|
|
41
|
-
const [pendingSignupData, setPendingSignupData] = useState(null);
|
|
42
41
|
// Effetto per gestire l'inizializzazione e pulizia
|
|
43
42
|
useEffect(() => {
|
|
44
43
|
var _a, _b;
|
|
@@ -333,12 +332,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
333
332
|
seedPhrase: result.seedPhrase,
|
|
334
333
|
authMethod: authMethod,
|
|
335
334
|
};
|
|
336
|
-
|
|
337
|
-
setPendingSignupData(signupPayload);
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
onSignupSuccess === null || onSignupSuccess === void 0 ? void 0 : onSignupSuccess(signupPayload);
|
|
341
|
-
}
|
|
335
|
+
onSignupSuccess === null || onSignupSuccess === void 0 ? void 0 : onSignupSuccess(signupPayload);
|
|
342
336
|
}
|
|
343
337
|
else {
|
|
344
338
|
onError === null || onError === void 0 ? void 0 : onError(result.error);
|
|
@@ -358,7 +352,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
358
352
|
setIsLoggedIn(false);
|
|
359
353
|
setUserPub(null);
|
|
360
354
|
setUsername(null);
|
|
361
|
-
setPendingSignupData(null);
|
|
362
355
|
};
|
|
363
356
|
// Implementazione del metodo setProvider
|
|
364
357
|
const setProvider = (provider) => {
|
|
@@ -472,13 +465,8 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
472
465
|
const gunPlugin = null;
|
|
473
466
|
// Plugin hooks removed - GunAdvancedPlugin no longer available
|
|
474
467
|
const pluginHooks = {};
|
|
475
|
-
const completePendingSignup = React.useCallback(() => {
|
|
476
|
-
|
|
477
|
-
const dataToEmit = pendingSignupData;
|
|
478
|
-
setPendingSignupData(null);
|
|
479
|
-
onSignupSuccess === null || onSignupSuccess === void 0 ? void 0 : onSignupSuccess(dataToEmit);
|
|
480
|
-
}
|
|
481
|
-
}, [pendingSignupData, onSignupSuccess]);
|
|
468
|
+
const completePendingSignup = React.useCallback(() => { }, []);
|
|
469
|
+
const hasPendingSignup = false;
|
|
482
470
|
// Create a properly typed context value
|
|
483
471
|
const contextValue = React.useMemo(() => ({
|
|
484
472
|
core,
|
|
@@ -497,7 +485,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
497
485
|
setProvider,
|
|
498
486
|
gunPlugin,
|
|
499
487
|
completePendingSignup,
|
|
500
|
-
hasPendingSignup
|
|
488
|
+
hasPendingSignup,
|
|
501
489
|
put: async (path, data) => {
|
|
502
490
|
if (isShogunCore(core)) {
|
|
503
491
|
if (!core.gun)
|
|
@@ -556,7 +544,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
556
544
|
importGunPair,
|
|
557
545
|
gunPlugin,
|
|
558
546
|
pluginHooks,
|
|
559
|
-
pendingSignupData,
|
|
560
547
|
completePendingSignup,
|
|
561
548
|
]);
|
|
562
549
|
// Provide the context value to children
|
|
@@ -607,7 +594,7 @@ const ExportIcon = () => (React.createElement("svg", { xmlns: "http://www.w3.org
|
|
|
607
594
|
// Component for Shogun login button
|
|
608
595
|
export const ShogunButton = (() => {
|
|
609
596
|
const Button = () => {
|
|
610
|
-
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, hasPlugin,
|
|
597
|
+
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, hasPlugin, } = useShogun();
|
|
611
598
|
// Form states
|
|
612
599
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
|
613
600
|
const [formUsername, setFormUsername] = useState("");
|
|
@@ -629,10 +616,8 @@ export const ShogunButton = (() => {
|
|
|
629
616
|
const [showCopySuccess, setShowCopySuccess] = useState(false);
|
|
630
617
|
const [showImportSuccess, setShowImportSuccess] = useState(false);
|
|
631
618
|
const [zkTrapdoor, setZkTrapdoor] = useState("");
|
|
632
|
-
const [zkGeneratedTrapdoor, setZkGeneratedTrapdoor] = useState("");
|
|
633
619
|
const [webauthnSeedPhrase, setWebauthnSeedPhrase] = useState("");
|
|
634
620
|
const dropdownRef = useRef(null);
|
|
635
|
-
const [pendingZkConfirmation, setPendingZkConfirmation] = useState(false);
|
|
636
621
|
// Handle click outside to close dropdown
|
|
637
622
|
useEffect(() => {
|
|
638
623
|
const handleClickOutside = (event) => {
|
|
@@ -803,15 +788,11 @@ export const ShogunButton = (() => {
|
|
|
803
788
|
setLoading(true);
|
|
804
789
|
try {
|
|
805
790
|
const result = await signUp("zkproof");
|
|
806
|
-
if (result
|
|
807
|
-
|
|
808
|
-
setZkGeneratedTrapdoor(result.seedPhrase);
|
|
809
|
-
setAuthView("zkproof-signup-result");
|
|
810
|
-
setPendingZkConfirmation(true);
|
|
811
|
-
}
|
|
812
|
-
else if (result && !result.success) {
|
|
813
|
-
throw new Error(result.error || "ZK-Proof signup failed");
|
|
791
|
+
if (!result || !result.success) {
|
|
792
|
+
throw new Error((result === null || result === void 0 ? void 0 : result.error) || "ZK-Proof signup failed");
|
|
814
793
|
}
|
|
794
|
+
setAuthView("options");
|
|
795
|
+
setModalIsOpen(false);
|
|
815
796
|
}
|
|
816
797
|
catch (e) {
|
|
817
798
|
setError(e.message || "ZK-Proof signup failed");
|
|
@@ -930,9 +911,7 @@ export const ShogunButton = (() => {
|
|
|
930
911
|
setShowImportSuccess(false);
|
|
931
912
|
setRecoveredHint("");
|
|
932
913
|
setZkTrapdoor("");
|
|
933
|
-
setZkGeneratedTrapdoor("");
|
|
934
914
|
setWebauthnSeedPhrase("");
|
|
935
|
-
setPendingZkConfirmation(false);
|
|
936
915
|
};
|
|
937
916
|
const openModal = () => {
|
|
938
917
|
resetForm();
|
|
@@ -940,17 +919,12 @@ export const ShogunButton = (() => {
|
|
|
940
919
|
setModalIsOpen(true);
|
|
941
920
|
};
|
|
942
921
|
const closeModal = () => {
|
|
943
|
-
|
|
944
|
-
setError("Please save your trapdoor and confirm before leaving this screen.");
|
|
945
|
-
return;
|
|
946
|
-
}
|
|
922
|
+
setError("");
|
|
947
923
|
setModalIsOpen(false);
|
|
948
924
|
};
|
|
949
925
|
const finalizeZkProofSignup = () => {
|
|
950
|
-
completePendingSignup();
|
|
951
926
|
setError("");
|
|
952
|
-
|
|
953
|
-
setAuthView("options");
|
|
927
|
+
resetForm();
|
|
954
928
|
setModalIsOpen(false);
|
|
955
929
|
};
|
|
956
930
|
const toggleMode = () => {
|
|
@@ -1222,52 +1196,6 @@ export const ShogunButton = (() => {
|
|
|
1222
1196
|
textAlign: "center",
|
|
1223
1197
|
} }, "\u2705 You're now logged in with WebAuthn!"),
|
|
1224
1198
|
React.createElement("button", { type: "button", className: "shogun-submit-button", style: { marginTop: "16px" }, onClick: finalizeZkProofSignup }, "Close and Start Using App")));
|
|
1225
|
-
const renderZkProofSignupResult = () => (React.createElement("div", { className: "shogun-auth-form" },
|
|
1226
|
-
React.createElement("h3", null, "ZK-Proof Account Created!"),
|
|
1227
|
-
React.createElement("div", { style: {
|
|
1228
|
-
backgroundColor: "#fef3c7",
|
|
1229
|
-
padding: "12px",
|
|
1230
|
-
borderRadius: "8px",
|
|
1231
|
-
marginBottom: "16px",
|
|
1232
|
-
border: "1px solid #f59e0b",
|
|
1233
|
-
} },
|
|
1234
|
-
React.createElement("p", { style: {
|
|
1235
|
-
fontSize: "14px",
|
|
1236
|
-
color: "#92400e",
|
|
1237
|
-
margin: "0",
|
|
1238
|
-
fontWeight: "500",
|
|
1239
|
-
} }, "\u26A0\uFE0F CRITICAL: Save Your Trapdoor!"),
|
|
1240
|
-
React.createElement("p", { style: { fontSize: "13px", color: "#a16207", margin: "4px 0 0 0" } }, "This is your ONLY way to recover your anonymous account. Save it in a secure location. If you lose it, you will lose access to your account permanently.")),
|
|
1241
|
-
React.createElement("div", { className: "shogun-form-group" },
|
|
1242
|
-
React.createElement("label", null, "Your Trapdoor (Recovery Phrase):"),
|
|
1243
|
-
React.createElement("textarea", { value: zkGeneratedTrapdoor, readOnly: true, rows: 4, style: {
|
|
1244
|
-
fontFamily: "monospace",
|
|
1245
|
-
fontSize: "12px",
|
|
1246
|
-
width: "100%",
|
|
1247
|
-
padding: "8px",
|
|
1248
|
-
border: "2px solid #f59e0b",
|
|
1249
|
-
borderRadius: "4px",
|
|
1250
|
-
backgroundColor: "#fffbeb",
|
|
1251
|
-
} }),
|
|
1252
|
-
React.createElement("button", { type: "button", className: "shogun-submit-button", style: { marginTop: "8px" }, onClick: async () => {
|
|
1253
|
-
if (navigator.clipboard) {
|
|
1254
|
-
await navigator.clipboard.writeText(zkGeneratedTrapdoor);
|
|
1255
|
-
setShowCopySuccess(true);
|
|
1256
|
-
setTimeout(() => setShowCopySuccess(false), 3000);
|
|
1257
|
-
}
|
|
1258
|
-
} }, showCopySuccess ? "✅ Copied!" : "📋 Copy Trapdoor"),
|
|
1259
|
-
!navigator.clipboard && (React.createElement("p", { style: { fontSize: "12px", color: "#666", marginTop: "8px" } }, "\u26A0\uFE0F Please manually copy the trapdoor above."))),
|
|
1260
|
-
React.createElement("div", { style: {
|
|
1261
|
-
backgroundColor: "#dcfce7",
|
|
1262
|
-
color: "#166534",
|
|
1263
|
-
padding: "12px",
|
|
1264
|
-
borderRadius: "8px",
|
|
1265
|
-
marginTop: "16px",
|
|
1266
|
-
fontSize: "14px",
|
|
1267
|
-
border: "1px solid #22c55e",
|
|
1268
|
-
textAlign: "center",
|
|
1269
|
-
} }, "\u2705 You're now logged in anonymously!"),
|
|
1270
|
-
React.createElement("button", { type: "button", className: "shogun-submit-button", style: { marginTop: "16px" }, onClick: finalizeZkProofSignup }, "Close and Start Using App")));
|
|
1271
1199
|
const renderImportForm = () => (React.createElement("div", { className: "shogun-auth-form" },
|
|
1272
1200
|
React.createElement("h3", null, "Import Gun Pair"),
|
|
1273
1201
|
React.createElement("div", { style: {
|
|
@@ -1327,13 +1255,7 @@ export const ShogunButton = (() => {
|
|
|
1327
1255
|
React.createElement("button", { className: "shogun-connect-button", onClick: openModal },
|
|
1328
1256
|
React.createElement(WalletIcon, null),
|
|
1329
1257
|
React.createElement("span", null, "Login / Sign Up")),
|
|
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
|
-
} },
|
|
1258
|
+
modalIsOpen && (React.createElement("div", { className: "shogun-modal-overlay", onClick: closeModal },
|
|
1337
1259
|
React.createElement("div", { className: "shogun-modal", onClick: (e) => e.stopPropagation() },
|
|
1338
1260
|
React.createElement("div", { className: "shogun-modal-header" },
|
|
1339
1261
|
React.createElement("h2", null, authView === "recover"
|
|
@@ -1348,12 +1270,10 @@ export const ShogunButton = (() => {
|
|
|
1348
1270
|
? "WebAuthn"
|
|
1349
1271
|
: authView === "zkproof-login"
|
|
1350
1272
|
? "ZK-Proof Login"
|
|
1351
|
-
:
|
|
1352
|
-
? "
|
|
1353
|
-
:
|
|
1354
|
-
|
|
1355
|
-
: "Sign Up"),
|
|
1356
|
-
React.createElement("button", { className: "shogun-close-button", onClick: closeModal, "aria-label": "Close", disabled: pendingZkConfirmation || hasPendingSignup },
|
|
1273
|
+
: formMode === "login"
|
|
1274
|
+
? "Login"
|
|
1275
|
+
: "Sign Up"),
|
|
1276
|
+
React.createElement("button", { className: "shogun-close-button", onClick: closeModal, "aria-label": "Close" },
|
|
1357
1277
|
React.createElement(CloseIcon, null))),
|
|
1358
1278
|
React.createElement("div", { className: "shogun-modal-content" },
|
|
1359
1279
|
error && React.createElement("div", { className: "shogun-error-message" }, error),
|
|
@@ -1374,9 +1294,7 @@ export const ShogunButton = (() => {
|
|
|
1374
1294
|
renderWebAuthnUsernameForm(),
|
|
1375
1295
|
authView === "webauthn-signup-result" &&
|
|
1376
1296
|
renderWebauthnSignupResult(),
|
|
1377
|
-
authView === "zkproof-login" && renderZkProofLoginForm()
|
|
1378
|
-
authView === "zkproof-signup-result" &&
|
|
1379
|
-
renderZkProofSignupResult()))))));
|
|
1297
|
+
authView === "zkproof-login" && renderZkProofLoginForm()))))));
|
|
1380
1298
|
};
|
|
1381
1299
|
Button.displayName = "ShogunButton";
|
|
1382
1300
|
return Object.assign(Button, {
|