Skip to content

Commit

Permalink
Merge pull request #338 from rulfo71/feature/330-Scheme-selection-con…
Browse files Browse the repository at this point in the history
…fig-clean-up

Feature 330 / Scheme selection config clean up
  • Loading branch information
rulfo71 authored Mar 31, 2023
2 parents 3ec4933 + 5528693 commit 5dacb54
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 33 deletions.
7 changes: 4 additions & 3 deletions apps/davi/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"consensusSystem": "Consensus System",
"proposalDuration": "Proposal Duration",
"quorum": "Quorum",
"boostedQuoroum": "Boosted Quorum",
"backToOverview": "Back to Overview",
"backToDiscussion": "Back to Discussion",
"originalDiscussion": "Original Discussion",
Expand Down Expand Up @@ -406,14 +407,14 @@
"proposalTimeInBoost": "Proposal time in boost",
"proposalTimeInPreBoost": "Proposal time in pre boost",
"canManageSchemes": "Can manage schemes",
"canControlMainTreasury": "Can control main treasury",
"canChangeReputation": "Can change reputation",
"canMakeAvatarCalls": "Can make avatar calls",
"maxRepPercentageChange": "Maximum rep percentage change",
"backToScheme": "Back to Scheme",
"type": "Type",
"next": "Next",
"errorFetchingSchemes": "Error while fetching schemes",
"daoHasNoSchemes": "This DAO has no schemes registered"
"daoHasNoSchemes": "This DAO has no schemes registered",
"daoBounty": "DAO Bounty"
},
"inputValidation": {
"recipientAddressIsRequired": "Recipient address is required",
Expand Down
21 changes: 20 additions & 1 deletion apps/davi/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
"information": "Información",
"consensusSystem": "Sistema de Consenso",
"proposalDuration": "Duración de la Propuesta",
"quorum": "Cuórum",
"quorum": "Quórum",
"boostedQuoroum": "Quórum impulsado",
"backToOverview": "Regresar a la Vista General",
"backToDiscussion": "Regresar a la Discusión",
"originalDiscussion": "Discusión Original",
Expand Down Expand Up @@ -395,6 +396,24 @@
"reload": "Recargar"
}
},
"schemes": {
"schemes_one": "Esquema",
"schemes_other": "Esquemas",
"schemeParameters": "Parámetros del Esquema",
"schemeForProposal": "Esquema para la propuesta",
"maxProposalTime": "Tiempo máximo de propuesta",
"proposalTimeInBoost": "Tiempo de propuesta impulsada",
"proposalTimeInPreBoost": "Tiempo de propuesta en pre-impulso",
"canManageSchemes": "Puede gestionar esquemas",
"canMakeAvatarCalls": "Puede hacer llamadas al avatar",
"maxRepPercentageChange": "Máximo porcentaje de cambio de REP",
"backToScheme": "Volver al Esquema",
"type": "Tipo",
"next": "Siguiente",
"errorFetchingSchemes": "Error buscando los esquemas",
"daoHasNoSchemes": "Esta DAO no tiene esquemas registrados",
"daoBounty": "Recompensa de la DAO"
},
"inputValidation": {
"recipientAddressIsRequired": "La dirección del destinatario es requerida",
"amountIsRequired": "La cantidad es requerida",
Expand Down
57 changes: 35 additions & 22 deletions apps/davi/src/Modules/Guilds/pages/SchemeSelection/SchemeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,59 @@ import {
InfoDetailMuted,
} from 'components/ProposalInfoCard/ProposalInfoCard.styled';
import { CardBody, SchemePropertiesGrid } from './SchemeSelection.styled';
import useTimeDifferenceHumanized from 'hooks/Guilds/time/useTimeDifferenceHumanized';

type Scheme = getSchemesQuery['dao']['schemes'][0];

const humanizedTime = (time: string) => {
const timeInSeconds = Number.parseInt(time);
return moment.duration(timeInSeconds, 'seconds').humanize({ ss: 1 });
};

export const SchemeInfo = ({ selectedScheme }: { selectedScheme: Scheme }) => {
const { t } = useTranslation();

const formattedQueuedVoteRequiredPercentage = BigNumber.from(
selectedScheme.votingMachine.queuedVoteRequiredPercentage
)
.div(100)
.toString();

const formattedBoostedVoteRequiredPercentage = BigNumber.from(
selectedScheme.votingMachine.boostedVoteRequiredPercentage
)
.div(100)
.toString();

const formattedQuietEndingPeriod = humanizedTime(
selectedScheme.votingMachine.quietEndingPeriod
const formattedQuietEndingPeriod = useTimeDifferenceHumanized(
moment().add(selectedScheme.votingMachine.quietEndingPeriod, 'seconds')
);

const formattedBoostedVotePeriodLimit = humanizedTime(
selectedScheme.votingMachine.boostedVotePeriodLimit
const formattedBoostedVotePeriodLimit = useTimeDifferenceHumanized(
moment().add(selectedScheme.votingMachine.boostedVotePeriodLimit, 'seconds')
);

const formattedPreBoostedVotePeriodLimit = humanizedTime(
selectedScheme.votingMachine.preBoostedVotePeriodLimit
const formattedPreBoostedVotePeriodLimit = useTimeDifferenceHumanized(
moment().add(
selectedScheme.votingMachine.preBoostedVotePeriodLimit,
'seconds'
)
);

return (
<CardBody>
<SchemePropertiesGrid>
<InfoDetail>
<span>{t('schemes.type')}</span>
<InfoDetailMuted>{selectedScheme.type}</InfoDetailMuted>
</InfoDetail>

<InfoDetail>
<span>{t('proposal.quorum')}</span>
<InfoDetailMuted>
{formattedBoostedVoteRequiredPercentage}%
{formattedQueuedVoteRequiredPercentage}%
</InfoDetailMuted>
</InfoDetail>

<InfoDetail>
<span>{t('schemes.canManageSchemes')}</span>
<span>{t('proposal.boostedQuoroum')}</span>
<InfoDetailMuted>
{selectedScheme.canManageSchemes ? 'yes' : 'no'}
{formattedBoostedVoteRequiredPercentage}%
</InfoDetailMuted>
</InfoDetail>

Expand All @@ -58,9 +69,9 @@ export const SchemeInfo = ({ selectedScheme }: { selectedScheme: Scheme }) => {
</InfoDetail>

<InfoDetail>
<span>{t('schemes.canControlMainTreasury')}</span>
<span>{t('schemes.proposalTimeInPreBoost')}</span>
<InfoDetailMuted>
{selectedScheme.canMakeAvatarCalls ? 'yes' : 'no'}
{formattedPreBoostedVotePeriodLimit}
</InfoDetailMuted>
</InfoDetail>

Expand All @@ -70,16 +81,16 @@ export const SchemeInfo = ({ selectedScheme }: { selectedScheme: Scheme }) => {
</InfoDetail>

<InfoDetail>
<span>{t('schemes.canChangeReputation')}</span>
<span>{t('schemes.canMakeAvatarCalls')}</span>
<InfoDetailMuted>
{selectedScheme.canChangeReputation ? 'yes' : 'no'}
{selectedScheme.canMakeAvatarCalls ? 'yes' : 'no'}
</InfoDetailMuted>
</InfoDetail>

<InfoDetail>
<span>{t('schemes.proposalTimeInPreBoost')}</span>
<span>{t('schemes.canManageSchemes')}</span>
<InfoDetailMuted>
{formattedPreBoostedVotePeriodLimit}
{selectedScheme.canManageSchemes ? 'yes' : 'no'}
</InfoDetailMuted>
</InfoDetail>

Expand All @@ -91,8 +102,10 @@ export const SchemeInfo = ({ selectedScheme }: { selectedScheme: Scheme }) => {
</InfoDetail>

<InfoDetail>
<span>{t('schemes.type')}</span>
<InfoDetailMuted>{selectedScheme.type}</InfoDetailMuted>
<span>{t('schemes.daoBounty')}</span>
<InfoDetailMuted>
{selectedScheme.votingMachine.daoBounty}
</InfoDetailMuted>
</InfoDetail>
</SchemePropertiesGrid>
</CardBody>
Expand Down
12 changes: 5 additions & 7 deletions apps/davi/src/hooks/Guilds/time/useTimeDifferenceHumanized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
const MONTH_IN_MILLIS = 1000 * 60 * 60 * 24 * 30;
const HOUR_IN_MILLIS = 1000 * 60 * 60;
const MINS_IN_MILLIS = 1000 * 60;
const SECONDS_IN_MILLIS = 1000;

/**
* Translates from and to time difference into human readable date format
Expand Down Expand Up @@ -59,10 +60,11 @@ const useTimeDifferenceHumanized = (
},
{
value: Math.floor(
((((timeDifferenceInMilliSecs % YEAR_IN_MILLIS) % MONTH_IN_MILLIS) %
(((((timeDifferenceInMilliSecs % YEAR_IN_MILLIS) % MONTH_IN_MILLIS) %
DAY_IN_MILLIS) %
HOUR_IN_MILLIS) %
MINS_IN_MILLIS
MINS_IN_MILLIS) /
SECONDS_IN_MILLIS
),
name: t('duration.seconds_other'),
},
Expand All @@ -72,11 +74,7 @@ const useTimeDifferenceHumanized = (

return levels
.reduce((acc, level) => {
if (
level.value === 0 ||
level.name === t('duration.seconds_other') ||
measurementDepth === 0
) {
if (level.value === 0 || measurementDepth === 0) {
return acc;
}
measurementDepth--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ export const useGetSubDAOs: IUseGetSubDAOs = daoId => {
votingMachine: {
boostedVoteRequiredPercentage:
scheme.votingMachine.boostedVoteRequiredPercentage,
queuedVoteRequiredPercentage:
scheme.votingMachine.queuedVoteRequiredPercentage,
preBoostedVotePeriodLimit:
scheme.votingMachine.preBoostedVotePeriodLimit,
boostedVotePeriodLimit: scheme.votingMachine.boostedVotePeriodLimit,
quietEndingPeriod: scheme.votingMachine.quietEndingPeriod,
daoBounty: scheme.votingMachine.boostedVoteRequiredPercentage,
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ query getSchemes($id: ID!) {
paramsHash
permissionRegistry
stakingTokenBalance

# capabilities
canChangeReputation
canMakeAvatarCalls
Expand All @@ -25,6 +26,8 @@ query getSchemes($id: ID!) {
preBoostedVotePeriodLimit
boostedVotePeriodLimit
quietEndingPeriod
daoBounty
queuedVoteRequiredPercentage
}
}
}
Expand Down

1 comment on commit 5dacb54

@vercel
Copy link

@vercel vercel bot commented on 5dacb54 Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.