From c9eefec9dd0e5010c0760585530b60965a5fefa2 Mon Sep 17 00:00:00 2001 From: Philemon Ukane Date: Fri, 26 Jan 2024 15:33:09 +0100 Subject: [PATCH] rebase changes and minor bug fixes Signed-off-by: Philemon Ukane --- go.mod | 6 +++--- go.sum | 4 ++-- libwallet/assets_manager.go | 2 +- libwallet/dex_interface.go | 1 + ui/page/dcrdex/market.go | 3 ++- ui/page/root/home_page.go | 26 +++++++++++++++----------- ui/values/localizable/en.go | 2 +- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 1b7b285ae..7f0c0031f 100644 --- a/go.mod +++ b/go.mod @@ -229,9 +229,9 @@ replace github.com/lib/pq => github.com/lib/pq v1.10.4 // github.com/btcsuite/btcwallet. replace github.com/btcsuite/btcwallet v0.16.10-0.20230706223227-037580c66b74 => github.com/btcsuite/btcwallet v0.16.9 -// github.com/ukane-philemon/dcrdex v0.0.0-20240123003034-3f8508fea639 is the -// latest dcrdex master plus 2 commits that adds methods required by +// github.com/ukane-philemon/dcrdex v0.0.0-20240126135833-b75c189e80a9 is the +// latest dcrdex master plus commits that adds methods required by // cryptopower. This should be updated when these PRs get merged. // 1. core: add ActiveOrders method to Core: https://github.com/decred/dcrdex/pull/2680 // 1. core: Add ExpiredBonds method to Core: https://github.com/decred/dcrdex/pull/2679 -replace decred.org/dcrdex v0.6.3 => github.com/ukane-philemon/dcrdex v0.0.0-20240123003034-3f8508fea639 +replace decred.org/dcrdex v0.6.3 => github.com/ukane-philemon/dcrdex v0.0.0-20240126135833-b75c189e80a9 diff --git a/go.sum b/go.sum index 626acdce1..64190564d 100644 --- a/go.sum +++ b/go.sum @@ -1578,8 +1578,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/ukane-philemon/dcrdex v0.0.0-20240123003034-3f8508fea639 h1:CWRRlD0T9X1DCkEXTMc2i+2I56qeydEkvYnoUethenw= -github.com/ukane-philemon/dcrdex v0.0.0-20240123003034-3f8508fea639/go.mod h1:2U+b4uDx4ZbAkk/pLaa2rv57G23XTyEe0Sw7Um+AdNE= +github.com/ukane-philemon/dcrdex v0.0.0-20240126135833-b75c189e80a9 h1:9k0cyp9qflL5PfHCTu8KMtjpBtpUEFu6vwAjZ8cd8mQ= +github.com/ukane-philemon/dcrdex v0.0.0-20240126135833-b75c189e80a9/go.mod h1:2U+b4uDx4ZbAkk/pLaa2rv57G23XTyEe0Sw7Um+AdNE= github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ultraware/funlen v0.0.3/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= diff --git a/libwallet/assets_manager.go b/libwallet/assets_manager.go index 10358a04d..f2f294ca8 100644 --- a/libwallet/assets_manager.go +++ b/libwallet/assets_manager.go @@ -954,7 +954,7 @@ func (mgr *AssetsManager) InitializeDEX(ctx context.Context) { mgr.dexcMtx.Unlock() go func() { - <-mgr.dexc.WaitForShutdown() + <-dexClient.WaitForShutdown() mgr.dexcMtx.Lock() mgr.dexc = nil mgr.dexcMtx.Unlock() diff --git a/libwallet/dex_interface.go b/libwallet/dex_interface.go index 4e432118f..df1e5b81b 100644 --- a/libwallet/dex_interface.go +++ b/libwallet/dex_interface.go @@ -30,6 +30,7 @@ type DEXClient interface { ExportSeed(pw []byte) ([]byte, error) SyncBook(dex string, base, quote uint32) (*orderbook.OrderBook, core.BookFeed, error) Orders(filter *core.OrderFilter) ([]*core.Order, error) + ActiveOrders() (map[string][]*core.Order, map[string][]*core.InFlightOrder, error) TradeAsync(pw []byte, form *core.TradeForm) (*core.InFlightOrder, error) WalletState(assetID uint32) *core.WalletState WalletSettings(assetID uint32) (map[string]string, error) diff --git a/ui/page/dcrdex/market.go b/ui/page/dcrdex/market.go index 668937a64..e23128c6a 100644 --- a/ui/page/dcrdex/market.go +++ b/ui/page/dcrdex/market.go @@ -269,6 +269,7 @@ func (pg *DEXMarketPage) OnNavigatedTo() { } if dexc.IsLoggedIn() { + go pg.refreshOrders() return // All good, return early. } @@ -1254,7 +1255,7 @@ func (pg *DEXMarketPage) openOrdersAndHistory(gtx C) D { return layout.Flex{Axis: horizontal, Spacing: layout.SpaceBetween, Alignment: layout.Middle}.Layout(gtx, pg.orderColumn(false, fmt.Sprintf("%s %s", values.String(ord.Type.String()), values.String(orderReader.SideString())), columnWidth, index), pg.orderColumn(false, ord.MarketID, columnWidth, index), - pg.orderColumn(false, components.TimeAgo(int64(ord.SubmitTime)), columnWidth, index), + pg.orderColumn(false, components.TimeAgo(int64(ord.SubmitTime/1000)), columnWidth, index), pg.orderColumn(false, orderReader.RateString(), columnWidth, index), pg.orderColumn(false, fmt.Sprintf("%s %s", orderReader.BaseQtyString(), strings.ToTitle(orderReader.BaseSymbol)), columnWidth, index), pg.orderColumn(false, fmt.Sprintf("%s%%", orderReader.FilledPercent()), columnWidth, index), diff --git a/ui/page/root/home_page.go b/ui/page/root/home_page.go index fa25090a5..286ddd7cc 100644 --- a/ui/page/root/home_page.go +++ b/ui/page/root/home_page.go @@ -6,6 +6,7 @@ import ( "sync/atomic" "time" + dexdb "decred.org/dcrdex/client/db" "gioui.org/io/key" "gioui.org/layout" "gioui.org/widget" @@ -150,6 +151,7 @@ func (hp *HomePage) OnNavigatedTo() { hp.ctx, hp.ctxCancel = context.WithCancel(context.TODO()) hp.initPageItems() + hp.initDEX() go hp.CalculateAssetsUSDBalance() if !hp.AssetsManager.DEXCInitialized() { @@ -173,7 +175,7 @@ func (hp *HomePage) OnNavigatedTo() { // initDEX initializes a new dex client if dex is not ready. func (hp *HomePage) initDEX() { - if hp.AssetsManager.DexcInitialized() { + if hp.AssetsManager.DEXCInitialized() { return // do nothing } @@ -194,16 +196,20 @@ func (hp *HomePage) initDEX() { log.Errorf("dexClient.ActiveOrders error: %w", err) } - expiredBonds := dexClient.ExpiredBonds() - if len(activeOrders) == 0 && len(expiredBonds) == 0 { - return // nothing to do. + var expiredBonds []*dexdb.Bond + xcs := dexClient.Exchanges() + for _, xc := range xcs { + if len(xc.Auth.ExpiredBonds) == 0 { + continue // nothing to do. + } + + expiredBonds = append(expiredBonds, xc.Auth.ExpiredBonds...) } dexPassEditor := hp.Theme.EditorPassword(new(widget.Editor), values.String(values.StrDexPassword)) dexPassEditor.Editor.SingleLine, dexPassEditor.IsRequired = true, true loginModal := modal.NewCustomModal(hp.Load). - Title(values.String(values.StrLoginWithDEXPassword)). UseCustomWidget(func(gtx C) D { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { @@ -228,15 +234,13 @@ func (hp *HomePage) initDEX() { walletsToSyncMap := make(map[uint32]*struct{}) for _, orders := range activeOrders { for _, ord := range orders { - walletsToSyncMap[ord.Base()] = &struct{}{} - walletsToSyncMap[ord.Quote()] = &struct{}{} + walletsToSyncMap[ord.BaseID] = &struct{}{} + walletsToSyncMap[ord.QuoteID] = &struct{}{} } } - for _, bonds := range expiredBonds { - for _, bond := range bonds { - walletsToSyncMap[bond.AssetID] = &struct{}{} - } + for _, bond := range expiredBonds { + walletsToSyncMap[bond.AssetID] = &struct{}{} } var walletsToSync []sharedW.Asset diff --git a/ui/values/localizable/en.go b/ui/values/localizable/en.go index b8a1ebe0b..215cf53c3 100644 --- a/ui/values/localizable/en.go +++ b/ui/values/localizable/en.go @@ -913,7 +913,7 @@ const EN = ` "availableBalance" = "Available Balance: %s" "missingDEXWalletMsg" = "No %s trade wallet found. Please add %s wallet to the DEX client to trade." "swapAndRedeemFee" = "swap - %s, redeem - %s" -"loginWithDEXPassword" = "Please login with your DEX password." +"loginWithDEXPassword" = "Login with your DEX password." "login" = "Login" "destinationWallet" = "Destination Wallet" "switchToMainnet" = "Switch to Mainnet"