diff --git a/libs/moloch-v3-data/src/vaults.ts b/libs/moloch-v3-data/src/vaults.ts index bcbb6cb6..c2145dc5 100644 --- a/libs/moloch-v3-data/src/vaults.ts +++ b/libs/moloch-v3-data/src/vaults.ts @@ -25,7 +25,7 @@ export const listTokenBalances = async ({ try { const res = await fetch.get( - `${url}/safes/${getAddress(safeAddress)}/balances/` + `${url}/safes/${getAddress(safeAddress)}/balances/?exclude_spam=true` ); return { data: transformTokenBalances(res, safeAddress) }; diff --git a/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeBalancesTable.tsx b/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeBalancesTable.tsx new file mode 100644 index 00000000..245de312 --- /dev/null +++ b/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeBalancesTable.tsx @@ -0,0 +1,71 @@ +import { useMemo } from 'react'; +import { Column, Row } from 'react-table'; + +import { DaoTable } from '../DaohausTable'; +import { Avatar } from '@daohaus/ui'; +import { SafeToken } from './SafeCard.styles'; + +type TokenBalanceType = { + tokenLogo?: string | null; + tokenName: string; + tokenSymbol: string; + balance: number; +}; + +type SafeBalancesTableProps = { + balances: Array; +}; + +export const SafeBalancesTable = ({ balances }: SafeBalancesTableProps) => { + const columns = useMemo[]>( + () => [ + { + Header: 'Asset', + accessor: 'tokenName', + Cell: ({ + value, + row, + }: { + value: string; + row: Row; + }) => { + return ( + +
+ +
+ {value} +
+ ); + }, + }, + { + Header: 'Balance', + accessor: 'balance', + Cell: ({ + value, + row, + }: { + value: number; + row: Row; + }) => { + return
{`${value} ${row.original.tokenSymbol}`}
; + }, + }, + ], + [balances] + ); + + return ( + + tableData={balances} + columns={columns} + sortableColumns={[]} + /> + ); +}; diff --git a/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.styles.ts b/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.styles.ts index b128fff3..807b5b79 100644 --- a/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.styles.ts +++ b/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.styles.ts @@ -69,3 +69,9 @@ export const SafeActionMenuLink = styled(RouterLink)` ${DropdownLinkStyles} font-weight: ${font.weight.bold}; `; + +export const SafeToken = styled.div` + display: flex; + align-items: center; + gap: 1rem; +`; diff --git a/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.tsx b/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.tsx index 97d1b964..cf2dd61e 100644 --- a/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.tsx +++ b/libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.tsx @@ -1,25 +1,29 @@ -import React, { useMemo } from 'react'; +import { useMemo } from 'react'; +import { Keychain, getNetwork } from '@daohaus/keychain-utils'; import { DaoSafe, MolochV3Dao } from '@daohaus/moloch-v3-data'; import { AddressDisplay, + Avatar, Bold, + CollapsibleCard, DataIndicator, H4, Link, ParXs, Tag, } from '@daohaus/ui'; -import { generateGnosisUiLink } from '@daohaus/utils'; -import { Keychain } from '@daohaus/keychain-utils'; +import { generateGnosisUiLink, toWholeUnits, truncValue } from '@daohaus/utils'; + import { DataGrid } from '../Layout'; +import { SafeActionMenu } from './SafeActionMenu'; +import { SafeBalancesTable } from './SafeBalancesTable'; import { SafeCardHeader, SafeContainer, SafeOverviewCard, TagSection, } from './SafeCard.styles'; -import { SafeActionMenu } from './SafeActionMenu'; type SafeCardProps = { dao: MolochV3Dao; @@ -38,6 +42,26 @@ export const SafeCard = ({ return safe.safeAddress === dao.safeAddress; }, [safe, dao]); + const nativeTokenSymbol = useMemo(() => { + const network = getNetwork(daoChain); + return network?.symbol || 'UNK'; + }, [daoChain]); + + const tokenBalances = useMemo(() => { + const network = getNetwork(daoChain); + return safe.tokenBalances.map((t) => { + return { + tokenLogo: t.token?.logoUri, + tokenName: t.token?.name || nativeTokenSymbol, + tokenSymbol: t.token?.symbol || nativeTokenSymbol, + balance: truncValue( + toWholeUnits(t.balance, t.token?.decimals || network?.tokenDecimals), + 4 + ), + }; + }); + }, [safe]); + return ( @@ -80,6 +104,24 @@ export const SafeCard = ({ + {safe.tokenBalances.length > 0 && ( + } + > +
+ {safe.tokenBalances.map((token) => ( + + ))} +
+
+ )}
);