mirror of
https://github.com/0xShay/ticketchain.git
synced 2026-01-11 13:13:25 +00:00
🐛 Partially fixed bugs with connecting to wallet button. Removed one button state for simplicity.
This commit is contained in:
@@ -37,20 +37,16 @@ function formatAddress(address: string | undefined): string {
|
||||
|
||||
function MetaMaskConnect() {
|
||||
const { sdk, connected, connecting, account } = useSDK();
|
||||
const [metaMaskInstalled, setMetaMaskInstalled] = useState(false);
|
||||
|
||||
const isMetaMaskInstalled = () =>
|
||||
typeof window !== 'undefined' && typeof window.ethereum !== 'undefined';
|
||||
const [isConnected, setIsConnected] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (isMetaMaskInstalled()) {
|
||||
setMetaMaskInstalled(true);
|
||||
}
|
||||
}, []);
|
||||
setIsConnected(connected);
|
||||
}, [connected]);
|
||||
|
||||
const connect = async () => {
|
||||
try {
|
||||
await sdk?.connect();
|
||||
setIsConnected(true);
|
||||
} catch (err) {
|
||||
console.warn(`No accounts found`, err);
|
||||
}
|
||||
@@ -59,36 +55,25 @@ function MetaMaskConnect() {
|
||||
const disconnect = () => {
|
||||
if (sdk) {
|
||||
sdk.terminate();
|
||||
setIsConnected(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!metaMaskInstalled) {
|
||||
return (
|
||||
<Button
|
||||
onClick={() =>
|
||||
window.open('https://metamask.io/download.html', '_blank')
|
||||
}
|
||||
className="bg-gradient-to-r from-blue-500 to-indigo-700"
|
||||
>
|
||||
Install MetaMask
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
{connected ? (
|
||||
{isConnected ? (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button>{formatAddress(account)}</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-44">
|
||||
<button
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={disconnect}
|
||||
className="w-full px-4 py-2 text-left text-destructive hover:bg-muted"
|
||||
className="w-full px-4 py-2 text-left hover:bg-muted hover:text-destructive"
|
||||
>
|
||||
Disconnect
|
||||
</button>
|
||||
</Button>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user