import React, { useCallback } from 'react';
import { Grid, Text, LinkButton, H5 } from 'indigo-react';
import { Just } from 'folktale/maybe';
import { useWallet } from 'store/wallet';
import { WALLET_TYPES } from 'lib/wallet';
import { MetamaskWallet } from 'lib/metamask';
import useLoginView from 'lib/useLoginView';
import SubmitButton from 'form/SubmitButton';
import BridgeForm from 'form/BridgeForm';
export default function Metamask({ className, goHome }) {
useLoginView(WALLET_TYPES.METAMASK);
const { setWallet, setWalletType } = useWallet();
const onSubmit = useCallback(async () => {
const accounts = await window.ethereum.enable();
const wallet = new MetamaskWallet(accounts[0]);
setWallet(Just(wallet));
setWalletType(WALLET_TYPES.METAMASK);
}, [setWallet, setWalletType]);
return (
{(window.ethereum && Login({ onSubmit, goHome })) || Unsupported()}
);
}
function Unsupported() {
return (
<>
Unsupported
Metamask is not installed on this browser.
Get Metamask
>
);
}
function Login({ onSubmit, goHome }) {
return (
<>
Authenticate with Metamask
If you wish to login with a different wallet, please change it in the
Metamask extension
{({ handleSubmit }) => (
Login
{window.ethereum.selectedAddress &&
' as ' + window.ethereum.selectedAddress}
)}
>
);
}