Skip to content

Commit

Permalink
update some code and clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeBoy committed Jul 2, 2024
1 parent 74f6577 commit 6ad63be
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 37 deletions.
16 changes: 6 additions & 10 deletions ui/cryptomaterial/modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ type Modal struct {
isDisabled bool
showScrollBar bool
isMobileView bool
isFirstDisplay bool
firstLoadWithContext func(gtx C)
}

// The firstLoad() parameter is used to perform actions
// that require Context before Layout() is called.
func (t *Theme) ModalFloatTitle(id string, isMobileView bool, firstLoad ...func(gtx C)) *Modal {
mod := t.Modal(id, isMobileView, firstLoad...)
func (t *Theme) ModalFloatTitle(id string, isMobileView bool, firstLoad func(gtx C)) *Modal {
mod := t.Modal(id, isMobileView, firstLoad)
mod.isFloatTitle = true
return mod
}

func (t *Theme) Modal(id string, isMobileView bool, firstLoad ...func(gtx C)) *Modal {
func (t *Theme) Modal(id string, isMobileView bool, firstLoad func(gtx C)) *Modal {
overlayColor := t.Color.Black
overlayColor.A = 200

Expand All @@ -64,11 +63,8 @@ func (t *Theme) Modal(id string, isMobileView bool, firstLoad ...func(gtx C)) *M
card: t.Card(),
padding: values.MarginPadding24,
isMobileView: isMobileView,
isFirstDisplay: true,
}
if len(firstLoad) > 0 {
m.firstLoadWithContext = firstLoad[0]
}
m.firstLoadWithContext = firstLoad

m.scroll = t.List(m.list)

Expand Down Expand Up @@ -100,9 +96,9 @@ func (m *Modal) IsShown() bool {
// Layout renders the modal widget to screen. The modal assumes the size of
// its content plus padding.
func (m *Modal) Layout(gtx C, widgets []layout.Widget, width ...float32) D {
if m.firstLoadWithContext != nil && m.isFirstDisplay {
if m.firstLoadWithContext != nil {
m.firstLoadWithContext(gtx)
m.isFirstDisplay = false
m.firstLoadWithContext = nil
}
mGtx := gtx
if m.isDisabled {
Expand Down
7 changes: 4 additions & 3 deletions ui/cryptomaterial/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type (
)

type Theme struct {
Shaper text.Shaper
Base *material.Theme
Color *values.Color
Styles *values.WidgetStyles
Expand Down Expand Up @@ -55,9 +54,11 @@ type Theme struct {
}

func NewTheme(fontCollection []text.FontFace, decredIcons map[string]image.Image, isDarkModeOn bool) *Theme {
base := material.NewTheme()
base.Shaper = text.NewShaper(text.WithCollection(fontCollection))

t := &Theme{
Shaper: *text.NewShaper(text.WithCollection(fontCollection)),
Base: material.NewTheme(),
Base: base,
Color: &values.Color{},
Icons: &Icons{},
Styles: values.DefaultWidgetStyles(),
Expand Down
3 changes: 3 additions & 0 deletions ui/load/appinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (

giouiApp "gioui.org/app"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget/material"
"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/libwallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/assets"
"github.com/crypto-power/cryptopower/ui/values"
)

Expand Down Expand Up @@ -280,6 +282,7 @@ func (app *AppInfo) ConvertIconSize(size unit.Dp) unit.Dp {

func networkSwitchTempPage(currentNetType, newNetType utils.NetworkType) app.Page {
theme := material.NewTheme()
theme.Shaper = text.NewShaper(text.WithCollection(assets.FontCollection()))
text := fmt.Sprintf("Switching from %s to %s, please wait...", currentNetType, newNetType)
lbl := material.Body1(theme, text)
return app.NewWidgetDisplayPage(func(gtx layout.Context) layout.Dimensions {
Expand Down
8 changes: 4 additions & 4 deletions ui/modal/info_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const (

// NewCustomModal returns a modal that can be customized.
func NewCustomModal(l *load.Load) *InfoModal {
return newInfoModalWithKey(l, "info_modal", InfoBtn)
return newInfoModalWithKey(l, "info_modal", InfoBtn, nil)
}

// NewSuccessModal returns the default success modal UI component.
Expand Down Expand Up @@ -94,7 +94,7 @@ func DefaultClickFunc() ClickFunc {
}

func newModal(l *load.Load, title string, icon *cryptomaterial.Image, clicked ClickFunc) *InfoModal {
info := newInfoModalWithKey(l, "info_modal", InfoBtn)
info := newInfoModalWithKey(l, "info_modal", InfoBtn, nil)
info.positiveButtonClicked = clicked
info.btnPositiveWidth = values.MarginPadding100
info.dialogIcon = icon
Expand All @@ -104,10 +104,10 @@ func newModal(l *load.Load, title string, icon *cryptomaterial.Image, clicked Cl
return info
}

func newInfoModalWithKey(l *load.Load, key string, btnPositiveType ButtonType, firstLoad ...func(gtx C)) *InfoModal {
func newInfoModalWithKey(l *load.Load, key string, btnPositiveType ButtonType, firstLoad func(gtx C)) *InfoModal {
in := &InfoModal{
Load: l,
Modal: l.Theme.ModalFloatTitle(key, l.IsMobileView(), firstLoad...),
Modal: l.Theme.ModalFloatTitle(key, l.IsMobileView(), firstLoad),
btnNegative: l.Theme.OutlineButton(""),
isCancelable: true,
isLoading: false,
Expand Down
4 changes: 2 additions & 2 deletions ui/page/components/asset_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type assetTypeModal struct {
onAssetTypeClicked func(*AssetTypeItem)
assetTypeList layout.List
assetTypeItems []*AssetTypeItem
eventSoruce input.Source
eventSoruce input.Source // Interface between the interface state and widgets
isCancelable bool
}

Expand Down Expand Up @@ -204,7 +204,7 @@ func (ats *AssetTypeSelector) Layout(window app.WindowNavigator, gtx C) D {
func newAssetTypeModal(l *load.Load) *assetTypeModal {
atm := &assetTypeModal{
Load: l,
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSelectAServer), l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSelectAServer), l.IsMobileView(), nil),
assetTypeList: layout.List{Axis: layout.Vertical},
isCancelable: true,
dialogTitle: values.String(values.StrSelectAssetType),
Expand Down
2 changes: 1 addition & 1 deletion ui/page/components/vsp_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type vspSelectorModal struct {
func newVSPSelectorModal(l *load.Load, dcrWallet *dcr.Asset) *vspSelectorModal {
v := &vspSelectorModal{
Load: l,
Modal: l.Theme.ModalFloatTitle("VSPSelectorModal", l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle("VSPSelectorModal", l.IsMobileView(), nil),

inputVSP: l.Theme.Editor(new(widget.Editor), values.String(values.StrAddVSP)),
addVSP: l.Theme.Button(values.String(values.StrSave)),
Expand Down
2 changes: 1 addition & 1 deletion ui/page/components/wallet_account_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ type SelectorItem struct {
func newSelectorModal(l *load.Load, assetType ...utils.AssetType) *selectorModal {
sm := &selectorModal{
Load: l,
Modal: l.Theme.ModalFloatTitle("SelectorModal", l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle("SelectorModal", l.IsMobileView(), nil),
walletsList: layout.List{Axis: layout.Vertical},
isCancelable: true,
infoBackdrop: new(widget.Clickable),
Expand Down
1 change: 0 additions & 1 deletion ui/page/components/wallet_setup_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func NewCreateWallet(l *load.Load, walletCreationSuccessCallback func(), assetTy

pg.walletName = l.Theme.Editor(new(widget.Editor), values.String(values.StrEnterWalletName))
pg.walletName.Editor.SingleLine, pg.walletName.Editor.Submit = true, true
pg.confirmPasswordEditor.Hint = values.String(values.StrWalletName)

pg.watchOnlyWalletHex = l.Theme.Editor(new(widget.Editor), values.String(values.StrExtendedPubKey))
pg.watchOnlyWalletHex.Editor.SingleLine, pg.watchOnlyWalletHex.Editor.Submit, pg.watchOnlyWalletHex.IsTitleLabel = false, true, false
Expand Down
2 changes: 1 addition & 1 deletion ui/page/exchange/exchange_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (es *ExSelector) Layout(window app.WindowNavigator, gtx C) D {
func newExchangeModal(l *load.Load) *exchangeModal {
em := &exchangeModal{
Load: l,
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSelectAServer), l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSelectAServer), l.IsMobileView(), nil),
exchangeList: layout.List{Axis: layout.Vertical},
isCancelable: true,
dialogTitle: values.String(values.StrSelectAServer),
Expand Down
2 changes: 1 addition & 1 deletion ui/page/exchange/frequency_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (fs *FrequencySelector) Layout(window app.WindowNavigator, gtx C) D {
func newFrequencyModal(l *load.Load) *frequencyModal {
fm := &frequencyModal{
Load: l,
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSelectFrequency), l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSelectFrequency), l.IsMobileView(), nil),
frequencyList: layout.List{Axis: layout.Vertical},
isCancelable: true,
dialogTitle: values.String(values.StrSelectFrequency),
Expand Down
2 changes: 1 addition & 1 deletion ui/page/exchange/order_scheduler_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type orderSchedulerModal struct {
func newOrderSchedulerModalModal(l *load.Load, data *orderData) *orderSchedulerModal {
osm := &orderSchedulerModal{
Load: l,
Modal: l.Theme.ModalFloatTitle(values.String(values.StrOrderScheduler), l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle(values.String(values.StrOrderScheduler), l.IsMobileView(), nil),
exchangeSelector: NewExSelector(l, instantswap.FlypMe),
frequencySelector: NewFrequencySelector(l),
orderData: data,
Expand Down
2 changes: 1 addition & 1 deletion ui/page/exchange/order_settings_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type orderSettingsModal struct {
func newOrderSettingsModalModal(l *load.Load, data *orderData) *orderSettingsModal {
osm := &orderSettingsModal{
Load: l,
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSettings), l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle(values.String(values.StrSettings), l.IsMobileView(), nil),
orderData: data,
copyRedirect: l.Theme.NewClickable(false),
}
Expand Down
1 change: 0 additions & 1 deletion ui/page/governance/consensus_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ func (pg *ConsensusPage) HandleUserInteractions(gtx C) {
layout.Flexed(0.1, func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
if pg.copyRedirectURL.Clicked(gtx) {
// clipboard.WriteOp{Text: host}.Add(gtx.Ops)
gtx.Execute(clipboard.WriteCmd{Data: io.NopCloser(strings.NewReader(host))})
pg.Toast.Notify(values.String(values.StrCopied))
}
Expand Down
2 changes: 1 addition & 1 deletion ui/page/governance/governance_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewGovernancePage(l *load.Load) *Page {
pg := &Page{
Load: l,
MasterPage: app.NewMasterPage(GovernancePageID),
modal: l.Theme.ModalFloatTitle(values.String(values.StrSettings), l.IsMobileView()),
modal: l.Theme.ModalFloatTitle(values.String(values.StrSettings), l.IsMobileView(), nil),
tabCategoryList: l.Theme.NewClickableList(layout.Horizontal),
}

Expand Down
1 change: 0 additions & 1 deletion ui/page/governance/proposal_details_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ func (pg *ProposalDetails) HandleUserInteractions(gtx C) {
return layout.E.Layout(gtx, func(gtx C) D {
return layout.Inset{Top: values.MarginPadding7}.Layout(gtx, func(gtx C) D {
if pg.copyRedirectURL.Clicked(gtx) {
// clipboard.WriteOp{Text: host}.Add(gtx.Ops)
gtx.Execute(clipboard.WriteCmd{Data: io.NopCloser(strings.NewReader(host))})
pg.Toast.Notify(values.String(values.StrCopied))
}
Expand Down
2 changes: 1 addition & 1 deletion ui/page/governance/proposal_vote_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type voteModal struct {
func newVoteModal(l *load.Load, proposal *libwallet.Proposal) *voteModal {
vm := &voteModal{
Load: l,
Modal: l.Theme.ModalFloatTitle("input_vote_modal", l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle("input_vote_modal", l.IsMobileView(), nil),
proposal: proposal,
materialLoader: material.Loader(l.Theme.Base),
voteBtn: l.Theme.Button(values.String(values.StrVote)),
Expand Down
2 changes: 1 addition & 1 deletion ui/page/governance/wallet_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type WalletSelectorModal struct {
func newWalletSelectorModal(l *load.Load, currentSelectedWallet sharedW.Asset) *WalletSelectorModal {
asm := &WalletSelectorModal{
Load: l,
Modal: l.Theme.ModalFloatTitle("WalletSelectorModal", l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle("WalletSelectorModal", l.IsMobileView(), nil),
walletsList: l.Theme.NewClickableList(layout.Vertical),

currentSelectedWallet: currentSelectedWallet,
Expand Down
2 changes: 1 addition & 1 deletion ui/page/receive/receive_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewReceivePage(l *load.Load, wallet sharedW.Asset) *Page {

_, pg.infoButton = components.SubpageHeaderButtons(l)
if wallet == nil {
pg.modalLayout = l.Theme.ModalFloatTitle(values.String(values.StrReceive), pg.IsMobileView())
pg.modalLayout = l.Theme.ModalFloatTitle(values.String(values.StrReceive), pg.IsMobileView(), nil)
pg.GenericPageModal = pg.modalLayout.GenericPageModal
pg.initWalletSelectors() // will auto select the first wallet in the dropdown as pg.selectedWallet
} else {
Expand Down
2 changes: 1 addition & 1 deletion ui/page/send/manual_coin_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func NewManualCoinSelectionPage(l *load.Load, sendPage *Page) *ManualCoinSelecti
}

if sendPage.modalLayout != nil {
pg.modalLayout = l.Theme.ModalFloatTitle(values.String(values.StrCoinSelection), pg.IsMobileView())
pg.modalLayout = l.Theme.ModalFloatTitle(values.String(values.StrCoinSelection), pg.IsMobileView(), nil)
pg.GenericPageModal = pg.modalLayout.GenericPageModal
} else {
pg.GenericPageModal = app.NewGenericPageModal(ManualCoinSelectionPageID)
Expand Down
2 changes: 1 addition & 1 deletion ui/page/send/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func NewSendPage(l *load.Load, wallet sharedW.Asset) *Page {
// When this page is opened from the home page, the wallet to use is not
// specified. This page will be opened as a modal and a wallet selector
// will be displayed.
pg.modalLayout = l.Theme.ModalFloatTitle(values.String(values.StrSend), pg.IsMobileView())
pg.modalLayout = l.Theme.ModalFloatTitle(values.String(values.StrSend), pg.IsMobileView(), nil)
pg.GenericPageModal = pg.modalLayout.GenericPageModal
pg.initModalWalletSelector() // will auto select the first wallet in the dropdown as pg.selectedWallet
} else {
Expand Down
2 changes: 1 addition & 1 deletion ui/page/staking/stake_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ticketBuyerModal struct {
func newTicketBuyerModal(l *load.Load, wallet *dcr.Asset) *ticketBuyerModal {
tb := &ticketBuyerModal{
Load: l,
Modal: l.Theme.ModalFloatTitle("staking_modal", l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle("staking_modal", l.IsMobileView(), nil),

cancel: l.Theme.OutlineButton(values.String(values.StrCancel)),
saveSettingsBtn: l.Theme.Button(values.String(values.StrSave)),
Expand Down
3 changes: 1 addition & 2 deletions ui/preference/list_preference.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewListPreference(l *load.Load, preferenceKey, defaultValue string, items [

preferenceItems: items,
optionsRadioGroup: new(widget.Enum),
Modal: l.Theme.ModalFloatTitle("list_preference", l.IsMobileView()),
Modal: l.Theme.ModalFloatTitle("list_preference", l.IsMobileView(), nil),
redirectIcon: l.Theme.Icons.RedirectIcon,
viewWarningAction: l.Theme.NewClickable(true),
copyRedirectURL: l.Theme.NewClickable(false),
Expand Down Expand Up @@ -265,7 +265,6 @@ func (lp *ListPreferenceModal) Layout(gtx C) D {
layout.Flexed(0.1, func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
if lp.copyRedirectURL.Clicked(gtx) {
// clipboard.WriteOp{Text: host}.Add(gtx.Ops)
gtx.Execute(clipboard.WriteCmd{Data: io.NopCloser(strings.NewReader(host))})
lp.Toast.Notify(values.String(values.StrCopied))
}
Expand Down

0 comments on commit 6ad63be

Please sign in to comment.