-
Notifications
You must be signed in to change notification settings - Fork 44
[Human app] Add proposals endpoint and update frontend #3509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c730fe
Add governance module with active proposals functionality
flopez7 f5de50c
Require auth for getting active proposals
flopez7 c7633ec
remove unused import from governance controller
flopez7 6499c31
update governance proposal handling and API integration
flopez7 5ad605c
improve proposal handling and update timestamps to milliseconds
flopez7 d3f627c
remove unused governance cache constants
flopez7 0c483db
remove unused CACHE_TTL_GOVERNANCE_SNAPSHOT constant
flopez7 9b145d5
enhance proposal handling and countdown formatting
flopez7 ade18bc
refactor governance proposal handling and remove unused cache utility
flopez7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
.../apps/human-app/frontend/src/modules/governance-banner/hooks/use-active-proposal-query.ts
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
packages/apps/human-app/frontend/src/modules/governance-banner/hooks/use-proposal-query.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { fetchProposal } from '../services/governance.service'; | ||
|
|
||
| export function useProposalQuery() { | ||
| return useQuery({ | ||
| queryKey: ['governanceProposal'], | ||
| queryFn: fetchProposal, | ||
| }); | ||
| } |
34 changes: 34 additions & 0 deletions
34
...ages/apps/human-app/frontend/src/modules/governance-banner/services/governance.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { authorizedHumanAppApiClient } from '@/api'; | ||
|
|
||
| const apiPaths = { | ||
| getProposals: '/governance/proposals', | ||
| }; | ||
|
|
||
| export interface ProposalResponse { | ||
| proposalId: string; | ||
| forVotes: number; | ||
| againstVotes: number; | ||
| abstainVotes: number; | ||
| voteStart: number; | ||
| voteEnd: number; | ||
| } | ||
|
|
||
| export async function fetchProposal(): Promise<ProposalResponse | null> { | ||
| const list = await authorizedHumanAppApiClient.get<ProposalResponse[]>( | ||
| apiPaths.getProposals | ||
| ); | ||
| if (!Array.isArray(list) || list.length === 0) return null; | ||
|
|
||
| const now = Date.now(); | ||
| const activeProposals = list.filter( | ||
| (p) => p.voteStart <= now && now < p.voteEnd | ||
| ); | ||
| if (activeProposals.length > 0) | ||
| return activeProposals.sort((a, b) => a.voteEnd - b.voteEnd)[0]; | ||
|
|
||
| const pendingProposals = list.filter((p) => now < p.voteStart); | ||
| if (pendingProposals.length > 0) | ||
| return pendingProposals.sort((a, b) => a.voteStart - b.voteStart)[0]; | ||
|
|
||
| return null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export function formatCountdown(targetMs: number): string { | ||
| const now = Date.now(); | ||
| const diffMs = targetMs - now; | ||
| if (diffMs <= 0) return '00:00:00'; | ||
| const totalSeconds = Math.floor(diffMs / 1000); | ||
| const hours = Math.floor(totalSeconds / 3600); | ||
| const minutes = Math.floor((totalSeconds % 3600) / 60); | ||
| const seconds = totalSeconds % 60; | ||
| const hh = String(hours).padStart(2, '0'); | ||
| const mm = String(minutes).padStart(2, '0'); | ||
| const ss = String(seconds).padStart(2, '0'); | ||
| return `${hh}:${mm}:${ss}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/apps/human-app/server/src/common/enums/proposal.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export enum ProposalState { | ||
| PENDING, | ||
| ACTIVE, | ||
| CANCELED, | ||
| DEFEATED, | ||
| SUCCEEDED, | ||
| QUEUED, | ||
| EXPIRED, | ||
| EXECUTED, | ||
| } |
25 changes: 25 additions & 0 deletions
25
packages/apps/human-app/server/src/modules/governance/governance.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Controller, Get, HttpCode, Header } from '@nestjs/common'; | ||
| import { | ||
| ApiBearerAuth, | ||
| ApiOkResponse, | ||
| ApiOperation, | ||
| ApiTags, | ||
| } from '@nestjs/swagger'; | ||
| import { GovernanceService } from './governance.service'; | ||
| import { ProposalResponse } from './model/governance.model'; | ||
|
|
||
| @ApiTags('Governance') | ||
| @ApiBearerAuth() | ||
| @Controller('/governance') | ||
| export class GovernanceController { | ||
| constructor(private readonly governanceService: GovernanceService) {} | ||
|
|
||
| @ApiOperation({ summary: 'Get pending and active governance proposals' }) | ||
| @ApiOkResponse({ type: ProposalResponse, isArray: true }) | ||
| @HttpCode(200) | ||
|
dnechay marked this conversation as resolved.
|
||
| @Header('Cache-Control', 'private, max-age=60') | ||
| @Get('/proposals') | ||
| public async getProposals(): Promise<ProposalResponse[]> { | ||
| return this.governanceService.getProposals(); | ||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
packages/apps/human-app/server/src/modules/governance/governance.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { GovernanceService } from './governance.service'; | ||
|
|
||
| @Module({ | ||
| providers: [GovernanceService], | ||
| exports: [GovernanceService], | ||
| }) | ||
| export class GovernanceModule {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.