Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
remove token container, image & symbol in balance container instead
Browse files Browse the repository at this point in the history
  • Loading branch information
g45t345rt committed Sep 23, 2023
1 parent ca3559b commit 9d88032
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 83 deletions.
2 changes: 1 addition & 1 deletion pages/wallet/balance_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func (d *DisplayBalance) Layout(gtx layout.Context, th *material.Theme) layout.D

return lbl.Layout(gtx)
}),
layout.Rigid(layout.Spacer{Height: unit.Dp(5)}.Layout),
//layout.Rigid(layout.Spacer{Height: unit.Dp(5)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
Expand Down
124 changes: 52 additions & 72 deletions pages/wallet/sc_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type PageSCToken struct {
buttonCopySCID *components.Button

token *wallet_manager.Token
tokenImage *prefabs.ImageHoverClick
scIdEditor *widget.Editor

list *widget.List
Expand All @@ -86,8 +85,6 @@ func NewPageSCToken() *PageSCToken {
list := new(widget.List)
list.Axis = layout.Vertical

image := prefabs.NewImageHoverClick()

scIdEditor := new(widget.Editor)
scIdEditor.WrapPolicy = text.WrapGraphemes
scIdEditor.ReadOnly = true
Expand Down Expand Up @@ -115,7 +112,6 @@ func NewPageSCToken() *PageSCToken {
animationLeave: animationLeave,

buttonOpenMenu: buttonOpenMenu,
tokenImage: image,
scIdEditor: scIdEditor,
sendReceiveButtons: sendReceiveButtons,
tabBars: tabBars,
Expand Down Expand Up @@ -439,10 +435,6 @@ func (p *PageSCToken) Layout(gtx layout.Context, th *material.Theme) layout.Dime
}()
}

if p.tokenImage.Clickable.Clicked() {
image_modal.Instance.Open(p.token.Name, p.tokenImage.Image.Src)
}

{
changed, tab := p.txBar.Changed()
if changed {
Expand Down Expand Up @@ -484,43 +476,6 @@ func (p *PageSCToken) Layout(gtx layout.Context, th *material.Theme) layout.Dime
listStyle := material.List(th, p.list)
listStyle.AnchorStrategy = material.Overlay

widgets = append(widgets, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
r := op.Record(gtx.Ops)
dims := layout.UniformInset(unit.Dp(15)).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{
Axis: layout.Horizontal,
Alignment: layout.Middle,
}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
p.tokenImage.Image.Src = p.token.LoadImageOp()
gtx.Constraints.Max.X = gtx.Dp(50)
gtx.Constraints.Max.Y = gtx.Dp(50)
return p.tokenImage.Layout(gtx)
}),
layout.Rigid(layout.Spacer{Width: unit.Dp(10)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
editor := material.Editor(th, p.scIdEditor, "")
editor.TextSize = unit.Sp(14)
return editor.Layout(gtx)
}),
)
})
c := r.Stop()

paint.FillShape(gtx.Ops, theme.Current.ListBgColor,
clip.UniformRRect(
image.Rectangle{Max: dims.Size},
gtx.Dp(15),
).Op(gtx.Ops))

c.Add(gtx.Ops)
return dims
}),
)
})

switch p.token.StandardType {
case sc.G45_AT_TYPE, sc.G45_FAT_TYPE, sc.G45_NFT_TYPE:
widgets = append(widgets, func(gtx layout.Context) layout.Dimensions {
Expand Down Expand Up @@ -626,6 +581,7 @@ type BalanceContainer struct {
token *wallet_manager.Token
balanceEditor *widget.Editor
buttonHideBalance *ButtonHideBalance
tokenImage *prefabs.ImageHoverClick
}

func NewBalanceContainer() *BalanceContainer {
Expand All @@ -637,6 +593,7 @@ func NewBalanceContainer() *BalanceContainer {
return &BalanceContainer{
buttonHideBalance: buttonHideBalance,
balanceEditor: balanceEditor,
tokenImage: prefabs.NewImageHoverClick(),
}
}

Expand All @@ -645,6 +602,10 @@ func (b *BalanceContainer) SetToken(token *wallet_manager.Token) {
}

func (b *BalanceContainer) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions {
if b.tokenImage.Clickable.Clicked() {
image_modal.Instance.Open(b.token.Name, b.tokenImage.Image.Src)
}

return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
r := op.Record(gtx.Ops)
Expand All @@ -658,37 +619,56 @@ func (b *BalanceContainer) Layout(gtx layout.Context, th *material.Theme) layout
Axis: layout.Vertical,
}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
lbl := material.Label(th, unit.Sp(14), lang.Translate("Available Balance"))
txt := utils.ReduceTxId(b.token.SCID)
if b.token.Symbol.String != "" {
txt += fmt.Sprintf(" (%s)", b.token.Symbol.String)
}

lbl := material.Label(th, unit.Sp(14), txt)
lbl.Color = theme.Current.TextMuteColor
return lbl.Layout(gtx)
}),
layout.Rigid(layout.Spacer{Height: unit.Dp(5)}.Layout),
//layout.Rigid(layout.Spacer{Height: unit.Dp(5)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
wallet := wallet_manager.OpenedWallet
balance, _ := wallet.Memory.Get_Balance_scid(b.token.GetHash())
amount := utils.ShiftNumber{Number: balance, Decimals: int(b.token.Decimals)}.Format()

if b.balanceEditor.Text() != amount {
b.balanceEditor.SetText(amount)
}

r := op.Record(gtx.Ops)
balanceEditor := material.Editor(th, b.balanceEditor, "")
balanceEditor.TextSize = unit.Sp(34)
balanceEditor.Font.Weight = font.Bold

dims := balanceEditor.Layout(gtx)
c := r.Stop()

if settings.App.HideBalance {
paint.FillShape(gtx.Ops, theme.Current.HideBalanceBgColor, clip.Rect{
Max: dims.Size,
}.Op())
} else {
c.Add(gtx.Ops)
}

return dims
return layout.Flex{
Axis: layout.Horizontal,
Alignment: layout.Middle,
}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
b.tokenImage.Image.Src = b.token.LoadImageOp()
gtx.Constraints.Max.X = gtx.Dp(35)
gtx.Constraints.Max.Y = gtx.Dp(35)
return b.tokenImage.Layout(gtx)
}),
layout.Rigid(layout.Spacer{Width: unit.Dp(10)}.Layout),
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
wallet := wallet_manager.OpenedWallet
balance, _ := wallet.Memory.Get_Balance_scid(b.token.GetHash())
amount := utils.ShiftNumber{Number: balance, Decimals: int(b.token.Decimals)}.Format()

if b.balanceEditor.Text() != amount {
b.balanceEditor.SetText(amount)
}

r := op.Record(gtx.Ops)
balanceEditor := material.Editor(th, b.balanceEditor, "")
balanceEditor.TextSize = unit.Sp(34)
balanceEditor.Font.Weight = font.Bold

dims := balanceEditor.Layout(gtx)
c := r.Stop()

if settings.App.HideBalance {
paint.FillShape(gtx.Ops, theme.Current.HideBalanceBgColor, clip.Rect{
Max: dims.Size,
}.Op())
} else {
c.Add(gtx.Ops)
}

return dims
}),
)
}),
)
}),
Expand Down
11 changes: 2 additions & 9 deletions pages/wallet/send_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type PageSendForm struct {
buttonOptions *components.Button
buttonSetMax *components.Button
balanceContainer *BalanceContainer
tokenContainer *TokenContainer
walletAddrInput *WalletAddrInput

token *wallet_manager.Token
Expand Down Expand Up @@ -119,7 +118,6 @@ func NewPageSendForm() *PageSendForm {
buttonSetMax.Style.Font.Weight = font.Bold

balanceContainer := NewBalanceContainer()
tokenContainer := NewTokenContainer()
walletAddrInput := NewWalletAddrInput()

return &PageSendForm{
Expand All @@ -132,7 +130,6 @@ func NewPageSendForm() *PageSendForm {
buttonOptions: buttonOptions,
buttonSetMax: buttonSetMax,
balanceContainer: balanceContainer,
tokenContainer: tokenContainer,
walletAddrInput: walletAddrInput,
}
}
Expand All @@ -158,7 +155,6 @@ func (p *PageSendForm) Leave() {
func (p *PageSendForm) SetToken(token *wallet_manager.Token) {
p.token = token
p.balanceContainer.SetToken(p.token)
p.tokenContainer.SetToken(p.token)
}

func (p *PageSendForm) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions {
Expand Down Expand Up @@ -217,9 +213,6 @@ func (p *PageSendForm) Layout(gtx layout.Context, th *material.Theme) layout.Dim
}

widgets := []layout.Widget{
func(gtx layout.Context) layout.Dimensions {
return p.tokenContainer.Layout(gtx, th)
},
func(gtx layout.Context) layout.Dimensions {
return p.balanceContainer.Layout(gtx, th)
},
Expand Down Expand Up @@ -272,11 +265,11 @@ func (p *PageSendForm) Layout(gtx layout.Context, th *material.Theme) layout.Dim
listStyle.AnchorStrategy = material.Overlay

if p.txtAmount.Input.Clickable.Clicked() {
p.list.ScrollTo(2)
p.list.ScrollTo(1)
}

if p.walletAddrInput.txtWalletAddr.Clickable.Clicked() {
p.list.ScrollTo(3)
p.list.ScrollTo(2)
}

return listStyle.Layout(gtx, len(widgets), func(gtx layout.Context, index int) layout.Dimensions {
Expand Down
2 changes: 1 addition & 1 deletion pages/wallet/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ func NewTxTransfers() *TxTransfers {
func (t *TxTransfers) Load(entry wallet_manager.Entry) {
wallet := wallet_manager.OpenedWallet

t.items = make([]*TxTransferItem, 0)
if entry.TXID != "" {
entries := wallet.GetEntries(nil, wallet_manager.GetEntriesParams{
TXID: sql.NullString{String: entry.TXID, Valid: true},
})

t.items = make([]*TxTransferItem, 0)
for _, entry := range entries {
t.items = append(t.items, NewTxTransferItem(entry))
}
Expand Down

0 comments on commit 9d88032

Please sign in to comment.