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 18 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
43 changes: 33 additions & 10 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,50 @@ 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) {
func (p *Politeia) getProposalsRaw(category int32, offset, limit int32, newestFirst bool, skipAbandoned bool, keySearch string) ([]Proposal, error) {
JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved
var query storm.Query
keySearch = strings.ToLower(keySearch)
switch category {
case ProposalCategoryAll:
JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved

JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved
if skipAbandoned {
if keySearch != "" {
query = p.db.Select(
q.Not(q.Eq("Category", ProposalCategoryAbandoned)),
q.Re("LowerName", "^"+keySearch),
)
} else {
query = p.db.Select(
q.Not(q.Eq("Category", ProposalCategoryAbandoned)),
)
}
} else {
if keySearch != "" {
query = p.db.Select(
q.True(),
q.Re("LowerName", "^"+keySearch),
)
} else {
query = p.db.Select(
q.True(),
)
}
}
default:
if keySearch != "" {
query = p.db.Select(
q.Not(q.Eq("Category", ProposalCategoryAbandoned)),
q.Eq("Category", category),
q.Re("LowerName", "^"+keySearch),
)
} else {
query = p.db.Select(
q.True(),
q.Eq("Category", category),
JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved
)
}
default:
query = p.db.Select(
q.Eq("Category", category),
)
}

if offset > 0 {
Expand Down Expand Up @@ -139,7 +162,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
11 changes: 11 additions & 0 deletions libwallet/internal/politeia/politeia_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ func (c *politeiaClient) tokenInventory() (*www.TokenInventoryReply, error) {
return &tokenInventoryReply, nil
}

func (c *politeiaClient) getInventory() (*www.TokenInventoryReply, error) {
var tokenInventoryReply www.TokenInventoryReply

JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved
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
7 changes: 5 additions & 2 deletions libwallet/internal/politeia/politeia_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"reflect"
"strconv"
"strings"
"time"

"decred.org/dcrwallet/v3/wallet"
Expand Down Expand Up @@ -113,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 @@ -131,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,6 +334,7 @@ func (p *Politeia) fetchBatchProposals(category int32, tokens []string, broadcas
return p.ctx.Err()
}

proposals[i].LowerName = strings.ToLower(proposals[i].Name)
JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved
proposals[i].Category = category
if voteSummary, ok := votesSummaries[proposals[i].Token]; ok {
proposals[i].VoteStatus = int32(voteSummary.Status)
Expand Down Expand Up @@ -397,6 +399,7 @@ func (p *Politeia) FetchProposalDescription(token string) (string, error) {
// index file version will be used to determine if the
// saved file is out of date when compared to version.
proposal.IndexFileVersion = proposal.Version
proposal.LowerName = strings.ToLower(proposal.Name)
err = p.saveOrOverwiteProposal(proposal)
if err != nil {
log.Errorf("error saving new proposal: %s", err.Error())
Expand Down
1 change: 1 addition & 0 deletions libwallet/internal/politeia/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Proposal struct {
Token string `json:"token" storm:"unique"`
Category int32 `json:"category" storm:"index"`
Name string `json:"name"`
LowerName string `json:"lower_name"`
JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved
State int32 `json:"state"`
Status int32 `json:"status"`
Timestamp int64 `json:"timestamp"`
Expand Down
54 changes: 31 additions & 23 deletions ui/cryptomaterial/dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ const (
var MaxWidth = unit.Dp(800)

type DropDown struct {
theme *Theme
items []DropDownItem
isOpen bool
backdrop *widget.Clickable
Position uint
revs bool
selectedIndex int
color color.NRGBA
background color.NRGBA
dropdownIcon *widget.Icon
navigationIcon *widget.Icon
clickable *Clickable
theme *Theme
items []DropDownItem
isOpen bool
backdrop *widget.Clickable
Position uint
revs bool
selectedIndex int
preSelectedIndex int
color color.NRGBA
background color.NRGBA
dropdownIcon *widget.Icon
navigationIcon *widget.Icon
clickable *Clickable

group uint
closeAllDropdown func(group uint)
Expand All @@ -50,17 +51,18 @@ type DropDownItem struct {
// dropdown backdrop.
func (t *Theme) DropDown(items []DropDownItem, group uint, pos uint) *DropDown {
d := &DropDown{
theme: t,
isOpen: false,
Position: pos,
selectedIndex: 0,
items: make([]DropDownItem, 0),
color: t.Color.Gray2,
background: t.Color.Surface,
dropdownIcon: t.dropDownIcon,
navigationIcon: t.navigationCheckIcon,
clickable: t.NewClickable(true),
backdrop: new(widget.Clickable),
theme: t,
isOpen: false,
Position: pos,
selectedIndex: 0,
preSelectedIndex: -1,
JustinBeBoy marked this conversation as resolved.
Show resolved Hide resolved
items: make([]DropDownItem, 0),
color: t.Color.Gray2,
background: t.Color.Surface,
dropdownIcon: t.dropDownIcon,
navigationIcon: t.navigationCheckIcon,
clickable: t.NewClickable(true),
backdrop: new(widget.Clickable),

group: group,
closeAllDropdown: t.closeAllDropdownMenus,
Expand Down Expand Up @@ -90,6 +92,10 @@ func (d *DropDown) Selected() string {
return d.items[d.SelectedIndex()].Text
}

func (d *DropDown) IsIndexChanged() bool {
return d.selectedIndex != d.preSelectedIndex
}
ukane-philemon marked this conversation as resolved.
Show resolved Hide resolved

func (d *DropDown) SelectedIndex() int {
return d.selectedIndex
}
Expand All @@ -103,6 +109,7 @@ func (d *DropDown) handleEvents() {
for i := range d.items {
index := i
for d.items[index].clickable.Clicked() {
d.preSelectedIndex = d.selectedIndex
d.selectedIndex = index
d.isOpen = false
break
Expand All @@ -124,6 +131,7 @@ func (d *DropDown) Changed() bool {
for i := range d.items {
index := i
for d.items[index].clickable.Clicked() {
d.preSelectedIndex = d.selectedIndex
d.selectedIndex = index
d.isOpen = false
return true
Expand Down
Loading
Loading