Skip to content

Commit

Permalink
Add amount USD field and add logic for USD amount field, update fee r…
Browse files Browse the repository at this point in the history
…ate and fix some comments
  • Loading branch information
JustinBeBoy committed Dec 21, 2023
1 parent 0db953a commit 5cd1772
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 31 deletions.
5 changes: 1 addition & 4 deletions ui/page/components/fee_rate_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ func (fs *FeeRateSelector) Layout(gtx C) D {
},
}
return border.Layout(gtx, func(gtx C) D {
return layout.Inset{
Top: values.MarginPadding4,
Bottom: values.MarginPadding4,
}.Layout(gtx, fs.ratesEditor.Layout)
return VerticalInset(values.MarginPadding4).Layout(gtx, fs.ratesEditor.Layout)
})
}),
layout.Rigid(func(gtx C) D {
Expand Down
33 changes: 15 additions & 18 deletions ui/page/send/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ func (pg *Page) contentLayout(gtx C) D {
pageContent := []func(gtx C) D{
pg.sendLayout,
pg.recipientsLayout,
}

if pg.modalLayout == nil || (pg.modalLayout != nil && pg.selectedWallet.GetAssetType() != libutils.DCRWalletAsset) {
pageContent = append(pageContent, pg.advanceOptionsLayout)
pg.advanceOptionsLayout,
}

cgtx := gtx
Expand Down Expand Up @@ -222,20 +219,20 @@ func (pg *Page) coinSelectionSection(gtx C) D {
return inset.Layout(gtx, func(gtx C) D {
textLabel := pg.Theme.Label(values.TextSizeTransform(pg.IsMobileView(), values.TextSize16), selectedOption)
textLabel.Font.Weight = font.SemiBold
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(textLabel.Layout),
layout.Flexed(1, func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
return cryptomaterial.LinearLayout{
Width: cryptomaterial.WrapContent,
Height: cryptomaterial.WrapContent,
Orientation: layout.Horizontal,
Alignment: layout.Middle,
Clickable: pg.toCoinSelection,
}.Layout2(gtx, pg.Theme.Icons.ChevronRight.Layout20dp)
})
}),
)
return cryptomaterial.LinearLayout{
Width: cryptomaterial.WrapContent,
Height: cryptomaterial.WrapContent,
Orientation: layout.Horizontal,
Alignment: layout.Middle,
Clickable: pg.toCoinSelection,
}.Layout2(gtx, func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.Flex{Axis: layout.Horizontal, Spacing: layout.SpaceBetween}.Layout(gtx,
layout.Rigid(textLabel.Layout),
layout.Rigid(pg.Theme.Icons.ChevronRight.Layout20dp),
)
})

})
})
})
Expand Down
27 changes: 25 additions & 2 deletions ui/page/send/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ type Page struct {
selectedUTXOs selectedUTXOsInfo
}

type getPageFields func() pageFields

type pageFields struct {
exchangeRate float64
usdExchangeSet bool
isFetchingExchangeRate bool
}

type authoredTxData struct {
destinationAddress string
destinationAccount *sharedW.Account
Expand Down Expand Up @@ -119,7 +127,7 @@ func NewSendPage(l *load.Load, wallet sharedW.Asset) *Page {
}
pg.feeRateSelector = components.NewFeeRateSelector(l, callbackFunc).ShowSizeAndCost()

pg.recipient = newRecipient(l, pg.selectedWallet)
pg.recipient = newRecipient(l, pg.selectedWallet, pg.pageFields)
pg.recipient.onAddressChanged(func() {
pg.validateAndConstructTx()
})
Expand All @@ -129,12 +137,19 @@ func NewSendPage(l *load.Load, wallet sharedW.Asset) *Page {
})

pg.initializeAccountSelectors()

pg.initLayoutWidgets()

return pg
}

func (pg *Page) pageFields() pageFields {
return pageFields{
exchangeRate: pg.exchangeRate,
usdExchangeSet: pg.usdExchangeSet,
isFetchingExchangeRate: pg.isFetchingExchangeRate,
}
}

// initWalletSelector is used for the send modal for wallet selection.
func (pg *Page) initWalletSelector() {
// initialize wallet selector
Expand All @@ -145,6 +160,8 @@ func (pg *Page) initWalletSelector() {
// Source wallet picker
pg.sourceWalletSelector.WalletSelected(func(selectedWallet sharedW.Asset) {
pg.selectedWallet = selectedWallet
go load.GetAPIFeeRate(pg.selectedWallet)
go pg.feeRateSelector.UpdatedFeeRate(pg.selectedWallet)
pg.recipient.setDestinationAssetType(selectedWallet.GetAssetType())
pg.initializeAccountSelectors()
pg.recipient.resetDestinationAccountSelector()
Expand Down Expand Up @@ -237,6 +254,11 @@ func (pg *Page) OnNavigatedTo() {
if pg.selectedWallet.GetAssetType() == libUtil.BTCWalletAsset && pg.isFeerateAPIApproved() {
// This API call may take sometime to return. Call this before and cache
// results.
// go func() {
// load.GetAPIFeeRate(pg.selectedWallet)
// pg.feeRateSelector.UpdatedFeeRate(pg.selectedWallet)
// pg.ParentWindow().Reload()
// }()
go load.GetAPIFeeRate(pg.selectedWallet)
go pg.feeRateSelector.UpdatedFeeRate(pg.selectedWallet)
}
Expand Down Expand Up @@ -275,6 +297,7 @@ func (pg *Page) fetchExchangeRate() {
}

pg.exchangeRate = rate.LastTradePrice
pg.recipient.amount.setExchangeRate(pg.exchangeRate)
pg.validateAndConstructTx() // convert estimates to usd

pg.isFetchingExchangeRate = false
Expand Down
34 changes: 27 additions & 7 deletions ui/page/send/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ type recipient struct {

sendDestination *destination
amount *sendAmount

exchangeRate float64
isFetchingExchangeRate bool
usdExchangeSet bool
pageParam getPageFields
}

func newRecipient(l *load.Load, selectedWallet sharedW.Asset) *recipient {
func newRecipient(l *load.Load, selectedWallet sharedW.Asset, pageParam getPageFields) *recipient {
rp := &recipient{
Load: l,
selectedWallet: selectedWallet,
exchangeRate: -1,
pageParam: pageParam,
}

assetType := rp.selectedWallet.GetAssetType()
Expand Down Expand Up @@ -269,7 +266,30 @@ func (rp *recipient) contentWrapper(gtx C, title string, content layout.Widget)
}

func (rp *recipient) addressAndAmountlayout(gtx C) D {
return rp.contentWrapper(gtx, values.String(values.StrAmount), rp.amount.amountEditor.Layout)
widget := func(gtx C) D { return rp.amount.amountEditor.Layout(gtx) }
if rp.pageParam().exchangeRate != -1 && rp.pageParam().usdExchangeSet {
widget = func(gtx C) D {
return layout.Flex{
Axis: layout.Horizontal,
Alignment: layout.Middle,
}.Layout(gtx,
layout.Flexed(0.45, func(gtx C) D {
return rp.amount.amountEditor.Layout(gtx)
}),
layout.Flexed(0.1, func(gtx C) D {
return layout.Center.Layout(gtx, func(gtx C) D {
icon := rp.Theme.Icons.CurrencySwapIcon
return icon.Layout12dp(gtx)
})
}),
layout.Flexed(0.45, func(gtx C) D {
return rp.amount.usdAmountEditor.Layout(gtx)
}),
)
}

}
return rp.contentWrapper(gtx, values.String(values.StrAmount), widget)
}

func (rp *recipient) txLabelSection(gtx C) D {
Expand Down

0 comments on commit 5cd1772

Please sign in to comment.