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

multi: Bug fixes and code improvements #696

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
29 changes: 19 additions & 10 deletions ui/page/exchange/order_details_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package exchange
import (
"context"
"fmt"
"time"

"gioui.org/layout"
"gioui.org/widget/material"
Expand All @@ -13,6 +12,7 @@ import (
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/modal"
"github.com/crypto-power/cryptopower/ui/page/components"
"github.com/crypto-power/cryptopower/ui/values"
api "github.com/crypto-power/instantswap/instantswap"
Expand Down Expand Up @@ -78,13 +78,14 @@ func NewOrderDetailsPage(l *load.Load, order *instantswap.Order) *OrderDetailsPa

go func() {
pg.isRefreshing = true
pg.orderInfo, err = pg.getOrderInfo(pg.orderInfo.UUID)
orderInfo, err := pg.getOrderInfo(pg.orderInfo.UUID)
if err != nil {
pg.isRefreshing = false
log.Error(err)
pg.notifyError(err)
} else {
pg.orderInfo = orderInfo
}

time.Sleep(1 * time.Second)
pg.isRefreshing = false
}()

Expand All @@ -109,9 +110,14 @@ func (pg *OrderDetailsPage) HandleUserInteractions(gtx C) {
if pg.refreshBtn.Clicked(gtx) {
go func() {
pg.isRefreshing = true
pg.orderInfo, _ = pg.getOrderInfo(pg.orderInfo.UUID)
orderInfo, err := pg.getOrderInfo(pg.orderInfo.UUID)
if err != nil {
log.Error(err)
pg.notifyError(err)
} else {
pg.orderInfo = orderInfo
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i try to avoid if else statements when possible to enhance readability

orderInfo, err := pg.getOrderInfo(pg.orderInfo.UUID)
			if err != nil {
				log.Error(err)
				pg.notifyError(err)
                               return
			}

			pg.orderInfo = orderInfo
			


time.Sleep(1 * time.Second)
pg.isRefreshing = false
}()
}
Expand All @@ -121,8 +127,13 @@ func (pg *OrderDetailsPage) HandleUserInteractions(gtx C) {
}
}

func (pg *OrderDetailsPage) notifyError(err error) {
m := modal.NewErrorModal(pg.Load, values.String(values.StrUnexpectedError), modal.DefaultClickFunc()).Body(values.StringF(values.StrUnexpectedErrorMsgFmt, err))
pg.ParentWindow().ShowModal(m)
}

func (pg *OrderDetailsPage) Layout(gtx C) D {
container := func(gtx C) D {
return cryptomaterial.UniformPadding(gtx, func(gtx C) D {
sp := components.SubPage{
Load: pg.Load,
Title: values.String(values.StrOrderDetails),
Expand All @@ -133,9 +144,7 @@ func (pg *OrderDetailsPage) Layout(gtx C) D {
Body: pg.layout,
}
return sp.Layout(pg.ParentWindow(), gtx)
}

return cryptomaterial.UniformPadding(gtx, container)
})
}

func (pg *OrderDetailsPage) layout(gtx C) D {
Expand Down