Skip to content

Commit

Permalink
Moves Hide balance to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
AdimekweEbuka committed Sep 29, 2021
1 parent 6899c7f commit fa30658
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
52 changes: 10 additions & 42 deletions ui/page/main_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"

"github.com/decred/dcrd/dcrutil"
"github.com/planetdecred/dcrlibwallet"
Expand Down Expand Up @@ -62,12 +61,9 @@ type MainPage struct {
totalBalanceUSD string

hideBalance *widget.Bool
text string
hide bool
}

func NewMainPage(l *load.Load) *MainPage {

mp := &MainPage{
Load: l,
autoSync: true,
Expand Down Expand Up @@ -482,14 +478,17 @@ func (mp *MainPage) LayoutUSDBalance(gtx layout.Context) layout.Dimensions {
)
}

func (mp *MainPage) titleRow(gtx layout.Context, leftWidget, rightWidget func(C) D) layout.Dimensions {
return layout.Flex{Axis: layout.Horizontal, Spacing: layout.SpaceBetween}.Layout(gtx,
layout.Rigid(leftWidget),
layout.Rigid(rightWidget),
)
func (mp *MainPage) HideMyBalance(gtx layout.Context, hbal bool) layout.Dimensions {
if hbal {
hidenText := mp.Theme.Label(values.TextSize24, "********")
return hidenText.Layout(gtx)
}
return components.LayoutBalance(gtx, mp.Load, mp.totalBalance.String())

}

func (mp *MainPage) LayoutTopBar(gtx layout.Context) layout.Dimensions {
hideValue:= mp.WL.MultiWallet.ReadBoolConfigValueForKey("HideBalance", false)
return decredmaterial.LinearLayout{
Width: decredmaterial.MatchParent,
Height: decredmaterial.WrapContent,
Expand Down Expand Up @@ -523,40 +522,9 @@ func (mp *MainPage) LayoutTopBar(gtx layout.Context) layout.Dimensions {
return img.Layout24dp(gtx)
})
}),
layout.Rigid(func(gtx C) D {
if mp.hideBalance.Changed() {
mp.hide = !mp.hide
}
return layout.Center.Layout(gtx, func(gtx C) D {
if mp.hide {
hidenText := mp.Theme.Label(values.TextSize24, "********")
return hidenText.Layout(gtx)
} else {
return components.LayoutBalance(gtx, mp.Load, mp.totalBalance.String())
}
})
layout.Rigid(func(gtx C) D{
return mp.HideMyBalance(gtx, hideValue)
}),
layout.Rigid(
func(gtx C) D {
margins := layout.Inset{
Top: unit.Dp(8),
Left: unit.Dp(18),
Bottom: unit.Dp(4),
}
return margins.Layout(gtx,
func(gtx C) D {
if mp.hide {
mp.text = "Show Balance "
} else {
mp.text = "Hide Balance "
}
// hidebal:= material.Button(mp.theme.Base, mp.hideBalance, mp.text)
hidebal := material.Switch(mp.Theme.Base, mp.hideBalance)
balTitle := mp.Theme.Label(values.TextSize12, mp.text)
balTitle.Color = mp.Theme.Color.Gray2
return mp.titleRow(gtx, balTitle.Layout, hidebal.Layout)
})
}),
layout.Rigid(func(gtx C) D {
return mp.LayoutUSDBalance(gtx)
}),
Expand Down
14 changes: 14 additions & 0 deletions ui/page/settings_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type SettingsPage struct {
beepNewBlocks *decredmaterial.Switch
connectToPeer *decredmaterial.Switch
userAgent *decredmaterial.Switch
HideBalance *decredmaterial.Switch

peerLabel, agentLabel decredmaterial.Label

Expand Down Expand Up @@ -80,6 +81,7 @@ func NewSettingsPage(l *load.Load) *SettingsPage {
beepNewBlocks: l.Theme.Switch(),
connectToPeer: l.Theme.Switch(),
userAgent: l.Theme.Switch(),
HideBalance: l.Theme.Switch(),
chevronRightIcon: chevronRightIcon,

errorReceiver: make(chan error),
Expand Down Expand Up @@ -177,6 +179,9 @@ func (pg *SettingsPage) general() layout.Widget {
layout.Rigid(func(gtx C) D {
return pg.subSectionSwitch(gtx, "Dark mode", pg.isDarkModeOn)
}),
layout.Rigid(func(gtx C) D {
return pg.subSectionSwitch(gtx, "Hide balance", pg.HideBalance)
}),
layout.Rigid(func(gtx C) D {
return pg.subSectionSwitch(gtx, values.String(values.StrUnconfirmedFunds), pg.spendUnconfirmed)
}),
Expand Down Expand Up @@ -407,6 +412,9 @@ func (pg *SettingsPage) Handle() {
pg.RefreshTheme()
}

if pg.HideBalance.Changed() {
pg.wal.SaveConfigValueForKey("HideBalance", pg.HideBalance.IsChecked())
}
if pg.spendUnconfirmed.Changed() {
pg.wal.SaveConfigValueForKey(dcrlibwallet.SpendUnconfirmedConfigKey, pg.spendUnconfirmed.IsChecked())
}
Expand Down Expand Up @@ -597,6 +605,12 @@ func (pg *SettingsPage) updateSettingOptions() {
pg.isDarkModeOn.SetChecked(isDarkModeOn)
}

HideBalance := pg.wal.ReadBoolConfigValueForKey("HideBalance")
pg.HideBalance.SetChecked(false)
if HideBalance {
pg.HideBalance.SetChecked(HideBalance)
}

isSpendUnconfirmed := pg.wal.ReadBoolConfigValueForKey(dcrlibwallet.SpendUnconfirmedConfigKey)
pg.spendUnconfirmed.SetChecked(false)
if isSpendUnconfirmed {
Expand Down

0 comments on commit fa30658

Please sign in to comment.