Skip to content

Commit

Permalink
cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirmorrison committed Dec 20, 2019
1 parent 8bc1229 commit 7dec5c7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 102 deletions.
1 change: 0 additions & 1 deletion cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
59 changes: 0 additions & 59 deletions fyne/helpers/amount.go

This file was deleted.

91 changes: 50 additions & 41 deletions fyne/pages/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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())
Expand All @@ -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})
Expand All @@ -94,22 +95,18 @@ 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(
walletDropDown).Add(fyne.NewPos(0, walletDropDown.Size().Height)))
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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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})

Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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}),
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion terminal/pages/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
MessageKindInfo
)

const txPerPage int32 = 10
const txPerPage int32 = 25

var historyPageData struct {
pageContentHolder *tview.Flex
Expand Down

0 comments on commit 7dec5c7

Please sign in to comment.