From 64c108453af72ba8289487e76e79c6956442c5ab Mon Sep 17 00:00:00 2001 From: Sasi Date: Tue, 21 Nov 2023 15:46:16 +0530 Subject: [PATCH] fix: total spent (#52) --- src/components/Stats.tsx | 10 ++-------- src/constants.ts | 2 +- src/hooks/useSubmitterSpent.ts | 4 ++-- src/pages/_app.tsx | 9 --------- src/store/app.ts | 6 +----- src/utils/weiToEth.ts | 12 ------------ 6 files changed, 6 insertions(+), 37 deletions(-) delete mode 100644 src/utils/weiToEth.ts diff --git a/src/components/Stats.tsx b/src/components/Stats.tsx index 3cecec5..e4e2261 100644 --- a/src/components/Stats.tsx +++ b/src/components/Stats.tsx @@ -7,7 +7,6 @@ import { useAppStore } from '@/store/app'; import formatNumber from '@/utils/formatNumber'; import { getRelativeTime } from '@/utils/formatTime'; import sanitizeDStorageUrl from '@/utils/sanitizeDStorageUrl'; -import weiToEth from '@/utils/weiToEth'; import StatsShimmer from './shimmers/StatsShimmer'; @@ -18,7 +17,6 @@ const Stats = () => { const setTopSubmitter = useAppStore((state) => state.setTopSubmitter); const topSubmitter = useAppStore((state) => state.topSubmitter); const totalSpent = useAppStore((state) => state.totalSpent); - const maticMarketPrice = useAppStore((state) => state.maticMarketPrice); const [fetchTopSubmitter, { loading: submittersDataLoading }] = useMomokaSubmittersLazyQuery({ fetchPolicy: 'no-cache' @@ -46,10 +44,6 @@ const Stats = () => { return ; } - const getTotalSpentInUsd = () => { - return totalSpent ? weiToEth(totalSpent.toString()) * maticMarketPrice : 0; - }; - return (
@@ -64,8 +58,8 @@ const Stats = () => {
{totalSpent && topSubmitter ? ( - $ {getTotalSpentInUsd().toFixed(2)} {' | '}${' '} - {(getTotalSpentInUsd() / topSubmitter.totalTransactions).toFixed(4)}{' '} + $ {Number(totalSpent).toFixed(2)} {' | '}${' '} + {(Number(totalSpent) / topSubmitter.totalTransactions).toFixed(4)}{' '} /txn ) : fetchingSpentAmount ? ( diff --git a/src/constants.ts b/src/constants.ts index 51ea9d2..adf4bf3 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,6 @@ export const ARWEAVE_GATEWAY_URL = 'https://arweave.net'; export const IPFS_GATEWAY_URL = 'https://gateway.ipfscdn.io/ipfs'; -export const BUNDLR_SPENT_API = 'https://node1.bundlr.network/bulk/account/spending/matic'; +export const BUNDLR_SPENT_API = 'https://node1.irys.xyz/bulk/account/spending_usd/matic'; export const WC_PROJECT_ID = '56d00bfc0436773edd053b651aec9399'; export enum HeyUrl { diff --git a/src/hooks/useSubmitterSpent.ts b/src/hooks/useSubmitterSpent.ts index ef08153..f8ab23d 100644 --- a/src/hooks/useSubmitterSpent.ts +++ b/src/hooks/useSubmitterSpent.ts @@ -13,8 +13,8 @@ const useSubmitterSpent = () => { setLoading(true); try { const response = await axios.post(BUNDLR_SPENT_API, submitters); - const { sum } = await response.data; - setTotalSpent(sum); + const { sumUSD } = await response.data; + setTotalSpent(sumUSD); } catch (error: any) { setError(error); } finally { diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index b64ceca..6527b80 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -22,8 +22,6 @@ import client from '@/apollo'; import Navbar from '@/components/Navbar'; import MetaTags from '@/components/shared/Metatags'; import { WC_PROJECT_ID } from '@/constants'; -import { useAppStore } from '@/store/app'; -import getMaticPrice from '@/utils/getMaticPrice'; const ginto = localFont({ src: [ @@ -96,15 +94,8 @@ const wagmiClient = createConfig({ export default function App({ Component, pageProps }: AppProps) { const [mounted, setMounted] = useState(false); const { theme } = useTheme(); - const setMaticMarketPrice = useAppStore((state) => state.setMaticMarketPrice); - - const fetchMaticPrice = async () => { - const price = await getMaticPrice(); - setMaticMarketPrice(price); - }; useEffect(() => { - fetchMaticPrice(); setMounted(true); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/src/store/app.ts b/src/store/app.ts index 84a486d..e9eea81 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -12,8 +12,6 @@ interface State { setTopSubmitter: (topSubmitter: MomokaSubmitterResult) => void; totalSpent: number; setTotalSpent: (totalSpent: number) => void; - maticMarketPrice: number; - setMaticMarketPrice: (maticMarketPrice: number) => void; } export const useAppStore = create((set) => ({ @@ -24,9 +22,7 @@ export const useAppStore = create((set) => ({ topSubmitter: null, setTopSubmitter: (topSubmitter: MomokaSubmitterResult) => set({ topSubmitter }), totalSpent: 0, - setTotalSpent: (totalSpent) => set({ totalSpent }), - maticMarketPrice: 0, - setMaticMarketPrice: (maticMarketPrice) => set({ maticMarketPrice }) + setTotalSpent: (totalSpent) => set({ totalSpent }) })); interface AppPersistState { diff --git a/src/utils/weiToEth.ts b/src/utils/weiToEth.ts deleted file mode 100644 index 81d4c19..0000000 --- a/src/utils/weiToEth.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { formatEther } from 'viem'; - -const weiToEth = (weiValue: string) => { - if (!weiValue) { - return 0; - } - const ethValue = formatEther(BigInt(weiValue), 'wei'); - - return Number(Number(ethValue).toFixed(2)); -}; - -export default weiToEth;