Skip to content

Commit

Permalink
Use dcrlibwallet directly in overview and transactions page (planetde…
Browse files Browse the repository at this point in the history
…cred#475)

* Start sync from main page and update overview from sync notifications

* overview: fetch transactions directly from dcrlibwallet
- add changeFragment function to main page for adding new page instances
- pass transaction object to transaction details page directly

* transactions: fetch, filter and sort transactions using dcrlibwallet

* Implement new transactions notification in overview page

* Implement sync notification in transactions page

* Add wallets parameter to wallet drop down selector

* Add OnResume lifecycle callback to pages

* overview: load transactions in OnResume

* Use latest dcrlibwallet version (f776ef6)

* Use wallet.AccountName to fetch tx input account
-  simplify tx output/input code
  • Loading branch information
beansgum committed Jun 19, 2021
1 parent 78a53eb commit ce16b9b
Show file tree
Hide file tree
Showing 40 changed files with 743 additions and 519 deletions.
5 changes: 4 additions & 1 deletion go.mod
Expand Up @@ -25,4 +25,7 @@ require (
golang.org/x/text v0.3.3
)

replace github.com/decred/dcrdata/txhelpers/v4 => github.com/decred/dcrdata/txhelpers/v4 v4.0.0-20200108145420-f82113e7e212
replace (
github.com/decred/dcrdata/txhelpers/v4 => github.com/decred/dcrdata/txhelpers/v4 v4.0.0-20200108145420-f82113e7e212
github.com/planetdecred/dcrlibwallet => github.com/planetdecred/dcrlibwallet v1.6.1-0.20210618124747-f776ef63322f
)
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -711,6 +711,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/planetdecred/dcrlibwallet v1.6.0 h1:Bn5es2IKoQkXSYSg1cD2h2Z3ndWkf7IiaU7aTqtvOcU=
github.com/planetdecred/dcrlibwallet v1.6.0/go.mod h1:gM1g2wCXwmLxICoV26M3rtCiyat7/YiIok+C2apx3pY=
github.com/planetdecred/dcrlibwallet v1.6.1-0.20210618124747-f776ef63322f h1:lgVy3wX3Y6dkEFZ4YjVyibegW/B7Rnn0W4m8lpTsOkA=
github.com/planetdecred/dcrlibwallet v1.6.1-0.20210618124747-f776ef63322f/go.mod h1:gM1g2wCXwmLxICoV26M3rtCiyat7/YiIok+C2apx3pY=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
4 changes: 4 additions & 0 deletions ui/about_page.go
Expand Up @@ -51,6 +51,10 @@ func AboutPage(common *pageCommon) Page {
return pg
}

func (pg *aboutPage) OnResume() {

}

func (pg *aboutPage) Layout(gtx layout.Context) layout.Dimensions {
body := func(gtx C) D {
page := SubPage{
Expand Down
4 changes: 4 additions & 0 deletions ui/account_details_page.go
Expand Up @@ -47,6 +47,10 @@ func AcctDetailsPage(common *pageCommon) Page {
return pg
}

func (pg *acctDetailsPage) OnResume() {

}

func (pg *acctDetailsPage) Layout(gtx layout.Context) layout.Dimensions {
common := pg.common

Expand Down
56 changes: 27 additions & 29 deletions ui/components.go
Expand Up @@ -30,7 +30,7 @@ const (

type (
TransactionRow struct {
transaction wallet.Transaction
transaction dcrlibwallet.Transaction
index int
showBadge bool
}
Expand Down Expand Up @@ -82,11 +82,13 @@ func transactionRow(gtx layout.Context, common *pageCommon, row TransactionRow)
directionIconTopMargin = values.MarginPadding0
}

wal := common.multiWallet.WalletWithID(row.transaction.WalletID)

return layout.Inset{Top: values.MarginPadding16}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
icon := common.icons.receiveIcon
if row.transaction.Txn.Direction == dcrlibwallet.TxDirectionSent {
if row.transaction.Direction == dcrlibwallet.TxDirectionSent {
icon = common.icons.sendIcon
}
icon.Scale = 1.0
Expand Down Expand Up @@ -128,11 +130,11 @@ func transactionRow(gtx layout.Context, common *pageCommon, row TransactionRow)
return layout.Inset{Left: values.MarginPadding16}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return common.layoutBalance(gtx, row.transaction.Balance, true)
return common.layoutBalance(gtx, dcrutil.Amount(row.transaction.Amount).String(), true)
}),
layout.Rigid(func(gtx C) D {
if row.showBadge {
return walletLabel(gtx, common, row.transaction.WalletName)
return walletLabel(gtx, common, wal.Name)
}
return layout.Dimensions{}
}),
Expand All @@ -144,15 +146,12 @@ func transactionRow(gtx layout.Context, common *pageCommon, row TransactionRow)
layout.Rigid(func(gtx C) D {
return layout.Inset{Right: values.MarginPadding8}.Layout(gtx,
func(gtx C) D {
s := formatDateOrTime(row.transaction.Txn.Timestamp)
if row.transaction.Status != "confirmed" {
s = row.transaction.Status
}
status := common.theme.Body1(s)
if row.transaction.Status != "confirmed" {
status := common.theme.Body1("pending")
if txConfirmations(common, row.transaction) <= 1 {
status.Color = common.theme.Color.Gray5
} else {
status.Color = common.theme.Color.Gray4
status.Text = formatDateOrTime(row.transaction.Timestamp)
}
status.Alignment = text.Middle
return status.Layout(gtx)
Expand All @@ -161,7 +160,7 @@ func transactionRow(gtx layout.Context, common *pageCommon, row TransactionRow)
layout.Rigid(func(gtx C) D {
return layout.Inset{Right: values.MarginPadding16}.Layout(gtx, func(gtx C) D {
statusIcon := common.icons.confirmIcon
if row.transaction.Status != "confirmed" {
if txConfirmations(common, row.transaction) <= 1 {
statusIcon = common.icons.pendingIcon
}
statusIcon.Scale = 1.0
Expand All @@ -179,6 +178,15 @@ func transactionRow(gtx layout.Context, common *pageCommon, row TransactionRow)
})
}

func txConfirmations(common *pageCommon, transaction dcrlibwallet.Transaction) int32 {
if transaction.BlockHeight != -1 {
// TODO
return (common.multiWallet.WalletWithID(transaction.WalletID).GetBestBlock() - transaction.BlockHeight) + 1
}

return 0
}

// walletLabel displays the wallet which a transaction belongs to. It is only displayed on the overview page when there
// are transactions from multiple wallets
func walletLabel(gtx layout.Context, c *pageCommon, walletName string) D {
Expand Down Expand Up @@ -967,26 +975,16 @@ func (page *pageCommon) handleToast() {

// createOrUpdateWalletDropDown check for len of wallets to create dropDown,
// also update the list when create, update, delete a wallet.
func (page *pageCommon) createOrUpdateWalletDropDown(dwn **decredmaterial.DropDown) {
init := func() {
var walletDropDownItems []decredmaterial.DropDownItem
for i := range page.info.Wallets {
item := decredmaterial.DropDownItem{
Text: page.info.Wallets[i].Name,
Icon: page.icons.walletIcon,
}
walletDropDownItems = append(walletDropDownItems, item)
func (page *pageCommon) createOrUpdateWalletDropDown(dwn **decredmaterial.DropDown, wallets []*dcrlibwallet.Wallet) {
var walletDropDownItems []decredmaterial.DropDownItem
for _, wal := range wallets {
item := decredmaterial.DropDownItem{
Text: wal.Name,
Icon: page.icons.walletIcon,
}
*dwn = page.theme.DropDown(walletDropDownItems, 2)
}

if *dwn == nil && len(page.info.Wallets) > 0 {
init()
return
}
if (*dwn).Len() != len(page.info.Wallets) {
init()
walletDropDownItems = append(walletDropDownItems, item)
}
*dwn = page.theme.DropDown(walletDropDownItems, 2)
}

func createOrderDropDown(c *pageCommon) *decredmaterial.DropDown {
Expand Down
4 changes: 4 additions & 0 deletions ui/create_restore_page.go
Expand Up @@ -150,6 +150,10 @@ func CreateRestorePage(common *pageCommon) Page {
return pg
}

func (pg *createRestore) OnResume() {

}

func (pg *createRestore) Layout(gtx layout.Context) layout.Dimensions {
pd := values.MarginPadding15
dims := layout.Flex{Axis: layout.Vertical, Spacing: layout.SpaceBetween}.Layout(gtx,
Expand Down
4 changes: 4 additions & 0 deletions ui/debug_page.go
Expand Up @@ -45,6 +45,10 @@ func DebugPage(common *pageCommon) Page {
return pg
}

func (pg *debugPage) OnResume() {

}

func (pg *debugPage) handle() {
for i := range pg.debugItems {
for pg.debugItems[i].clickable.Clicked() {
Expand Down
3 changes: 3 additions & 0 deletions ui/decredmaterial/dropdown.go
Expand Up @@ -105,6 +105,9 @@ func (c *DropDown) Changed() bool {
if index != 0 {
for c.items[index].button.Button.Clicked() {
if c.items[0].label.Text != c.items[index].Text {
c.selectedIndex = index
c.items[0].label.Text = c.items[index].Text
c.isOpen = false
return true
}
}
Expand Down
4 changes: 4 additions & 0 deletions ui/help_page.go
Expand Up @@ -28,6 +28,10 @@ func HelpPage(common *pageCommon) Page {
return pg
}

func (pg *helpPage) OnResume() {

}

// main settings layout
func (pg *helpPage) Layout(gtx layout.Context) layout.Dimensions {
body := func(gtx C) D {
Expand Down
29 changes: 21 additions & 8 deletions ui/listeners.go
@@ -1,6 +1,8 @@
package ui

import (
"encoding/json"

"github.com/planetdecred/dcrlibwallet"
"github.com/planetdecred/godcr/wallet"
)
Expand All @@ -11,10 +13,21 @@ func (mp *mainPage) OnTransaction(transaction string) {
mp.updateBalance()

// beeep send notification

var tx dcrlibwallet.Transaction
err := json.Unmarshal([]byte(transaction), &tx)
if err == nil {
mp.notificationsUpdate <- wallet.NewTransaction{
Transaction: &tx,
}
}
}

func (mp *mainPage) OnBlockAttached(walletID int, blockHeight int32) {
mp.updateBalance()
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.BlockAttached,
}
}

func (mp *mainPage) OnTransactionConfirmed(walletID int, hash string, blockHeight int32) {
Expand All @@ -35,35 +48,35 @@ func (mp *mainPage) OnProposalVoteFinished(proposal *dcrlibwallet.Proposal) {}
// Sync notifications

func (mp *mainPage) OnSyncStarted(wasRestarted bool) {
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.SyncStarted,
}
}

func (mp *mainPage) OnPeerConnectedOrDisconnected(numberOfConnectedPeers int32) {
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.PeersConnected,
ConnectedPeers: numberOfConnectedPeers,
}
}

func (mp *mainPage) OnCFiltersFetchProgress(cfiltersFetchProgress *dcrlibwallet.CFiltersFetchProgressReport) {
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.CfiltersFetchProgress,
ProgressReport: cfiltersFetchProgress,
}
}

func (mp *mainPage) OnHeadersFetchProgress(headersFetchProgress *dcrlibwallet.HeadersFetchProgressReport) {
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.HeadersFetchProgress,
ProgressReport: wallet.SyncHeadersFetchProgress{
Progress: headersFetchProgress,
},
}
}
func (mp *mainPage) OnAddressDiscoveryProgress(addressDiscoveryProgress *dcrlibwallet.AddressDiscoveryProgressReport) {
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.AddressDiscoveryProgress,
ProgressReport: wallet.SyncAddressDiscoveryProgress{
Progress: addressDiscoveryProgress,
Expand All @@ -72,7 +85,7 @@ func (mp *mainPage) OnAddressDiscoveryProgress(addressDiscoveryProgress *dcrlibw
}

func (mp *mainPage) OnHeadersRescanProgress(headersRescanProgress *dcrlibwallet.HeadersRescanProgressReport) {
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.HeadersRescanProgress,
ProgressReport: wallet.SyncHeadersRescanProgress{
Progress: headersRescanProgress,
Expand All @@ -81,13 +94,13 @@ func (mp *mainPage) OnHeadersRescanProgress(headersRescanProgress *dcrlibwallet.
}
func (mp *mainPage) OnSyncCompleted() {
mp.updateBalance()
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.SyncCompleted,
}
}

func (mp *mainPage) OnSyncCanceled(willRestart bool) {
mp.syncStatusUpdate <- wallet.SyncStatusUpdate{
mp.notificationsUpdate <- wallet.SyncStatusUpdate{
Stage: wallet.SyncCanceled,
}
}
Expand Down
4 changes: 4 additions & 0 deletions ui/log_page.go
Expand Up @@ -46,6 +46,10 @@ func LogPage(common *pageCommon) Page {
return pg
}

func (pg *logPage) OnResume() {

}

func (pg *logPage) copyLogEntries(gtx C) {
go func() {
pg.entriesLock.Lock()
Expand Down

0 comments on commit ce16b9b

Please sign in to comment.