shogun-button-react 1.4.3 → 1.5.1
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.d.ts +2 -3
- package/dist/components/ShogunButton.js +117 -89
- package/dist/connector.d.ts +1 -1
- package/dist/connector.js +0 -32
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/types/connector-options.d.ts +0 -2
- package/package.json +2 -2
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -4
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ShogunCore } from "shogun-core";
|
|
3
3
|
import { Observable } from "rxjs";
|
|
4
|
-
import "../types/index.js";
|
|
5
4
|
import "../styles/index.css";
|
|
6
5
|
type ShogunContextType = {
|
|
7
6
|
sdk: ShogunCore | null;
|
|
@@ -13,7 +12,6 @@ type ShogunContextType = {
|
|
|
13
12
|
signUp: (method: string, ...args: any[]) => Promise<any>;
|
|
14
13
|
logout: () => void;
|
|
15
14
|
observe: <T>(path: string) => Observable<T>;
|
|
16
|
-
setProvider: (provider: any) => boolean;
|
|
17
15
|
hasPlugin: (name: string) => boolean;
|
|
18
16
|
getPlugin: <T>(name: string) => T | undefined;
|
|
19
17
|
exportGunPair: (password?: string) => Promise<string>;
|
|
@@ -37,8 +35,9 @@ type ShogunButtonProviderProps = {
|
|
|
37
35
|
authMethod?: "password" | "web3" | "webauthn" | "nostr" | "oauth";
|
|
38
36
|
}) => void;
|
|
39
37
|
onError?: (error: string) => void;
|
|
38
|
+
onLogout?: () => void;
|
|
40
39
|
};
|
|
41
|
-
export declare function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, onSignupSuccess, onError, }: ShogunButtonProviderProps): React.JSX.Element;
|
|
40
|
+
export declare function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, onSignupSuccess, onError, onLogout, }: ShogunButtonProviderProps): React.JSX.Element;
|
|
42
41
|
type ShogunButtonComponent = React.FC & {
|
|
43
42
|
Provider: typeof ShogunButtonProvider;
|
|
44
43
|
useShogun: typeof useShogun;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React, { useContext, useState, createContext, useEffect, useRef } from "react";
|
|
1
|
+
import React, { useContext, useState, createContext, useEffect, useRef, } from "react";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
|
-
import "../types/index.js"; // Import type file to extend definitions
|
|
4
3
|
import "../styles/index.css";
|
|
5
4
|
// Default context
|
|
6
5
|
const defaultShogunContext = {
|
|
@@ -13,7 +12,6 @@ const defaultShogunContext = {
|
|
|
13
12
|
signUp: async () => ({}),
|
|
14
13
|
logout: () => { },
|
|
15
14
|
observe: () => new Observable(),
|
|
16
|
-
setProvider: () => false,
|
|
17
15
|
hasPlugin: () => false,
|
|
18
16
|
getPlugin: () => undefined,
|
|
19
17
|
exportGunPair: async () => "",
|
|
@@ -24,7 +22,8 @@ const ShogunContext = createContext(defaultShogunContext);
|
|
|
24
22
|
// Custom hook to access the context
|
|
25
23
|
export const useShogun = () => useContext(ShogunContext);
|
|
26
24
|
// Provider component
|
|
27
|
-
export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, onSignupSuccess, onError,
|
|
25
|
+
export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, onSignupSuccess, onError, onLogout, // AGGIUNTA
|
|
26
|
+
}) {
|
|
28
27
|
// Use React's useState directly
|
|
29
28
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
|
30
29
|
const [userPub, setUserPub] = useState(null);
|
|
@@ -40,10 +39,10 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
40
39
|
if (pub) {
|
|
41
40
|
setIsLoggedIn(true);
|
|
42
41
|
setUserPub(pub);
|
|
43
|
-
setUsername(pub.slice(0, 8) +
|
|
42
|
+
setUsername(pub.slice(0, 8) + "...");
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
// Poiché il metodo 'on' non esiste su ShogunCore,
|
|
45
|
+
// Poiché il metodo 'on' non esiste su ShogunCore,
|
|
47
46
|
// gestiamo gli stati direttamente nei metodi di login/logout
|
|
48
47
|
}, [sdk, onLoginSuccess]);
|
|
49
48
|
// RxJS observe method
|
|
@@ -51,7 +50,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
51
50
|
if (!sdk) {
|
|
52
51
|
return new Observable();
|
|
53
52
|
}
|
|
54
|
-
return sdk.observe(path);
|
|
53
|
+
return sdk.rx.observe(path);
|
|
55
54
|
};
|
|
56
55
|
// Unified login
|
|
57
56
|
const login = async (method, ...args) => {
|
|
@@ -71,7 +70,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
71
70
|
case "pair":
|
|
72
71
|
// New pair authentication method
|
|
73
72
|
const pair = args[0];
|
|
74
|
-
if (!pair || typeof pair !==
|
|
73
|
+
if (!pair || typeof pair !== "object") {
|
|
75
74
|
throw new Error("Invalid pair data provided");
|
|
76
75
|
}
|
|
77
76
|
result = await new Promise((resolve, reject) => {
|
|
@@ -86,7 +85,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
86
85
|
success: true,
|
|
87
86
|
userPub: pub,
|
|
88
87
|
alias: alias,
|
|
89
|
-
method:
|
|
88
|
+
method: "pair",
|
|
90
89
|
});
|
|
91
90
|
});
|
|
92
91
|
});
|
|
@@ -99,6 +98,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
99
98
|
if (!webauthn)
|
|
100
99
|
throw new Error("WebAuthn plugin not available");
|
|
101
100
|
result = await webauthn.login(username);
|
|
101
|
+
authMethod = "webauthn";
|
|
102
102
|
break;
|
|
103
103
|
case "web3":
|
|
104
104
|
const web3 = sdk.getPlugin("web3");
|
|
@@ -110,6 +110,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
110
110
|
}
|
|
111
111
|
username = connectionResult.address;
|
|
112
112
|
result = await web3.login(connectionResult.address);
|
|
113
|
+
authMethod = "web3";
|
|
113
114
|
break;
|
|
114
115
|
case "nostr":
|
|
115
116
|
const nostr = sdk.getPlugin("nostr");
|
|
@@ -124,6 +125,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
124
125
|
throw new Error("Nessuna chiave pubblica ottenuta");
|
|
125
126
|
username = pubkey;
|
|
126
127
|
result = await nostr.login(pubkey);
|
|
128
|
+
authMethod = "nostr";
|
|
127
129
|
break;
|
|
128
130
|
case "oauth":
|
|
129
131
|
const oauth = sdk.getPlugin("oauth");
|
|
@@ -141,7 +143,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
141
143
|
}
|
|
142
144
|
if (result.success) {
|
|
143
145
|
const userPub = result.userPub || ((_b = (_a = sdk.gun.user()) === null || _a === void 0 ? void 0 : _a.is) === null || _b === void 0 ? void 0 : _b.pub) || "";
|
|
144
|
-
const displayName = result.alias || username || userPub.slice(0, 8) +
|
|
146
|
+
const displayName = result.alias || username || userPub.slice(0, 8) + "...";
|
|
145
147
|
setIsLoggedIn(true);
|
|
146
148
|
setUserPub(userPub);
|
|
147
149
|
setUsername(displayName);
|
|
@@ -216,6 +218,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
216
218
|
if (!oauth)
|
|
217
219
|
throw new Error("OAuth plugin not available");
|
|
218
220
|
const provider = args[0] || "google";
|
|
221
|
+
// NON serve più setPin né passare il pin
|
|
219
222
|
result = await oauth.signUp(provider);
|
|
220
223
|
authMethod = "oauth";
|
|
221
224
|
if (result.redirectUrl) {
|
|
@@ -227,7 +230,7 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
227
230
|
}
|
|
228
231
|
if (result.success) {
|
|
229
232
|
const userPub = result.userPub || ((_b = (_a = sdk.gun.user()) === null || _a === void 0 ? void 0 : _a.is) === null || _b === void 0 ? void 0 : _b.pub) || "";
|
|
230
|
-
const displayName = result.alias || username || userPub.slice(0, 8) +
|
|
233
|
+
const displayName = result.alias || username || userPub.slice(0, 8) + "...";
|
|
231
234
|
setIsLoggedIn(true);
|
|
232
235
|
setUserPub(userPub);
|
|
233
236
|
setUsername(displayName);
|
|
@@ -256,31 +259,8 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
256
259
|
sessionStorage.removeItem("gun/pair");
|
|
257
260
|
sessionStorage.removeItem("gun/session");
|
|
258
261
|
sessionStorage.removeItem("pair");
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const setProvider = (provider) => {
|
|
262
|
-
if (!sdk) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
try {
|
|
266
|
-
let newProviderUrl = null;
|
|
267
|
-
if (provider && provider.connection && provider.connection.url) {
|
|
268
|
-
newProviderUrl = provider.connection.url;
|
|
269
|
-
}
|
|
270
|
-
else if (typeof provider === 'string') {
|
|
271
|
-
newProviderUrl = provider;
|
|
272
|
-
}
|
|
273
|
-
if (newProviderUrl) {
|
|
274
|
-
if (typeof sdk.setRpcUrl === 'function') {
|
|
275
|
-
return sdk.setRpcUrl(newProviderUrl);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
catch (error) {
|
|
281
|
-
console.error("Error setting provider:", error);
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
262
|
+
if (onLogout)
|
|
263
|
+
onLogout(); // AGGIUNTA
|
|
284
264
|
};
|
|
285
265
|
const hasPlugin = (name) => {
|
|
286
266
|
return sdk ? sdk.hasPlugin(name) : false;
|
|
@@ -361,7 +341,6 @@ export function ShogunButtonProvider({ children, sdk, options, onLoginSuccess, o
|
|
|
361
341
|
signUp,
|
|
362
342
|
logout,
|
|
363
343
|
observe,
|
|
364
|
-
setProvider,
|
|
365
344
|
hasPlugin,
|
|
366
345
|
getPlugin,
|
|
367
346
|
exportGunPair,
|
|
@@ -414,7 +393,7 @@ const ExportIcon = () => (React.createElement("svg", { xmlns: "http://www.w3.org
|
|
|
414
393
|
// Component for Shogun login button
|
|
415
394
|
export const ShogunButton = (() => {
|
|
416
395
|
const Button = () => {
|
|
417
|
-
const { isLoggedIn, username, logout, login, signUp, sdk, options, exportGunPair, importGunPair } = useShogun();
|
|
396
|
+
const { isLoggedIn, username, logout, login, signUp, sdk, options, exportGunPair, importGunPair, } = useShogun();
|
|
418
397
|
// Form states
|
|
419
398
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
|
420
399
|
const [formUsername, setFormUsername] = useState("");
|
|
@@ -436,17 +415,19 @@ export const ShogunButton = (() => {
|
|
|
436
415
|
const [showCopySuccess, setShowCopySuccess] = useState(false);
|
|
437
416
|
const [showImportSuccess, setShowImportSuccess] = useState(false);
|
|
438
417
|
const dropdownRef = useRef(null);
|
|
418
|
+
// Rimuovi tutto ciò che riguarda oauthPin
|
|
439
419
|
// Handle click outside to close dropdown
|
|
440
420
|
useEffect(() => {
|
|
441
421
|
const handleClickOutside = (event) => {
|
|
442
|
-
if (dropdownRef.current &&
|
|
422
|
+
if (dropdownRef.current &&
|
|
423
|
+
!dropdownRef.current.contains(event.target)) {
|
|
443
424
|
setDropdownOpen(false);
|
|
444
425
|
}
|
|
445
426
|
};
|
|
446
427
|
if (dropdownOpen) {
|
|
447
|
-
document.addEventListener(
|
|
428
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
448
429
|
return () => {
|
|
449
|
-
document.removeEventListener(
|
|
430
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
450
431
|
};
|
|
451
432
|
}
|
|
452
433
|
}, [dropdownOpen]);
|
|
@@ -530,7 +511,6 @@ export const ShogunButton = (() => {
|
|
|
530
511
|
setLoading(false);
|
|
531
512
|
}
|
|
532
513
|
};
|
|
533
|
-
const handleWeb3Auth = () => handleAuth("web3");
|
|
534
514
|
const handleWebAuthnAuth = () => {
|
|
535
515
|
if (!(sdk === null || sdk === void 0 ? void 0 : sdk.hasPlugin("webauthn"))) {
|
|
536
516
|
setError("WebAuthn is not supported in your browser");
|
|
@@ -538,8 +518,6 @@ export const ShogunButton = (() => {
|
|
|
538
518
|
}
|
|
539
519
|
setAuthView("webauthn-username");
|
|
540
520
|
};
|
|
541
|
-
const handleNostrAuth = () => handleAuth("nostr");
|
|
542
|
-
const handleOAuth = (provider) => handleAuth("oauth", provider);
|
|
543
521
|
const handleRecover = async () => {
|
|
544
522
|
setError("");
|
|
545
523
|
setLoading(true);
|
|
@@ -628,6 +606,7 @@ export const ShogunButton = (() => {
|
|
|
628
606
|
setShowCopySuccess(false);
|
|
629
607
|
setShowImportSuccess(false);
|
|
630
608
|
setRecoveredHint("");
|
|
609
|
+
// Rimuovi tutto ciò che riguarda oauthPin
|
|
631
610
|
};
|
|
632
611
|
const openModal = () => {
|
|
633
612
|
resetForm();
|
|
@@ -647,11 +626,15 @@ export const ShogunButton = (() => {
|
|
|
647
626
|
options.showMetamask !== false && (sdk === null || sdk === void 0 ? void 0 : sdk.hasPlugin("web3")) && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
648
627
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => handleAuth("web3"), disabled: loading },
|
|
649
628
|
React.createElement(WalletIcon, null),
|
|
650
|
-
formMode === "login"
|
|
629
|
+
formMode === "login"
|
|
630
|
+
? "Login with MetaMask"
|
|
631
|
+
: "Signup with MetaMask"))),
|
|
651
632
|
options.showWebauthn !== false && (sdk === null || sdk === void 0 ? void 0 : sdk.hasPlugin("webauthn")) && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
652
633
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: handleWebAuthnAuth, disabled: loading },
|
|
653
634
|
React.createElement(WebAuthnIcon, null),
|
|
654
|
-
formMode === "login"
|
|
635
|
+
formMode === "login"
|
|
636
|
+
? "Login with WebAuthn"
|
|
637
|
+
: "Signup with WebAuthn"))),
|
|
655
638
|
options.showNostr !== false && (sdk === null || sdk === void 0 ? void 0 : sdk.hasPlugin("nostr")) && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
656
639
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => handleAuth("nostr"), disabled: loading },
|
|
657
640
|
React.createElement(NostrIcon, null),
|
|
@@ -659,12 +642,16 @@ export const ShogunButton = (() => {
|
|
|
659
642
|
options.showOauth !== false && (sdk === null || sdk === void 0 ? void 0 : sdk.hasPlugin("oauth")) && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
660
643
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button shogun-google-button", onClick: () => handleAuth("oauth", "google"), disabled: loading },
|
|
661
644
|
React.createElement(GoogleIcon, null),
|
|
662
|
-
formMode === "login"
|
|
645
|
+
formMode === "login"
|
|
646
|
+
? "Login with Google"
|
|
647
|
+
: "Signup with Google"))),
|
|
663
648
|
React.createElement("div", { className: "shogun-divider" },
|
|
664
649
|
React.createElement("span", null, "or")),
|
|
665
650
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => setAuthView("password"), disabled: loading },
|
|
666
651
|
React.createElement(LockIcon, null),
|
|
667
|
-
formMode === "login"
|
|
652
|
+
formMode === "login"
|
|
653
|
+
? "Login with Password"
|
|
654
|
+
: "Signup with Password"),
|
|
668
655
|
formMode === "login" && (React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => setAuthView("import"), disabled: loading },
|
|
669
656
|
React.createElement(ImportIcon, null),
|
|
670
657
|
"Import Gun Pair"))));
|
|
@@ -711,11 +698,25 @@ export const ShogunButton = (() => {
|
|
|
711
698
|
: "Already have an account? Log in"),
|
|
712
699
|
formMode === "login" && (React.createElement("button", { type: "button", className: "shogun-toggle-mode", onClick: () => setAuthView("recover"), disabled: loading }, "Forgot password?")))));
|
|
713
700
|
const renderWebAuthnUsernameForm = () => (React.createElement("div", { className: "shogun-auth-form" },
|
|
714
|
-
React.createElement("h3", null, formMode === "login"
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
701
|
+
React.createElement("h3", null, formMode === "login"
|
|
702
|
+
? "Login with WebAuthn"
|
|
703
|
+
: "Sign Up with WebAuthn"),
|
|
704
|
+
React.createElement("div", { style: {
|
|
705
|
+
backgroundColor: "#f0f9ff",
|
|
706
|
+
padding: "12px",
|
|
707
|
+
borderRadius: "8px",
|
|
708
|
+
marginBottom: "16px",
|
|
709
|
+
border: "1px solid #0ea5e9",
|
|
710
|
+
} },
|
|
711
|
+
React.createElement("p", { style: {
|
|
712
|
+
fontSize: "14px",
|
|
713
|
+
color: "#0c4a6e",
|
|
714
|
+
margin: "0",
|
|
715
|
+
fontWeight: "500",
|
|
716
|
+
} }, "\uD83D\uDD11 WebAuthn Authentication"),
|
|
717
|
+
React.createElement("p", { style: { fontSize: "13px", color: "#075985", margin: "4px 0 0 0" } },
|
|
718
|
+
"Please enter your username to continue with WebAuthn",
|
|
719
|
+
" ",
|
|
719
720
|
formMode === "login" ? "login" : "registration",
|
|
720
721
|
".")),
|
|
721
722
|
React.createElement("div", { className: "shogun-form-group" },
|
|
@@ -753,9 +754,20 @@ export const ShogunButton = (() => {
|
|
|
753
754
|
} }, "Back to Login")));
|
|
754
755
|
const renderExportForm = () => (React.createElement("div", { className: "shogun-auth-form" },
|
|
755
756
|
React.createElement("h3", null, "Export Gun Pair"),
|
|
756
|
-
React.createElement("div", { style: {
|
|
757
|
-
|
|
758
|
-
|
|
757
|
+
React.createElement("div", { style: {
|
|
758
|
+
backgroundColor: "#f0f9ff",
|
|
759
|
+
padding: "12px",
|
|
760
|
+
borderRadius: "8px",
|
|
761
|
+
marginBottom: "16px",
|
|
762
|
+
border: "1px solid #0ea5e9",
|
|
763
|
+
} },
|
|
764
|
+
React.createElement("p", { style: {
|
|
765
|
+
fontSize: "14px",
|
|
766
|
+
color: "#0c4a6e",
|
|
767
|
+
margin: "0",
|
|
768
|
+
fontWeight: "500",
|
|
769
|
+
} }, "\uD83D\uDD12 Backup Your Account"),
|
|
770
|
+
React.createElement("p", { style: { fontSize: "13px", color: "#075985", margin: "4px 0 0 0" } }, "Export your Gun pair to backup your account. You can use this to login from another device or restore access if needed.")),
|
|
759
771
|
React.createElement("div", { className: "shogun-form-group" },
|
|
760
772
|
React.createElement("label", { htmlFor: "exportPassword" },
|
|
761
773
|
React.createElement(LockIcon, null),
|
|
@@ -764,23 +776,23 @@ export const ShogunButton = (() => {
|
|
|
764
776
|
exportedPair && (React.createElement("div", { className: "shogun-form-group" },
|
|
765
777
|
React.createElement("label", null, "Your Gun Pair (copy this safely):"),
|
|
766
778
|
showCopySuccess && (React.createElement("div", { style: {
|
|
767
|
-
backgroundColor:
|
|
768
|
-
color:
|
|
769
|
-
padding:
|
|
770
|
-
borderRadius:
|
|
771
|
-
marginBottom:
|
|
772
|
-
fontSize:
|
|
773
|
-
border:
|
|
779
|
+
backgroundColor: "#dcfce7",
|
|
780
|
+
color: "#166534",
|
|
781
|
+
padding: "8px 12px",
|
|
782
|
+
borderRadius: "4px",
|
|
783
|
+
marginBottom: "8px",
|
|
784
|
+
fontSize: "14px",
|
|
785
|
+
border: "1px solid #22c55e",
|
|
774
786
|
} }, "\u2705 Copied to clipboard successfully!")),
|
|
775
787
|
React.createElement("textarea", { value: exportedPair, readOnly: true, rows: 6, style: {
|
|
776
|
-
fontFamily:
|
|
777
|
-
fontSize:
|
|
778
|
-
width:
|
|
779
|
-
padding:
|
|
780
|
-
border:
|
|
781
|
-
borderRadius:
|
|
788
|
+
fontFamily: "monospace",
|
|
789
|
+
fontSize: "12px",
|
|
790
|
+
width: "100%",
|
|
791
|
+
padding: "8px",
|
|
792
|
+
border: "1px solid #ccc",
|
|
793
|
+
borderRadius: "4px",
|
|
782
794
|
} }),
|
|
783
|
-
!navigator.clipboard && (React.createElement("p", { style: { fontSize:
|
|
795
|
+
!navigator.clipboard && (React.createElement("p", { style: { fontSize: "12px", color: "#666", marginTop: "8px" } }, "\u26A0\uFE0F Auto-copy not available. Please manually copy the text above.")))),
|
|
784
796
|
React.createElement("button", { type: "button", className: "shogun-submit-button", onClick: handleExportPair, disabled: loading }, loading ? "Exporting..." : "Export Pair"),
|
|
785
797
|
React.createElement("div", { className: "shogun-form-footer" },
|
|
786
798
|
React.createElement("button", { className: "shogun-toggle-mode", onClick: () => {
|
|
@@ -798,20 +810,31 @@ export const ShogunButton = (() => {
|
|
|
798
810
|
}, disabled: loading }, "Back"))));
|
|
799
811
|
const renderImportForm = () => (React.createElement("div", { className: "shogun-auth-form" },
|
|
800
812
|
React.createElement("h3", null, "Import Gun Pair"),
|
|
801
|
-
React.createElement("div", { style: {
|
|
802
|
-
|
|
803
|
-
|
|
813
|
+
React.createElement("div", { style: {
|
|
814
|
+
backgroundColor: "#fef3c7",
|
|
815
|
+
padding: "12px",
|
|
816
|
+
borderRadius: "8px",
|
|
817
|
+
marginBottom: "16px",
|
|
818
|
+
border: "1px solid #f59e0b",
|
|
819
|
+
} },
|
|
820
|
+
React.createElement("p", { style: {
|
|
821
|
+
fontSize: "14px",
|
|
822
|
+
color: "#92400e",
|
|
823
|
+
margin: "0",
|
|
824
|
+
fontWeight: "500",
|
|
825
|
+
} }, "\uD83D\uDD11 Restore Your Account"),
|
|
826
|
+
React.createElement("p", { style: { fontSize: "13px", color: "#a16207", margin: "4px 0 0 0" } }, "Import a Gun pair to login with your existing account from another device. Make sure you have your backup data ready.")),
|
|
804
827
|
React.createElement("div", { className: "shogun-form-group" },
|
|
805
828
|
React.createElement("label", { htmlFor: "importPairData" },
|
|
806
829
|
React.createElement(ImportIcon, null),
|
|
807
830
|
React.createElement("span", null, "Gun Pair Data")),
|
|
808
831
|
React.createElement("textarea", { id: "importPairData", value: importPairData, onChange: (e) => setImportPairData(e.target.value), disabled: loading, placeholder: "Paste your Gun pair JSON here...", rows: 6, style: {
|
|
809
|
-
fontFamily:
|
|
810
|
-
fontSize:
|
|
811
|
-
width:
|
|
812
|
-
padding:
|
|
813
|
-
border:
|
|
814
|
-
borderRadius:
|
|
832
|
+
fontFamily: "monospace",
|
|
833
|
+
fontSize: "12px",
|
|
834
|
+
width: "100%",
|
|
835
|
+
padding: "8px",
|
|
836
|
+
border: "1px solid #ccc",
|
|
837
|
+
borderRadius: "4px",
|
|
815
838
|
} })),
|
|
816
839
|
React.createElement("div", { className: "shogun-form-group" },
|
|
817
840
|
React.createElement("label", { htmlFor: "importPassword" },
|
|
@@ -819,16 +842,20 @@ export const ShogunButton = (() => {
|
|
|
819
842
|
React.createElement("span", null, "Decryption Password (if encrypted)")),
|
|
820
843
|
React.createElement("input", { type: "password", id: "importPassword", value: importPassword, onChange: (e) => setImportPassword(e.target.value), disabled: loading, placeholder: "Enter password if pair was encrypted" })),
|
|
821
844
|
showImportSuccess && (React.createElement("div", { style: {
|
|
822
|
-
backgroundColor:
|
|
823
|
-
color:
|
|
824
|
-
padding:
|
|
825
|
-
borderRadius:
|
|
826
|
-
marginBottom:
|
|
827
|
-
fontSize:
|
|
828
|
-
border:
|
|
829
|
-
textAlign:
|
|
845
|
+
backgroundColor: "#dcfce7",
|
|
846
|
+
color: "#166534",
|
|
847
|
+
padding: "12px",
|
|
848
|
+
borderRadius: "8px",
|
|
849
|
+
marginBottom: "16px",
|
|
850
|
+
fontSize: "14px",
|
|
851
|
+
border: "1px solid #22c55e",
|
|
852
|
+
textAlign: "center",
|
|
830
853
|
} }, "\u2705 Pair imported successfully! Logging you in...")),
|
|
831
|
-
React.createElement("button", { type: "button", className: "shogun-submit-button", onClick: handleImportPair, disabled: loading || showImportSuccess }, loading
|
|
854
|
+
React.createElement("button", { type: "button", className: "shogun-submit-button", onClick: handleImportPair, disabled: loading || showImportSuccess }, loading
|
|
855
|
+
? "Importing..."
|
|
856
|
+
: showImportSuccess
|
|
857
|
+
? "Success!"
|
|
858
|
+
: "Import and Login"),
|
|
832
859
|
React.createElement("div", { className: "shogun-form-footer" },
|
|
833
860
|
React.createElement("button", { className: "shogun-toggle-mode", onClick: () => {
|
|
834
861
|
setAuthView("options");
|
|
@@ -873,7 +900,8 @@ export const ShogunButton = (() => {
|
|
|
873
900
|
authView === "showHint" && renderHint(),
|
|
874
901
|
authView === "export" && renderExportForm(),
|
|
875
902
|
authView === "import" && renderImportForm(),
|
|
876
|
-
authView === "webauthn-username" &&
|
|
903
|
+
authView === "webauthn-username" &&
|
|
904
|
+
renderWebAuthnUsernameForm()))))));
|
|
877
905
|
};
|
|
878
906
|
Button.displayName = "ShogunButton";
|
|
879
907
|
return Object.assign(Button, {
|
package/dist/connector.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ShogunConnectorOptions, ShogunConnectorResult } from "./types";
|
|
1
|
+
import { ShogunConnectorOptions, ShogunConnectorResult } from "./types/connector-options";
|
|
2
2
|
export declare function shogunConnector(options: ShogunConnectorOptions): ShogunConnectorResult;
|
package/dist/connector.js
CHANGED
|
@@ -8,36 +8,6 @@ export function shogunConnector(options) {
|
|
|
8
8
|
timeouts,
|
|
9
9
|
oauth,
|
|
10
10
|
});
|
|
11
|
-
const setProvider = (provider) => {
|
|
12
|
-
if (!sdk) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
let newProviderUrl = null;
|
|
17
|
-
if (provider && provider.connection && provider.connection.url) {
|
|
18
|
-
newProviderUrl = provider.connection.url;
|
|
19
|
-
}
|
|
20
|
-
else if (typeof provider === "string") {
|
|
21
|
-
newProviderUrl = provider;
|
|
22
|
-
}
|
|
23
|
-
if (newProviderUrl) {
|
|
24
|
-
if (typeof sdk.setRpcUrl === "function") {
|
|
25
|
-
return sdk.setRpcUrl(newProviderUrl);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
console.error("Error setting provider:", error);
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const getCurrentProviderUrl = () => {
|
|
36
|
-
if (sdk && typeof sdk.getRpcUrl === "function") {
|
|
37
|
-
return sdk.getRpcUrl();
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
};
|
|
41
11
|
const registerPlugin = (plugin) => {
|
|
42
12
|
if (sdk && typeof sdk.register === "function") {
|
|
43
13
|
try {
|
|
@@ -57,8 +27,6 @@ export function shogunConnector(options) {
|
|
|
57
27
|
return {
|
|
58
28
|
sdk,
|
|
59
29
|
options,
|
|
60
|
-
setProvider,
|
|
61
|
-
getCurrentProviderUrl,
|
|
62
30
|
registerPlugin,
|
|
63
31
|
hasPlugin,
|
|
64
32
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,4 @@ import { ShogunConnectorOptions, ShogunConnectorResult } from './types/connector
|
|
|
3
3
|
import { shogunConnector } from './connector.js';
|
|
4
4
|
export { ShogunButton, ShogunButtonProvider, useShogun };
|
|
5
5
|
export { shogunConnector };
|
|
6
|
-
export * from './types/index.js';
|
|
7
6
|
export { ShogunConnectorOptions, ShogunConnectorResult };
|
package/dist/index.js
CHANGED
|
@@ -34,8 +34,6 @@ export interface ShogunConnectorOptions {
|
|
|
34
34
|
export interface ShogunConnectorResult {
|
|
35
35
|
sdk: ShogunCore;
|
|
36
36
|
options: ShogunConnectorOptions;
|
|
37
|
-
setProvider: (provider: any) => boolean;
|
|
38
|
-
getCurrentProviderUrl: () => string | null;
|
|
39
37
|
registerPlugin: (plugin: any) => boolean;
|
|
40
38
|
hasPlugin: (name: string) => boolean;
|
|
41
39
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogun-button-react",
|
|
3
3
|
"description": "Shogun connector button",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.1",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"src/styles/index.css"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"ethers": "^6.13.5",
|
|
35
35
|
"prettier": "^3.5.3",
|
|
36
36
|
"rxjs": "^7.8.1",
|
|
37
|
-
"shogun-core": "
|
|
37
|
+
"shogun-core": "^1.5.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "^18.0.0",
|
package/dist/types/index.d.ts
DELETED
package/dist/types/index.js
DELETED
package/dist/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types/connector-options.js';
|
package/dist/types.js
DELETED