@@ -1,25 +1,17 @@
11import React, { useCallback, useState } from 'react';
22import cn from 'classnames';
3−import Web3 from 'web3';
43import { Grid } from 'indigo-react';
54import { Box, Button, Icon, LoadingSpinner, Text } from '@tlon/indigo-react';
65import { useHistory } from 'store/history';
7−import { Just, Nothing } from 'folktale/maybe';
8−import { FORM_ERROR } from 'final-form';
9−
10−import { useWallet } from 'store/wallet';
11−import { usePointCursor } from 'store/pointCursor';
126
137import { WALLET_TYPES } from 'lib/constants';
14−import { MetamaskWallet } from 'lib/metamask';
15−import { getAuthToken } from 'lib/authToken';
168import { useWalletConnect } from 'lib/useWalletConnect';
17−import useLoginView from 'lib/useLoginView';
189
1910import Modal from 'components/L2/Modal';
2011import HeaderButton from 'components/L2/Headers/HeaderButton';
2112import './LoginSelector.scss';
2213import { NAMES } from './Other';
14+import useLoginView from 'lib/useLoginView';
2315
2416interface LoginSelectorProps {
2517 className: string;
@@ -51,77 +43,30 @@ export default function LoginSelector({
5143 const [showModal, setShowModal] = useState(false);
5244 const [metamaskSelected, setMetamaskSelected] = useState(false);
5345
54− const {
55− setWallet,
56− setWalletType,
57− resetWallet,
58− setAuthToken,
59− }: any = useWallet();
60−
6146 const { connect } = useWalletConnect();
6247
63− const { setPointCursor }: any = usePointCursor();
64−
6548 const goToActivate = useCallback(() => push(names.ACTIVATE), [
6649 push,
6750 names.ACTIVATE,
6851 ]);
6952
70− const connectMetamask = useCallback(async () => {
71− try {
72− setMetamaskSelected(true);
73− resetWallet();
74− setWalletType(WALLET_TYPES.METAMASK);
75− setPointCursor(Nothing());
76−
77− const accounts = await (window as any).ethereum.send(
78− 'eth_requestAccounts'
79− );
80− const wallet = new MetamaskWallet(accounts.result[0]);
81−
82− const web3 = new Web3((window as any).ethereum);
83− const authToken = await getAuthToken({
84− address: wallet.address,
85− walletType: WALLET_TYPES.METAMASK,
86− web3,
87− });
88−
89− setAuthToken(Just(authToken));
90− setWallet(Just(wallet));
91− setWalletType(WALLET_TYPES.METAMASK);
92− goHome();
93− } catch (e) {
94− setMetamaskSelected(false);
95− console.error(e);
96− return { [FORM_ERROR]: (e as any).message };
97− }
98− }, [
99− setAuthToken,
100− setWallet,
101− setWalletType,
102− resetWallet,
103− setPointCursor,
104− setMetamaskSelected,
105− goHome,
106− ]);
107−
108− const selectOption = (value: string) => () => {
109− if (value === NAMES.METAMASK) {
110− connectMetamask();
111− } else {
112− if (value === NAMES.WALLET_CONNECT) {
113− connect();
114− }
115− setCurrentTab(value);
53+ const selectOption = (value: string) => async () => {
54+ if (value === NAMES.WALLET_CONNECT) {
55+ connect();
11656 }
57+ setCurrentTab(value);
11758 };
11859
11960 const loader = <LoadingSpinner background="#bce2ff" foreground="#219DFF" />;
12061
62+ const availableOptions = options.filter(
63+ ({ value }) => value !== NAMES.METAMASK || !!(window as any).ethereum
64+ );
65+
12166 if (!currentTab) {
12267 return (
12368 <Grid className={className}>
124− {options.map((option, i) => (
69+ {availableOptions.map((option, i) => (
12570 <React.Fragment key={option.value}>
12671 <Grid.Item
12772 full