Skip to content

Commit

Permalink
Use actual token count for freeze threshold default on erc20 safe
Browse files Browse the repository at this point in the history
  • Loading branch information
DarksightKellar committed Sep 20, 2024
1 parent 30ec7c5 commit 8e3338f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions src/components/DaoCreator/formComponents/GuardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useEffect, useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useFractal } from '../../../providers/App/AppProvider';
import { ICreationStepProps, GovernanceType, BigIntValuePair } from '../../../types';
import { formatBigIntDisplay } from '../../../utils/numberFormats';
import { formatBigIntToHumanReadableString } from '../../../utils/numberFormats';
import ContentBoxTitle from '../../ui/containers/ContentBox/ContentBoxTitle';
import { BigIntInput } from '../../ui/forms/BigIntInput';
import { CustomNonceInput } from '../../ui/forms/CustomNonceInput';
Expand Down Expand Up @@ -47,19 +47,32 @@ function GuardDetails(props: ICreationStepProps) {
const { totalParentVotingWeight, parentVotingQuorum } = useParentSafeVotingWeight();

useEffect(() => {
if (parentVotingQuorum) {
const bigIntValueStr = formatBigIntDisplay(parentVotingQuorum);
setFieldValue('freeze.freezeVotesThreshold', {
if (!parentVotingQuorum || !totalParentVotingWeight) {
return;
}

let initialVotesThresholdBigIntValuePair: BigIntValuePair;

if (governance.type === GovernanceType.AZORIUS_ERC20) {
const actualTokenQuorum = (parentVotingQuorum * totalParentVotingWeight) / 100n;
initialVotesThresholdBigIntValuePair = {
bigintValue: actualTokenQuorum,
value: actualTokenQuorum.toString(),
};
} else {
initialVotesThresholdBigIntValuePair = {
bigintValue: parentVotingQuorum,
value: bigIntValueStr,
});
value: parentVotingQuorum.toString(),
};
}
}, [parentVotingQuorum, setFieldValue]);

setFieldValue('freeze.freezeVotesThreshold', initialVotesThresholdBigIntValuePair);
}, [governance.type, parentVotingQuorum, setFieldValue, totalParentVotingWeight]);

useStepRedirect({ values });

const freezeHelper = totalParentVotingWeight
? t('helperFreezeVotesThreshold', { totalVotes: formatBigIntDisplay(totalParentVotingWeight) })
? t('helperFreezeVotesThreshold', { totalVotes: formatBigIntToHumanReadableString(totalParentVotingWeight) })
: null;

return (
Expand Down
2 changes: 1 addition & 1 deletion src/utils/numberFormats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ function getNumberSeparator(type: 'group' | 'decimal'): string {
);
}

export function formatBigIntDisplay(num: bigint | string | number): string {
export function formatBigIntToHumanReadableString(num: bigint | string | number): string {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, getNumberSeparator('group'));
}

0 comments on commit 8e3338f

Please sign in to comment.