Skip to content
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

Update Governance page #221

Merged
merged 41 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2be6190
tab for governance page
JustinBeBoy Oct 27, 2023
e4a2202
fix scroll
JustinBeBoy Oct 30, 2023
7f3c3b3
fix scroll view to the end
JustinBeBoy Oct 31, 2023
a7e2664
update logic save proposal, logic search proposal, create ui search
JustinBeBoy Nov 1, 2023
8b5c33e
clean code
JustinBeBoy Nov 1, 2023
69605c4
fix conflict
JustinBeBoy Nov 1, 2023
71145ff
update from master
JustinBeBoy Nov 6, 2023
c38af5f
update UI for votebar
JustinBeBoy Nov 6, 2023
0176a30
update list item for In discussion proposal state
JustinBeBoy Nov 6, 2023
390b91f
Add wallet selector and order drop down to proposal page, relayout pr…
JustinBeBoy Nov 6, 2023
9e2f5f3
Update ui for proposal detail, add option layout on subpage
JustinBeBoy Nov 7, 2023
8a9ee53
update header for proposal detail page and refactor code
JustinBeBoy Nov 7, 2023
721ae67
add new option for wallet account selector, update ui for wallet sele…
JustinBeBoy Nov 8, 2023
3038fc6
update ui for Consensus changes page and add option for dropdown
JustinBeBoy Nov 8, 2023
d96bbf0
Update new UI for Treasury page
JustinBeBoy Nov 9, 2023
dd239e7
update logic load agenda
JustinBeBoy Nov 9, 2023
79c336d
clean code
JustinBeBoy Nov 9, 2023
f712a30
fix lint
JustinBeBoy Nov 9, 2023
02bd5f7
fix conflict
JustinBeBoy Nov 11, 2023
14bee4a
fix comments
JustinBeBoy Nov 14, 2023
1526126
Merge branch 'government' of github.com:JustinBeBoy/cryptopower into …
JustinBeBoy Nov 14, 2023
130e8de
clean code
JustinBeBoy Nov 14, 2023
a65244c
update logic fetch agenda on consensus page and fetch proposal on pro…
JustinBeBoy Nov 14, 2023
76da46b
update layout for votebar widget and proposal list
JustinBeBoy Nov 19, 2023
37d9a0d
update layout for proposal detail page
JustinBeBoy Nov 19, 2023
7d35913
optimize code
JustinBeBoy Nov 22, 2023
a9d451a
update struct of proposal, layuot RPF proposal in list
JustinBeBoy Nov 24, 2023
9f2fcd2
fix lint
JustinBeBoy Nov 24, 2023
8580e40
update dropdown
JustinBeBoy Nov 27, 2023
0830b32
update query proposal, update editor, clean code
JustinBeBoy Nov 28, 2023
4540bd6
fix conflict
JustinBeBoy Dec 2, 2023
a5cf87d
clean code
JustinBeBoy Dec 2, 2023
6467557
fix conflict
JustinBeBoy Dec 6, 2023
2b8cc2f
update dropdown wallet on proposal page
JustinBeBoy Dec 6, 2023
e695579
update dropdown wallet to proposal page, treasury page and consensus_…
JustinBeBoy Dec 6, 2023
e846fd2
fix conflict and update dropdown for governance page
JustinBeBoy Dec 6, 2023
112f9af
fix conflict
JustinBeBoy Dec 6, 2023
396b419
clean code
JustinBeBoy Dec 6, 2023
ab257c2
update layout proposal page, consensus page and treaury page
JustinBeBoy Dec 7, 2023
2b81ed7
clean code
JustinBeBoy Dec 8, 2023
acfce58
fix dropdown down't show when have only 1 item
JustinBeBoy Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions libwallet/assets/dcr/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ func AllVoteAgendas(chainParams *chaincfg.Params, newestFirst bool) ([]*Agenda,
}
}

if newestFirst {
sort.Slice(agendas, func(i, j int) bool {
sort.Slice(agendas, func(i, j int) bool {
if newestFirst {
return agendas[i].StartTime > agendas[j].StartTime
})
}
}
return agendas[i].StartTime < agendas[j].StartTime
})
return agendas, nil
}
33 changes: 15 additions & 18 deletions libwallet/internal/politeia/politeia.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"

"decred.org/dcrwallet/v3/errors"
Expand Down Expand Up @@ -90,28 +91,24 @@ func (p *Politeia) saveOrOverwiteProposal(proposal *Proposal) error {
}

// GetProposalsRaw fetches and returns a proposals from the db
func (p *Politeia) GetProposalsRaw(category int32, offset, limit int32, newestFirst bool) ([]Proposal, error) {
return p.getProposalsRaw(category, offset, limit, newestFirst, false)
func (p *Politeia) GetProposalsRaw(category int32, offset, limit int32, newestFirst bool, key string) ([]Proposal, error) {
return p.getProposalsRaw(category, offset, limit, newestFirst, false, key)
}

func (p *Politeia) getProposalsRaw(category int32, offset, limit int32, newestFirst bool, skipAbandoned bool) ([]Proposal, error) {
var query storm.Query
switch category {
case ProposalCategoryAll:

func (p *Politeia) getProposalsRaw(category int32, offset, limit int32, newestFirst bool, skipAbandoned bool, searchPhrase string) ([]Proposal, error) {
searchPhrase = strings.TrimSpace(strings.ToLower(searchPhrase))
matcher := q.Eq("Category", category)
if category == ProposalCategoryAll {
if skipAbandoned {
query = p.db.Select(
q.Not(q.Eq("Category", ProposalCategoryAbandoned)),
)
matcher = q.Not(q.Eq("Category", ProposalCategoryAbandoned))
} else {
query = p.db.Select(
q.True(),
)
matcher = q.True()
}
default:
query = p.db.Select(
q.Eq("Category", category),
)
}

query := p.db.Select(matcher)
if searchPhrase != "" {
query = p.db.Select(matcher, q.Re("Name", "(?i)"+searchPhrase))
}

if offset > 0 {
Expand Down Expand Up @@ -139,7 +136,7 @@ func (p *Politeia) getProposalsRaw(category int32, offset, limit int32, newestFi

// GetProposals returns the result of GetProposalsRaw as a JSON string
func (p *Politeia) GetProposals(category int32, offset, limit int32, newestFirst bool) (string, error) {
result, err := p.GetProposalsRaw(category, offset, limit, newestFirst)
result, err := p.GetProposalsRaw(category, offset, limit, newestFirst, "")
if err != nil {
return "", err
}
Expand Down
46 changes: 46 additions & 0 deletions libwallet/internal/politeia/politeia_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package politeia

import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -18,6 +19,12 @@ type politeiaClient struct {
cookies []*http.Cookie
}

type metadataProposal struct {
Name string `json:"name"`
LinkBy int64 `json:"linkby"`
LinkTo string `json:"linkto"`
}

const (
ticketVoteAPI = tkv1.APIRoute
proposalDetailsPath = "/proposals/"
Expand Down Expand Up @@ -104,6 +111,13 @@ func (c *politeiaClient) batchProposals(tokens []string) ([]Proposal, error) {
PublishedAt: proposalRecord.PublishedAt,
}

for _, meta := range proposalRecord.Metadata {
if meta.Hint == "proposalmetadata" {
proposal.Type = getProposalType(meta.Payload)
break
}
}

for _, file := range proposalRecord.Files {
if file.Name == "index.md" {
proposal.IndexFile = file.Payload
Expand All @@ -117,6 +131,28 @@ func (c *politeiaClient) batchProposals(tokens []string) ([]Proposal, error) {
return proposals, nil
}

func getProposalType(payload string) ProposalType {
decodedBytes, err := base64.StdEncoding.DecodeString(payload)
if err != nil {
fmt.Println("error decoding proposalmetadata:", err)
return ProposalTypeNormal
}

var meta metadataProposal
err = json.Unmarshal(decodedBytes, &meta)
if err != nil {
log.Error("error unmarshalling metadataProposal:", err)
}

if meta.LinkTo != "" {
return ProposalTypeRFPSubmission
} else if meta.LinkBy != 0 {
return ProposalTypeRFPProposal
} else {
return ProposalTypeNormal
}
}

func (c *politeiaClient) proposalDetails(token string) (*www.ProposalDetailsReply, error) {
route := proposalDetailsPath + token

Expand All @@ -140,6 +176,16 @@ func (c *politeiaClient) tokenInventory() (*www.TokenInventoryReply, error) {
return &tokenInventoryReply, nil
}

func (c *politeiaClient) getInventory() (*www.TokenInventoryReply, error) {
var tokenInventoryReply www.TokenInventoryReply
err := c.makeRequest(http.MethodGet, apiPath, tkv1.RouteInventory, nil, &tokenInventoryReply)
if err != nil {
return nil, err
}

return &tokenInventoryReply, nil
}

func (c *politeiaClient) voteDetails(token string) (*tkv1.DetailsReply, error) {
requestBody, err := json.Marshal(&tkv1.Details{Token: token})
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions libwallet/internal/politeia/politeia_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (p *Politeia) checkForUpdates() error {
return p.ctx.Err()
}

proposals, err := p.getProposalsRaw(ProposalCategoryAll, int32(offset), limit, true, true)
proposals, err := p.getProposalsRaw(ProposalCategoryAll, int32(offset), limit, true, true, "")
if err != nil && err != storm.ErrNotFound {
return err
}
Expand All @@ -132,7 +132,7 @@ func (p *Politeia) checkForUpdates() error {
}

// include abandoned proposals
allProposals, err := p.getProposalsRaw(ProposalCategoryAll, 0, 0, true, false)
allProposals, err := p.getProposalsRaw(ProposalCategoryAll, 0, 0, true, false, "")
if err != nil && err != storm.ErrNotFound {
return err
}
Expand Down Expand Up @@ -333,7 +333,6 @@ func (p *Politeia) fetchBatchProposals(category int32, tokens []string, broadcas
if p.ctx.Err() != nil {
return p.ctx.Err()
}

proposals[i].Category = category
if voteSummary, ok := votesSummaries[proposals[i].Token]; ok {
proposals[i].VoteStatus = int32(voteSummary.Status)
Expand Down
9 changes: 9 additions & 0 deletions libwallet/internal/politeia/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ package politeia

import "github.com/crypto-power/cryptopower/libwallet/utils"

type ProposalType int

const (
ProposalTypeNormal ProposalType = iota
ProposalTypeRFPProposal
ProposalTypeRFPSubmission
)

type Proposal struct {
ID int `storm:"id,increment"`
Token string `json:"token" storm:"unique"`
Expand All @@ -24,6 +32,7 @@ type Proposal struct {
EligibleTickets int32 `json:"eligibletickets"`
QuorumPercentage int32 `json:"quorumpercentage"`
PassPercentage int32 `json:"passpercentage"`
Type ProposalType
}

type ProposalOverview struct {
Expand Down
6 changes: 6 additions & 0 deletions libwallet/politeia.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const (
ProposalCategoryAbandoned = politeia.ProposalCategoryAbandoned
)

const (
ProposalTypeNormal = politeia.ProposalTypeNormal
ProposalTypeRFPProposal = politeia.ProposalTypeRFPProposal
ProposalTypeRFPSubmission = politeia.ProposalTypeRFPSubmission
)

type Proposal struct {
politeia.Proposal
}
Expand Down
28 changes: 12 additions & 16 deletions ui/cryptomaterial/dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ type DropDown struct {
shadow *Shadow
expandedViewAlignment layout.Direction

noSelectedItemText string
FontWeight font.Weight
BorderWidth unit.Dp
BorderColor *color.NRGBA
Background *color.NRGBA
noSelectedItem DropDownItem

FontWeight font.Weight
BorderWidth unit.Dp
BorderColor *color.NRGBA
Background *color.NRGBA
// SelectedItemIconColor is a custom color that will be applied to the icon
// use in identifying selected item when this dropdown is expanded.
SelectedItemIconColor *color.NRGBA
Expand Down Expand Up @@ -139,9 +140,9 @@ func (d *DropDown) Selected() string {
return d.items[d.SelectedIndex()].Text
}

func (d *DropDown) ClearSelection(text string) {
func (d *DropDown) ClearWithSelectedItem(item DropDownItem) {
d.selectedIndex = -1
d.noSelectedItemText = text
d.noSelectedItem = item
}

func (d *DropDown) SelectedIndex() int {
Expand Down Expand Up @@ -247,8 +248,7 @@ func (d *DropDown) collapsedAndExpandedLayout(gtx C) D {
return display
})}

// No need to display expanded view when there is only one item.
if d.expanded && len(d.items) > 1 {
if d.expanded {
layoutContents = append(layoutContents, layout.Expanded(func(gtx layout.Context) layout.Dimensions {
// Adding d.ExpandedLayoutInset.Top accounts for the the extra
// shift in vertical space set by d.ExpandedLayoutInset.Top to
Expand Down Expand Up @@ -294,10 +294,7 @@ func (d *DropDown) collapsedLayout(gtx C) D {
if len(d.items) > 0 && d.selectedIndex > -1 {
selectedItem = d.items[d.selectedIndex]
} else {
selectedItem = DropDownItem{
Text: d.noSelectedItemText,
PreventSelection: true,
}
selectedItem = d.noSelectedItem
}

bodyLayout := LinearLayout{
Expand Down Expand Up @@ -332,8 +329,7 @@ func (d *DropDown) itemLayout(gtx C, index int, clickable *Clickable, item *Drop
if item.Icon == nil {
return D{}
}

return item.Icon.Layout24dp(gtx)
return layout.Inset{Right: values.MarginPadding5}.Layout(gtx, item.Icon.Layout24dp)
}),
layout.Flexed(1, func(gtx C) D {
if item.DisplayFn != nil {
Expand All @@ -350,7 +346,7 @@ func (d *DropDown) itemLayout(gtx C, index int, clickable *Clickable, item *Drop
})
}),
layout.Rigid(func(gtx C) D {
if !item.PreventSelection && len(d.items) > 1 {
if !item.PreventSelection {
return d.layoutActiveIcon(gtx, index)
}
return D{}
Expand Down
Loading
Loading