Skip to content

Commit

Permalink
feat: show message to allow an account if none are enabled (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleOTheven authored Jun 23, 2023
1 parent 15f919c commit e6ae3f1
Showing 1 changed file with 58 additions and 49 deletions.
107 changes: 58 additions & 49 deletions frontend/src/components/ConnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,70 @@
import { useInstalledWallets, useUninstalledWallets, useWallet } from "useink";
import { Button } from "./Button";
import { Modal } from "./Modal";
import { useEffect } from "react";
import { useInstalledWallets, useUninstalledWallets, useWallet } from 'useink';
import { Button } from './Button';
import { Modal } from './Modal';
import { useEffect } from 'react';

type Props = {
show: boolean;
onClose: () => void;
};

export const ConnectWallet: React.FC<Props> = ({ show, onClose }) => {
const { account, connect } = useWallet();
const installed = useInstalledWallets();
const uninstalled = useUninstalledWallets();
const { account, connect, accounts } = useWallet();
const installed = useInstalledWallets();
const uninstalled = useUninstalledWallets();

useEffect(() => { account && onClose() }, [account, onClose])
useEffect(() => {
account && onClose();
}, [account, onClose]);

return (
<Modal open={show} className="p-6 max-w-lg">
<h2 className="text-2xl font-bold mb-8">Connect Wallet</h2>
const isConnectedWithZeroEnabledAccounts = !account && accounts?.length === 0;

{!account && installed.length > 0 && (
return (
<Modal open={show} className="p-6 max-w-lg">
<h2 className="text-2xl font-bold mb-8">Connect Wallet</h2>

{isConnectedWithZeroEnabledAccounts ? (
<p>Please open your wallet settings and enable at least one account for this URL.</p>
) : (
!account &&
installed.length > 0 && (
<ul>
{installed.map((w => (
<li key={w.title} className="mt-3">
<Button className="flex items-center gap-2 w-full" onClick={() => connect(w.extensionName)}>
<img className="w-10 mr-2" src={w.logo.src} alt={w.logo.alt} />
Connect to {w.extensionName}
</Button>
</li>
)))}
{installed.map((w) => (
<li key={w.title} className="mt-3">
<Button className="flex items-center gap-2 w-full" onClick={() => connect(w.extensionName)}>
<img className="w-10 mr-2" src={w.logo.src} alt={w.logo.alt} />
Connect to {w.extensionName}
</Button>
</li>
))}
</ul>
)}

{!account && uninstalled.length && installed.length === 0 && (
<>
<p className="font-semibold my-6 text-center">
Please install one of these supported wallets.
</p>

<ul>
{uninstalled.map((w => (
<li key={w.title} className="mt-3">

<Button className="flex items-center gap-2 w-full"
onClick={() => window.open(w.installUrl, '_blank')}
rel="noopener noreferrer"
>
<img className="w-10 mr-2" src={w.logo.src} alt={w.logo.alt} />
Install {w.extensionName}
</Button>
</li>
)))}
</ul>
</>
)}

<Button className="mt-6" onClick={onClose}>Close</Button>
</Modal>
)
}
)
)}

{!account && uninstalled.length && installed.length === 0 && (
<>
<p className="font-semibold my-6 text-center">Please install one of these supported wallets.</p>

<ul>
{uninstalled.map((w) => (
<li key={w.title} className="mt-3">
<Button
className="flex items-center gap-2 w-full"
onClick={() => window.open(w.installUrl, '_blank')}
rel="noopener noreferrer"
>
<img className="w-10 mr-2" src={w.logo.src} alt={w.logo.alt} />
Install {w.extensionName}
</Button>
</li>
))}
</ul>
</>
)}

<Button className="mt-6" onClick={onClose}>
Close
</Button>
</Modal>
);
};

0 comments on commit e6ae3f1

Please sign in to comment.