diff --git a/src/components/ConnectWallet.tsx b/src/components/ConnectWallet.tsx new file mode 100644 index 0000000..9bbe910 --- /dev/null +++ b/src/components/ConnectWallet.tsx @@ -0,0 +1,21 @@ +import { useModal } from '../hooks/useModal'; +import Button from './Button'; + +export default function ConnectWallet() { + const { dispatch } = useModal(); + return ( + + ); +} diff --git a/src/components/ConnectWalletButton/index.tsx b/src/components/ConnectWalletButton/index.tsx deleted file mode 100644 index 19d35d0..0000000 --- a/src/components/ConnectWalletButton/index.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import ConnectWalletButton from './ConnectWalletButton'; - -export default ConnectWalletButton; diff --git a/src/components/ConnectWalletButton/ConnectWalletButton.tsx b/src/components/Connectors/Connectors.tsx similarity index 75% rename from src/components/ConnectWalletButton/ConnectWalletButton.tsx rename to src/components/Connectors/Connectors.tsx index 4ee847a..e9d3b9b 100644 --- a/src/components/ConnectWalletButton/ConnectWalletButton.tsx +++ b/src/components/Connectors/Connectors.tsx @@ -1,13 +1,15 @@ import { useEffect } from 'react'; import { useConnect } from 'wagmi'; +import { useModal } from '../../hooks/useModal'; import { useToast } from '../../hooks/useToast'; import Button from '../Button'; -function ConnectWalletButton() { +export default function Connectors() { // const { connector: activeConnector, isConnected } = useAccount(); - const { connect, connectors, error } = useConnect(); + const { connect, connectors, error, isSuccess } = useConnect(); const { dispatch: toastDispatch } = useToast(); + const { dispatch: modalDispatch } = useModal(); // if (!!activeConnector && isConnected) throw new Error('Connector error!'); @@ -19,8 +21,15 @@ function ConnectWalletButton() { }); }, [error]); + useEffect(() => { + if (isSuccess) + modalDispatch({ + type: 'CLEAR_MODAL', + }); + }, [isSuccess]); + return ( -
+
{connectors && connectors.map((connector) => ( @@ -38,5 +47,3 @@ function ConnectWalletButton() {
); } - -export default ConnectWalletButton; diff --git a/src/components/Connectors/index.tsx b/src/components/Connectors/index.tsx new file mode 100644 index 0000000..4cccdaa --- /dev/null +++ b/src/components/Connectors/index.tsx @@ -0,0 +1,3 @@ +import Connectors from './Connectors'; + +export default Connectors; diff --git a/src/components/Modal/ConnectorsModal.tsx b/src/components/Modal/ConnectorsModal.tsx new file mode 100644 index 0000000..77850a0 --- /dev/null +++ b/src/components/Modal/ConnectorsModal.tsx @@ -0,0 +1,20 @@ +import ConnectWalletButton from '../Connectors'; +import { CloseModalButton, Container, Inner } from './ui'; + +export default function ConnectorsModal({ + handleCloseModal, +}: { + handleCloseModal: () => void; +}) { + return ( + + + +
+

Connect Wallet

+ +
+
+
+ ); +} diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index 8c6701c..ead583d 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -7,6 +7,7 @@ import AddTokens from './AddTokens'; import { CloseModalButton, Container, Heading, Inner, Message } from './ui'; import { html as disclaimerHtml } from '../../markdown/disclaimer.md'; +import ConnectorsModal from './ConnectorsModal'; type TProps = { type: TModalType; @@ -23,6 +24,8 @@ function Modal({ type, title, status }: TProps) { modalDispatch({ type: 'CLEAR_MODAL' }); }; switch (type) { + case 'CONNECTORS': + return ; case 'DISCLAIMER': return ( diff --git a/src/components/Modal/ui.tsx b/src/components/Modal/ui.tsx index 7147e42..dcc5068 100644 --- a/src/components/Modal/ui.tsx +++ b/src/components/Modal/ui.tsx @@ -4,7 +4,7 @@ export function Container({ children }: { children: ReactNode }) { return (
{children} {/*
@@ -15,7 +15,7 @@ export function Container({ children }: { children: ReactNode }) { export function Inner({ children }: { children: ReactNode }) { return ( -
+
{children}
); diff --git a/src/hooks/useModal.tsx b/src/hooks/useModal.tsx index 9465002..9550ec8 100644 --- a/src/hooks/useModal.tsx +++ b/src/hooks/useModal.tsx @@ -14,7 +14,8 @@ export type TModalType = | 'APPROVAL' | 'BAKING' | 'BURNING' - | 'CLAIMING'; + | 'CLAIMING' + | 'CONNECTORS'; export type TModalStatus = 'LOCKED' | 'UNLOCKED'; diff --git a/src/modules/dashboard/components/AAVE.tsx b/src/modules/dashboard/components/AAVE.tsx index 5d9d692..1ac1758 100644 --- a/src/modules/dashboard/components/AAVE.tsx +++ b/src/modules/dashboard/components/AAVE.tsx @@ -1,19 +1,26 @@ import useAAVE from '../hooks/useAAVE'; +export const yieldRateFormatter = new Intl.NumberFormat('en-US', { + minimumFractionDigits: 2, + minimumIntegerDigits: 1, + maximumFractionDigits: 2, + useGrouping: true, +}); + export default function AAVE() { const { data } = useAAVE(); return ( -
-

AAVE

- {data && ( -
-
Current Yield:
-
{data.currentYield}
-
% of Pool:
-
{data.poolPercentage}
-
- )} +
+ Current Yield + + {data && ( + +
%
+ {yieldRateFormatter.format(data.currentYield)} +
+ )} +
); } diff --git a/src/modules/dashboard/components/Arrakis.tsx b/src/modules/dashboard/components/Arrakis.tsx new file mode 100644 index 0000000..f8e3bfb --- /dev/null +++ b/src/modules/dashboard/components/Arrakis.tsx @@ -0,0 +1,13 @@ +import useArrakis from '../hooks/useArrakis'; +import { yieldFormatter } from './Yield/Yield'; + +export default function Arrakis() { + const { data } = useArrakis(); + + return ( +
+ Arrakis TVL + {data && yieldFormatter.format(parseFloat(data.tvl))} +
+ ); +} diff --git a/src/modules/dashboard/components/EconomyDisplay.tsx b/src/modules/dashboard/components/EconomyDisplay.tsx index 4e1479c..c54eac5 100644 --- a/src/modules/dashboard/components/EconomyDisplay.tsx +++ b/src/modules/dashboard/components/EconomyDisplay.tsx @@ -2,6 +2,8 @@ import clsx from 'clsx'; import { WRAPPER_CLASSES } from '../../../util'; import useBread from '../hooks/useBread'; +import AAVE from './AAVE'; +import Arrakis from './Arrakis'; import BreadChart from './BreadChart'; import Yield from './Yield/Yield'; @@ -20,7 +22,8 @@ export default function EconomyDisplay() { {data && }
- {/* */} + +
); diff --git a/src/modules/dashboard/components/Yield/ClaimYield.tsx b/src/modules/dashboard/components/Yield/ClaimYield.tsx index 64ded90..c0524c5 100644 --- a/src/modules/dashboard/components/Yield/ClaimYield.tsx +++ b/src/modules/dashboard/components/Yield/ClaimYield.tsx @@ -4,7 +4,7 @@ import { useContractWrite } from 'wagmi'; import BREADABI from '../../../../BreadPolygon.json'; import Button from '../../../../components/Button'; -import ConnectWalletButton from '../../../../components/ConnectWalletButton'; +import ConnectWallet from '../../../../components/ConnectWallet'; import { ChainConfiguration } from '../../../../config'; import { useConnectedUser } from '../../../../hooks/useConnectedUser'; import { useModal } from '../../../../hooks/useModal'; @@ -93,7 +93,7 @@ export default function ClaimYield({ amount }: IProps) { ) : ( <> connect wallet to claim - + )} diff --git a/src/modules/dashboard/hooks/useArrakis.ts b/src/modules/dashboard/hooks/useArrakis.ts index 0fc171d..45e9fdc 100644 --- a/src/modules/dashboard/hooks/useArrakis.ts +++ b/src/modules/dashboard/hooks/useArrakis.ts @@ -1,60 +1,19 @@ -import { ApolloClient, InMemoryCache, gql, useQuery } from '@apollo/client'; -import { useMemo } from 'react'; -import { formatUnits } from 'viem'; - -const SUBGRAPH_URL = - 'https://api.thegraph.com/subgraphs/name/messari/arrakis-finance-polygon'; - -const arrakisClient = new ApolloClient({ - uri: SUBGRAPH_URL, - cache: new InMemoryCache(), -}); - -const ARRAKIS_QUERY = gql` - query vault { - vault(id: "0x3055c602454dde1bda3e98b1bcfd2ed68ab9789e") { - name - totalValueLockedUSD - _token0 { - name - } - _token0Amount - _token1 { - name - } - _token1Amount - } - } -`; +import { useEffect, useState } from 'react'; export default function useArrakis() { - const { data: apolloData, loading } = useQuery(ARRAKIS_QUERY, { - client: arrakisClient, - }); - - const data = useMemo(() => { - if (!apolloData) return null; - const { - vault: { - name, - totalValueLockedUSD, - _token0: { name: token0Name }, - _token0Amount, - _token1: { name: token1Name }, - _token1Amount, - }, - } = apolloData; + const [data, setData] = useState<{ tvl: string } | null>(null); - return { - vaultName: name, - totalValueLockedUSD, - token0: { name: token0Name, amount: formatUnits(_token0Amount, 18) }, - token1: { name: token1Name, amount: formatUnits(_token1Amount, 18) }, - }; - }, [apolloData]); + useEffect(() => { + fetch('https://indexer.api.arrakis.finance/api/vault?version=V1&name=bread') + .then((res) => res.json()) + .then((jsonData) => { + setData({ + tvl: jsonData.vaults[0].tvl, + }); + }); + }, []); return { data, - loading, }; } diff --git a/src/routes/bake.tsx b/src/routes/bake.tsx index 681f87d..25033f8 100644 --- a/src/routes/bake.tsx +++ b/src/routes/bake.tsx @@ -1,9 +1,9 @@ import { Suspense, lazy } from 'react'; import { useAccount, useNetwork } from 'wagmi'; -import ConnectWalletButton from '../components/ConnectWalletButton'; import BakeLayout from '../components/BakeLayout'; +import ConnectWallet from '../components/ConnectWallet'; import UnsupportedNetwork from '../components/UnsupportedNetwork/UnsupportedNetwork'; import config from '../config'; @@ -25,7 +25,7 @@ export function Bake() { if (!activeConnector || !activeChain || !accountAddress || !isConnected) { return ( - + ); }