Skip to content

Commit

Permalink
fix: fix v1 proposal titles for Kujira (#53)
Browse files Browse the repository at this point in the history
* fix: fix v1 proposal titles for Kujira

* chore: fix linting
  • Loading branch information
freak12techno authored Nov 9, 2023
1 parent 2bdc82b commit 7cfa3a0
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions pkg/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,38 @@ type V1Proposal struct {
Status string `json:"status"`
VotingEndTime time.Time `json:"voting_end_time"`
Messages []V1ProposalMessage `json:"messages"`

Title string `json:"title"`
Summary string `json:"summary"`
}

func (p V1Proposal) ToProposal() Proposal {
titles := utils.Map(p.Messages, func(m V1ProposalMessage) string {
return m.Content.Title
})
// Some chains (namely, Quicksilver) do not have title and description fields,
// instead they have content.title and content.description per each message.
// Others (namely, Kujira) have title and summary text.
// This should work for all of them.
title := p.Title
if title == "" {
titles := utils.Map(p.Messages, func(m V1ProposalMessage) string {
return m.Content.Title
})

title = strings.Join(titles, ", ")
}

descriptions := utils.Map(p.Messages, func(m V1ProposalMessage) string {
return m.Content.Description
})
description := p.Summary
if description == "" {
descriptions := utils.Map(p.Messages, func(m V1ProposalMessage) string {
return m.Content.Description
})

description = strings.Join(descriptions, ", ")
}

return Proposal{
ID: p.ProposalID,
Title: strings.Join(titles, ", "),
Description: strings.Join(descriptions, ", "),
Title: title,
Description: description,
EndTime: p.VotingEndTime,
}
}
Expand Down

0 comments on commit 7cfa3a0

Please sign in to comment.