Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: total spent #52

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/components/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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'
Expand Down Expand Up @@ -46,10 +44,6 @@ const Stats = () => {
return <StatsShimmer />;
}

const getTotalSpentInUsd = () => {
return totalSpent ? weiToEth(totalSpent.toString()) * maticMarketPrice : 0;
};

return (
<div className="grid gap-4 lg:grid-cols-4">
<div className="flex flex-col items-center space-y-0.5 rounded-[20px] bg-[#FFFFFF] p-6 dark:bg-[#2C2B35]">
Expand All @@ -64,8 +58,8 @@ const Stats = () => {
<div className="space-x-2 truncate font-gintoNord">
{totalSpent && topSubmitter ? (
<span className="truncate text-2xl font-medium">
$ {getTotalSpentInUsd().toFixed(2)} {' | '}${' '}
{(getTotalSpentInUsd() / topSubmitter.totalTransactions).toFixed(4)}{' '}
$ {Number(totalSpent).toFixed(2)} {' | '}${' '}
{(Number(totalSpent) / topSubmitter.totalTransactions).toFixed(4)}{' '}
<span className="text-xs">/txn</span>
</span>
) : fetchingSpentAmount ? (
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSubmitterSpent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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
}, []);
Expand Down
6 changes: 1 addition & 5 deletions src/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<State>((set) => ({
Expand All @@ -24,9 +22,7 @@ export const useAppStore = create<State>((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 {
Expand Down
12 changes: 0 additions & 12 deletions src/utils/weiToEth.ts

This file was deleted.