From 1c868995a143ffcbed69afafffef0a2a93294c6b Mon Sep 17 00:00:00 2001 From: Maximilian Schneider Date: Fri, 16 Jul 2021 12:18:21 +0200 Subject: [PATCH] implement new connect wallet button --- components/Button.tsx | 4 +- components/ConnectWalletButton.tsx | 126 +++++++++++++++++------------ components/ContributionModal.tsx | 10 +-- components/RedeemModal.tsx | 8 +- components/TopBar.tsx | 99 ----------------------- hooks/useWallet.tsx | 2 +- stores/useWalletStore.tsx | 1 + 7 files changed, 85 insertions(+), 165 deletions(-) diff --git a/components/Button.tsx b/components/Button.tsx index 4d5ab67..8bb8a6c 100644 --- a/components/Button.tsx +++ b/components/Button.tsx @@ -3,7 +3,7 @@ import styled from '@emotion/styled' import tw from 'twin.macro' export const idleGradient = - 'bg-gradient-to-r from-secondary-2-light to-primary-light' + 'bg-gradient-to-r from-secondary-2-light to-primary-dark' export const activeGradient = 'bg-gradient-to-bl from-secondary-1-light via-primary-dark to-secondary-2-light' @@ -55,7 +55,7 @@ const Button: FunctionComponent = ({ }) => { return ( ( + + + +) -const ConnectWalletButton = () => { - const wallet = useWalletStore((s) => s.current) - const [savedProviderUrl] = useLocalStorageState( - 'walletProvider', - DEFAULT_PROVIDER.url - ) +const CheckIcon = (props) => ( + + + +) + +const ConnectWalletButton = (props) => { + const { connected, provider, setSavedProviderUrl } = useWallet() return ( -
- -
- + + {connected ? 'Disconnect' : 'Connect Wallet'} + + +
+ + {({ open }) => ( + <> + + {open ? ( + + ) : ( + + )} + + + {WALLET_PROVIDERS.map(({ name, url, icon }) => ( + + + + ))} + + + )} +
) } export default ConnectWalletButton - -export const ConnectWalletButtonSmall = ({ connected, ...props }) => ( -
- - {!connected && ( -
- )} -
-) diff --git a/components/ContributionModal.tsx b/components/ContributionModal.tsx index 6284911..e43b948 100644 --- a/components/ContributionModal.tsx +++ b/components/ContributionModal.tsx @@ -7,7 +7,7 @@ import { import useWalletStore from '../stores/useWalletStore' import Input from './Input' import Button from './Button' -import { ConnectWalletButtonSmall } from './ConnectWalletButton' +import ConnectWalletButton from './ConnectWalletButton' import PoolCountdown from './PoolCountdown' import Slider from './Slider' import Loading from './Loading' @@ -273,12 +273,8 @@ const ContributionModal = () => {
-
- +
+
)} diff --git a/components/RedeemModal.tsx b/components/RedeemModal.tsx index 58aeca7..ecc0af7 100644 --- a/components/RedeemModal.tsx +++ b/components/RedeemModal.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react' import useWalletStore from '../stores/useWalletStore' import Button from './Button' import Input from './Input' -import { ConnectWalletButtonSmall } from './ConnectWalletButton' +import ConnectWalletButton from './ConnectWalletButton' import Loading from './Loading' import useLargestAccounts from '../hooks/useLargestAccounts' import useVaults from '../hooks/useVaults' @@ -155,11 +155,7 @@ const RedeemModal = () => {
- +
)} diff --git a/components/TopBar.tsx b/components/TopBar.tsx index 695a1cc..8596678 100644 --- a/components/TopBar.tsx +++ b/components/TopBar.tsx @@ -1,55 +1,4 @@ -import { useEffect, useState } from 'react' -import { Menu } from '@headlessui/react' -import styled from '@emotion/styled' -import { - ChevronUpIcon, - ChevronDownIcon, - DuplicateIcon, - LogoutIcon, -} from '@heroicons/react/outline' -import ConnectWalletButton from './ConnectWalletButton' -import WalletIcon from './WalletIcon' -import useWalletStore from '../stores/useWalletStore' - -const Code = styled.code` - border: 1px solid hsla(0, 0%, 39.2%, 0.2); - border-radius: 3px; - background: hsla(0, 0%, 58.8%, 0.1); - font-size: 13px; -` - -const WALLET_OPTIONS = [ - { name: 'Copy address', icon: }, - { name: 'Disconnect', icon: }, -] - const TopBar = () => { - const { connected, current: wallet } = useWalletStore((s) => s) - const [isCopied, setIsCopied] = useState(false) - - useEffect(() => { - if (isCopied) { - const timer = setTimeout(() => { - setIsCopied(false) - }, 2000) - return () => clearTimeout(timer) - } - }, [isCopied]) - - const handleWalletMenu = (option) => { - if (option === 'Copy address') { - const el = document.createElement('textarea') - el.value = wallet.publicKey.toString() - document.body.appendChild(el) - el.select() - document.execCommand('copy') - document.body.removeChild(el) - setIsCopied(true) - } else { - wallet.disconnect() - } - } - return ( diff --git a/hooks/useWallet.tsx b/hooks/useWallet.tsx index 500cfbe..7e07dc4 100644 --- a/hooks/useWallet.tsx +++ b/hooks/useWallet.tsx @@ -139,5 +139,5 @@ export default function useWallet() { actions.fetchUsdcVault() }, 20 * SECONDS) - return { connected, wallet } + return { connected, wallet, provider, setSavedProviderUrl } } diff --git a/stores/useWalletStore.tsx b/stores/useWalletStore.tsx index a0be023..065af45 100644 --- a/stores/useWalletStore.tsx +++ b/stores/useWalletStore.tsx @@ -110,6 +110,7 @@ const useWalletStore = create((set, get) => ({ const connection = get().connection.current const wallet = get().current const programId = get().connection.programId + const set = get().set console.log('fetchPool', connection, poolIdl) if (connection) {