Skip to content

Commit

Permalink
Merge pull request #509 from HausDAO/develop
Browse files Browse the repository at this point in the history
Merge and deploy usd balance fix
  • Loading branch information
dekanbro authored May 21, 2024
2 parents b5e4241 + 873b10d commit d9c4115
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 119 deletions.
1 change: 0 additions & 1 deletion apps/admin/src/components/DaoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const DaoCard = ({
dao,
daoAvatarImg,
activeMemberCount,
fiatTotal,
activeProposalCount,
totalProposalCount,
votingPower,
Expand Down
14 changes: 0 additions & 14 deletions apps/admin/src/components/DaoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const DaoTable = ({ daoData }: IDaoTableData) => {
networkId: dao.networkId,
},
activeProposalCount: dao.activeProposalCount,
fiatTotal: dao.fiatTotal,
activeMemberCount: dao.activeMemberCount,
votingPower: dao.votingPower,
networkId: dao.networkId,
Expand Down Expand Up @@ -139,19 +138,6 @@ export const DaoTable = ({ daoData }: IDaoTableData) => {
);
},
},
{
Header: 'Vaults',
accessor: 'fiatTotal',
Cell: ({ value }: { value?: number }) => {
return (
<Highlight>
{value != null
? readableNumbers.toDollars({ value, separator: ' ' })
: '--'}
</Highlight>
);
},
},
{
Header: 'Members',
accessor: 'activeMemberCount',
Expand Down
5 changes: 0 additions & 5 deletions libs/moloch-v3-data/src/daos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export const findDao = async ({

return {
...vault,
fiatTotal: vaultResMatch?.data?.fiatTotal,
tokenBalances: vaultResMatch?.data?.tokenBalances,
};
});
Expand All @@ -99,10 +98,6 @@ export const findDao = async ({
...daoRes.data.dao,
...addDaoProfileFields(daoRes.data.dao),
vaults: hydratedVaults,
fiatTotal: tokenData.reduce((sum, vault) => {
sum += Number(vault.data?.fiatTotal);
return sum;
}, 0),
},
},
};
Expand Down
2 changes: 0 additions & 2 deletions libs/moloch-v3-data/src/types/dao.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ type DaoWithProfileQuery = {
dao: DaoWithProfile | undefined;
};
export type DaoSafe = DaoWithProfile['vaults'][number] & {
fiatTotal: number;
tokenBalances: TokenBalance[];
};
type MolochV3DaoQuery = {
dao: MolochV3Dao;
};
export type MolochV3Dao = Omit<DaoWithProfile, 'vaults'> & {
vaults: DaoSafe[];
fiatTotal: number;
};
export type FindDaoQueryRes =
| DaoWithProfileQuery
Expand Down
10 changes: 1 addition & 9 deletions libs/moloch-v3-data/src/utils/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ export const transformTokenBalances = (
tokenBalanceRes: TokenBalance[],
safeAddress: string
): DaoTokenBalances => {
const fiatTotal = tokenBalanceRes.reduce(
(sum: number, balance: TokenBalance): number => {
sum += Number(balance.fiatBalance);
return sum;
},
0
);

return { safeAddress, tokenBalances: tokenBalanceRes, fiatTotal };
return { safeAddress, tokenBalances: tokenBalanceRes };
};

export const transformMembershipList = (
Expand Down
3 changes: 2 additions & 1 deletion libs/moloch-v3-data/src/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const listTokenBalances = async ({
safeAddress: string;
}): Promise<IFindQueryResult<DaoTokenBalances>> => {
const url = ENDPOINTS['GNOSIS_API'][networkId];

if (!url) {
return {
error: formatFetchError({ type: 'INVALID_NETWORK_ERROR' }),
Expand All @@ -24,7 +25,7 @@ export const listTokenBalances = async ({

try {
const res = await fetch.get<TokenBalance[]>(
`${url}/safes/${getAddress(safeAddress)}/balances/usd/`
`${url}/safes/${getAddress(safeAddress)}/balances/`
);

return { data: transformTokenBalances(res, safeAddress) };
Expand Down
28 changes: 4 additions & 24 deletions libs/moloch-v3-fields/src/fields/RagequitTokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useFormContext } from 'react-hook-form';
import {
formatValueTo,
memberTokenBalanceShare,
memberUsdValueShare,
NETWORK_TOKEN_ETH_ADDRESS,
} from '@daohaus/utils';
import { getNetwork } from '@daohaus/keychain-utils';
Expand Down Expand Up @@ -48,7 +47,6 @@ const DataColumn = styled(Column)`
type TokenTable = {
tokenCheckboxes: CheckboxProps[];
amounts: React.ReactNode[];
usdValue: React.ReactNode[];
};

export const RagequitTokenList = (props: Buildable<Field>) => {
Expand Down Expand Up @@ -139,26 +137,12 @@ export const RagequitTokenList = (props: Buildable<Field>) => {
</DataSm>,
];

acc.usdValue = [
...acc.usdValue,
<DataSm key={token.tokenAddress}>
{formatValueTo({
value: memberUsdValueShare(
token.fiatBalance,
dao.totalShares || 0,
dao.totalLoot || 0,
sharesToBurn || 0,
lootToBurn || 0
),
decimals: 2,
format: 'currency',
})}
</DataSm>,
];

return acc;
},
{ tokenCheckboxes: [], amounts: [], usdValue: [] }
{
tokenCheckboxes: [],
amounts: [],
}
);
}, [
dao,
Expand Down Expand Up @@ -210,9 +194,6 @@ export const RagequitTokenList = (props: Buildable<Field>) => {
<Column>
<ParSm>Amount</ParSm>
</Column>
<Column>
<ParSm>USD Value</ParSm>
</Column>
</TokenListContainer>
<TokenListContainer>
<Column>
Expand All @@ -223,7 +204,6 @@ export const RagequitTokenList = (props: Buildable<Field>) => {
/>
</Column>
<DataColumn>{tokenTable.amounts}</DataColumn>
<DataColumn>{tokenTable.usdValue}</DataColumn>
</TokenListContainer>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ export const DaoOverview = ({
<OverviewCard>
<DaoProfile dao={dao} />
<DataGrid>
<DataIndicator
label="Total in Safes"
data={formatValueTo({
value: dao.fiatTotal,
decimals: 2,
format: 'currencyShort',
})}
/>
<DataIndicator label="Members" data={dao.activeMemberCount} />
<DataIndicator label="Proposals" data={dao.proposalCount} />
<DataIndicator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ValidNetwork } from '@daohaus/keychain-utils';
import { MolochV3Member } from '@daohaus/moloch-v3-data';
import { useDaoData, useProfile } from '@daohaus/moloch-v3-hooks';
import { DataIndicator, ParLg, Loading } from '@daohaus/ui';
import { formatValueTo, memberUsdValueShare } from '@daohaus/utils';
import { ParLg, Loading } from '@daohaus/ui';

import {
AlertContainer,
LoadingContainer,
MProfileCard,
ValueRow,
} from './MemberProfileCard.styles';
import { MemberProfile } from './MemberProfile';
import { MemberTokens } from './MemberTokens';
Expand Down Expand Up @@ -64,22 +62,6 @@ export const MemberProfileCard = ({
allowLinks={allowLinks}
allowMemberMenu={allowMemberMenu}
/>
<ValueRow>
<DataIndicator
label="Total Exit Amount"
data={formatValueTo({
value: memberUsdValueShare(
dao?.fiatTotal || 0,
dao?.totalShares || 0,
dao?.totalLoot || 0,
member?.shares || 0,
member?.loot || 0
),
decimals: 2,
format: 'currency',
})}
/>
</ValueRow>
<MemberTokens daoChain={daoChain} dao={dao} member={member} />
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
charLimit,
formatValueTo,
memberTokenBalanceShare,
memberUsdValueShare,
NETWORK_TOKEN_ETH_ADDRESS,
} from '@daohaus/utils';

Expand All @@ -21,7 +20,6 @@ type TokenTableType = {
name: string | undefined;
};
balance: string;
fiatBalance: string;
};

type MemberTokensProps = {
Expand Down Expand Up @@ -53,17 +51,6 @@ export const MemberTokens = ({ daoChain, dao, member }: MemberTokensProps) => {
address: bal.tokenAddress || NETWORK_TOKEN_ETH_ADDRESS,
name: charLimit(bal.token?.name, 21),
},
fiatBalance: formatValueTo({
value: memberUsdValueShare(
bal.fiatBalance,
dao.totalShares || 0,
dao.totalLoot || 0,
member.shares || 0,
member.loot || 0
),
decimals: 2,
format: 'currency',
}),
balance: formatValueTo({
value: memberTokenBalanceShare(
bal.balance,
Expand Down Expand Up @@ -108,15 +95,6 @@ export const MemberTokens = ({ daoChain, dao, member }: MemberTokensProps) => {
return <div>{value}</div>;
},
},
{
Header: () => {
return <div>USD Value</div>;
},
accessor: 'fiatBalance',
Cell: ({ value }: { value: string }) => {
return <div>{value}</div>;
},
},
],
[daoChain, networks]
);
Expand Down
10 changes: 1 addition & 9 deletions libs/moloch-v3-macro-ui/src/components/SafeCard/SafeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ParXs,
Tag,
} from '@daohaus/ui';
import { formatValueTo, generateGnosisUiLink } from '@daohaus/utils';
import { generateGnosisUiLink } from '@daohaus/utils';
import { Keychain } from '@daohaus/keychain-utils';
import { DataGrid } from '../Layout';
import {
Expand Down Expand Up @@ -78,14 +78,6 @@ export const SafeCard = ({
</div>
</SafeCardHeader>
<DataGrid>
<DataIndicator
label="Balance"
data={formatValueTo({
value: safe.fiatTotal,
decimals: 2,
format: 'currencyShort',
})}
/>
<DataIndicator label="Tokens" data={safe.tokenBalances.length} />
</DataGrid>
</SafeOverviewCard>
Expand Down
5 changes: 0 additions & 5 deletions libs/utils/src/types/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface MolochV3Membership {
delegatingTo?: string;
isDelegate: boolean;
memberAddress: string;
fiatTotal?: number;
totalProposalCount: string;
contractType: string;
tokenBalances?: TokenBalance[];
Expand All @@ -32,13 +31,9 @@ export type TokenBalance = {
balance: string;
ethValue: string;
timestamp: string;
fiatBalance: string;
fiatConversion: string;
fiatCode: string;
};
export type DaoTokenBalances = {
safeAddress: string;
fiatTotal: number;
tokenBalances: TokenBalance[];
};
export type AccountProfile = {
Expand Down
1 change: 1 addition & 0 deletions libs/utils/src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const memberTokenBalanceShare = (
return memberSharesWei / 10 ** Number(decimals);
};

// if we have a usd value of the Safe, we can calculate the usd value of the member's shares
export const memberUsdValueShare = (
usdValue: string | number,
daoTotalShares: string | number,
Expand Down

0 comments on commit d9c4115

Please sign in to comment.