Skip to content

Commit

Permalink
Merge branch 'master' into mb_transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeBoy committed Dec 15, 2023
2 parents bb7c3e2 + 828a886 commit d8fba76
Show file tree
Hide file tree
Showing 31 changed files with 893 additions and 623 deletions.
3 changes: 2 additions & 1 deletion ui/cryptomaterial/icon_gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Icons struct {
ContentAdd, NavigationCheck, NavigationMore, ActionCheckCircle, ActionInfo, NavigationArrowBack,
NavigationArrowForward, ActionCheck, NavigationCancel, NavMoreIcon,
ImageBrightness1, ContentClear, DropDownIcon, Cached, ContentRemove, SearchIcon, PlayIcon,
ActionSettings, ActionSwapHoriz, NavigationRefresh, ContentCopy *widget.Icon
ActionSettings, ActionSwapHoriz, ActionSwapVertical, NavigationRefresh, ContentCopy *widget.Icon

OverviewIcon, OverviewIconInactive, WalletIcon, WalletIconInactive, TradeIconActive, TradeIconInactive, MixerInactive, RedAlert, Alert,
ReceiveIcon, Transferred, TransactionsIcon, TransactionsIconInactive, SendIcon, MoreIcon, MoreIconInactive,
Expand Down Expand Up @@ -62,6 +62,7 @@ func (i *Icons) StandardMaterialIcons() *Icons {
i.PlayIcon = MustIcon(widget.NewIcon(icons.AVPlayArrow))
i.ActionSettings = MustIcon(widget.NewIcon(icons.ActionSettings))
i.ActionSwapHoriz = MustIcon(widget.NewIcon(icons.ActionSwapHoriz))
i.ActionSwapVertical = MustIcon(widget.NewIcon(icons.ActionSwapVert))
i.NavigationRefresh = MustIcon(widget.NewIcon(icons.NavigationRefresh))
i.ContentCopy = MustIcon(widget.NewIcon(icons.ContentContentPaste))

Expand Down
9 changes: 9 additions & 0 deletions ui/cryptomaterial/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ func (img *Image) LayoutSize(gtx C, size unit.Dp) D {
return i.Layout(gtx)
}

// LayoutTransform is used to scale images for mobile view.
func (img *Image) LayoutTransform(gtx C, isMobileView bool, size unit.Dp) D {
if isMobileView {
size = values.MarginPaddingTransform(isMobileView, size)
}

return img.LayoutSize(gtx, size)
}

func (img *Image) LayoutSize2(gtx C, width, height unit.Dp) D {
var dst *image.RGBA
img.layoutSize2Mtx.Lock()
Expand Down
5 changes: 5 additions & 0 deletions ui/cryptomaterial/modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gioui.org/unit"
"gioui.org/widget"
"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/ui/values"
)

type Modal struct {
Expand Down Expand Up @@ -118,6 +119,10 @@ func (m *Modal) Layout(gtx layout.Context, widgets []layout.Widget, width ...flo
maxWidth := float32(360)
if len(width) > 0 {
maxWidth = width[0]
} else if currentAppWidth := gtx.Metric.PxToDp(gtx.Constraints.Max.X); currentAppWidth <= values.StartMobileView {
// maxWidth must be less than currentAppWidth on mobile, so the
// modal does not touch the left and right edges of the screen.
maxWidth = 0.9 * float32(currentAppWidth)
}
gtx.Constraints.Max.X = gtx.Dp(unit.Dp(maxWidth))
inset := layout.Inset{
Expand Down
14 changes: 12 additions & 2 deletions ui/modal/create_password_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,26 @@ func (cm *CreatePasswordModal) passwordsMatch(editors ...*widget.Editor) bool {
func (cm *CreatePasswordModal) titleLayout() layout.Widget {
return func(gtx C) D {
t := cm.Theme.H6(cm.dialogTitle)
if cm.IsMobileView() {
t.TextSize = values.TextSize16
}
t.Font.Weight = font.SemiBold
return layout.Inset{Bottom: values.MarginPadding16}.Layout(gtx, t.Layout)
}
}

func (cm *CreatePasswordModal) Layout(gtx C) D {
return cm.Modal.Layout(gtx, cm.LayoutComponents(gtx))
return cm.Modal.Layout(gtx, cm.LayoutComponents())
}

func (cm *CreatePasswordModal) LayoutComponents(_ C) []layout.Widget {
func (cm *CreatePasswordModal) LayoutComponents() []layout.Widget {
btnTextSize := values.TextSize16
if cm.IsMobileView() {
btnTextSize = values.TextSize14
}
cm.btnNegative.TextSize = btnTextSize
cm.btnPositive.TextSize = btnTextSize

w := []layout.Widget{}

if cm.dialogTitle != "" {
Expand Down
13 changes: 13 additions & 0 deletions ui/modal/info_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ func (in *InfoModal) Layout(gtx layout.Context) D {

return layout.Inset{Top: values.MarginPaddingMinus5, Left: values.MarginPaddingMinus5}.Layout(gtx, func(gtx C) D {
in.checkbox.TextSize = values.TextSize14
if in.IsMobileView() {
in.checkbox.TextSize = values.TextSize12
}
in.checkbox.Color = in.Theme.Color.GrayText1
in.checkbox.IconColor = in.Theme.Color.Gray2
if in.checkbox.CheckBox.Value {
Expand Down Expand Up @@ -397,13 +400,23 @@ func (in *InfoModal) Layout(gtx layout.Context) D {
func (in *InfoModal) titleLayout() layout.Widget {
return func(gtx C) D {
t := in.Theme.H6(in.dialogTitle)
if in.IsMobileView() {
t.TextSize = values.TextSize16
}
t.Alignment = in.titleTextAlignment
t.Font.Weight = font.SemiBold
return in.titleAlignment.Layout(gtx, t.Layout)
}
}

func (in *InfoModal) actionButtonsLayout() layout.Widget {
btnTextSize := values.TextSize16
if in.IsMobileView() {
btnTextSize = values.TextSize14
}
in.btnNegative.TextSize = btnTextSize
in.btnPositive.TextSize = btnTextSize

return func(gtx C) D {
return in.btnAlignment.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
Expand Down
4 changes: 4 additions & 0 deletions ui/page/components/coinformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func formatBalance(gtx C, l *load.Load, amount string, mainTextSize unit.Sp, col
stopIndex = len(amount)
}

if startIndex > stopIndex || stopIndex <= 0 || stopIndex > len(amount) {
return D{}
}

mainText, subText, unitText := amount[:startIndex], amount[startIndex:stopIndex], amount[stopIndex:]

subTextSize := unit.Sp(float32(mainTextSize) * defaultScale)
Expand Down
40 changes: 40 additions & 0 deletions ui/page/components/coinformat_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package components

import (
"image/color"
"testing"

"gioui.org/op"
"github.com/crypto-power/cryptopower/ui/assets"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/load"
)

// TestFormatBalance currently only tests for panics.
func TestFormatBalance(t *testing.T) {
th := cryptomaterial.NewTheme(assets.FontCollection(), assets.DecredIcons, false)
ld := &load.Load{Theme: th}
gtx := C{Ops: new(op.Ops)}
tests := []struct {
name, amount string
}{{
name: "normal",
amount: "1 DCR",
}, {
name: "one d",
amount: "1 D",
}, {
name: "decimals",
amount: "1.1 DCR",
}, {
name: "blank amount",
}, {
name: "just the coin",
amount: "DCR",
}}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
formatBalance(gtx, ld, test.amount, 1, color.NRGBA{}, false, false)
})
}
}
34 changes: 34 additions & 0 deletions ui/page/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/libwallet/assets/dcr"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/instantswap"
"github.com/crypto-power/cryptopower/libwallet/txhelper"
libutils "github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
Expand Down Expand Up @@ -958,3 +959,36 @@ func IconButton(icon *widget.Icon, txt string, inset layout.Inset, th *cryptomat
})
}
}

// ConditionalFlexedRigidLayout decides whether to use layout.Rigid or layout.Flexed
func ConditionalFlexedRigidLayout(flexWeight float32, isMobileView bool, content layout.Widget) layout.FlexChild {
if isMobileView {
return layout.Rigid(content)
}
return layout.Flexed(flexWeight, content)
}

// GetServerIcon returns the icon for the provided server name.
func GetServerIcon(theme *cryptomaterial.Theme, serverName string) *cryptomaterial.Image {
switch serverName {
case instantswap.Changelly.ToString():
return theme.Icons.ChangellyIcon
case instantswap.ChangeNow.ToString():
return theme.Icons.ChangeNowIcon
case instantswap.CoinSwitch.ToString():
return theme.Icons.CoinSwitchIcon
case instantswap.FlypMe.ToString():
return theme.Icons.FlypMeIcon
case instantswap.GoDex.ToString():
return theme.Icons.GodexIcon
case instantswap.SimpleSwap.ToString():
return theme.Icons.SimpleSwapIcon
case instantswap.SwapZone.ToString():
return theme.Icons.SwapzoneIcon
case instantswap.Trocador.ToString():
return theme.Icons.TrocadorIcon

default:
return theme.Icons.AddExchange
}
}
90 changes: 50 additions & 40 deletions ui/page/components/order_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ import (

func OrderItemWidget(gtx C, l *load.Load, orderItem *instantswap.Order) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return cryptomaterial.LinearLayout{
Width: cryptomaterial.WrapContent,
Height: cryptomaterial.WrapContent,
Alignment: layout.Middle,
Border: cryptomaterial.Border{Radius: cryptomaterial.Radius(14)},
Margin: layout.Inset{
Top: values.MarginPadding8,
Bottom: values.MarginPadding10,
},
return cryptomaterial.Card{
Radius: cryptomaterial.Radius(14),
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
func(gtx C) D {
textSize16 := values.TextSizeTransform(l.IsMobileView(), values.TextSize16)
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Expand All @@ -35,10 +29,10 @@ func OrderItemWidget(gtx C, l *load.Load, orderItem *instantswap.Order) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Right: values.MarginPadding10,
Left: values.MarginPadding10,
Right: values.MarginPadding8,
}.Layout(gtx, func(gtx C) D {
return SetWalletLogo(l, gtx, libutils.AssetType(orderItem.FromCurrency), values.MarginPadding30)
size := values.MarginPaddingTransform(l.IsMobileView(), values.MarginPadding24)
return SetWalletLogo(l, gtx, libutils.AssetType(orderItem.FromCurrency), size)
})
}),
layout.Rigid(func(gtx C) D {
Expand All @@ -53,9 +47,9 @@ func OrderItemWidget(gtx C, l *load.Load, orderItem *instantswap.Order) D {
layout.Rigid(func(gtx C) D {
return layout.Inset{
Right: values.MarginPadding10,
Left: values.MarginPadding10,
}.Layout(gtx, func(gtx C) D {
return SetWalletLogo(l, gtx, libutils.AssetType(orderItem.ToCurrency), values.MarginPadding30)
size := values.MarginPaddingTransform(l.IsMobileView(), values.MarginPadding24)
return SetWalletLogo(l, gtx, libutils.AssetType(orderItem.ToCurrency), size)
})
}),
layout.Rigid(func(gtx C) D {
Expand All @@ -70,19 +64,34 @@ func OrderItemWidget(gtx C, l *load.Load, orderItem *instantswap.Order) D {
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Right: values.MarginPadding50,
}.Layout(gtx, func(gtx C) D {
return D{}
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(l.Theme.Label(values.TextSize16, orderItem.Status.String()).Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
layout.Rigid(func(gtx C) D {
return layout.Inset{
Right: values.MarginPadding5,
}.Layout(gtx, func(gtx C) D {
serverIcon := GetServerIcon(l.Theme, orderItem.ExchangeServer.Server.ToString())
if serverIcon == nil {
return D{}
}
return serverIcon.LayoutTransform(gtx, l.IsMobileView(), values.MarginPadding24)
})
}),
layout.Rigid(func(gtx C) D {
if l.IsMobileView() {
return D{}
}
return l.Theme.Label(textSize16, orderItem.ExchangeServer.Server.CapFirstLetter()).Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
return layout.Center.Layout(gtx, func(gtx C) D {
return UniformHorizontalInset(values.MarginPadding8).Layout(gtx, l.Theme.Icons.Dot.Layout8dp)
})
}),
layout.Rigid(l.Theme.Label(textSize16, orderItem.Status.String()).Layout),
layout.Rigid(func(gtx C) D {
statusLayout := statusIcon(l, orderItem.Status)
if statusLayout == nil {
return layout.Dimensions{}
return D{}
}
return layout.Inset{Left: values.MarginPadding6}.Layout(gtx, statusLayout)
}),
Expand All @@ -98,7 +107,10 @@ func OrderItemWidget(gtx C, l *load.Load, orderItem *instantswap.Order) D {
date := time.Unix(orderItem.CreatedAt, 0).Format("Jan 2, 2006")
timeSplit := time.Unix(orderItem.CreatedAt, 0).Format("03:04:05 PM")
createdAt := fmt.Sprintf("%v at %v", date, timeSplit)
timestamp := l.Theme.Label(values.TextSize16, createdAt)
if l.IsMobileView() {
createdAt = fmt.Sprintf("%v", date)
}
timestamp := l.Theme.Label(textSize16, createdAt)
timestamp.Color = l.Theme.Color.GrayText2
return timestamp.Layout(gtx)
}),
Expand All @@ -108,36 +120,34 @@ func OrderItemWidget(gtx C, l *load.Load, orderItem *instantswap.Order) D {
)
}),
)
}),
},
)
}

func statusIcon(l *load.Load, status api.Status) func(gtx C) layout.Dimensions {
func statusIcon(l *load.Load, status api.Status) func(gtx C) D {
switch status {
case api.OrderStatusCompleted:
return l.Theme.Icons.ConfirmIcon.Layout16dp
return func(gtx C) D {
return l.Theme.Icons.ConfirmIcon.LayoutTransform(gtx, l.IsMobileView(), values.MarginPadding16)
}
case api.OrderStatusCanceled, api.OrderStatusExpired, api.OrderStatusFailed:
return l.Theme.Icons.FailedIcon.Layout16dp
return func(gtx C) D {
return l.Theme.Icons.FailedIcon.LayoutTransform(gtx, l.IsMobileView(), values.MarginPadding16)
}
}
return nil
}

func LayoutNoOrderHistory(gtx C, l *load.Load, syncing bool) D {
return LayoutNoOrderHistoryWithMsg(gtx, l, syncing, values.String(values.StrNoOrders))
}

func LayoutNoOrderHistoryWithMsg(gtx C, l *load.Load, syncing bool, msg string) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
text := l.Theme.Body1(msg)
text := l.Theme.Label(values.TextSizeTransform(l.IsMobileView(), values.TextSize16), msg)
text.Color = l.Theme.Color.GrayText3
if syncing {
text = l.Theme.Body1(values.String(values.StrFetchingOrders))
text = l.Theme.Label(values.TextSizeTransform(l.IsMobileView(), values.TextSize16),
values.String(values.StrFetchingOrders))
}
return layout.Center.Layout(gtx, func(gtx C) D {
return layout.Inset{
Top: values.MarginPadding30,
Bottom: values.MarginPadding30,
}.Layout(gtx, text.Layout)
return UniformVeticalInset(values.MarginPadding30).Layout(gtx, text.Layout)
})
}

Expand Down
2 changes: 1 addition & 1 deletion ui/page/components/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ func LayoutOrderAmount(l *load.Load, gtx C, assetType string, amount float64) D
convertedAmountStr = "Unsupported asset type"
}

return l.Theme.Label(values.TextSize16, convertedAmountStr).Layout(gtx)
return l.Theme.Label(values.TextSizeTransform(l.IsMobileView(), values.TextSize16), convertedAmountStr).Layout(gtx)
}
2 changes: 1 addition & 1 deletion ui/page/dcrdex/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
var (
dp5 = values.MarginPadding5
dp8 = values.MarginPadding8
dp300 = values.DP300
dp300 = values.MarginPadding300
orderFormAndOrderBookWidth = (values.AppWidth / 2) - 40 // Minus 40 px to allow for margin between the order form and order book.
// orderFormAndOrderBookHeight is a an arbitrary height that accommodates
// the current order form elements and maxOrderDisplayedInOrderBook. Use
Expand Down
Loading

0 comments on commit d8fba76

Please sign in to comment.