Skip to content

Commit

Permalink
dcr: Use default account on creation.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JoeGruffins committed Dec 6, 2023
1 parent cdff39d commit d0abc59
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
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)

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)

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)

case libutils.BTCWalletAsset:
_, err := pg.AssetsManager.CreateNewBTCWallet(pg.walletName.Editor.Text(), pg.passwordEditor.Editor.Text(), sharedW.PassphraseTypePass)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion ui/page/privacy/manual_mixer_setup_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions ui/page/privacy/shared_modals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion ui/page/root/wallet_settings_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ui/values/localizable/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions ui/values/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ const (
StrSetTreasuryPolicy = "setTreasuryPolicy"
StrSetUp = "setUp"
StrSetupMixerInfo = "setupMixerInfo"
StrMixingNotSetUp = "mixingNotSetUp"
StrSetUpNeededAccs = "setUpNeededAccs"
StrSetUpPrivacy = "setUpPrivacy"
StrSetupStakeShuffle = "setUpStakeShuffle"
Expand Down

0 comments on commit d0abc59

Please sign in to comment.