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

implement layout for treasury spending #975

Merged
merged 12 commits into from
Aug 9, 2022
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ require (
github.com/jessevdk/go-flags v1.5.0
github.com/jrick/logrotate v1.0.0
github.com/nxadm/tail v1.4.4
github.com/onsi/ginkgo v1.15.0
github.com/onsi/gomega v1.10.5
github.com/planetdecred/dcrlibwallet v1.7.0
github.com/planetdecred/dcrlibwallet v1.7.1-0.20220802190450-f4374efae977
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220425133823-833d52a7cdd5 // indirect
github.com/yeqown/go-qrcode v1.5.1
golang.org/x/exp v0.0.0-20210722180016-6781d3edade3
Expand Down Expand Up @@ -133,7 +131,6 @@ require (
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

// Older versions of github.com/lib/pq are required by politeia (v1.9.0)
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwu
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dreacot/dcrlibwallet v1.6.1-0.20220727154925-dced69c7c544 h1:X9jDLAcgypZeBgDqtoXCqOkweub8XCWB8PVazYh6mGs=
github.com/dreacot/dcrlibwallet v1.6.1-0.20220727154925-dced69c7c544/go.mod h1:l92aoja59ClX7O67tx1z08JkL6/kYu8EdM7c092vTfg=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -790,12 +792,10 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.2/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg=
Expand Down Expand Up @@ -941,8 +941,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
github.com/planetdecred/dcrlibwallet v1.7.0 h1:UHZwYnvm/8cpSVG17lB3rx1wOAf+ZP4v5RbkPk6MYKE=
github.com/planetdecred/dcrlibwallet v1.7.0/go.mod h1:QTADevJvo+ugI0LZkwVVwCMiqtVf/W0DKlODTYwbnCs=
github.com/planetdecred/dcrlibwallet v1.7.1-0.20220802190450-f4374efae977 h1:em4zKTny1WN02NUuO3TfxK/5oYtTvEmvkhHW2k+CsuE=
github.com/planetdecred/dcrlibwallet v1.7.1-0.20220802190450-f4374efae977/go.mod h1:l92aoja59ClX7O67tx1z08JkL6/kYu8EdM7c092vTfg=
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220223161805-c736f970653d/go.mod h1:jO4RP2rgqom8CLgl3rMwZ4cGzmalJqBkKjHgVS812lM=
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220425133823-833d52a7cdd5 h1:dpLTuQ9DjQ/J070/KKmlvdti1+BEd38Wt+xqHngk98Y=
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220425133823-833d52a7cdd5/go.mod h1:jO4RP2rgqom8CLgl3rMwZ4cGzmalJqBkKjHgVS812lM=
Expand Down Expand Up @@ -1546,7 +1546,6 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
Expand Down
153 changes: 153 additions & 0 deletions ui/page/components/treasury_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package components

import (
"strings"

"gioui.org/layout"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget"

"github.com/planetdecred/dcrlibwallet"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/load"
"github.com/planetdecred/godcr/ui/values"
)

type TreasuryItem struct {
Policy dcrlibwallet.TreasuryKeyPolicy
OptionsRadioGroup *widget.Enum
VoteChoices [3]string
SetChoiceButton decredmaterial.Button
}

func (t *TreasuryItem) SetVoteChoices(voteChoices [3]string) {
t.VoteChoices = voteChoices
}

func TreasuryItemWidget(gtx C, l *load.Load, treasuryItem *TreasuryItem) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layoutPiKey(gtx, l, treasuryItem.Policy)
}),
layout.Rigid(layoutVoteChoice(l, treasuryItem)),
layout.Rigid(func(gtx C) D {
return layoutPolicyVoteAction(gtx, l, treasuryItem)
}),
)
}

func layoutPiKey(gtx C, l *load.Load, treasuryKeyPolicy dcrlibwallet.TreasuryKeyPolicy) D {

statusLabel := l.Theme.Label(values.TextSize14, treasuryKeyPolicy.PiKey)
backgroundColor := l.Theme.Color.LightBlue

return layout.Flex{Spacing: layout.SpaceBetween}.Layout(gtx,
layout.Rigid(func(gtx C) D {
lbl := l.Theme.Label(values.TextSize20, values.String(values.StrPiKey))
lbl.Font.Weight = text.SemiBold
return lbl.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
return decredmaterial.LinearLayout{
Background: backgroundColor,
Width: decredmaterial.WrapContent,
Height: decredmaterial.WrapContent,
Direction: layout.Center,
Alignment: layout.Middle,
Border: decredmaterial.Border{
Color: backgroundColor,
Width: values.MarginPadding1,
Radius: decredmaterial.Radius(4),
},
Padding: layout.Inset{
Top: values.MarginPadding3,
Bottom: values.MarginPadding3,
Left: values.MarginPadding8,
Right: values.MarginPadding8},
Margin: layout.Inset{Left: values.MarginPadding10},
}.Layout2(gtx, statusLabel.Layout)
}),
)
}

func layoutVoteChoice(l *load.Load, treasuryItem *TreasuryItem) layout.Widget {
return func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
lbl := l.Theme.Label(values.TextSize16, values.String(values.StrSetTreasuryPolicy))
lbl.Font.Weight = text.SemiBold
return layout.Inset{Top: values.MarginPadding15}.Layout(gtx, lbl.Layout)
}),
layout.Rigid(func(gtx C) D {
return layout.Inset{Top: values.MarginPadding10, Left: values.MarginPadding0}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx, layoutItems(l, treasuryItem)...)
})
}),
)
}
}

func layoutItems(l *load.Load, treasuryItem *TreasuryItem) []layout.FlexChild {
voteChoices := [...]string{
strings.ToLower(values.String(values.StrYes)),
strings.ToLower(values.String(values.StrNo)),
strings.ToLower(values.String(values.StrAbstain)),
}
items := make([]layout.FlexChild, 0)
for _, voteChoice := range voteChoices {
radioBtn := l.Theme.RadioButton(treasuryItem.OptionsRadioGroup, voteChoice, voteChoice, l.Theme.Color.DeepBlue, l.Theme.Color.Primary)
radioItem := layout.Rigid(radioBtn.Layout)
items = append(items, radioItem)
}

return items
}

func layoutPolicyVoteAction(gtx C, l *load.Load, treasuryItem *TreasuryItem) D {
gtx.Constraints.Min.X, gtx.Constraints.Max.X = gtx.Dp(unit.Dp(150)), gtx.Dp(unit.Dp(200))
treasuryItem.SetChoiceButton.Background = l.Theme.Color.Gray3
treasuryItem.SetChoiceButton.SetEnabled(false)

if treasuryItem.OptionsRadioGroup.Value != "" && treasuryItem.OptionsRadioGroup.Value != treasuryItem.Policy.Policy {
treasuryItem.SetChoiceButton.Background = l.Theme.Color.Primary
treasuryItem.SetChoiceButton.SetEnabled(true)
}
return layout.Inset{Top: values.MarginPadding15}.Layout(gtx, treasuryItem.SetChoiceButton.Layout)
}

func LayoutNoPoliciesFound(gtx C, l *load.Load, syncing bool) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
text := values.String(values.StrNoPoliciesYet)
if syncing {
text = values.String(values.StrFetchingPolicies)
}
return layout.Center.Layout(gtx, func(gtx C) D {
lbl := l.Theme.Body1(text)
lbl.Color = l.Theme.Color.GrayText3
return layout.Inset{
Top: values.MarginPadding10,
Bottom: values.MarginPadding10,
}.Layout(gtx, lbl.Layout)
})
}

func LoadPolicies(l *load.Load, selectedWallet *dcrlibwallet.Wallet, pikey string) []*TreasuryItem {
policies, err := selectedWallet.TreasuryPolicies(pikey, "")
if err != nil {
return nil
}

treasuryItems := make([]*TreasuryItem, len(policies))
for i := 0; i < len(policies); i++ {
treasuryItems[i] = &TreasuryItem{
Policy: *policies[i],
OptionsRadioGroup: new(widget.Enum),
SetChoiceButton: l.Theme.Button(values.String(values.StrUpdatePreference)),
}

treasuryItems[i].OptionsRadioGroup.Value = treasuryItems[i].Policy.Policy
}
return treasuryItems
}
4 changes: 2 additions & 2 deletions ui/page/components/votebar_widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ func (v *VoteBar) Layout(window app.WindowNavigator, gtx C) D {
layout.Rigid(func(gtx C) D {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
yesLabel := v.Theme.Body1(values.String(values.StrYes))
yesLabel := v.Theme.Body1(values.String(values.StrYes) + values.String(values.StrColon))
return v.layoutIconAndText(gtx, yesLabel, v.yesVotes, v.yesColor)
}),
layout.Rigid(func(gtx C) D {
noLabel := v.Theme.Body1(values.String(values.StrNo))
noLabel := v.Theme.Body1(values.String(values.StrNo) + values.String(values.StrColon))
return v.layoutIconAndText(gtx, noLabel, v.noVotes, v.noColor)
}),
layout.Flexed(1, func(gtx C) D {
Expand Down
10 changes: 10 additions & 0 deletions ui/page/governance/governance_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Page struct {
var governanceTabTitles = []string{
values.String(values.StrProposal),
values.String(values.StrConsensusChange),
values.String(values.StrTreasurySpending),
}

func NewGovernancePage(l *load.Load) *Page {
Expand Down Expand Up @@ -98,8 +99,15 @@ func (pg *Page) HandleUserInteractions() {
pg.Display(NewProposalsPage(pg.Load)) // Display should do nothing if the page is already displayed.
} else if clickedTabIndex == 1 {
pg.Display(NewConsensusPage(pg.Load))
} else {
pg.Display(NewTreasuryPage(pg.Load))
}
}

// Handle individual page user interactions.
if activeTab := pg.CurrentPage(); activeTab != nil {
activeTab.HandleUserInteractions()
}
}

func (pg *Page) Layout(gtx C) D {
Expand Down Expand Up @@ -152,6 +160,8 @@ func (pg *Page) selectedTabIndex() int {
return 0
case ConsensusPageID:
return 1
case TreasuryPageID:
return 2
default:
return -1
}
Expand Down
Loading