From c9fec6bc5302981c6551265a48e7ff79ed6a0b0d Mon Sep 17 00:00:00 2001 From: Sergey <83376337+freak12techno@users.noreply.github.com> Date: Sun, 19 Mar 2023 13:51:46 +0300 Subject: [PATCH] feat: display proposal voting left time on /proposals (#41) --- pkg/reporters/telegram/list_proposals.go | 4 ++-- pkg/types/responses.go | 4 ++++ templates/telegram/proposals.html | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/reporters/telegram/list_proposals.go b/pkg/reporters/telegram/list_proposals.go index 0dd62ea..581224c 100644 --- a/pkg/reporters/telegram/list_proposals.go +++ b/pkg/reporters/telegram/list_proposals.go @@ -2,7 +2,7 @@ package telegram import ( "bytes" - "main/pkg/state" + statePkg "main/pkg/state" tele "gopkg.in/telebot.v3" ) @@ -13,7 +13,7 @@ func (reporter *TelegramReporter) HandleProposals(c tele.Context) error { Str("text", c.Text()). Msg("Got proposals list query") - state := reporter.StateGenerator.GetState(state.NewState()) + state := reporter.StateGenerator.GetState(statePkg.NewState()) template, _ := reporter.GetTemplate("proposals") var buffer bytes.Buffer if err := template.Execute(&buffer, state); err != nil { diff --git a/pkg/types/responses.go b/pkg/types/responses.go index 783f8d1..3f4956e 100644 --- a/pkg/types/responses.go +++ b/pkg/types/responses.go @@ -13,6 +13,10 @@ type Proposal struct { VotingEndTime time.Time `json:"voting_end_time"` } +func (p Proposal) GetTimeLeft() string { + return utils.FormatDuration(time.Until(p.VotingEndTime).Round(time.Second)) +} + type ProposalContent struct { Title string `json:"title"` Description string `json:"description"` diff --git a/templates/telegram/proposals.html b/templates/telegram/proposals.html index 5e74216..ffba3b2 100644 --- a/templates/telegram/proposals.html +++ b/templates/telegram/proposals.html @@ -6,7 +6,7 @@ {{- end }} {{- range .ProposalVotes }} {{- $proposalLink := $chain.GetProposalLink .Proposal }} -Proposal #{{ .Proposal.ProposalID }}: {{ SerializeLink $proposalLink }} +Proposal #{{ .Proposal.ProposalID }}: {{ SerializeLink $proposalLink }} (voting ends in {{ .Proposal.GetTimeLeft }}) {{- range $wallet, $vote := .Votes }} {{- $walletLink := $chain.GetWalletLink $vote.Wallet -}} {{- if $vote.IsError }}