1import React, { useCallback, useEffect } 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';
15import SubmitButton from 'form/SubmitButton';
16import BridgeForm from 'form/BridgeForm';
17import Window from 'components/L2/Window/Window';
18import HeaderPane from 'components/L2/Window/HeaderPane';
19import BodyPane from 'components/L2/Window/BodyPane';
20import { Row } from '@tlon/indigo-react';
21import Web3 from 'web3';
23export default function Metamask({ className, goHome }) {
24 useLoginView(WALLET_TYPES.METAMASK);
33 const { setMetamask } = useNetwork();
37 }, []); // eslint-disable-line react-hooks/exhaustive-deps
39 const onSubmit = useCallback(async () => {
42 const accounts = await window.ethereum.request({
43 method: 'eth_requestAccounts',
45 const wallet = new MetamaskWallet(accounts.result[0]);
46 const web3 = new Web3(window.ethereum);
47 setWallet(Just(wallet));
48 setWalletType(WALLET_TYPES.METAMASK);
50 if (skipLoginSigning) {
55 const authToken = await getAuthToken({
56 address: wallet.address,
57 walletType: WALLET_TYPES.METAMASK,
61 setAuthToken(Just(authToken));
64 return { [FORM_ERROR]: e.message };
76 <Grid className={className}>
77 {(window.ethereum && Login({ onSubmit, goHome })) || Unsupported()}
82function Unsupported() {
85 <Grid.Item full as={H5}>
88 <Grid.Item full as={Text} className="f6 mb3">
89 Metamask is not installed on this browser. <br />
90 <LinkButton href="https://metamask.io" as={LinkButton}>
97function Login({ onSubmit, goHome }) {
99 <Window className="master-ticket">
101 <Row className="header-row">
105 <BodyPane className="login-body-pane">
106 <Grid.Item full as={Text} className="f6 gray4 mb3">
107 If you wish to login with a different wallet, please change it in the
110 <BridgeForm onSubmit={onSubmit} afterSubmit={goHome}>
111 {({ handleSubmit }) => (
112 <Grid.Item full className="flex-col justify-end w-full">
117 handleSubmit={handleSubmit}>
119 {window.ethereum.selectedAddress &&
120 ' 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