Skip to content

Commit

Permalink
multi: display active order error for active dex orders on shutdown (#…
Browse files Browse the repository at this point in the history
…686)

Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
  • Loading branch information
ukane-philemon authored Oct 18, 2024
1 parent 820b88f commit 158a43c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ui/values/localizable/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ const EN = `
"destinationModalInfo" = "A new receiving address will be automatically generated within the selected account."
"destinationWalletNotSynced" = "Destination wallet is not synced"
"dex" = "DEX"
"activeDexOrderError" = "Oops, you have an active dex order. Are you sure you want to proceed with shutdown?"
"dexError" = "DCRDEX Error"
"dexDataReset" = "DEX client data reset complete."
"dexDataResetFalse" = "DEX client data reset failed. Check the logs."
"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."
Expand Down
2 changes: 2 additions & 0 deletions ui/values/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ const (
StrDestinationWalletNotSynced = "destinationWalletNotSynced"
StrDEX = "dex"
StrDexContent = "dexContent"
StrDexError = "dexError"
StrActiveDexOrderError = "activeDexOrderError"
StrDexDataReset = "dexDataReset"
StrDexDataResetFalse = "dexDataResetFalse"
StrTradeSettingsMsg = "tradeSettingsMsg"
Expand Down
62 changes: 50 additions & 12 deletions ui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/crypto-power/cryptopower/ui/assets"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/load"
"github.com/crypto-power/cryptopower/ui/modal"
"github.com/crypto-power/cryptopower/ui/notification"
"github.com/crypto-power/cryptopower/ui/page"
"github.com/crypto-power/cryptopower/ui/values"
Expand Down Expand Up @@ -173,19 +174,56 @@ func (win *Window) HandleEvents() {

var isShuttingDown bool

displayShutdownPage := func() {
displayShutdownPage := func(windowAlreadyDestroyed bool) {
if isShuttingDown {
return
}
isShuttingDown = true

log.Info("...Initiating the app shutdown protocols...")
// clear all stack and display the shutdown page as backend processes are
// terminating.
win.navigator.ClearStackAndDisplay(page.NewStartPage(win.ctx, win.load, true))
win.ctxCancel()
// Trigger the backend processes shutdown.
win.Quit <- struct{}{}

doShutdown := func() {
isShuttingDown = true

log.Info("...Initiating the app shutdown protocols...")

// clear all stack and display the shutdown page as backend processes are
// terminating.
win.navigator.ClearStackAndDisplay(page.NewStartPage(win.ctx, win.load, true))
win.ctxCancel()

// Trigger the backend processes shutdown.
win.Quit <- struct{}{}
}

if !win.load.AssetsManager.DEXCInitialized() || windowAlreadyDestroyed {
doShutdown()
return
}

ord, inflight, err := win.load.AssetsManager.DexClient().ActiveOrders()
if err != nil {
log.Errorf("AssetsManager.DexClient().ActiveOrders error: %v", err)
return
}

if len(ord) == 0 && len(inflight) == 0 {
doShutdown()
return
}

// User has active orders, show an error modal and only allow shutdown
// if user allows it.
m := modal.NewErrorModal(win.load, values.String(values.StrDexError), modal.DefaultClickFunc())
m.SetPositiveButtonText(values.String(values.StrYes)).SetPositiveButtonCallback(func(_ bool, _ *modal.InfoModal) bool {
doShutdown()
return true
}).
SetNegativeButtonText(values.String(values.StrNo)).
SetNegativeButtonCallback(func() {
win.navigator.Display(win.navigator.CurrentPage())
}).
SetCancelable(true).
Body(values.String(values.StrActiveDexOrderError))

win.navigator.ShowModal(m)
}

// Create window chan event and listen events from window event
Expand All @@ -207,15 +245,15 @@ func (win *Window) HandleEvents() {
// ready first.
select {
case <-done:
displayShutdownPage()
displayShutdownPage(false)
case <-win.IsShutdown:
// backend processes shutdown is complete, exit UI process too.
_ = win.load.Device.SetScreenAwake(false)
return
case e := <-events:
switch evt := e.(type) {
case giouiApp.DestroyEvent:
displayShutdownPage()
displayShutdownPage(true)
acks <- struct{}{}
case giouiApp.FrameEvent:
ops := win.handleFrameEvent(evt)
Expand Down

0 comments on commit 158a43c

Please sign in to comment.