From 73aedb383d7f2058bf493a3761a564a1cde9444a Mon Sep 17 00:00:00 2001 From: jcezetah Date: Wed, 1 Nov 2023 18:51:41 -0600 Subject: [PATCH] update functionality --- libwallet/assets/wallet/wallet_config.go | 1 + libwallet/assets_config.go | 12 +++++++++++ ui/load/utils.go | 1 + ui/page/dcrdex/dcrdex_page.go | 11 ++++------ ui/page/dcrdex/dex_splash_page.go | 13 ++++++------ ui/page/exchange/cex_splash_page.go | 27 ++++++++++++++---------- ui/page/exchange/create_order_page.go | 18 ++-------------- ui/values/localizable/en.go | 6 ++++-- ui/values/strings.go | 2 ++ 9 files changed, 49 insertions(+), 42 deletions(-) diff --git a/libwallet/assets/wallet/wallet_config.go b/libwallet/assets/wallet/wallet_config.go index c146b6f94..09bd3ca12 100644 --- a/libwallet/assets/wallet/wallet_config.go +++ b/libwallet/assets/wallet/wallet_config.go @@ -56,6 +56,7 @@ const ( LanguagePreferenceKey = "app_language" DarkModeConfigKey = "dark_mode" HideTotalBalanceConfigKey = "hideTotalUSDBalance" + DexFirstVisitKey = "dexFirstVisit" PassphraseTypePin int32 = 0 PassphraseTypePass int32 = 1 diff --git a/libwallet/assets_config.go b/libwallet/assets_config.go index dde205d30..01fea5fb7 100644 --- a/libwallet/assets_config.go +++ b/libwallet/assets_config.go @@ -278,3 +278,15 @@ func (mgr *AssetsManager) SetTotalBalanceVisibility(data bool) { func genKey(prefix, identifier interface{}) string { return fmt.Sprintf("%v-%v", prefix, identifier) } + +// IsDexFirstVisit checks if its the users first visit to DCRDEX page +func (mgr *AssetsManager) IsDexFirstVisit() bool { + var data bool + mgr.db.ReadWalletConfigValue(sharedW.DexFirstVisitKey, &data) + return data +} + +// SetDexFirstVisit sets the first visit to DCRDEX . +func (mgr *AssetsManager) SetDexFirstVisit(data bool) { + mgr.db.SaveWalletConfigValue(sharedW.DexFirstVisitKey, data) +} diff --git a/ui/load/utils.go b/ui/load/utils.go index 9b2c3d727..d656fc792 100644 --- a/ui/load/utils.go +++ b/ui/load/utils.go @@ -16,6 +16,7 @@ const ( SpendUnmixedFundsKey = "spend_unmixed_funds" KnownDexServersConfigKey = "known_dex_servers" GapLimitConfigKey = "gap_limit_key" + DexFirstVisitKey = "dexFirstVisit" ) // SetCurrentAppWidth stores the current width of the app's window. diff --git a/ui/page/dcrdex/dcrdex_page.go b/ui/page/dcrdex/dcrdex_page.go index 28e87943a..9dffdc59e 100644 --- a/ui/page/dcrdex/dcrdex_page.go +++ b/ui/page/dcrdex/dcrdex_page.go @@ -5,7 +5,6 @@ import ( "gioui.org/layout" "github.com/crypto-power/cryptopower/app" - libutils "github.com/crypto-power/cryptopower/libwallet/utils" "github.com/crypto-power/cryptopower/ui/cryptomaterial" "github.com/crypto-power/cryptopower/ui/load" "github.com/crypto-power/cryptopower/ui/page/components" @@ -59,7 +58,6 @@ func (pg *DEXPage) ID() string { // Part of the load.Page interface. func (pg *DEXPage) OnNavigatedTo() { pg.ctx, pg.ctxCancel = context.WithCancel(context.TODO()) - if pg.CurrentPage() == nil { // TODO: Handle pg.inited pg.Display(NewDEXOnboarding(pg.Load)) @@ -68,15 +66,11 @@ func (pg *DEXPage) OnNavigatedTo() { pg.CurrentPage().OnNavigatedTo() } -func (pg *DEXPage) isExchangeAPIAllowed() bool { - return pg.WL.AssetsManager.IsHTTPAPIPrivacyModeOff(libutils.ExchangeHTTPAPI) -} - // 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 *DEXPage) Layout(gtx C) D { - if !pg.isExchangeAPIAllowed() { + if !pg.WL.AssetsManager.IsDexFirstVisit() { return components.UniformPadding(gtx, pg.splashPage) } return layout.Stack{}.Layout(gtx, @@ -106,6 +100,9 @@ func (pg *DEXPage) HandleUserInteractions() { if pg.splashPageInfoButton.Button.Clicked() { pg.showInfoModal() } + if pg.navigateToSettingsBtn.Button.Clicked() { + pg.WL.AssetsManager.SetDexFirstVisit(true) + } } // OnNavigatedFrom is called when the page is about to be removed from the diff --git a/ui/page/dcrdex/dex_splash_page.go b/ui/page/dcrdex/dex_splash_page.go index 0c50a3657..66a561a1d 100644 --- a/ui/page/dcrdex/dex_splash_page.go +++ b/ui/page/dcrdex/dex_splash_page.go @@ -3,11 +3,11 @@ package dcrdex import ( "gioui.org/font" "gioui.org/layout" + "gioui.org/text" "github.com/crypto-power/cryptopower/ui/cryptomaterial" "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" ) @@ -35,17 +35,18 @@ func (pg *DEXPage) splashPage(gtx layout.Context) layout.Dimensions { return pg.Theme.Icons.DcrDex.LayoutSize(gtx, values.MarginPadding100) }), layout.Rigid(func(gtx C) D { - txt := pg.Theme.Label(values.TextSize24, values.String(values.StrWhatIsDex)) - txt.Font.Weight = font.SemiBold + pgTitle := pg.Theme.Label(values.TextSize24, values.String(values.StrWhatIsDex)) + pgTitle.Font.Weight = font.SemiBold return layout.Inset{ Top: values.MarginPadding30, Bottom: values.MarginPadding16, - }.Layout(gtx, txt.Layout) + }.Layout(gtx, pgTitle.Layout) }), layout.Rigid(func(gtx C) D { - text := values.StringF(values.StrDexContent, ``, `
`, `
`) - return renderers.RenderHTML(text, pg.Theme).Layout(gtx) + pgContent := pg.Theme.Label(values.TextSize16, values.String(values.StrDexContent)) + pgContent.Alignment = text.Middle + return layout.Inset{Top: values.MarginPadding10}.Layout(gtx, pgContent.Layout) }), ) }), diff --git a/ui/page/exchange/cex_splash_page.go b/ui/page/exchange/cex_splash_page.go index cde89ae15..6b8065e86 100644 --- a/ui/page/exchange/cex_splash_page.go +++ b/ui/page/exchange/cex_splash_page.go @@ -3,11 +3,11 @@ package exchange import ( "gioui.org/font" "gioui.org/layout" + "gioui.org/text" "github.com/crypto-power/cryptopower/ui/cryptomaterial" "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" ) @@ -25,7 +25,7 @@ func (pg *CreateOrderPage) splashPage(gtx layout.Context) layout.Dimensions { Direction: layout.Center, Alignment: layout.Middle, Border: cryptomaterial.Border{Radius: cryptomaterial.Radius(14)}, - Padding: layout.UniformInset(values.MarginPadding24), + Padding: layout.UniformInset(values.MarginPadding20), }.Layout(gtx, layout.Flexed(1, func(gtx C) D { return layout.Stack{Alignment: layout.NE}.Layout(gtx, @@ -35,17 +35,22 @@ func (pg *CreateOrderPage) splashPage(gtx layout.Context) layout.Dimensions { return pg.Theme.Icons.TradeExchange.LayoutSize(gtx, values.MarginPadding100) }), layout.Rigid(func(gtx C) D { - txt := pg.Theme.Label(values.TextSize24, values.String(values.StrWhatIsCex)) - txt.Font.Weight = font.SemiBold + pgTitle := pg.Theme.Label(values.TextSize24, values.String(values.StrWhatIsCex)) + pgTitle.Font.Weight = font.SemiBold return layout.Inset{ - Top: values.MarginPadding30, - Bottom: values.MarginPadding16, - }.Layout(gtx, txt.Layout) + Top: values.MarginPadding26, + Bottom: values.MarginPadding12, + }.Layout(gtx, pgTitle.Layout) }), layout.Rigid(func(gtx C) D { - text := values.StringF(values.StrCexContent, ``, `
`, `
`) - return renderers.RenderHTML(text, pg.Theme).Layout(gtx) + pgContent := pg.Theme.Label(values.TextSize16, values.String(values.StrCexContent)) + pgContent.Alignment = text.Middle + return layout.Inset{Top: values.MarginPadding10}.Layout(gtx, pgContent.Layout) + }), + layout.Rigid(func(gtx C) D { + pgQuestion := pg.Theme.Label(values.TextSize16, values.String(values.StrWouldTradeCex)) + return layout.Inset{Top: values.MarginPadding20}.Layout(gtx, pgQuestion.Layout) }), ) }), @@ -55,7 +60,7 @@ func (pg *CreateOrderPage) splashPage(gtx layout.Context) layout.Dimensions { layout.Rigid(func(gtx C) D { gtx.Constraints.Min.X = gtx.Dp(values.MarginPadding350) return layout.Inset{ - Top: values.MarginPadding24, + Top: values.MarginPadding20, Right: values.MarginPadding16, }.Layout(gtx, pg.navToSettingsBtn.Layout) }), @@ -64,7 +69,7 @@ func (pg *CreateOrderPage) splashPage(gtx layout.Context) layout.Dimensions { func (pg *CreateOrderPage) showInfoModal() { info := modal.NewCustomModal(pg.Load). - Title(values.String(values.StrCentralizedExchange)). + Title(values.String(values.StrCentralizedExchangeCex)). Body(values.String(values.StrDexInfo)). SetPositiveButtonText(values.String(values.StrGotIt)) pg.ParentWindow().ShowModal(info) diff --git a/ui/page/exchange/create_order_page.go b/ui/page/exchange/create_order_page.go index b74bf4dfc..5e73a6c6d 100644 --- a/ui/page/exchange/create_order_page.go +++ b/ui/page/exchange/create_order_page.go @@ -16,7 +16,6 @@ import ( sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet" "github.com/crypto-power/cryptopower/libwallet/ext" "github.com/crypto-power/cryptopower/libwallet/instantswap" - "github.com/crypto-power/cryptopower/libwallet/utils" libutils "github.com/crypto-power/cryptopower/libwallet/utils" "github.com/crypto-power/cryptopower/ui/cryptomaterial" "github.com/crypto-power/cryptopower/ui/load" @@ -199,7 +198,7 @@ func NewCreateOrderPage(l *load.Load) *CreateOrderPage { return pg } -func (pg *CreateOrderPage) updateWalletAndAccountSelector(selectedFromAsset []utils.AssetType, selectedToAsset []utils.AssetType) bool { +func (pg *CreateOrderPage) updateWalletAndAccountSelector(selectedFromAsset []libutils.AssetType, selectedToAsset []libutils.AssetType) bool { asset, ok := pg.updateAssetSelection(selectedFromAsset, selectedToAsset) if !ok { isSourceWallet := len(selectedFromAsset) != 0 @@ -500,7 +499,7 @@ func (pg *CreateOrderPage) inputsNotEmpty(editors ...*widget.Editor) bool { return true } -func (pg *CreateOrderPage) updateAssetSelection(selectedFromAsset []utils.AssetType, selectedToAsset []utils.AssetType) (libutils.AssetType, bool) { +func (pg *CreateOrderPage) updateAssetSelection(selectedFromAsset []libutils.AssetType, selectedToAsset []libutils.AssetType) (libutils.AssetType, bool) { if len(selectedFromAsset) > 0 { selectedAsset := selectedFromAsset[0] ok := pg.sourceWalletSelector.SetSelectedAsset(selectedAsset) @@ -614,14 +613,6 @@ func (pg *CreateOrderPage) swapCurrency() { pg.updateExchangeConfig() } -// func (pg *CreateOrderPage) isExchangeAPIAllowed() bool { -// isAllowed := pg.WL.AssetsManager.IsHTTPAPIPrivacyModeOff(libutils.ExchangeHTTPAPI) -// if !isAllowed { -// pg.errMsg = values.StringF(values.StrNotAllowed, values.String(values.StrExchange)) -// } -// return isAllowed -// } - // isMultipleAssetTypeWalletAvailable checks if multiple asset types are // available for exchange functionality to run smoothly. Otherwise exchange // functionality is disable till different asset type wallets are created. @@ -661,11 +652,6 @@ func (pg *CreateOrderPage) Layout(gtx C) D { msg = values.String(values.StrNoExchangeOnTestnet) overlaySet = true - // case !pg.isExchangeAPIAllowed(): - // msg = pg.errMsg - // navBtn = &pg.navToSettingsBtn - // overlaySet = true - case !pg.isMultipleAssetTypeWalletAvailable(): msg = pg.errMsg overlaySet = true diff --git a/ui/values/localizable/en.go b/ui/values/localizable/en.go index 224c5d2d4..0f6d9e1d5 100644 --- a/ui/values/localizable/en.go +++ b/ui/values/localizable/en.go @@ -79,7 +79,8 @@ const EN = ` "canceling" = "Cancelling..." "cancelMixer" = "Cancel mixer?" "centralizedExchange" = "Centralized Exchange" -"cexContent" = "%v The Centralized Exchange(CEX) is a system that enables exchange of currency using predefined or custom servers that are accessible through a centralized exchange system. This system of exchange is simple, quick, and secure.%vWould you like to trade on CEX?%v" +"centralExchangeCex" = "Centralized Exchange(CEX)" +"cexContent" = "The Centralized Exchange(CEX) is a system that enables exchange of currency using predefined or custom servers that are accessible through a centralized exchange system. This system of exchange is simple, quick, and secure." "changeAccount" = "Change account" "changeSpecificPeer" = "Change specific peer" "changeSpendingPass" = "Change spending passphrase" @@ -176,7 +177,7 @@ const EN = ` "dex" = "Dex" "dexDataReset" = "DEX client data reset complete." "dexDataResetFalse" = "DEX client data reset failed. Check the logs." -"dexContent" = "%vThe Decred Decentralized Exchange (DEX) is a system that enables exchange of different types of blockchain assets via a familiar market-based API. DEX uses atomic swap technology to match trading parties and facilitates price discovery while communicating swap details.%vWould you like to trade on Decred DEX?%v" +"dexContent" = "The Decred Decentralized Exchange (DEX) is a system that enables exchange of different types of blockchain assets via a familiar market-based API. DEX uses atomic swap technology to match trading parties and facilitates price discovery while communicating swap details." "dexInfo" = "Customization and notification of trading can be modified from the settings page" "dexResetInfo" = "You may need to restart cryptopower before you can use the DEX again. Proceed?" "dexStartupErr" = "Unable to start DEX client: %v" @@ -739,6 +740,7 @@ const EN = ` "whatIsCex" = "What is Centralized Exchange?" "whatIsDex" = "What is Decred Decentralized Exchange?" "word" = "Word" +"wouldTradeCex" = "Would you like to trade on CEX?" "writeDownAll33Words" = "Write down all 33 words in the correct order." "writeDownSeed" = "Write down seed phrase" "wroteAllWords" = "I have written down all 33 words" diff --git a/ui/values/strings.go b/ui/values/strings.go index 412a87957..5f775710b 100644 --- a/ui/values/strings.go +++ b/ui/values/strings.go @@ -189,6 +189,7 @@ const ( StrCanceling = "canceling" StrCancelMixer = "cancelMixer" StrCentralizedExchange = "centralizedExchange" + StrCentralizedExchangeCex = "centralExchangeCex" StrCexContent = "cexContent" StrChangeAccount = "changeAccount" StrChangeSpecificPeer = "changeSpecificPeer" @@ -849,6 +850,7 @@ const ( StrWhatIsCex = "whatIsCex" StrWhatToCallWallet = "whatToCallWallet" StrWord = "word" + StrWouldTradeCex = "wouldTradeCex" StrWriteDownAll33Words = "writeDownAll33Words" StrWriteDownSeed = "writeDownSeed" StrWroteAllWords = "wroteAllWords"