diff --git a/cli/go.sum b/cli/go.sum index 3acbe15f1..c5edaa216 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -14,7 +14,6 @@ github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0 github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/asdine/storm v0.0.0-20190216191021-fe89819f6282 h1:DmSVc81daQAPvXwcCZi0W6A14sTCYQ1QI21C0E37KoY= github.com/asdine/storm v0.0.0-20190216191021-fe89819f6282/go.mod h1:cMLKpjHSP4q0P133fV15ojQgwWWB2IMv+hrFsmBF/wI= -github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY= github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= diff --git a/fyne/helpers/amount.go b/fyne/helpers/amount.go deleted file mode 100644 index 83ed14f61..000000000 --- a/fyne/helpers/amount.go +++ /dev/null @@ -1,59 +0,0 @@ -package helpers - -import ( - "fmt" - "math" - "strconv" - "strings" - - "github.com/decred/dcrd/dcrutil" -) - -func DecimalPortion(n float64) string { - decimalPlaces := fmt.Sprintf("%f", n-math.Floor(n)) // produces 0.xxxx0000 - decimalPlaces = strings.Replace(decimalPlaces, "0.", "", -1) // remove 0. - decimalPlaces = strings.TrimRight(decimalPlaces, "0") // remove trailing 0s - return decimalPlaces -} - -func SplitAmountIntoParts(amount float64) []string { - balanceParts := make([]string, 3) - - wholeNumber := int(math.Floor(amount)) - balanceParts[0] = strconv.Itoa(wholeNumber) - - decimalPortion := DecimalPortion(amount) - if len(decimalPortion) == 0 { - balanceParts[2] = " DCR" - } else if len(decimalPortion) <= 2 { - balanceParts[1] = fmt.Sprintf(".%s DCR", decimalPortion) - } else { - balanceParts[1] = fmt.Sprintf(".%s", decimalPortion[0:2]) - balanceParts[2] = fmt.Sprintf("%s DCR", decimalPortion[2:]) - } - - return balanceParts -} - -func MaxDecimalPlaces(amounts []int64) (maxDecimalPlaces int) { - for _, amount := range amounts { - decimalPortion := DecimalPortion(dcrutil.Amount(amount).ToCoin()) - nDecimalPlaces := len(decimalPortion) - if nDecimalPlaces > maxDecimalPlaces { - maxDecimalPlaces = nDecimalPlaces - } - } - return -} - -func FormatAmountDisplay(amount int64, maxDecimalPlaces int) string { - dcrAmount := dcrutil.Amount(amount).ToCoin() - wholeNumber := int(math.Floor(dcrAmount)) - decimalPortion := DecimalPortion(dcrAmount) - - if len(decimalPortion) == 0 { - return fmt.Sprintf("%2d%-*s DCR", wholeNumber, maxDecimalPlaces+1, decimalPortion) - } else { - return fmt.Sprintf("%2d.%-*s DCR", wholeNumber, maxDecimalPlaces, decimalPortion) - } -} diff --git a/fyne/pages/history.go b/fyne/pages/history.go index 084c9439a..3067e9f46 100644 --- a/fyne/pages/history.go +++ b/fyne/pages/history.go @@ -24,23 +24,23 @@ import ( const txPerPage int32 = 25 type txHistoryPageData struct { - txTable widgets.Table allTxCount int + selectedWalletID int selectedFilterId int32 - errorLabel *widget.Label - selectedTxFilterLabel *widget.Label - selectedTxSortFilterLabel *widget.Label - selectedWalletLabel *widget.Label TotalTxFetched int32 - selectedWalletID int selectedtxSort bool + errorMessage string walletListTab *widget.Box txFilterTab *widget.Box txSortFilterTab *widget.Box + txTable widgets.Table + errorLabel *widget.Label + selectedTxFilterLabel *widget.Label + selectedTxSortFilterLabel *widget.Label + selectedWalletLabel *widget.Label txFilterSelectionPopup *widget.PopUp txSortFilterSelectionPopup *widget.PopUp txWalletSelectionPopup *widget.PopUp - errorMessage string icons map[string]*fyne.StaticResource } @@ -55,6 +55,7 @@ func historyPageContent(app *AppInterface) fyne.CanvasObject { txHistory.selectedTxFilterLabel = widget.NewLabel("") txHistory.selectedTxSortFilterLabel = widget.NewLabel("") + // gets all icons used on this page icons, err := assets.GetIcons(assets.CollapseIcon, assets.InfoIcon, assets.SendIcon, assets.ReceiveIcon, assets.ReceiveIcon, assets.InfoIcon) if err != nil { errorMessage := fmt.Sprintf("Error: %s", err.Error()) @@ -66,8 +67,8 @@ func historyPageContent(app *AppInterface) fyne.CanvasObject { // history page title label pageTitleLabel := widget.NewLabelWithStyle("Transactions", fyne.TextAlignLeading, fyne.TextStyle{Bold: true, Italic: true}) - // infoIcon holds history page hint-text - var infoIcon *widgets.ImageButton + // infoPopUp creates a popup with history page hint-text + var infoPopUp *widgets.ImageButton info := "- Tap Hash to view Transaction details.\n\n- Tap Blue Text to Copy." infoIcon = widgets.NewImageButton(txHistory.icons[assets.InfoIcon], nil, func() { infoLabel := widget.NewLabelWithStyle(info, fyne.TextAlignLeading, fyne.TextStyle{Monospace: true}) @@ -94,8 +95,10 @@ func historyPageContent(app *AppInterface) fyne.CanvasObject { widgets.NewVSpacer(5), ) + // initialize history page data txWalletList(app.MultiWallet, app.Window, app.tabMenu) + // walletDropDown creates a popup like dropdown that holds the list of available wallets. var walletDropDown *widgets.ClickableBox walletDropDown = widgets.NewClickableBox(txHistory.walletListTab, func() { txHistory.txWalletSelectionPopup.Move(fyne.CurrentApp().Driver().AbsolutePositionForObject( @@ -103,13 +106,7 @@ func historyPageContent(app *AppInterface) fyne.CanvasObject { txHistory.txWalletSelectionPopup.Show() }) - var txSortFilterDropDown *widgets.ClickableBox - txSortFilterDropDown = widgets.NewClickableBox(txHistory.txSortFilterTab, func() { - txHistory.txSortFilterSelectionPopup.Move(fyne.CurrentApp().Driver().AbsolutePositionForObject( - txSortFilterDropDown).Add(fyne.NewPos(0, txSortFilterDropDown.Size().Height))) - txHistory.txSortFilterSelectionPopup.Show() - }) - + // txFilterDropDown creates a popup like dropdown that holds the list of tx filters. var txFilterDropDown *widgets.ClickableBox txFilterDropDown = widgets.NewClickableBox(txHistory.txFilterTab, func() { if txHistory.allTxCount == 0 { @@ -121,6 +118,19 @@ func historyPageContent(app *AppInterface) fyne.CanvasObject { } }) + // txSortFilterDropDown creates a popup like dropdown that holds the list of sort filters. + var txSortFilterDropDown *widgets.ClickableBox + txSortFilterDropDown = widgets.NewClickableBox(txHistory.txSortFilterTab, func() { + if txHistory.allTxCount == 0 { + txHistory.txSortFilterSelectionPopup.Hide() + } else { + txHistory.txSortFilterSelectionPopup.Move(fyne.CurrentApp().Driver().AbsolutePositionForObject( + txSortFilterDropDown).Add(fyne.NewPos(0, txSortFilterDropDown.Size().Height))) + txHistory.txSortFilterSelectionPopup.Show() + } + }) + + // catch all errors when trying to setup and render tx page data. if txHistory.errorMessage != "" { errorHandler(txHistory.errorMessage, txHistory.errorLabel) txHistoryPageOutput.Append(txHistory.errorLabel) @@ -151,9 +161,9 @@ func txWalletList(multiWallet *dcrlibwallet.MultiWallet, window fyne.Window, tab txHistory.selectedWalletLabel.SetText(multiWallet.WalletWithID(walletsID[0]).Name) txFilterDropDown(multiWallet, window, tabMenu, walletsID[0]) + txSortDropDown(multiWallet, window, tabMenu) txTableHeader(multiWallet, &txHistory.txTable, window) fetchTx(&txHistory.txTable, 0, dcrlibwallet.TxFilterAll, multiWallet, window, tabMenu, false) - txSortDropDown(multiWallet, window, tabMenu) for index, walletID := range walletsID { wallet := multiWallet.WalletWithID(walletID) @@ -227,6 +237,7 @@ func txFilterDropDown(multiWallet *dcrlibwallet.MultiWallet, window fyne.Window, "Coinbase": dcrlibwallet.TxFilterCoinBase, "Staking": dcrlibwallet.TxFilterStaking, } + if walletId != txHistory.selectedWalletID { txHistory.selectedWalletID = walletId } @@ -282,6 +293,7 @@ func txFilterDropDown(multiWallet *dcrlibwallet.MultiWallet, window fyne.Window, txHistory.selectedTxFilterLabel, widgets.NewHSpacer(10), widget.NewIcon(txHistory.icons[assets.CollapseIcon]), + widgets.NewHSpacer(10), ) widget.Refresh(txHistory.txFilterTab) } @@ -364,7 +376,7 @@ func fetchTx(txTable *widgets.Table, txOffset, filter int32, multiWallet *dcrlib } if len(txns) == 0 { - errorHandler("No transactions yet.", txHistory.errorLabel) + errorHandler(fmt.Sprintf("No transactions for %s yet.", multiWallet.WalletWithID(txHistory.selectedWalletID).Name), txHistory.errorLabel) txHistory.txTable.Container.Hide() return } @@ -421,7 +433,6 @@ func updateTable(multiWallet *dcrlibwallet.MultiWallet, window fyne.Window, tabM if txHistory.allTxCount > int(txHistory.TotalTxFetched) { if txHistory.txTable.Container.Offset.Y == 0 { - time.AfterFunc(time.Second*8, func() { updateTable(multiWallet, window, tabMenu) }) @@ -455,10 +466,9 @@ func fetchTxDetails(hash string, multiWallet *dcrlibwallet.MultiWallet, window f } }) - var txDetailsPopUp *widget.PopUp - txDetailslabel := widget.NewLabelWithStyle("Transaction Details", fyne.TextAlignLeading, fyne.TextStyle{Bold: true, Italic: true}) + var txDetailsPopUp *widget.PopUp minimizeIcon := widgets.NewImageButton(theme.CancelIcon(), nil, func() { txDetailsPopUp.Hide() }) errorMessageLabel := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true}) @@ -504,11 +514,6 @@ func fetchTxDetails(hash string, multiWallet *dcrlibwallet.MultiWallet, window f status = "Pending" } - tableConfirmations := widget.NewHBox( - widget.NewLabelWithStyle("Confirmations:", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}), - widget.NewLabelWithStyle(strconv.Itoa(int(confirmations)), fyne.TextAlignCenter, fyne.TextStyle{}), - ) - copyAbleText := func(text string, copyAble bool) *widgets.ClickableBox { var textToCopy *canvas.Text if copyAble { @@ -534,6 +539,11 @@ func fetchTxDetails(hash string, multiWallet *dcrlibwallet.MultiWallet, window f ) } + tableConfirmations := widget.NewHBox( + widget.NewLabelWithStyle("Confirmations:", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}), + widget.NewLabelWithStyle(strconv.Itoa(int(confirmations)), fyne.TextAlignCenter, fyne.TextStyle{}), + ) + tableHash := widget.NewHBox( widget.NewLabelWithStyle("Transaction ID:", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}), copyAbleText(txDetails.Hash, true), @@ -576,20 +586,6 @@ func fetchTxDetails(hash string, multiWallet *dcrlibwallet.MultiWallet, window f widget.NewLabelWithStyle(fmt.Sprintf("%s UTC", dcrlibwallet.FormatUTCTime(txDetails.Timestamp)), fyne.TextAlignCenter, fyne.TextStyle{}), ) - tableData := widget.NewVBox( - tableConfirmations, - tableHash, - tableBlockHeight, - tableDirection, - tableType, - tableAmount, - tableSize, - tableFee, - tableFeeRate, - tableStatus, - tableDate, - ) - var txInput widgets.Table inputTableColumnLabels := widget.NewHBox( widget.NewLabelWithStyle("Previous Outpoint", fyne.TextAlignCenter, fyne.TextStyle{Bold: true}), @@ -624,6 +620,20 @@ func fetchTxDetails(hash string, multiWallet *dcrlibwallet.MultiWallet, window f } txOutput.NewTable(outputTableColumnLabels, outputBox...) + tableData := widget.NewVBox( + tableConfirmations, + tableHash, + tableBlockHeight, + tableDirection, + tableType, + tableAmount, + tableSize, + tableFee, + tableFeeRate, + tableStatus, + tableDate, + ) + txDetailsData := widget.NewVBox( widgets.NewHSpacer(10), tableData, @@ -636,7 +646,6 @@ func fetchTxDetails(hash string, multiWallet *dcrlibwallet.MultiWallet, window f ) txDetailsScrollContainer := widget.NewScrollContainer(txDetailsData) - //fixing exit icon txDetailsOutput := widget.NewVBox( widgets.NewHSpacer(10), widget.NewHBox( diff --git a/terminal/pages/history.go b/terminal/pages/history.go index 9b66225aa..c9e303186 100644 --- a/terminal/pages/history.go +++ b/terminal/pages/history.go @@ -20,7 +20,7 @@ const ( MessageKindInfo ) -const txPerPage int32 = 10 +const txPerPage int32 = 25 var historyPageData struct { pageContentHolder *tview.Flex