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

show fullscreen when create/backup wallet, verify a wallet name before continue #669

Merged
merged 5 commits into from
Sep 25, 2024
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
13 changes: 13 additions & 0 deletions libwallet/assets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/crypto-power/cryptopower/libwallet/assets/btc"
"github.com/crypto-power/cryptopower/libwallet/assets/dcr"
"github.com/crypto-power/cryptopower/libwallet/assets/ltc"
"github.com/crypto-power/cryptopower/libwallet/assets/wallet"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
)

Expand Down Expand Up @@ -615,6 +616,18 @@ func (mgr *AssetsManager) DeleteBadWallet(walletID int) error {
return nil
}

// Check if wallet name already exists
func (mgr *AssetsManager) DoesWalletNameExist(walletName string) (bool, error) {
wallet := wallet.Wallet{}
err := mgr.params.DB.One("Name", walletName, &wallet)
if err == nil {
return true, nil
} else if err != storm.ErrNotFound {
return false, err
}
return false, nil
}

// RootDirFileSizeInBytes returns the total directory size of
// Assets Manager's root directory in bytes.
func (mgr *AssetsManager) RootDirFileSizeInBytes(dataDir string) (int64, error) {
Expand Down
23 changes: 22 additions & 1 deletion ui/page/components/wallet_setup_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (pg *CreateWallet) restoreWallet(gtx C) D {
}

func (pg *CreateWallet) handleEditorEvents(gtx C) {
isSubmit, isChanged := cryptomaterial.HandleEditorEvents(gtx, &pg.watchOnlyWalletHex, &pg.passwordEditor, &pg.confirmPasswordEditor)
isSubmit, isChanged := cryptomaterial.HandleEditorEvents(gtx, &pg.watchOnlyWalletHex, &pg.walletName, &pg.passwordEditor, &pg.confirmPasswordEditor)
if isChanged {
// reset error when any editor is modified
pg.walletName.SetError("")
Expand All @@ -434,6 +434,9 @@ func (pg *CreateWallet) handleEditorEvents(gtx C) {

// create wallet action
if (pg.continueBtn.Clicked(gtx) || isSubmit) && pg.validCreateWalletInputs() {
if pg.checkWalletNameExists() {
return
}
go pg.createWallet()
}

Expand Down Expand Up @@ -565,6 +568,10 @@ func (pg *CreateWallet) HandleUserInteractions(gtx C) {

// restore wallet actions
if pg.restoreBtn.Clicked(gtx) && pg.validRestoreWalletInputs() {
if pg.checkWalletNameExists() {
return
}

afterRestore := func(newWallet sharedW.Asset) {
// todo setup mixer for restored accounts automatically
pg.walletCreationSuccessCallback(newWallet)
Expand All @@ -574,6 +581,20 @@ func (pg *CreateWallet) HandleUserInteractions(gtx C) {
}
}

func (pg *CreateWallet) checkWalletNameExists() bool {
walletName := pg.walletName.Editor.Text()
exists, err := pg.AssetsManager.DoesWalletNameExist(walletName)
if err != nil {
pg.walletName.SetError(err.Error())
return true
}
if exists {
pg.walletName.SetError(values.StringF(values.StrWalletExist, walletName))
return true
}
return false
}

func (pg *CreateWallet) passwordsMatch(editors ...*widget.Editor) bool {
if len(editors) < 2 {
return false
Expand Down
8 changes: 4 additions & 4 deletions ui/page/exchange/create_order_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (pg *CreateOrderPage) displayCreateWalletModal(isSourceWallet bool, asset l
SetCancelable(true).
SetContentAlignment(layout.Center, layout.W, layout.Center).
SetPositiveButtonCallback(func(_ bool, _ *modal.InfoModal) bool {
pg.ParentNavigator().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.ParentWindow().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.walletCreationSuccessFunc(isSourceWallet, asset)
}, asset))
return true
Expand All @@ -278,7 +278,7 @@ func (pg *CreateOrderPage) walletCreationSuccessFunc(isSourceWallet bool, asset
} else {
pg.updateWalletAndAccountSelector(nil, []libutils.AssetType{asset})
}
pg.ParentNavigator().ClosePagesAfter(CreateOrderPageID)
pg.ParentWindow().CloseCurrentPage()
pg.ParentWindow().Reload()
}

Expand Down Expand Up @@ -475,7 +475,7 @@ func (pg *CreateOrderPage) HandleUserInteractions(gtx C) {

if pg.createWalletBtn.Button.Clicked(gtx) {
assetToCreate := pg.AssetToCreate()
pg.ParentNavigator().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.ParentWindow().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.walletCreationSuccessFunc(false, assetToCreate)
}, assetToCreate))
}
Expand Down Expand Up @@ -739,7 +739,7 @@ func (pg *CreateOrderPage) Layout(gtx C) D {
Orientation: layout.Vertical,
Background: pg.Theme.Color.Surface,
Border: cryptomaterial.Border{Radius: cryptomaterial.Radius(14)},
Margin: layout.Inset{Right: values.MarginPadding8, Bottom: values.MarginPadding8},
Margin: layout.Inset{Bottom: values.MarginPadding8},
}.Layout2(gtx, func(gtx C) D {
return inset.Layout(gtx, func(gtx C) D {
return cryptomaterial.LinearLayout{
Expand Down
8 changes: 2 additions & 6 deletions ui/page/exchange/trade_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (pg *TradePage) ID() string {
func (pg *TradePage) OnNavigatedTo() {
// on mobile view, we display the cex tab by default
if pg.IsMobileView() {
tab.SetSelectedSegment(tabTitles[1])
pg.Display(NewCreateOrderPage(pg.Load))
} else if activeTab := pg.CurrentPage(); activeTab != nil {
activeTab.OnNavigatedTo()
Expand All @@ -97,13 +98,8 @@ func (pg *TradePage) OnNavigatedTo() {
// displayed.
// Part of the load.Page interface.
func (pg *TradePage) HandleUserInteractions(gtx C) {
selectedIndex := tab.SelectedIndex()
if pg.IsMobileView() {
selectedIndex++ // Adjust index for mobile view
}

if pg.CurrentPage() == nil || tab.Changed() {
switch selectedIndex {
switch tab.SelectedIndex() {
case 0: // DCRDEX
if pg.CurrentPageID() != dcrdex.DCRDEXPageID {
pg.Display(dcrdex.NewDEXPage(pg.Load))
Expand Down
4 changes: 2 additions & 2 deletions ui/page/governance/treasury_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (pg *TreasuryPage) HandleUserInteractions(gtx C) {
}

if pg.createWalletBtn.Button.Clicked(gtx) {
pg.ParentNavigator().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.ParentWindow().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.walletCreationSuccessFunc()
}, libutils.DCRWalletAsset))
}
Expand Down Expand Up @@ -409,6 +409,6 @@ func (pg *TreasuryPage) decredWalletRequired(gtx C) D {

func (pg *TreasuryPage) walletCreationSuccessFunc() {
pg.OnNavigatedTo()
pg.ParentNavigator().ClosePagesAfter(TreasuryPageID)
pg.ParentWindow().CloseCurrentPage()
pg.ParentWindow().Reload()
}
12 changes: 2 additions & 10 deletions ui/page/info/info_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/crypto-power/cryptopower/ui/load"
"github.com/crypto-power/cryptopower/ui/page/components"
"github.com/crypto-power/cryptopower/ui/page/privacy"
"github.com/crypto-power/cryptopower/ui/page/seedbackup"
"github.com/crypto-power/cryptopower/ui/page/staking"
"github.com/crypto-power/cryptopower/ui/page/transaction"
"github.com/crypto-power/cryptopower/ui/values"
Expand Down Expand Up @@ -60,7 +59,7 @@ type WalletInfo struct {
showMaterialLoader bool
}

func NewInfoPage(l *load.Load, wallet sharedW.Asset) *WalletInfo {
func NewInfoPage(l *load.Load, wallet sharedW.Asset, backup func(sharedW.Asset)) *WalletInfo {
pg := &WalletInfo{
Load: l,
GenericPageModal: app.NewGenericPageModal(InfoID),
Expand All @@ -72,7 +71,7 @@ func NewInfoPage(l *load.Load, wallet sharedW.Asset) *WalletInfo {
recentStakes: l.Theme.NewClickableList(layout.Vertical),
materialLoader: material.Loader(l.Theme.Base),
}
pg.walletSyncInfo = components.NewWalletSyncInfo(l, wallet, pg.reload, pg.backup)
pg.walletSyncInfo = components.NewWalletSyncInfo(l, wallet, pg.reload, backup)
pg.recentTransactions.Radius = cryptomaterial.Radius(14)
pg.recentTransactions.IsShadowEnabled = true
pg.recentStakes.Radius = cryptomaterial.Radius(14)
Expand Down Expand Up @@ -121,13 +120,6 @@ func (pg *WalletInfo) reload() {
pg.ParentWindow().Reload()
}

func (pg *WalletInfo) backup(wallet sharedW.Asset) {
currentPage := pg.ParentWindow().CurrentPageID()
pg.ParentWindow().Display(seedbackup.NewBackupInstructionsPage(pg.Load, wallet, func(_ *load.Load, navigator app.WindowNavigator) {
navigator.ClosePagesAfter(currentPage)
}))
}

// Layout draws the page UI components into the provided layout context
// to be eventually drawn on screen.
// Part of the load.Page interface.
Expand Down
2 changes: 1 addition & 1 deletion ui/page/seedbackup/backup_instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func container(gtx C, isMobile bool, theme cryptomaterial.Theme, body layout.Wid
bodyLayout := func(gtx C) D {
return layout.Stack{}.Layout(gtx,
layout.Expanded(func(gtx C) D {
return body(gtx)
return layout.Inset{Top: values.MarginPadding10}.Layout(gtx, body)
}),
layout.Stacked(func(gtx C) D {
if !showActionBtn {
Expand Down
32 changes: 17 additions & 15 deletions ui/page/settings/app_settings_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,23 @@ func (pg *AppSettingsPage) layoutMobile(gtx C, body func(gtx C) D) D {
}

func (pg *AppSettingsPage) pageHeaderLayout(gtx C) layout.Dimensions {
return layout.Flex{Spacing: layout.SpaceBetween}.Layout(gtx,
layout.Flexed(1, func(gtx C) D {
return layout.W.Layout(gtx, func(gtx C) D {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Top: values.MarginPadding2,
Right: values.MarginPadding16,
}.Layout(gtx, pg.backButton.Layout)
}),
layout.Rigid(pg.Theme.Label(values.TextSizeTransform(pg.Load.IsMobileView(), values.TextSize20), values.String(values.StrSettings)).Layout),
)
})
}),
)
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Center.Layout(gtx, func(gtx C) D {
gtx.Constraints.Min.X = gtx.Dp(values.MarginPadding500)
if pg.Load.IsMobileView() {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
}
gtx.Constraints.Max.X = gtx.Constraints.Min.X
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Top: values.MarginPadding2,
Right: values.MarginPadding16,
}.Layout(gtx, pg.backButton.Layout)
}),
layout.Rigid(pg.Theme.Label(values.TextSizeTransform(pg.Load.IsMobileView(), values.TextSize20), values.String(values.StrSettings)).Layout),
)
})
}

func (pg *AppSettingsPage) pageContentLayout(gtx C) D {
Expand Down
20 changes: 13 additions & 7 deletions ui/page/wallet/single_wallet_main_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (swmp *SingleWalletMasterPage) OnNavigatedTo() {
swmp.PageNavigationTab.SetSelectedSegment(tab)
swmp.navigateToSelectedTab()
} else if swmp.CurrentPage() == nil {
swmp.Display(info.NewInfoPage(swmp.Load, swmp.selectedWallet)) // TODO: Should pagestack have a start page? YES!
swmp.Display(info.NewInfoPage(swmp.Load, swmp.selectedWallet, swmp.backup)) // TODO: Should pagestack have a start page? YES!
} else {
swmp.CurrentPage().OnNavigatedTo()
}
Expand Down Expand Up @@ -243,6 +243,7 @@ func (swmp *SingleWalletMasterPage) initTabOptions() {
}

swmp.PageNavigationTab = swmp.Theme.SegmentedControl(commonTabs, cryptomaterial.SegmentTypeSplit)
swmp.PageNavigationTab.SetEnableSwipe(false)
dp5 := values.MarginPadding5
swmp.PageNavigationTab.ContentPadding = layout.Inset{
Left: dp5,
Expand Down Expand Up @@ -372,7 +373,7 @@ func (swmp *SingleWalletMasterPage) HandleUserInteractions(gtx C) {
if swmp.navigateToSyncBtn.Button.Clicked(gtx) {
swmp.ToggleSync(swmp.selectedWallet, func(b bool) {
swmp.selectedWallet.SaveUserConfigValue(sharedW.AutoSyncConfigKey, b)
swmp.Display(info.NewInfoPage(swmp.Load, swmp.selectedWallet))
swmp.Display(info.NewInfoPage(swmp.Load, swmp.selectedWallet, swmp.backup))
})
}

Expand All @@ -396,7 +397,7 @@ func (swmp *SingleWalletMasterPage) navigateToSelectedTab() {
case values.String(values.StrReceive):
pg = receive.NewReceivePage(swmp.Load, swmp.selectedWallet)
case values.String(values.StrInfo):
pg = info.NewInfoPage(swmp.Load, swmp.selectedWallet)
pg = info.NewInfoPage(swmp.Load, swmp.selectedWallet, swmp.backup)
case values.String(values.StrTransactions):
txPage := transaction.NewTransactionsPage(swmp.Load, swmp.selectedWallet)
txPage.DisableUniformTab()
Expand Down Expand Up @@ -849,11 +850,16 @@ func (swmp *SingleWalletMasterPage) showBackupInfo() {
PositiveButtonStyle(swmp.Load.Theme.Color.Primary, swmp.Load.Theme.Color.InvText).
SetPositiveButtonText(values.String(values.StrBackupNow)).
SetPositiveButtonCallback(func(_ bool, _ *modal.InfoModal) bool {
swmp.ParentNavigator().Display(seedbackup.NewBackupInstructionsPage(swmp.Load, swmp.selectedWallet, func(_ *load.Load, _ app.WindowNavigator) {
swmp.selectedWallet.SaveUserConfigValue(sharedW.SeedBackupNotificationConfigKey, true)
swmp.ParentNavigator().ClosePagesAfter(MainPageID)
}))
swmp.backup(swmp.selectedWallet)
return true
})
swmp.ParentWindow().ShowModal(backupNowOrLaterModal)
}

func (swmp *SingleWalletMasterPage) backup(wallet sharedW.Asset) {
currentPage := swmp.ParentWindow().CurrentPageID()
swmp.ParentWindow().Display(seedbackup.NewBackupInstructionsPage(swmp.Load, wallet, func(_ *load.Load, navigator app.WindowNavigator) {
wallet.SaveUserConfigValue(sharedW.SeedBackupNotificationConfigKey, true)
navigator.ClosePagesAfter(currentPage)
}))
}
Loading