Skip to content

Commit

Permalink
fix: one time payments logic in projects (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyesp authored Aug 25, 2023
1 parent 618a93a commit a7ea862
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/components/Projects/ProjectCard/VestingProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ const getRoundedPercentage = (value: number, total: number) => Math.min(Math.rou

const VestingProgress = ({ project, basic }: Props) => {
const t = useFormatMessage()
const { contract, enacting_tx, tx_amount, token, enacted_at } = project
const { contract, enacting_tx, token, enacted_at } = project
if (!enacted_at) return null

const total = contract?.vesting_total_amount || 100
const vestedPercentage = contract ? getRoundedPercentage(contract.vestedAmount, total) : 100
const releasedPercentage = contract ? getRoundedPercentage(contract.released, total) : null
const vestedAmountText = `${t(`general.number`, {
value: contract ? contract.vestedAmount : tx_amount || 0,
})} ${token}`
const vestedAmountText = contract
? `${t(`general.number`, {
value: contract.vestedAmount || 0,
})} ${token}`
: null
const releasedText = contract
? `${t(`general.number`, { value: contract.released })} ${token} ${t('page.grants.released')}`
: t('page.grants.one_time_payment')
Expand All @@ -38,7 +40,9 @@ const VestingProgress = ({ project, basic }: Props) => {
{!basic && (
<div className="VestingProgress__Labels">
<div className="VestingProgress__VestedInfo">
<span className="VestingProgress__Bold VestingProgress__Ellipsis">{vestedAmountText}</span>
{vestedAmountText && (
<span className="VestingProgress__Bold VestingProgress__Ellipsis">{vestedAmountText}</span>
)}
<span className="VestingProgress__Ellipsis">
{enacting_tx ? t('page.grants.transferred') : t('page.grants.vested')}
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/intl/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@
"button": "View all Projects"
},
"vested": "vested",
"transferred": "transferred",
"transferred": "Transferred",
"one_time_payment": "One-time payment",
"one_month_cliff": "1-month Cliff Period",
"cliff_remaining": "{count} {count, plural, one {day} other {days}} to go",
Expand Down
16 changes: 12 additions & 4 deletions src/services/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { ProposalInCreation } from './ProposalService'
export class ProjectService {
public static async getProjects() {
const data = await ProposalModel.getProjectList()

const vestings = await DclData.get().getVestings()
const projects: ProjectWithUpdate[] = []

Expand All @@ -58,7 +57,8 @@ export class ProjectService {
category: proposal.configuration.category || proposal.type,
tier: proposal.configuration.tier,
},
...this.getProjectVestingData(latestVesting),

...this.getProjectVestingData(proposal, latestVesting),
}

try {
Expand All @@ -85,7 +85,15 @@ export class ProjectService {
}
}

private static getProjectVestingData(vesting: TransparencyVesting) {
private static getProjectVestingData(proposal: ProposalAttributes, vesting: TransparencyVesting) {
if (proposal.enacting_tx) {
return {
status: ProjectStatus.Finished,
enacting_tx: proposal.enacting_tx,
enacted_at: Time(proposal.updated_at).unix(),
}
}

if (!vesting) {
return {
status: ProjectStatus.Pending,
Expand All @@ -104,7 +112,7 @@ export class ProjectService {

return {
status: vesting_status,
token: token,
token,
enacted_at: Time(vesting_start_at).unix(),
contract: {
vesting_total_amount: Math.round(vesting_total_amount),
Expand Down

0 comments on commit a7ea862

Please sign in to comment.