diff --git a/apps/frontend/pages/accounting.tsx b/apps/frontend/pages/accounting.tsx index 3fadd1db..70b69996 100644 --- a/apps/frontend/pages/accounting.tsx +++ b/apps/frontend/pages/accounting.tsx @@ -1,3 +1,4 @@ +/* eslint-disable simple-import-sort/imports */ import { Button, Flex, @@ -9,6 +10,7 @@ import { Tabs, } from '@raidguild/design-system'; import { + useAccountingV3, useAccountingV2, useFormattedData, useMemberList, @@ -35,6 +37,7 @@ export const Accounting = () => { } = useAccountingV2({ token, }); + const { data: dataFromMolochV3 } = useAccountingV3(); const { data: memberData } = useMemberList({ token, limit: 1000, diff --git a/libs/dm-hooks/src/useAccountingV3.ts b/libs/dm-hooks/src/useAccountingV3.ts index ff5f2d2d..9a2dd52b 100644 --- a/libs/dm-hooks/src/useAccountingV3.ts +++ b/libs/dm-hooks/src/useAccountingV3.ts @@ -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;