1import React, { useCallback } from 'react';
2import { Grid, Text, LinkButton, H5 } from 'indigo-react';
3import { Just } from 'folktale/maybe';
4import { FORM_ERROR } from 'final-form';
6import { useWallet } from 'store/wallet';
7import { useNetwork } from 'store/network';
9import { abbreviateAddress } from 'lib/utils/address';
10import { WALLET_TYPES } from 'lib/constants';
11import { MetamaskWallet } from 'lib/metamask';
12import { getAuthToken } from 'lib/authToken';
13import useLoginView from 'lib/useLoginView';
14import * as need from 'lib/need';
16import SubmitButton from 'form/SubmitButton';
17import BridgeForm from 'form/BridgeForm';
19export default function Metamask({ className, goHome }) {
20 useLoginView(WALLET_TYPES.METAMASK);
21 const { setWallet, setWalletType, setAuthToken } = useWallet();
23 const { web3 } = useNetwork();
24 const _web3 = need.web3(web3);
26 const onSubmit = useCallback(async () => {
28 const accounts = await window.ethereum.enable();
29 const wallet = new MetamaskWallet(accounts[0]);
31 const authToken = await getAuthToken({
33 walletType: WALLET_TYPES.METAMASK,
37 setAuthToken(Just(authToken));
38 setWallet(Just(wallet));
39 setWalletType(WALLET_TYPES.METAMASK);
42 return { [FORM_ERROR]: e.message };
44 }, [_web3, setAuthToken, setWallet, setWalletType]);
47 <Grid className={className}>
48 {(window.ethereum && Login({ onSubmit, goHome })) || Unsupported()}
53function Unsupported() {
56 <Grid.Item full as={H5}>
59 <Grid.Item full as={Text} className="f6 mb3">
60 Metamask is not installed on this browser. <br />
61 <LinkButton href="https://metamask.io" as={LinkButton}>
68function Login({ onSubmit, goHome }) {
71 <Grid.Item full as={Text} className="f6 gray4 mb3">
72 If you wish to login with a different wallet, please change it in the
75 <BridgeForm onSubmit={onSubmit} afterSubmit={goHome}>
76 {({ handleSubmit }) => (
77 <Grid.Item full as={SubmitButton} handleSubmit={handleSubmit}>
79 {window.ethereum.selectedAddress &&
80 ' as ' + abbreviateAddress(window.ethereum.selectedAddress)}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list