Skip to content

Commit

Permalink
Added history pagination
Browse files Browse the repository at this point in the history
Added history pagination
  • Loading branch information
inkeliz authored Sep 19, 2018
2 parents fdf1756 + ec4f444 commit 47fe65a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 23 deletions.
13 changes: 12 additions & 1 deletion Block/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func GetSubType(tx, txPrevious Transaction) BlockType {
return Change
}

if txPrevious.GetBalance() == nil {
return NotABlock
}

if tx.GetBalance().Compare(txPrevious.GetBalance()) == 1 {
return Receive
} else {
Expand All @@ -168,14 +172,21 @@ func GetSubType(tx, txPrevious Transaction) BlockType {
}

func GetAmount(tx, txPrevious Transaction) *Numbers.RawAmount {
if tx.GetBalance() == nil {
return Numbers.NewMin()
}

switch GetSubType(tx, txPrevious) {
case Open:
return tx.GetBalance()
case Change:
return Numbers.NewMin()
case Send:
return tx.GetBalance().Subtract(txPrevious.GetBalance()).Abs()
fallthrough
case Receive:
if txPrevious.GetBalance() == nil {
return Numbers.NewMin()
}
return tx.GetBalance().Subtract(txPrevious.GetBalance()).Abs()
}

Expand Down
6 changes: 3 additions & 3 deletions GUI/App/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (c *PageMFA) OnContinue(w *DOM.Window, dom *DOM.DOM, _ string) {

type PageAddress struct{}

const ADDRESS_PER_PAGE uint32 = 5
const AddressesPerPage uint32 = 5

func (c *PageAddress) Name() string {
return "address"
Expand Down Expand Up @@ -272,7 +272,7 @@ func (c *PageAddress) Next(dom *DOM.DOM) {
return
}

c.UpdateList(dom, pos+ADDRESS_PER_PAGE, pos+(ADDRESS_PER_PAGE*2))
c.UpdateList(dom, pos+AddressesPerPage, pos+(AddressesPerPage*2))
}

func (c *PageAddress) Previous(dom *DOM.DOM) {
Expand All @@ -281,7 +281,7 @@ func (c *PageAddress) Previous(dom *DOM.DOM) {
return
}

c.UpdateList(dom, pos-ADDRESS_PER_PAGE, pos)
c.UpdateList(dom, pos-AddressesPerPage, pos)
}

func (c *PageAddress) OnView(w *DOM.Window, dom *DOM.DOM) {
Expand Down
67 changes: 52 additions & 15 deletions GUI/App/nanollet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"image/color"
)

const TransactionsPerPage = 5

type NanolletApp struct{}

func (c *NanolletApp) Name() string {
Expand Down Expand Up @@ -202,25 +204,28 @@ func (c *PageRepresentative) OnContinue(w *DOM.Window, dom *DOM.DOM, _ string) {
dom.ApplyFor(".address", DOM.ClearValue)
}

type PageList struct{}
type PageList struct {
Position int
}

func (c *PageList) Name() string {
return "history"
}

func (c *PageList) OnView(w *DOM.Window, dom *DOM.DOM) {
balance, _ := Numbers.NewHumanFromRaw(Storage.AccountStorage.Balance).ConvertToBase(Numbers.MegaXRB, int(Numbers.MegaXRB))
display, _ := dom.SelectFirstElement(".fullamount")
display.SetValue(balance)
func (c *PageList) UpdateList(dom *DOM.DOM, min, max int) {
txbox, _ := dom.SelectFirstElement(".txbox")

if Storage.TransactionStorage.Count() == 0 {
return
txs := Storage.TransactionStorage.GetByFrontier(Storage.AccountStorage.Frontier)
if l := len(txs); max > l {
max = l
}

txbox, _ := dom.SelectFirstElement(".txbox")
txbox.Apply(DOM.ClearHTML)
if max > 0 {
txbox.Apply(DOM.ClearHTML)
}

for i, tx := range Storage.TransactionStorage.GetByFrontier(Storage.AccountStorage.Frontier) {
for i := min; i < max; i++ {
tx := txs[i]

hashPrev := tx.GetPrevious()
txPrev, _ := Storage.TransactionStorage.GetByHash(&hashPrev)
Expand All @@ -237,14 +242,46 @@ func (c *PageList) OnView(w *DOM.Window, dom *DOM.DOM) {

txdiv.CreateElementWithAttr("div", strings.ToUpper(txType.String()), DOM.Attrs{"class": "type"})
txdiv.CreateElementWithAttr("div", humanAmount, DOM.Attrs{"class": "amount"})
}
}

if i == 4 {
break
}
func (c *PageList) Next(dom *DOM.DOM) {
pos := c.Position
if pos+TransactionsPerPage >= len(Storage.TransactionStorage.GetByFrontier(Storage.AccountStorage.Frontier)) {
return
}

c.Position = pos + TransactionsPerPage
c.UpdateList(dom, c.Position, pos+(TransactionsPerPage*2))
}

func (c *PageList) Previous(dom *DOM.DOM) {
pos := c.Position
if pos == 0 {
return
}

c.Position = pos - TransactionsPerPage
c.UpdateList(dom, c.Position, pos)
}

func (c *PageList) OnView(w *DOM.Window, dom *DOM.DOM) {
balance, _ := Numbers.NewHumanFromRaw(Storage.AccountStorage.Balance).ConvertToBase(Numbers.MegaXRB, int(Numbers.MegaXRB))
display, _ := dom.SelectFirstElement(".fullamount")
display.SetValue(balance)

if Storage.TransactionStorage.Count() == 0 {
return
}

c.UpdateList(dom, 0, TransactionsPerPage)
}

func (c *PageList) OnContinue(w *DOM.Window, dom *DOM.DOM, _ string) {
//no-op
func (c *PageList) OnContinue(w *DOM.Window, dom *DOM.DOM, action string) {
switch action {
case "next":
c.Next(dom)
case "previous":
c.Previous(dom)
}
}
15 changes: 12 additions & 3 deletions GUI/Front/html/nanollet.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,21 @@
</div>

<label>TRANSACTIONS</label>
<div class="box txbox">
<div class="item">
No transactions were found. :(
<div class="box">
<button class="next">
<icon class="icon-next"/>
</button>
<button class="previous">
<icon class="icon-previous"/>
</button>
<div class="txbox">
<div class="item">
No transactions were found. :(
</div>
</div>
</div>


</div>
</section>

Expand Down
3 changes: 2 additions & 1 deletion GUI/Front/less/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ header {
.box {
float: left;
display: block;
width: 200px;
min-width: 200px;
}

icon {
Expand Down Expand Up @@ -517,6 +517,7 @@ section.dynamic {
cursor: pointer;
width: 18px;
height: 30px;
margin-top: -17px;
display: block;
position: absolute;
top: 50%;
Expand Down

0 comments on commit 47fe65a

Please sign in to comment.