From 0d5264ca836b996cb6dfdb7109171a4e73a6cd75 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 9 Jul 2021 16:38:39 -0400 Subject: [PATCH] updating connect modal based on connectors in state --- src/components/Connect.tsx | 59 ++++++++++++++++++++++------------- src/contexts/ChainContext.tsx | 7 ++++- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/components/Connect.tsx b/src/components/Connect.tsx index 96c1c26c5..8eafc76c1 100644 --- a/src/components/Connect.tsx +++ b/src/components/Connect.tsx @@ -1,17 +1,45 @@ -import React, { useContext } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { Box, Button, Text } from 'grommet'; -import { FiX } from 'react-icons/fi'; +import { FiCheckSquare, FiX } from 'react-icons/fi'; import { ChainContext } from '../contexts/ChainContext'; const Connect = ({ setConnectOpen }: any) => { - const { chainState } = useContext(ChainContext); + const { + chainState: { connector, connectors }, + chainActions: { connect }, + } = useContext(ChainContext); - console.log(chainState); - const connectTypes: string[] = ['Metamask', 'Ledger', 'WalletConnect']; + const [activatingConnector, setActivatingConnector] = useState(); - const handleConnect = (connectType: string) => { - console.log(`Connecting with ${connectType}`); - }; + /* Handle logic to recognize the connector currently being activated */ + useEffect(() => { + activatingConnector && activatingConnector === connector && setActivatingConnector(undefined); + }, [activatingConnector, connector]); + + const connectorsRender = [...connectors.keys()].map((name: string) => { + const currentConnector = connectors.get(name); + const activating = currentConnector === activatingConnector; + const connected = currentConnector === connector; + + return ( + { + setActivatingConnector(name); + connect(name); + }} + border={{ color: 'tailwind-blue', size: 'xsmall' }} + hoverIndicator={{ color: 'tailwind-blue', size: 'xsmall' }} + pad="small" + round="small" + > + + {connected && } + {activating ? 'Connecting' : name} + + + ); + }); return ( @@ -19,20 +47,7 @@ const Connect = ({ setConnectOpen }: any) => { Connect