Skip to content

Commit

Permalink
Merge pull request #140 from raid-guild/133-gnosissafe-sdk-accountingv3
Browse files Browse the repository at this point in the history
needs clean up
  • Loading branch information
Seroxdesign authored May 20, 2024
2 parents eddcc4c + a630802 commit 763cab0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
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;

0 comments on commit 763cab0

Please sign in to comment.