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

improve dex screens on mobile #719

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
31 changes: 29 additions & 2 deletions libwallet/assets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/crypto-power/cryptopower/libwallet/instantswap"
"github.com/crypto-power/cryptopower/libwallet/internal/politeia"
"github.com/crypto-power/cryptopower/libwallet/utils"
libutils "github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/notification"
"github.com/crypto-power/cryptopower/ui/values"
bolt "go.etcd.io/bbolt"
Expand Down Expand Up @@ -980,8 +981,8 @@ func (mgr *AssetsManager) DEXDBExists() bool {
// initialized first so the DEX client can bind previously added wallets when it
// starts.
func (mgr *AssetsManager) InitializeDEX() {
// Ignore attempts to InitializeDEX on mobile.
if appos.Current().IsMobile() {
// Ignore attempts to InitializeDEX on iOS.
if appos.Current().IsIOS() {
return
}

Expand Down Expand Up @@ -1109,3 +1110,29 @@ func (mgr *AssetsManager) BadgerDB() string {
func (mgr *AssetsManager) BoltDB() string {
return BoltDB
}

// AssetToCreate checks if there is any asset type that has not been created
// and returns the first one.
func (mgr *AssetsManager) AssetToCreate() libutils.AssetType {
assetToCreate := mgr.AllAssetTypes()
wallets := mgr.AllWallets()

assetsNotCreated := make([]libutils.AssetType, 0)

for _, asset := range assetToCreate {
assetExists := false

for _, wallet := range wallets {
if wallet.GetAssetType() == asset {
assetExists = true
break
}
}

if !assetExists {
assetsNotCreated = append(assetsNotCreated, asset)
}
}

return assetsNotCreated[0]
}
20 changes: 19 additions & 1 deletion ui/page/dcrdex/dcrdex_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"gioui.org/widget/material"
"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/libwallet"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
libutils "github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/load"
Expand All @@ -30,6 +31,7 @@ type DEXPage struct {
splashPageInfoButton cryptomaterial.IconButton
splashPageContainer *widget.List
startTradingBtn cryptomaterial.Button
createWalletBtn cryptomaterial.Button
showSplashPage bool
dexIsLoading bool
materialLoader material.LoaderStyle
Expand All @@ -41,6 +43,7 @@ func NewDEXPage(l *load.Load) *DEXPage {
Load: l,
openTradeMainPage: l.Theme.NewClickable(false),
startTradingBtn: l.Theme.Button(values.String(values.StrStartTrading)),
createWalletBtn: l.Theme.Button(values.String(values.StrCreateANewWallet)),
splashPageContainer: &widget.List{List: layout.List{
Alignment: layout.Middle,
Axis: layout.Vertical,
Expand Down Expand Up @@ -124,7 +127,7 @@ func (pg *DEXPage) Layout(gtx C) D {
}

if hasMultipleWallets := pg.isMultipleAssetTypeWalletAvailable(); !hasMultipleWallets {
return components.DisablePageWithOverlay(pg.Load, nil, gtx, values.String(values.StrMultipleAssetRequiredMsg), "", nil)
return components.DisablePageWithOverlay(pg.Load, nil, gtx, values.String(values.StrMultipleAssetRequiredMsg), "", &pg.createWalletBtn)
}

return pg.CurrentPage().Layout(gtx)
Expand Down Expand Up @@ -153,9 +156,11 @@ func (pg *DEXPage) HandleUserInteractions(gtx C) {
if pg.CurrentPage() != nil {
pg.CurrentPage().HandleUserInteractions(gtx)
}

if pg.splashPageInfoButton.Button.Clicked(gtx) {
pg.showInfoModal()
}

if pg.startTradingBtn.Button.Clicked(gtx) {
if !pg.AssetsManager.DEXDBExists() && !pg.AssetsManager.DEXCInitialized() {
// Attempt to initialize dex again.
Expand All @@ -168,6 +173,13 @@ func (pg *DEXPage) HandleUserInteractions(gtx C) {
}()
}
}

if pg.createWalletBtn.Button.Clicked(gtx) {
assetToCreate := pg.AssetsManager.AssetToCreate()
pg.ParentWindow().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.walletCreationSuccessFunc()
}, assetToCreate))
}
}

// OnNavigatedFrom is called when the page is about to be removed from the
Expand Down Expand Up @@ -196,3 +208,9 @@ func pendingBondConfirmation(am *libwallet.AssetsManager, host string) (string,
}
return "", nil, nil
}

func (pg *DEXPage) walletCreationSuccessFunc() {
pg.OnNavigatedTo()
pg.ParentWindow().CloseCurrentPage()
pg.ParentWindow().Reload()
}
28 changes: 19 additions & 9 deletions ui/page/dcrdex/dex_onboarding_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"gioui.org/widget/material"

"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/appos"
"github.com/crypto-power/cryptopower/dexc"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
libutils "github.com/crypto-power/cryptopower/libwallet/utils"
Expand Down Expand Up @@ -269,15 +270,16 @@ func (pg *DEXOnboarding) Layout(gtx C) D {
return D{}
}

padding := layout.Inset{
Right: dp10,
Left: dp10,
}
return cryptomaterial.LinearLayout{
Width: cryptomaterial.MatchParent,
Width: cryptomaterial.WrapContent,
Height: cryptomaterial.MatchParent,
Orientation: layout.Vertical,
Background: pg.Theme.Color.Surface,
Margin: layout.Inset{
Right: dp20,
Left: dp20,
},
Padding: padding,
Border: cryptomaterial.Border{
Radius: cryptomaterial.Radius(8),
},
Expand All @@ -295,8 +297,10 @@ func (pg *DEXOnboarding) Layout(gtx C) D {
return pg.Theme.Separator().Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
gtx.Constraints.Max.X = gtx.Dp(formWidth)
gtx.Constraints.Min.X = gtx.Constraints.Max.X
if !appos.Current().IsMobile() {
gtx.Constraints.Max.X = gtx.Dp(formWidth)
gtx.Constraints.Min.X = gtx.Constraints.Max.X
}
return pg.onBoardingSteps[pg.currentStep].stepFn(gtx)
}),
)
Expand Down Expand Up @@ -328,7 +332,9 @@ func (pg *DEXOnboarding) onBoardingStepRow(gtx C) D {
layout.Stacked(func(gtx C) D {
dp30 := values.MarginPadding30
sep := pg.Theme.Separator()
sep.Width = gtx.Dp(values.MarginPadding500)
if !appos.Current().IsMobile() {
sep.Width = gtx.Dp(values.MarginPadding500)
}
sep.Height = gtx.Dp(values.MarginPadding3)
return layout.Inset{Bottom: values.MarginPadding35, Right: dp30, Left: dp30}.Layout(gtx, sep.Layout)
}),
Expand Down Expand Up @@ -1132,7 +1138,11 @@ func (pg *DEXOnboarding) setAddServerStep() {
}

pg.serverDropDown = pg.Theme.DropDown(dropdownServers, nil, values.DEXServerDropdownGroup, false)
pg.serverDropDown.Width = formWidth
width := formWidth
if appos.Current().IsMobile() {
width = values.MarginPadding280
}
pg.serverDropDown.Width = width
pg.serverDropDown.MakeCollapsedLayoutVisibleWhenExpanded = true

pg.currentStep = onBoardingStepAddServer
Expand Down
28 changes: 1 addition & 27 deletions ui/page/exchange/create_order_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (pg *CreateOrderPage) HandleUserInteractions(gtx C) {
}

if pg.createWalletBtn.Button.Clicked(gtx) {
assetToCreate := pg.AssetToCreate()
assetToCreate := pg.AssetsManager.AssetToCreate()
pg.ParentWindow().Display(components.NewCreateWallet(pg.Load, func(_ sharedW.Asset) {
pg.walletCreationSuccessFunc(false, assetToCreate)
}, assetToCreate))
Expand Down Expand Up @@ -1464,29 +1464,3 @@ func (pg *CreateOrderPage) fetchInstantExchangeCurrencies() error {
pg.rateError = err != nil
return err
}

// AssetToCreate check if there is any asset type that has not been created
// and returns the first one.
func (pg *CreateOrderPage) AssetToCreate() libutils.AssetType {
assetToCreate := pg.AssetsManager.AllAssetTypes()
wallets := pg.AssetsManager.AllWallets()

assetsNotCreated := make([]libutils.AssetType, 0)

for _, asset := range assetToCreate {
assetExists := false

for _, wallet := range wallets {
if wallet.GetAssetType() == asset {
assetExists = true
break
}
}

if !assetExists {
assetsNotCreated = append(assetsNotCreated, asset)
}
}

return assetsNotCreated[0]
}
16 changes: 8 additions & 8 deletions ui/page/root/home_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ func (hp *HomePage) initPageItems() {
}

// Add trade tab only if not on macOS
if !appos.Current().IsDarwin() {
// Determine the insertion point, which is second to last position
insertionPoint := len(navigationTabTitles) - 1
if insertionPoint < 0 {
insertionPoint = 0
}
// Append at the second to last position
navigationTabTitles = append(navigationTabTitles[:insertionPoint], append([]string{values.String(values.StrTrade)}, navigationTabTitles[insertionPoint:]...)...)
// if !appos.Current().IsDarwin() {
// Determine the insertion point, which is second to last position
insertionPoint := len(navigationTabTitles) - 1
if insertionPoint < 0 {
insertionPoint = 0
}
// Append at the second to last position
navigationTabTitles = append(navigationTabTitles[:insertionPoint], append([]string{values.String(values.StrTrade)}, navigationTabTitles[insertionPoint:]...)...)
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

oops?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch


hp.navigationTab = hp.Theme.Tab(layout.Horizontal, false, navigationTabTitles)

Expand Down
Loading