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

DEX create password, DCR wallet and add server #676

Merged
merged 17 commits into from Dec 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions go.mod
Expand Up @@ -3,6 +3,7 @@ module github.com/planetdecred/godcr
go 1.16

require (
decred.org/dcrdex v0.0.0-20211109012459-ce823c3315bc
gioui.org v0.0.0-20211011183043-05f0f5c20f45
github.com/JohannesKaufmann/html-to-markdown v1.2.1
github.com/PuerkitoBio/goquery v1.6.1
Expand All @@ -21,12 +22,10 @@ require (
github.com/nxadm/tail v1.4.4
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/planetdecred/dcrlibwallet v1.6.2-0.20211019025657-3c6b25766450
github.com/planetdecred/dcrlibwallet v1.6.2-0.20211208155954-3ba1589ff83f
github.com/yeqown/go-qrcode v1.5.1
golang.org/x/exp v0.0.0-20210722180016-6781d3edade3
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
golang.org/x/text v0.3.7
)

replace github.com/decred/dcrdata/txhelpers/v4 => github.com/decred/dcrdata/txhelpers/v4 v4.0.0-20200108145420-f82113e7e212
397 changes: 336 additions & 61 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -65,7 +65,7 @@ func main() {

win, appWindow, err := ui.CreateWindow(wal)
if err != nil {
fmt.Printf("Could not initialize window: %s\ns", err)
log.Errorf("Could not initialize window: %s\ns", err)
return
}

Expand Down
Binary file added ui/assets/decredicons/dex_btc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/assets/decredicons/dex_dcr.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/assets/decredicons/dex_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/assets/decredicons/dex_icon_inactive.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions ui/load/load.go
Expand Up @@ -59,6 +59,8 @@ type Icons struct {
TicketExpiredIcon,
TicketRevokedIcon,
TicketUnminedIcon *decredmaterial.Image

DexIcon, DexIconInactive, BTC, DCR *decredmaterial.Image
}

type Load struct {
Expand Down Expand Up @@ -115,6 +117,7 @@ func NewLoad() (*Load, error) {
if th == nil {
return nil, errors.New("unexpected error while loading theme")
}

l := &Load{
Theme: th,
Icons: icons,
Expand All @@ -134,6 +137,9 @@ func (l *Load) RefreshTheme() {
l.Theme.SwitchDarkMode(isDarkModeOn, assets.DecredIcons)
l.RefreshWindow()
}
func (l *Load) Dexc() *dcrlibwallet.DexClient {
return l.WL.MultiWallet.DexClient()
}
Sirmorrison marked this conversation as resolved.
Show resolved Hide resolved

func loadIcons() Icons {
decredIcons := assets.DecredIcons
Expand Down Expand Up @@ -222,6 +228,11 @@ func loadIcons() Icons {
GovernanceInactiveIcon: decredmaterial.NewImage(decredIcons["governance_inactive"]),
LogoDarkMode: decredmaterial.NewImage(decredIcons["logo_darkmode"]),
TimerDarkMode: decredmaterial.NewImage(decredIcons["timer_dm"]),

DexIcon: decredmaterial.NewImage(decredIcons["dex_icon"]),
DexIconInactive: decredmaterial.NewImage(decredIcons["dex_icon_inactive"]),
BTC: decredmaterial.NewImage(decredIcons["dex_btc"]),
DCR: decredmaterial.NewImage(decredIcons["dex_dcr"]),
}
return ic
}
13 changes: 12 additions & 1 deletion ui/modal/create_password_modal.go
Expand Up @@ -37,6 +37,7 @@ type CreatePasswordModal struct {
dialogTitle string
randomID string
serverError string
description string

materialLoader material.LoaderStyle

Expand Down Expand Up @@ -142,6 +143,11 @@ func (cm *CreatePasswordModal) SetCancelable(min bool) *CreatePasswordModal {
return cm
}

func (cm *CreatePasswordModal) SetDescription(description string) *CreatePasswordModal {
cm.description = description
return cm
}

func (cm *CreatePasswordModal) SetError(err string) {
cm.serverError = err
}
Expand Down Expand Up @@ -250,6 +256,12 @@ func (cm *CreatePasswordModal) Layout(gtx layout.Context) D {
t.Font.Weight = text.SemiBold
return t.Layout(gtx)
},
func(gtx C) D {
if cm.description != "" {
return cm.Theme.Body2(cm.description).Layout(gtx)
}
return layout.Dimensions{}
},
func(gtx C) D {
if cm.serverError != "" {
t := cm.Theme.Body2(cm.serverError)
Expand All @@ -258,7 +270,6 @@ func (cm *CreatePasswordModal) Layout(gtx layout.Context) D {
}
return layout.Dimensions{}
},

func(gtx C) D {
if cm.walletNameEnabled {
return cm.walletName.Layout(gtx)
Expand Down
12 changes: 12 additions & 0 deletions ui/modal/password_modal.go
Expand Up @@ -23,6 +23,7 @@ type PasswordModal struct {
password decredmaterial.Editor

dialogTitle string
description string

isLoading bool
isCancelable bool
Expand Down Expand Up @@ -87,6 +88,11 @@ func (pm *PasswordModal) Title(title string) *PasswordModal {
return pm
}

func (pm *PasswordModal) Description(description string) *PasswordModal {
pm.description = description
return pm
}

func (pm *PasswordModal) Hint(hint string) *PasswordModal {
pm.password.Hint = hint
return pm
Expand Down Expand Up @@ -167,6 +173,11 @@ func (pm *PasswordModal) Layout(gtx layout.Context) D {
return t.Layout(gtx)
}

description := func(gtx C) D {
t := pm.Theme.Body2(pm.description)
return t.Layout(gtx)
}

editor := func(gtx C) D {
return pm.password.Layout(gtx)
}
Expand Down Expand Up @@ -200,6 +211,7 @@ func (pm *PasswordModal) Layout(gtx layout.Context) D {
var w []layout.Widget

w = append(w, title)
w = append(w, description)
w = append(w, editor)
w = append(w, actionButtons)

Expand Down
11 changes: 11 additions & 0 deletions ui/page/components/components.go
Expand Up @@ -663,3 +663,14 @@ func TranslateErr(err error) string {

return err.Error()
}

// CoinImageBySymbol returns image widget for supported asset coins.
func CoinImageBySymbol(icons *load.Icons, coinName string) *decredmaterial.Image {
switch strings.ToLower(coinName) {
case "btc":
return icons.BTC
case "dcr":
return icons.DCR
}
return nil
}
26 changes: 26 additions & 0 deletions ui/page/debug_page.go
Expand Up @@ -2,8 +2,10 @@ package page

import (
"gioui.org/layout"

"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/load"
"github.com/planetdecred/godcr/ui/modal"
"github.com/planetdecred/godcr/ui/page/components"
"github.com/planetdecred/godcr/ui/values"
)
Expand Down Expand Up @@ -49,6 +51,14 @@ func NewDebugPage(l *load.Load) *DebugPage {
}
pg.list.Radius = decredmaterial.Radius(14)

// Add a "Reset DEX Client" option.
pg.debugItems = append(pg.debugItems, debugItem{
text: "Reset DEX Client",
action: func() {
pg.resetDexData()
},
})

pg.backButton, _ = components.SubpageHeaderButtons(l)

return pg
Expand Down Expand Up @@ -129,3 +139,19 @@ func (pg *DebugPage) Layout(gtx C) D {
}
return components.UniformPadding(gtx, container)
}

func (pg *DebugPage) resetDexData() {
// Show confirm modal before resetting dex client data.
confirmModal := modal.NewInfoModal(pg.Load).
Title("Confirm DEX Client Reset").
Body("You may need to restart godcr before you can use the DEX again. Proceed?").
NegativeButton(values.String(values.StrCancel), func() {}).
PositiveButton("Reset DEX Client", func() {
if pg.Dexc().Reset() {
Sirmorrison marked this conversation as resolved.
Show resolved Hide resolved
song50119 marked this conversation as resolved.
Show resolved Hide resolved
pg.Toast.Notify("DEX client data reset complete.")
} else {
pg.Toast.NotifyError("DEX client data reset failed. Check the logs.")
}
})
pg.ShowModal(confirmModal)
}