From d0abc599f713b867804f1603cfa3c9da3ebee58d Mon Sep 17 00:00:00 2001 From: JoeGruff Date: Tue, 7 Nov 2023 19:45:02 +0900 Subject: [PATCH] dcr: Use default account on creation. In order to make mixing opt in, start with it off and do not create the accounts. Allow sending from the default account on creation. --- libwallet/assets/dcr/account_mixer.go | 3 +++ libwallet/dcr.go | 9 +++++++++ ui/page/components/wallet_setup_page.go | 12 +----------- ui/page/privacy/manual_mixer_setup_page.go | 1 - ui/page/privacy/shared_modals.go | 2 -- ui/page/root/wallet_settings_page.go | 10 +++++++++- ui/values/localizable/en.go | 1 + ui/values/strings.go | 1 + 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/libwallet/assets/dcr/account_mixer.go b/libwallet/assets/dcr/account_mixer.go index 3ecb3c0fc..ce8f62028 100644 --- a/libwallet/assets/dcr/account_mixer.go +++ b/libwallet/assets/dcr/account_mixer.go @@ -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) return nil } @@ -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) return nil } @@ -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) { diff --git a/libwallet/dcr.go b/libwallet/dcr.go index d646463f8..e7d5412ac 100644 --- a/libwallet/dcr.go +++ b/libwallet/dcr.go @@ -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 } @@ -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 } @@ -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 } diff --git a/ui/page/components/wallet_setup_page.go b/ui/page/components/wallet_setup_page.go index 659cfd0eb..55a3be42c 100644 --- a/ui/page/components/wallet_setup_page.go +++ b/ui/page/components/wallet_setup_page.go @@ -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" @@ -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())) @@ -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) - case libutils.BTCWalletAsset: _, err := pg.AssetsManager.CreateNewBTCWallet(pg.walletName.Editor.Text(), pg.passwordEditor.Editor.Text(), sharedW.PassphraseTypePass) if err != nil { diff --git a/ui/page/privacy/manual_mixer_setup_page.go b/ui/page/privacy/manual_mixer_setup_page.go index dc04fc3bd..ac2aeb019 100644 --- a/ui/page/privacy/manual_mixer_setup_page.go +++ b/ui/page/privacy/manual_mixer_setup_page.go @@ -214,7 +214,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)) diff --git a/ui/page/privacy/shared_modals.go b/ui/page/privacy/shared_modals.go index 53ef98020..fbea4b296 100644 --- a/ui/page/privacy/shared_modals.go +++ b/ui/page/privacy/shared_modals.go @@ -3,7 +3,6 @@ package privacy import ( "github.com/crypto-power/cryptopower/app" "github.com/crypto-power/cryptopower/libwallet/assets/dcr" - sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet" "github.com/crypto-power/cryptopower/libwallet/utils" "github.com/crypto-power/cryptopower/ui/cryptomaterial" "github.com/crypto-power/cryptopower/ui/load" @@ -76,7 +75,6 @@ func showModalSetupMixerAcct(conf *sharedModalConfig, dcrWallet *dcr.Asset, move pm.SetLoading(false) return false } - dcrWallet.SetBoolConfigValueForKey(sharedW.AccountMixerConfigSet, true) if movefundsChecked { err := moveFundsFromDefaultToUnmixed(conf, dcrWallet, password) diff --git a/ui/page/root/wallet_settings_page.go b/ui/page/root/wallet_settings_page.go index 70ee615ff..ecd2fcdff 100644 --- a/ui/page/root/wallet_settings_page.go +++ b/ui/page/root/wallet_settings_page.go @@ -649,7 +649,15 @@ func (pg *WalletSettingsPage) HandleUserInteractions() { pg.ParentWindow().ShowModal(textModal) } else { - pg.wallet.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, false) + mixingEnabled := pg.wallet.ReadBoolConfigValueForKey(sharedW.AccountMixerConfigSet, false) + if !mixingEnabled { + pg.spendUnmixedFunds.SetChecked(true) + mixingNotEnabled := values.String(values.StrMixingNotSetUp) + info := modal.NewErrorModal(pg.Load, mixingNotEnabled, modal.DefaultClickFunc()) + pg.ParentWindow().ShowModal(info) + } else { + pg.wallet.SetBoolConfigValueForKey(sharedW.SpendUnmixedFundsKey, false) + } } } diff --git a/ui/values/localizable/en.go b/ui/values/localizable/en.go index 9ceba9ede..568a84a42 100644 --- a/ui/values/localizable/en.go +++ b/ui/values/localizable/en.go @@ -550,6 +550,7 @@ const EN = ` "setTreasuryPolicy" = "Set treasury policy" "setUp" = "Set up" "setupMixerInfo" = "%v Two dedicated accounts %v mixed %v & %v unmixed %v will be created in order to use the mixer. %v This action cannot be undone.%v" +"mixingNotSetUp" = "Set up mixing from the StakeShuffle tab in order to disable." "setUpNeededAccs" = "Set up needed accounts" "setUpPrivacy" = "Using StakeShuffle increases the privacy of your wallet transactions." "setUpStakeShuffle" = "Set up StakeShuffle" diff --git a/ui/values/strings.go b/ui/values/strings.go index 4c44e7497..c2cb53b66 100644 --- a/ui/values/strings.go +++ b/ui/values/strings.go @@ -660,6 +660,7 @@ const ( StrSetTreasuryPolicy = "setTreasuryPolicy" StrSetUp = "setUp" StrSetupMixerInfo = "setupMixerInfo" + StrMixingNotSetUp = "mixingNotSetUp" StrSetUpNeededAccs = "setUpNeededAccs" StrSetUpPrivacy = "setUpPrivacy" StrSetupStakeShuffle = "setUpStakeShuffle"