From 0a0df5d10f95c5683efa2aa537dc497e4747c267 Mon Sep 17 00:00:00 2001 From: Hayden Shively <17186559+haydenshively@users.noreply.github.com> Date: Wed, 5 Jun 2024 20:05:34 -0500 Subject: [PATCH] Require accepting terms before connecting Smart Wallet --- .../components/navbar/ConnectWalletButton.tsx | 204 ++++++++++-------- .../components/navbar/CreateWalletButton.tsx | 20 +- shared/src/components/navbar/NavBar.tsx | 15 +- 3 files changed, 128 insertions(+), 111 deletions(-) diff --git a/shared/src/components/navbar/ConnectWalletButton.tsx b/shared/src/components/navbar/ConnectWalletButton.tsx index 67452ba7..36d544b4 100644 --- a/shared/src/components/navbar/ConnectWalletButton.tsx +++ b/shared/src/components/navbar/ConnectWalletButton.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { FilledStylizedButton, OutlinedGradientButton } from '../common/Buttons'; import { Text } from '../common/Typography'; @@ -8,6 +8,7 @@ import { useChainId, useConnect } from 'wagmi'; import Modal, { MODAL_BLACK_TEXT_COLOR } from '../common/Modal'; import { GREY_700 } from '../../data/constants/Colors'; +import { BlueCreateWalletButton } from './CreateWalletButton'; const Container = styled.div.attrs((props: { fillWidth: boolean }) => props)` width: ${(props) => (props.fillWidth ? '100%' : 'max-content')}; @@ -29,12 +30,19 @@ export default function ConnectWalletButton(props: ConnectWalletButtonProps) { const [acceptedTerms, setAcceptedTerms] = useState(false); // MARK: component state - const [walletModalOpen, setWalletModalOpen] = useState(false); + const [walletModalOpen, setWalletModalOpen] = useState(false); // MARK: wagmi hooks const { connect, connectors, error } = useConnect(); const targetChainId = useChainId(); + const createWallet = useCallback(() => { + const coinbaseWalletConnector = connectors.find((connector) => connector.id === 'coinbaseWalletSDK'); + if (coinbaseWalletConnector) { + connect({ connector: coinbaseWalletConnector, chainId: targetChainId }); + } + }, [connectors, connect, targetChainId]); + const orderedFilteredConnectors = useMemo(() => { let hasNamedInjectedConnector = false; let idxPlainInjectedConnector = -1; @@ -79,97 +87,115 @@ export default function ConnectWalletButton(props: ConnectWalletButtonProps) { const acknowledgedAllCheckboxes = acknowledgedCheckboxes.every((acknowledged) => acknowledged); return ( - - + { - setWalletModalOpen(true); + if (acceptedTerms) { + createWallet(); + return; + } + setWalletModalOpen('create'); }} - size='M' - fillWidth={fillWidth} - disabled={disabled} - className='connect-wallet-button' - > - {props.shouldShortenText ? 'Connect' : 'Connect Wallet'} - - - {acceptedTerms ? ( -
-
- {orderedFilteredConnectors.map((connector) => ( -
- {connector.icon !== undefined ? ( - {`${connector.icon} - ) : ( - getIconForWagmiConnectorNamed(connector.name) - )} - { - // Manually close the modal when the connector is connecting - // This indicates the connector's modal/popup is or will soon be open - connector.emitter.once('connect', () => setWalletModalOpen(false)); - connect({ connector, chainId: targetChainId }); - - if (connector.id === 'walletConnect') setWalletModalOpen(false); - }} - > - {connector.name} - -
- ))} -
- {error && ( - - {error?.message ?? 'Failed to connect'} - - )} -
- ) : ( -
-
- - At Aloe Labs, we believe everyone should be able to use financial services free of censorship. But - running a site like this makes some data collection inevitable, and the US Government feels differently - about financial access and surveillance.{' '} - As such, we have to ask you to confirm the following: - - {checkboxes?.map((checkbox, index) => ( -