fix(governance): tranches data (#3708)

This commit is contained in:
Sam Keen 2023-05-11 11:22:52 +01:00 committed by GitHub
parent b4c7dc6f59
commit a8c17b6807
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 18 deletions

View File

@ -50,7 +50,22 @@ export const useTranches = create<TranchesStore>()((set) => ({
?.map((t) => {
const tranche_progress =
t.duration !== 0 ? (now - t.cliff_start) / t.duration : 0;
const lockedDecimal = tranche_progress < 0 ? 1 : 1 - tranche_progress;
let lockedDecimal;
if (t.duration !== 0) {
if (tranche_progress < 0) {
lockedDecimal = 1;
} else {
lockedDecimal = 1 - tranche_progress;
}
} else {
if (now < t.cliff_start) {
lockedDecimal = 1;
} else {
lockedDecimal = 0;
}
}
const clampedLockedDecimal = Math.max(0, Math.min(1, lockedDecimal));
return {
tranche_id: t.tranche_id,
tranche_start: secondsToDate(t.cliff_start),
@ -60,7 +75,7 @@ export const useTranches = create<TranchesStore>()((set) => ({
toBigNum(t.current_balance, decimals)
),
locked_amount: toBigNum(t.initial_balance, decimals).times(
lockedDecimal
clampedLockedDecimal
),
users: t.users,
};

View File

@ -54,22 +54,16 @@ export const TrancheItem = ({
{formatNumber(total, 2)}
</span>
</div>
<table className="w-full">
<tbody>
<tr>
<td>{t('Starts unlocking')}</td>
<td className="text-right">
{format(tranche.tranche_start, DATE_FORMAT_LONG)}
</td>
</tr>
<tr>
<td>{t('Fully unlocked')}</td>
<td className="text-right">
{format(tranche.tranche_end, DATE_FORMAT_LONG)}
</td>
</tr>
</tbody>
</table>
<div className="grid grid-cols-2 my-2">
<div>
<span>{t('Starts unlocking')}:</span>{' '}
<span>{format(tranche.tranche_start, DATE_FORMAT_LONG)}</span>
</div>
<div className="justify-self-end">
<span>{t('Fully unlocked')}:</span>{' '}
<span>{format(tranche.tranche_end, DATE_FORMAT_LONG)}</span>
</div>
</div>
<LockedProgress
locked={locked}
unlocked={unlocked}