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

dcr: Reimplemint privacy screens. #248

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions libwallet/assets/dcr/account_mixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (asset *Asset) CreateMixerAccounts(mixedAccount, unmixedAccount, privPass s
asset.SetInt32ConfigValueForKey(sharedW.AccountMixerMixedAccount, mixedAccountNumber)
asset.SetInt32ConfigValueForKey(sharedW.AccountMixerUnmixedAccount, unmixedAccountNumber)
asset.SetBoolConfigValueForKey(sharedW.AccountMixerConfigSet, true)
asset.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set false for sharedW.SpendUnmixedFundsKey not need because when read it, default value return is false

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set the default to true in this commit I believe. Please see the CreateNewDCRWallet variants in libwallet/dcr.go.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it fine


return nil
}
Expand Down Expand Up @@ -108,6 +109,7 @@ func (asset *Asset) SetAccountMixerConfig(mixedAccount, unmixedAccount int32, pr
asset.SetInt32ConfigValueForKey(sharedW.AccountMixerMixedAccount, mixedAccount)
asset.SetInt32ConfigValueForKey(sharedW.AccountMixerUnmixedAccount, unmixedAccount)
asset.SetBoolConfigValueForKey(sharedW.AccountMixerConfigSet, true)
asset.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same above


return nil
}
Expand All @@ -132,6 +134,7 @@ func (asset *Asset) ClearMixerConfig() {
asset.SetInt32ConfigValueForKey(sharedW.AccountMixerMixedAccount, -1)
asset.SetInt32ConfigValueForKey(sharedW.AccountMixerUnmixedAccount, -1)
asset.SetBoolConfigValueForKey(sharedW.AccountMixerConfigSet, false)
asset.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, true)
}

func (asset *Asset) ReadyToMix(_ int) (bool, error) {
Expand Down
9 changes: 9 additions & 0 deletions libwallet/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (mgr *AssetsManager) CreateNewDCRWallet(walletName, privatePassphrase strin
mgr.setDBInterface(wallet.(sharedW.AssetsManagerDB))
}

// Allow spending from the default account by default.
wallet.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, true)

return wallet, nil
}

Expand All @@ -60,6 +63,9 @@ func (mgr *AssetsManager) CreateNewDCRWatchOnlyWallet(walletName, extendedPublic
mgr.setDBInterface(wallet.(sharedW.AssetsManagerDB))
}

// Allow spending from the default account by default.
wallet.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, true)

return wallet, nil
}

Expand All @@ -82,6 +88,9 @@ func (mgr *AssetsManager) RestoreDCRWallet(walletName, seedMnemonic, privatePass
mgr.setDBInterface(wallet.(sharedW.AssetsManagerDB))
}

// Allow spending from the default account by default.
wallet.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, true)

return wallet, nil
}

Expand Down
12 changes: 1 addition & 11 deletions ui/page/components/wallet_setup_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"gioui.org/widget/material"

"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/libwallet/assets/dcr"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
libutils "github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
Expand Down Expand Up @@ -455,7 +454,7 @@ func (pg *CreateWallet) HandleUserInteractions() {

switch *pg.assetTypeSelector.SelectedAssetType() {
case libutils.DCRWalletAsset:
wal, err := pg.AssetsManager.CreateNewDCRWallet(pg.walletName.Editor.Text(), pg.passwordEditor.Editor.Text(), sharedW.PassphraseTypePass)
_, err := pg.AssetsManager.CreateNewDCRWallet(pg.walletName.Editor.Text(), pg.passwordEditor.Editor.Text(), sharedW.PassphraseTypePass)
if err != nil {
if err.Error() == libutils.ErrExist {
pg.walletName.SetError(values.StringF(values.StrWalletExist, pg.walletName.Editor.Text()))
Expand All @@ -467,15 +466,6 @@ func (pg *CreateWallet) HandleUserInteractions() {
return
}

dcrUniqueImpl := wal.(*dcr.Asset)
err = dcrUniqueImpl.CreateMixerAccounts(values.String(values.StrMixed), values.String(values.StrUnmixed), pg.passwordEditor.Editor.Text())
if err != nil {
errModal := modal.NewErrorModal(pg.Load, err.Error(), modal.DefaultClickFunc())
pg.ParentWindow().ShowModal(errModal)
return
}
wal.SetBoolConfigValueForKey(sharedW.AccountMixerConfigSet, true)

Comment on lines -470 to -478
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So not creating the accounts until the user turns mixing on.

case libutils.BTCWalletAsset:
_, err := pg.AssetsManager.CreateNewBTCWallet(pg.walletName.Editor.Text(), pg.passwordEditor.Editor.Text(), sharedW.PassphraseTypePass)
if err != nil {
Expand Down
197 changes: 122 additions & 75 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

dcrWallet *dcr.Asset
}
Expand All @@ -46,6 +42,9 @@ func NewManualMixerSetupPage(l *load.Load, dcrWallet *dcr.Asset) *ManualMixerSet
toPrivacySetup: l.Theme.Button(values.String(values.StrSetUp)),
dcrWallet: dcrWallet,
}
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 @@ -105,78 +104,116 @@ func NewManualMixerSetupPage(l *load.Load, dcrWallet *dcr.Asset) *ManualMixerSet
// the page is displayed.
// Part of the load.Page interface.
func (pg *ManualMixerSetupPage) OnNavigatedTo() {
pg.ctx, pg.ctxCancel = context.WithCancel(context.TODO())

pg.mixedAccountSelector.SelectFirstValidAccount(pg.dcrWallet)
pg.unmixedAccountSelector.SelectFirstValidAccount(pg.dcrWallet)
}

// Layout draws the page UI components into the provided layout context
// 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
func (pg *ManualMixerSetupPage) Layout(gtx C) D {
return pg.Theme.Card().Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Inset{Top: values.MarginPadding15}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Start}.Layout(gtx,
layout.Rigid(func(gtx C) D {
Comment on lines +118 to +119
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lines are not needed and seem repeated. I would recommend using the linear Layout widget for this though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, was able to remove the Flex layout here and it looks the same.

Linear in place of the Center below or the Card above?

return layout.Inset{Left: values.MarginPadding15}.Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.Y = gtx.Dp(values.MarginPadding50)
return pg.backClickable.Layout(gtx, pg.backLayout)
})
}),
layout.Rigid(func(gtx C) D {
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,
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 pg.mixerAccountSections(gtx, values.String(values.StrMixedAccount), func(gtx C) D {
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 C) D {
return pg.unmixedAccountSelector.Layout(pg.ParentWindow(), gtx)
})
})
}),
layout.Rigid(layout.Spacer{Height: values.MarginPadding15}.Layout),
layout.Rigid(pg.cautionCard),
layout.Rigid(layout.Spacer{Height: values.MarginPadding15}.Layout),
)
}),
layout.Rigid(func(gtx C) D {
return layout.UniformInset(values.MarginPadding15).Layout(gtx, pg.toPrivacySetup.Layout)
}),
)
})
})
}

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 = gtx.Dp(values.MarginPadding100)
gtx.Constraints.Max.Y = gtx.Constraints.Min.Y
return layout.UniformInset(values.MarginPadding15).Layout(gtx, func(gtx C) D {
return layout.Flex{Alignment: layout.Start}.Layout(gtx,
layout.Rigid(func(gtx C) D {
gtx.Constraints.Max.X = gtx.Dp(values.MarginPadding40)
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return pg.Theme.Icons.ActionInfo.Layout(gtx, pg.Theme.Color.Gray1)
})
}),
layout.Rigid(func(gtx C) D {
return layout.Inset{
Left: values.MarginPadding10,
}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(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)
})
})
label := pg.Theme.H6(values.String(values.StrSetUpStakeShuffleWarningTitle))
return label.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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this would allow to bold text in the middle of a sentence, the font ends up being different from the rest of the page so not using. Could also make everything html...

</span>`
return layout.Inset{
Left: values.MarginPadding8,
}.Layout(gtx, renderers.RenderHTML(txt, pg.Theme).Layout)
}),
)
})
label := pg.Theme.Body1(values.String(values.StrSetUpStakeShuffleWarningDesc))
return label.Layout(gtx)
}),
)
}),
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 cryptomaterial.UniformPadding(gtx, body)
func (pg *ManualMixerSetupPage) backLayout(gtx C) D {
return layout.Inset{Right: values.MarginPadding15}.Layout(gtx, func(gtx C) D {
// Setting a minimum Y larger than the label allows it to be centered.
gtx.Constraints.Min.Y = gtx.Dp(values.MarginPadding50)
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Left: values.MarginPadding15,
Right: values.MarginPadding15,
}.Layout(gtx, func(gtx C) D {
return pg.backIcon.Layout(gtx, values.MarginPadding30)
})
}),
layout.Rigid(func(gtx C) D {
return layout.Center.Layout(gtx, func(gtx C) D {
return pg.Theme.H6(values.String(values.StrSetUpStakeShuffleManualTitle)).Layout(gtx)
})
}),
)
})
}

func (pg *ManualMixerSetupPage) mixerAccountSections(gtx layout.Context, title string, body layout.Widget) layout.Dimensions {
func (pg *ManualMixerSetupPage) mixerAccountSections(gtx C, title string, body layout.Widget) D {
return pg.Theme.Card().Layout(gtx, func(gtx C) D {
return layout.UniformInset(values.MarginPadding16).Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
Expand Down Expand Up @@ -214,7 +251,6 @@ func (pg *ManualMixerSetupPage) showModalSetupMixerAcct() {
if err != nil {
return errfunc(err)
}
pg.dcrWallet.SetBoolConfigValueForKey(sharedW.AccountMixerConfigSet, true)

// rename mixed account
err = pg.dcrWallet.RenameAccount(mixedAcctNumber, values.String(values.StrMixed))
Expand Down Expand Up @@ -243,21 +279,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 @@ -267,6 +316,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
Loading