Skip to content

Commit

Permalink
update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanvians committed Nov 2, 2023
1 parent 4e6981b commit a0a57ef
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 42 deletions.
1 change: 1 addition & 0 deletions libwallet/assets/wallet/wallet_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
LanguagePreferenceKey = "app_language"
DarkModeConfigKey = "dark_mode"
HideTotalBalanceConfigKey = "hideTotalUSDBalance"
DexFirstVisitKey = "dexFirstVisit"

PassphraseTypePin int32 = 0
PassphraseTypePass int32 = 1
Expand Down
12 changes: 12 additions & 0 deletions libwallet/assets_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Check failure on line 292 in libwallet/assets_config.go

View workflow job for this annotation

GitHub Actions / Build

File is not `goimports`-ed (goimports)
1 change: 1 addition & 0 deletions ui/load/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions ui/page/dcrdex/dcrdex_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,25 +57,22 @@ func (pg *DEXPage) ID() string {
// displayed.
// Part of the load.Page interface.
func (pg *DEXPage) OnNavigatedTo() {
pg.ctx, pg.ctxCancel = context.WithCancel(context.TODO())
pg.ctx, pg.ctxCancel = context.WithCancel(context.TODO())

Check failure on line 60 in ui/page/dcrdex/dcrdex_page.go

View workflow job for this annotation

GitHub Actions / Build

File is not `goimports`-ed (goimports)

if pg.CurrentPage() == nil {
// TODO: Handle pg.inited
pg.Display(NewDEXOnboarding(pg.Load))
pg.inited = false
}

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,
Expand Down Expand Up @@ -106,6 +102,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
Expand Down
13 changes: 7 additions & 6 deletions ui/page/dcrdex/dex_splash_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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, `<span style="text-color: gray">`, `<br>`, `</span>`)
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)
}),
)
}),
Expand Down
27 changes: 16 additions & 11 deletions ui/page/exchange/cex_splash_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand All @@ -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, `<span style="text-color: gray">`, `<br>`, `</span>`)
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)
}),
)
}),
Expand All @@ -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)
}),
Expand All @@ -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)
Expand Down
18 changes: 2 additions & 16 deletions ui/page/exchange/create_order_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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/listeners"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
Expand Down Expand Up @@ -209,7 +208,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
Expand Down Expand Up @@ -514,7 +513,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)
Expand Down Expand Up @@ -628,14 +627,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.
Expand Down Expand Up @@ -675,11 +666,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
Expand Down
6 changes: 4 additions & 2 deletions ui/values/localizable/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions ui/values/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const (
StrCanceling = "canceling"
StrCancelMixer = "cancelMixer"
StrCentralizedExchange = "centralizedExchange"
StrCentralizedExchangeCex = "centralExchangeCex"
StrCexContent = "cexContent"
StrChangeAccount = "changeAccount"
StrChangeSpecificPeer = "changeSpecificPeer"
Expand Down Expand Up @@ -849,6 +850,7 @@ const (
StrWhatIsCex = "whatIsCex"
StrWhatToCallWallet = "whatToCallWallet"
StrWord = "word"
StrWouldTradeCex = "wouldTradeCex"
StrWriteDownAll33Words = "writeDownAll33Words"
StrWriteDownSeed = "writeDownSeed"
StrWroteAllWords = "wroteAllWords"
Expand Down

0 comments on commit a0a57ef

Please sign in to comment.