Skip to content

Commit a8dbeea

Browse files
authored
Update WalletShell.tsx
1 parent 5e11897 commit a8dbeea

1 file changed

Lines changed: 68 additions & 47 deletions

File tree

src/components/WalletShell.tsx

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ import { handleRequestMethod } from "../lib/wcRequestHandlers";
3434
import { isValidSeedPhrase, normalizeSeed } from "../lib/inri";
3535
import { getSecuritySettings, type SecuritySettings } from "../lib/security";
3636
import { installDesktopEthereumProvider } from "../lib/desktopProvider";
37-
import { captureWcLaunchFromLocation, finishPendingWcLaunch, getPendingWcLaunch } from "../lib/wcLaunch";
38-
import { getInriNetwork, getStoredNetwork, saveStoredNetwork } from "../lib/network";
37+
import {
38+
captureWcLaunchFromLocation,
39+
finishPendingWcLaunch,
40+
getPendingWcLaunch,
41+
} from "../lib/wcLaunch";
42+
import { getStoredNetwork, saveStoredNetwork } from "../lib/network";
3943
import type { AppToastPayload, AppToastType } from "../lib/ui";
4044
import type { Tab } from "../lib/navigation";
4145

4246
const VAULTS_KEY = "lust_wallet_vaults_v6";
4347
const CURRENT_WALLET_KEY = "lust_wallet_current_id_v6";
4448
const LANG_KEY = "lust_wallet_lang_v6";
4549
const THEME_KEY = "lust_wallet_theme_v6";
50+
const BASE = import.meta.env.BASE_URL || "/";
4651

4752
type View = "auth" | "wallet";
4853

@@ -86,7 +91,9 @@ export default function WalletShell() {
8691

8792
const [message, setMessage] = useState("");
8893
const [loading, setLoading] = useState(false);
89-
const [toasts, setToasts] = useState<Array<{ id: number; message: string; type: AppToastType }>>([]);
94+
const [toasts, setToasts] = useState<Array<{ id: number; message: string; type: AppToastType }>>(
95+
[]
96+
);
9097

9198
const [unlockedWallet, setUnlockedWallet] = useState<UnlockedWallet | null>(null);
9299
const [security, setSecurity] = useState<SecuritySettings>(() => getSecuritySettings());
@@ -95,7 +102,9 @@ export default function WalletShell() {
95102
const [reauthError, setReauthError] = useState("");
96103

97104
const autoLockTimerRef = useRef<number | null>(null);
98-
const pendingSensitiveActionRef = useRef<null | ((overridePrivateKey?: string) => Promise<void>)>(null);
105+
const pendingSensitiveActionRef = useRef<null | ((overridePrivateKey?: string) => Promise<void>)>(
106+
null
107+
);
99108
const handledWcLaunchRef = useRef<string>("");
100109

101110
const [wcProposal, setWcProposal] = useState<any | null>(null);
@@ -135,25 +144,29 @@ export default function WalletShell() {
135144
walletAlreadyExists: tr(lang, "auth_wallet_already_exists"),
136145
};
137146

138-
139147
useEffect(() => {
140148
const handler = (event: Event) => {
141149
const detail = (event as CustomEvent<AppToastPayload>).detail;
142150
if (!detail?.message) return;
143151
const id = Date.now() + Math.floor(Math.random() * 1000);
144152
const duration = Math.max(1200, Math.min(detail.durationMs || 2600, 6000));
145153
setToasts((prev) => [...prev, { id, message: detail.message, type: detail.type || "info" }]);
146-
window.setTimeout(() => setToasts((prev) => prev.filter((item) => item.id !== id)), duration);
154+
window.setTimeout(() => {
155+
setToasts((prev) => prev.filter((item) => item.id !== id));
156+
}, duration);
147157
};
158+
148159
window.addEventListener("app-toast", handler as EventListener);
149160
return () => window.removeEventListener("app-toast", handler as EventListener);
150161
}, []);
151162

152163
useEffect(() => {
153164
if (!localStorage.getItem("wallet_active_network")) {
154-
saveStoredNetwork(getInriNetwork());
165+
const initialNetwork = getStoredNetwork();
166+
saveStoredNetwork(initialNetwork);
155167
window.dispatchEvent(new Event("wallet-network-updated"));
156168
}
169+
157170
const saved = localStorage.getItem(VAULTS_KEY);
158171
const currentId = localStorage.getItem(CURRENT_WALLET_KEY);
159172

@@ -205,14 +218,14 @@ export default function WalletShell() {
205218
sync();
206219
return wcStoreSubscribe(sync);
207220
}, []);
221+
208222
useEffect(() => {
209223
const launch = captureWcLaunchFromLocation();
210224
if (!launch) return;
211225
setTab("walletconnect");
212226
showMessage("WalletConnect launch detected");
213227
}, []);
214228

215-
216229
function ensureFavicon() {
217230
let link = document.querySelector("link[rel='icon']") as HTMLLinkElement | null;
218231

@@ -409,30 +422,31 @@ export default function WalletShell() {
409422
}
410423
}
411424

412-
const lockWallet = useCallback((reason?: string) => {
413-
pendingSensitiveActionRef.current = null;
414-
setReauthOpen(false);
415-
setReauthPassword("");
416-
setReauthError("");
417-
setUnlockedWallet((current) => {
418-
if (!current) return null;
419-
return null;
420-
});
421-
setView("auth");
422-
setUnlockPassword("");
423-
showMessage(reason || t.locked);
424-
}, [t.locked]);
425+
const lockWallet = useCallback(
426+
(reason?: string) => {
427+
pendingSensitiveActionRef.current = null;
428+
setReauthOpen(false);
429+
setReauthPassword("");
430+
setReauthError("");
431+
setUnlockedWallet(() => null);
432+
setView("auth");
433+
setUnlockPassword("");
434+
showMessage(reason || t.locked);
435+
},
436+
[t.locked]
437+
);
425438

426439
const markActivity = useCallback(() => {
427440
if (!unlockedWallet || !security.autoLockEnabled) return;
441+
428442
if (autoLockTimerRef.current) {
429443
window.clearTimeout(autoLockTimerRef.current);
430444
}
431445

432446
autoLockTimerRef.current = window.setTimeout(() => {
433447
lockWallet(trf(lang, "security_locked_inactivity", { minutes: security.autoLockMinutes }));
434448
}, security.autoLockMinutes * 60 * 1000);
435-
}, [lockWallet, security.autoLockEnabled, security.autoLockMinutes, unlockedWallet]);
449+
}, [lang, lockWallet, security.autoLockEnabled, security.autoLockMinutes, unlockedWallet]);
436450

437451
useEffect(() => {
438452
if (!unlockedWallet || !security.autoLockEnabled) {
@@ -443,8 +457,16 @@ export default function WalletShell() {
443457
return;
444458
}
445459

446-
const events: Array<keyof WindowEventMap> = ["pointerdown", "keydown", "touchstart", "focus", "mousemove"];
460+
const events: Array<keyof WindowEventMap> = [
461+
"pointerdown",
462+
"keydown",
463+
"touchstart",
464+
"focus",
465+
"mousemove",
466+
];
467+
447468
let throttle = 0;
469+
448470
const handleActivity = () => {
449471
const now = Date.now();
450472
if (now - throttle < 1500) return;
@@ -462,7 +484,9 @@ export default function WalletShell() {
462484
};
463485

464486
markActivity();
465-
events.forEach((eventName) => window.addEventListener(eventName, handleActivity, { passive: true }));
487+
events.forEach((eventName) =>
488+
window.addEventListener(eventName, handleActivity, { passive: true })
489+
);
466490
document.addEventListener("visibilitychange", handleVisibility);
467491

468492
return () => {
@@ -473,7 +497,7 @@ export default function WalletShell() {
473497
autoLockTimerRef.current = null;
474498
}
475499
};
476-
}, [lockWallet, markActivity, security.autoLockEnabled, security.lockOnHidden, unlockedWallet]);
500+
}, [lang, lockWallet, markActivity, security.autoLockEnabled, security.lockOnHidden, unlockedWallet]);
477501

478502
async function runSensitiveAction(action: (overridePrivateKey?: string) => Promise<void>) {
479503
if (!security.requirePasswordForSensitiveActions) {
@@ -502,7 +526,11 @@ export default function WalletShell() {
502526
}
503527

504528
try {
505-
const decrypted = await ethers.Wallet.fromEncryptedJson(vault.encryptedJson, reauthPassword.trim());
529+
const decrypted = await ethers.Wallet.fromEncryptedJson(
530+
vault.encryptedJson,
531+
reauthPassword.trim()
532+
);
533+
506534
setUnlockedWallet((current) =>
507535
current
508536
? {
@@ -550,6 +578,7 @@ export default function WalletShell() {
550578
console.error("WalletConnect init failed:", err);
551579
});
552580
}, [activeAddress]);
581+
553582
useEffect(() => {
554583
if (!activeAddress || view !== "wallet") return;
555584

@@ -609,7 +638,7 @@ export default function WalletShell() {
609638
});
610639

611640
return cleanup;
612-
}, [unlockedWallet, security, lang]);
641+
}, [lang, security, unlockedWallet]);
613642

614643
async function onApproveProposal() {
615644
if (!unlockedWallet || !wcProposal) {
@@ -714,9 +743,6 @@ export default function WalletShell() {
714743
case "swap":
715744
return <SwapScreen theme={theme} lang={lang} address={address} />;
716745

717-
case "bridge":
718-
return <BridgeScreen theme={theme} lang={lang} address={address} privateKey={privateKey} />;
719-
720746
case "staking":
721747
return <StakingScreen theme={theme} lang={lang} address={address} privateKey={privateKey} />;
722748

@@ -732,7 +758,6 @@ export default function WalletShell() {
732758
case "assets":
733759
return <AssetManagerScreen theme={theme} lang={lang} />;
734760

735-
736761
case "settings":
737762
return (
738763
<SettingsScreen
@@ -807,12 +832,12 @@ export default function WalletShell() {
807832
style={{
808833
background:
809834
theme === "light"
810-
? "linear-gradient(180deg,#eef3fb 0%, #f7f9fd 100%)"
811-
: "linear-gradient(180deg,#0b0b0f 0%, #101625 100%)",
835+
? "linear-gradient(180deg,#fff7fb 0%, #fffafe 100%)"
836+
: "linear-gradient(180deg,#000000 0%, #08080d 100%)",
812837
}}
813838
>
814839
<Header
815-
onOpenSettings={() => setTab("settings")}
840+
onOpenSettings={() => setTab("settings")}
816841
walletName={currentWalletMeta?.name || "Lust Wallet"}
817842
theme={theme}
818843
lang={lang}
@@ -849,7 +874,10 @@ export default function WalletShell() {
849874
onReject={onRejectRequest}
850875
/>
851876

852-
<ToastViewport toasts={toasts} onDismiss={(id) => setToasts((prev) => prev.filter((item) => item.id !== id))} />
877+
<ToastViewport
878+
toasts={toasts}
879+
onDismiss={(id) => setToasts((prev) => prev.filter((item) => item.id !== id))}
880+
/>
853881

854882
<ReauthModal
855883
open={reauthOpen}
@@ -875,22 +903,15 @@ export default function WalletShell() {
875903
);
876904
}
877905

878-
879-
880-
881-
882-
883-
884-
885-
886-
887906
function secondaryButtonStyle(theme: "dark" | "light"): React.CSSProperties {
888907
return {
889908
padding: "10px 14px",
890909
borderRadius: 12,
891-
border: `1px solid ${theme === "light" ? "#dbe2f0" : "#252b39"}`,
892-
background: theme === "light" ? "#ffffff" : "#1b2741",
893-
color: theme === "light" ? "#10131a" : "#fff",
910+
border: `1px solid ${
911+
theme === "light" ? "rgba(215,46,126,.20)" : "rgba(215,46,126,.28)"
912+
}`,
913+
background: theme === "light" ? "#ffffff" : "#0d0d12",
914+
color: theme === "light" ? "#10131a" : "#ffffff",
894915
cursor: "pointer",
895916
fontWeight: 700,
896917
};

0 commit comments

Comments
 (0)