Skip to content

Commit

Permalink
dcr: Reimplemint privacy screens.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Nov 24, 2023
1 parent 6486fb6 commit b2dd44e
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 267 deletions.
208 changes: 137 additions & 71 deletions ui/page/privacy/manual_mixer_setup_page.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package privacy

import (
"context"

"gioui.org/layout"

"github.com/crypto-power/cryptopower/app"
Expand All @@ -12,7 +10,6 @@ import (
"github.com/crypto-power/cryptopower/ui/load"
"github.com/crypto-power/cryptopower/ui/modal"
"github.com/crypto-power/cryptopower/ui/page/components"
"github.com/crypto-power/cryptopower/ui/renderers"
"github.com/crypto-power/cryptopower/ui/values"
)

Expand All @@ -26,15 +23,14 @@ type ManualMixerSetupPage struct {
// and the root WindowNavigator.
*app.GenericPageModal

ctx context.Context // page context
ctxCancel context.CancelFunc

mixedAccountSelector *components.WalletAndAccountSelector
unmixedAccountSelector *components.WalletAndAccountSelector

backButton cryptomaterial.IconButton
infoButton cryptomaterial.IconButton
backClickable *cryptomaterial.Clickable
toPrivacySetup cryptomaterial.Button
backIcon *cryptomaterial.Icon

dcrImpl *dcr.Asset
}
Expand All @@ -52,6 +48,9 @@ func NewManualMixerSetupPage(l *load.Load) *ManualMixerSetupPage {
toPrivacySetup: l.Theme.Button(values.String(values.StrSetUp)),
dcrImpl: impl,
}
pg.backClickable = pg.Theme.NewClickable(true)
pg.backIcon = cryptomaterial.NewIcon(pg.Theme.Icons.NavigationArrowBack)
pg.backIcon.Color = pg.Theme.Color.Gray1

// Mixed account picker
pg.mixedAccountSelector = components.NewWalletAndAccountSelector(l).
Expand Down Expand Up @@ -111,8 +110,6 @@ func NewManualMixerSetupPage(l *load.Load) *ManualMixerSetupPage {
// the page is displayed.
// Part of the load.Page interface.
func (pg *ManualMixerSetupPage) OnNavigatedTo() {
pg.ctx, pg.ctxCancel = context.WithCancel(context.TODO())

wl := load.NewWalletMapping(pg.WL.SelectedWallet.Wallet)
pg.mixedAccountSelector.SelectFirstValidAccount(wl)
pg.unmixedAccountSelector.SelectFirstValidAccount(wl)
Expand All @@ -122,65 +119,123 @@ func (pg *ManualMixerSetupPage) OnNavigatedTo() {
// to be eventually drawn on screen.
// Part of the load.Page interface.
func (pg *ManualMixerSetupPage) Layout(gtx layout.Context) layout.Dimensions {
body := func(gtx C) D {
page := components.SubPage{
Load: pg.Load,
Title: values.String(values.StrManualSetUp),
BackButton: pg.backButton,
Back: func() {
pg.ParentNavigator().CloseCurrentPage()
},
Body: func(gtx C) D {
return pg.Theme.Card().Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle}.Layout(gtx,
layout.Flexed(1, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle}.Layout(gtx,
return layout.Inset{Top: values.MarginPadding40}.Layout(gtx, func(gtx C) D {
return pg.Theme.Card().Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Start}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Center.Layout(gtx, func(gtx C) D {
return layout.Inset{Top: values.MarginPadding25}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Start}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return pg.mixerAccountSections(gtx, values.String(values.StrMixedAccount), func(gtx layout.Context) layout.Dimensions {
return pg.mixedAccountSelector.Layout(pg.ParentWindow(), gtx)
})
return pg.backClickable.Layout(gtx, pg.backLayout)
}),
layout.Rigid(func(gtx C) D {
return layout.Inset{Top: values.MarginPaddingMinus15}.Layout(gtx, func(gtx C) D {
return pg.mixerAccountSections(gtx, values.String(values.StrUnmixedAccount), func(gtx layout.Context) layout.Dimensions {
return pg.unmixedAccountSelector.Layout(pg.ParentWindow(), gtx)
})
})
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return pg.mixerAccountSections(gtx, values.String(values.StrMixedAccount), func(gtx layout.Context) layout.Dimensions {
return pg.mixedAccountSelector.Layout(pg.ParentWindow(), gtx)
})
}),
layout.Rigid(func(gtx C) D {
return layout.Inset{Top: values.MarginPaddingMinus15}.Layout(gtx, func(gtx C) D {
return pg.mixerAccountSections(gtx, values.String(values.StrUnmixedAccount), func(gtx layout.Context) layout.Dimensions {
return pg.unmixedAccountSelector.Layout(pg.ParentWindow(), gtx)
})
})
}),
layout.Rigid(func(gtx C) D {
return layout.Spacer{Height: values.MarginPadding10}.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
return pg.cautionCard(gtx)
}),
layout.Rigid(func(gtx C) D {
return layout.Spacer{Height: values.MarginPadding40}.Layout(gtx)
}),
)
}),
layout.Rigid(func(gtx C) D {
return layout.Inset{Top: values.MarginPadding10, Left: values.MarginPadding16, Right: values.MarginPadding16}.Layout(gtx, func(gtx C) D {
return layout.Flex{
Axis: layout.Horizontal,
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return pg.Theme.Icons.ActionInfo.Layout(gtx, pg.Theme.Color.Gray1)
}),
layout.Rigid(func(gtx C) D {
txt := `<span style="text-color: grayText2">
<b>Make sure to select the same accounts from the previous privacy setup. </b><br>Failing to do so could compromise wallet privacy.<br> You may not select the same account for mixed and unmixed.
</span>`
return layout.Inset{
Left: values.MarginPadding8,
}.Layout(gtx, renderers.RenderHTML(txt, pg.Theme).Layout)
}),
)
})
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.UniformInset(values.MarginPadding15).Layout(gtx, pg.toPrivacySetup.Layout)
}),
)
}),
layout.Rigid(func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.UniformInset(values.MarginPadding15).Layout(gtx, pg.toPrivacySetup.Layout)
}),
)
})
},
}
return page.Layout(pg.ParentWindow(), gtx)
}
})
})
}),
)
})
})
}

return components.UniformPadding(gtx, body)
func (pg *ManualMixerSetupPage) cautionCard(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Inset{Left: values.MarginPadding15, Right: values.MarginPadding15}.Layout(gtx, func(gtx C) D {
card := pg.Theme.Card()
card.Color = pg.Theme.Color.Gray4
return card.Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
gtx.Constraints.Min.Y = int(values.MarginPadding100)
gtx.Constraints.Max.Y = gtx.Constraints.Min.Y
return layout.Inset{Top: values.MarginPadding15, Left: values.MarginPadding15,
Right: values.MarginPadding15, Bottom: values.MarginPadding15}.Layout(gtx, func(gtx C) D {
return layout.Flex{Alignment: layout.Start}.Layout(gtx,
layout.Flexed(1, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle, Spacing: layout.SpaceAround}.Layout(gtx,
layout.Rigid(func(gtx C) D {
gtx.Constraints.Max.X = int(values.MarginPadding40)
return pg.Theme.Icons.ActionInfo.Layout(gtx, pg.Theme.Color.Gray1)
}),
)
}),
layout.Flexed(7, func(gtx C) D {
return layout.Inset{
Left: values.MarginPadding10,
}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(func(gtx C) D {
label := pg.Theme.H6(values.String(values.StrSetUpStakeShuffleManualA))
return label.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
label := pg.Theme.Body1(values.String(values.StrSetUpStakeShuffleManualB))
return label.Layout(gtx)
}),
)
})
}),
)
})
})
})
}

func (pg *ManualMixerSetupPage) backLayout(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
// Setting a minimum Y larger than the label allows it to be centered.
gtx.Constraints.Min.Y = int(values.MarginPadding50)
return layout.Flex{Alignment: layout.Start}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Left: values.MarginPadding15,
Right: values.MarginPadding15,
}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle, Spacing: layout.SpaceAround}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return pg.backIcon.Layout(gtx, values.MarginPadding30)
}),
)
})
}),
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle, Spacing: layout.SpaceAround}.Layout(gtx,
layout.Rigid(func(gtx C) D {
label := pg.Theme.H6(values.String(values.StrSetUpStakeShuffleAutoOrManualG))
return layout.E.Layout(gtx, label.Layout)
}),
)
}),
)
}

func (pg *ManualMixerSetupPage) mixerAccountSections(gtx layout.Context, title string, body layout.Widget) layout.Dimensions {
Expand Down Expand Up @@ -249,21 +304,34 @@ func (pg *ManualMixerSetupPage) showModalSetupMixerAcct() {
// displayed.
// Part of the load.Page interface.
func (pg *ManualMixerSetupPage) HandleUserInteractions() {
if pg.backClickable.Clicked() {
pg.ParentNavigator().CloseCurrentPage()
}

if pg.toPrivacySetup.Clicked() {
go pg.showModalSetupMixerAcct()
}
enableToPriv := func() {
mixed, unmixed := pg.mixedAccountSelector.SelectedAccount(), pg.unmixedAccountSelector.SelectedAccount()
if mixed == nil || unmixed == nil {
pg.toPrivacySetup.SetEnabled(false)
return
}

if pg.mixedAccountSelector.SelectedAccount().Number == pg.unmixedAccountSelector.SelectedAccount().Number {
pg.toPrivacySetup.SetEnabled(false)
} else {
pg.toPrivacySetup.SetEnabled(true)
}
if mixed.Number == unmixed.Number {
pg.toPrivacySetup.SetEnabled(false)
return
}

// Disable set up button if either mixed or unmixed account is the default account.
if pg.mixedAccountSelector.SelectedAccount().Number == dcr.DefaultAccountNum ||
pg.unmixedAccountSelector.SelectedAccount().Number == dcr.DefaultAccountNum {
pg.toPrivacySetup.SetEnabled(false)
// Disable set up button if either mixed or unmixed account is the default account.
if mixed.Number == dcr.DefaultAccountNum ||
unmixed.Number == dcr.DefaultAccountNum {
pg.toPrivacySetup.SetEnabled(false)
return
}
pg.toPrivacySetup.SetEnabled(true)
}
enableToPriv()
}

// OnNavigatedFrom is called when the page is about to be removed from
Expand All @@ -273,6 +341,4 @@ func (pg *ManualMixerSetupPage) HandleUserInteractions() {
// OnNavigatedTo() will be called again. This method should not destroy UI
// components unless they'll be recreated in the OnNavigatedTo() method.
// Part of the load.Page interface.
func (pg *ManualMixerSetupPage) OnNavigatedFrom() {
pg.ctxCancel()
}
func (pg *ManualMixerSetupPage) OnNavigatedFrom() {}
Loading

0 comments on commit b2dd44e

Please sign in to comment.