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 { WALLET_TYPES, abbreviateAddress } from 'lib/wallet';
10import { MetamaskWallet } from 'lib/metamask';
11import { getAuthToken } from 'lib/authToken';
12import useLoginView from 'lib/useLoginView';
13import * as need from 'lib/need';
15import SubmitButton from 'form/SubmitButton';
16import BridgeForm from 'form/BridgeForm';
18export default function Metamask({ className, goHome }) {
19 useLoginView(WALLET_TYPES.METAMASK);
20 const { setWallet, setWalletType, setAuthToken } = useWallet();
22 const { web3 } = useNetwork();
23 const _web3 = need.web3(web3);
25 const onSubmit = useCallback(async () => {
27 const accounts = await window.ethereum.enable();
28 const wallet = new MetamaskWallet(accounts[0]);
30 const authToken = await getAuthToken({
32 walletType: WALLET_TYPES.METAMASK,
36 setAuthToken(Just(authToken));
37 setWallet(Just(wallet));
38 setWalletType(WALLET_TYPES.METAMASK);
41 return { [FORM_ERROR]: e.message };
43 }, [_web3, setAuthToken, setWallet, setWalletType]);
46 <Grid className={className}>
47 {(window.ethereum && Login({ onSubmit, goHome })) || Unsupported()}
52function Unsupported() {
55 <Grid.Item full as={H5}>
58 <Grid.Item full as={Text} className="f6 mb3">
59 Metamask is not installed on this browser. <br />
60 <LinkButton href="https://metamask.io" as={LinkButton}>
67function Login({ onSubmit, goHome }) {
70 <Grid.Item full as={Text} className="f6 gray4 mb3">
71 If you wish to login with a different wallet, please change it in the
74 <BridgeForm onSubmit={onSubmit} afterSubmit={goHome}>
75 {({ handleSubmit }) => (
76 <Grid.Item full as={SubmitButton} handleSubmit={handleSubmit}>
78 {window.ethereum.selectedAddress &&
79 ' 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