Skip to content

Commit da4f59f

Browse files
Merge pull request #622 from AbelOsaretin/fix/wallet-security-issues
fix: wallet security issues — stale address fallback, disconnect confirmation, PostHog audit
2 parents 34ebfab + 709e31d commit da4f59f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎src/components/WalletButton.tsx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useState } from 'react';
3+
import { useState, useEffect, useCallback } from 'react';
44
import { useWalletContext } from '@/context/WalletContext';
55
import { useDebounce } from '@/hooks/useDebounce';
66
import { shortenAddress } from '@/lib/format';
@@ -9,6 +9,8 @@ import { shortenAddress } from '@/lib/format';
99
* that resolves faster than this never flashes a loading state at all. */
1010
const CONNECTING_INDICATOR_DELAY_MS = 200;
1111

12+
const DISMISS_TIMEOUT_MS = 5000;
13+
1214
interface WalletButtonProps {
1315
className?: string;
1416
}
@@ -18,6 +20,14 @@ export function WalletButton({ className }: WalletButtonProps) {
1820
const [confirmDisconnect, setConfirmDisconnect] = useState(false);
1921
const showConnecting = useDebounce(connecting, CONNECTING_INDICATOR_DELAY_MS) && connecting;
2022

23+
const dismiss = useCallback(() => setConfirmDisconnect(false), []);
24+
25+
useEffect(() => {
26+
if (!confirmDisconnect) return;
27+
const timer = setTimeout(dismiss, DISMISS_TIMEOUT_MS);
28+
return () => clearTimeout(timer);
29+
}, [confirmDisconnect, dismiss]);
30+
2131
if (connected && address) {
2232
return (
2333
<div className={`flex items-center gap-2 ${className ?? ''}`}>
@@ -36,7 +46,7 @@ export function WalletButton({ className }: WalletButtonProps) {
3646
Sure?
3747
</button>
3848
<button
39-
onClick={() => setConfirmDisconnect(false)}
49+
onClick={dismiss}
4050
className="rounded-full border border-white/10 px-3 py-1.5 text-xs text-gray-400 hover:border-white/20 hover:text-white transition-all"
4151
>
4252
Cancel

‎src/lib/stellar.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function getConnectedAddress(): Promise<WalletAddress | null> {
7474
const { address } = await kit.getAddress();
7575
return address ?? null;
7676
} catch {
77-
return saved;
77+
return null;
7878
}
7979
}
8080

0 commit comments

Comments
 (0)