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

needs clean up #140

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
3 changes: 3 additions & 0 deletions apps/frontend/pages/accounting.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable simple-import-sort/imports */
import {
Button,
Flex,
Expand All @@ -9,6 +10,7 @@ import {
Tabs,
} from '@raidguild/design-system';
import {
useAccountingV3,
useAccountingV2,
useFormattedData,
useMemberList,
Expand All @@ -35,6 +37,7 @@ export const Accounting = () => {
} = useAccountingV2({
token,
});
const { data: dataFromMolochV3 } = useAccountingV3();
const { data: memberData } = useMemberList({
token,
limit: 1000,
Expand Down
43 changes: 40 additions & 3 deletions libs/dm-hooks/src/useAccountingV3.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { getAddress } from 'viem';

const API_URL = 'https://safe-transaction-gnosis-chain.safe.global/api/v1';

const transformTokenBalances = (tokenBalanceRes, safeAddress: string) => {
const fiatTotal = tokenBalanceRes.reduce(
(sum: number, balance) => sum + Number(balance.fiatBalance),
0
);
return { safeAddress, tokenBalances: tokenBalanceRes, fiatTotal };
};

const listTokenBalances = async (safeAddress: string) => {
try {
const res = await fetch(`${API_URL}/safes/${safeAddress}/balances/usd/`);
const data = await res.json();
return { data: transformTokenBalances(data, safeAddress) };
} catch (err) {
return { error: 'Error fetching token balances. Please try again.' };
}
};

// this is a dummy hook
const useAccountingV3 = () => {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

return { data: null, loading: false, error: null };
useEffect(() => {
const fetchData = async () => {
const checksum = getAddress('0x181ebdb03cb4b54f4020622f1b0eacd67a8c63ac');
const response = await listTokenBalances(checksum);

if (response.error) {
setError(response.error);
} else {
setData(response.data);
}

setLoading(false);
};

fetchData();
}, []);

return { data, loading, error };
};

export default useAccountingV3;