diff --git a/src/components/lib/Web3Status.js b/src/components/lib/Web3Status.js index c11dc8a6..0043bc36 100644 --- a/src/components/lib/Web3Status.js +++ b/src/components/lib/Web3Status.js @@ -1,51 +1,49 @@ import React, { Component, useReducer, useState } from 'react' - +import Check from '../svgs/Check' import { useWeb3React } from '@web3-react/core' import { InjectedConnector } from '@web3-react/injected-connector' import { LedgerConnector } from '@web3-react/ledger-connector' import { TrezorConnector } from '@web3-react/trezor-connector' -import Check from '../svgs/Check' - -const MAINNET = 1 - -const CHAIN_IDS = [ - 1, - 3, - 1337, - 123, -] - -const REACT_APP_CHAIN_ID = '1337' -// const NETWORK_URL = 'http://localhost:8545' +// Connectors. const injectedConnector = new InjectedConnector({ - supportedChainIds: CHAIN_IDS.map(Number) + // supportedChainIds: CHAIN_IDS.map(Number) }) - const ledgerConnector = new LedgerConnector({ chainId: 1, url: '...' }) const trezorConnector = new TrezorConnector({ chainId: 1, url: '...', manifestEmail: '...', manifestAppUrl: '...' }) +// Wallets. +const WALLETS = [ + { + name: "Metamask", + icon: "/images/metamask-fox.svg", + showName: true + }, + { + name: "Ledger", + icon: "/images/ledger.svg" + }, + { + name: "Trezor", + icon: "/images/trezor.png" + } +] -export const ConnectWalletDialog = ({ shown }) => { - const { active, account, connector, activate, error } = useWeb3React("WALLET") - - function closeModal() { } +export const ConnectWalletDialog = ({ shown, onConnected }) => { + const { active, account, connector, activate } = useWeb3React("WALLET") const CHOOSE_WALLET = 'CHOOSE_WALLET' const CONNECT_TO_WALLET = 'CONNECT_TO_WALLET' const WALLET_CONNECTED = 'WALLET_CONNECTED' - const initialState = { - chosenWallet: null, - status: CHOOSE_WALLET - } - let [chosenWallet, setChosenWallet] = useState(null) let [status, setStatus] = useState(CHOOSE_WALLET) + let [error, setError] = useState(null) let state = { chosenWallet, - status + status, + error } async function chooseWallet(wallet) { @@ -60,24 +58,15 @@ export const ConnectWalletDialog = ({ shown }) => { connector = injectedConnector } - await activate(connector) - } - - const WALLETS = [ - { - name: "Metamask", - icon: "/images/metamask-fox.svg", - showName: true - }, - { - name: "Ledger", - icon: "/images/ledger.svg" - }, - { - name: "Trezor", - icon: "/images/trezor.png" + try { + await activate(connector, undefined, true) + onConnected() + } catch(ex) { + setError(ex.toString()) + throw ex } - ] + + } const ChooseWalletStep = () => { return <> @@ -105,7 +94,7 @@ export const ConnectWalletDialog = ({ shown }) => {
Connecting to {state.chosenWallet} wallet...
-{error && error.toString()}
+{state.error}
> } @@ -124,11 +113,6 @@ export const ConnectWalletDialog = ({ shown }) => { } - const HARDWARE_WALLETS = [ - 'Ledger', 'Trezor' - ] - - return