history.go raw

   1  package gui
   2  
   3  import (
   4  	"fmt"
   5  	"time"
   6  
   7  	l "github.com/p9c/p9/pkg/gel/gio/layout"
   8  
   9  	"github.com/p9c/p9/pkg/gel"
  10  )
  11  
  12  func (wg *WalletGUI) HistoryPage() l.Widget {
  13  	if wg.TxHistoryWidget == nil {
  14  		wg.TxHistoryWidget = func(gtx l.Context) l.Dimensions {
  15  			return l.Dimensions{Size: gtx.Constraints.Max}
  16  		}
  17  	}
  18  	return func(gtx l.Context) l.Dimensions {
  19  		if wg.openTxID.Load() != "" {
  20  			for i := range wg.txHistoryList {
  21  				if wg.txHistoryList[i].TxID == wg.openTxID.Load() {
  22  					txs := wg.txHistoryList[i]
  23  					// instead return detail view
  24  					var out []l.Widget
  25  					out = []l.Widget{
  26  						wg.txDetailEntry("Abandoned", fmt.Sprint(txs.Abandoned), "DocBg", false),
  27  						wg.txDetailEntry("Account", fmt.Sprint(txs.Account), "DocBgDim", false),
  28  						wg.txDetailEntry("Address", txs.Address, "DocBg", false),
  29  						wg.txDetailEntry("Block Hash", txs.BlockHash, "DocBgDim", true),
  30  						wg.txDetailEntry("Block Index", fmt.Sprint(txs.BlockIndex), "DocBg", false),
  31  						wg.txDetailEntry("Block Time", fmt.Sprint(time.Unix(txs.BlockTime, 0)), "DocBgDim", false),
  32  						wg.txDetailEntry("Category", txs.Category, "DocBg", false),
  33  						wg.txDetailEntry("Confirmations", fmt.Sprint(txs.Confirmations), "DocBgDim", false),
  34  						wg.txDetailEntry("Fee", fmt.Sprintf("%0.8f", txs.Fee), "DocBg", false),
  35  						wg.txDetailEntry("Generated", fmt.Sprint(txs.Generated), "DocBgDim", false),
  36  						wg.txDetailEntry("Involves Watch Only", fmt.Sprint(txs.InvolvesWatchOnly), "DocBg", false),
  37  						wg.txDetailEntry("Time", fmt.Sprint(time.Unix(txs.Time, 0)), "DocBgDim", false),
  38  						wg.txDetailEntry("Time Received", fmt.Sprint(time.Unix(txs.TimeReceived, 0)), "DocBg", false),
  39  						wg.txDetailEntry("Trusted", fmt.Sprint(txs.Trusted), "DocBgDim", false),
  40  						wg.txDetailEntry("TxID", txs.TxID, "DocBg", true),
  41  						// todo: add WalletConflicts here
  42  						wg.txDetailEntry("Comment", fmt.Sprintf("%0.8f", txs.Amount), "DocBgDim", false),
  43  						wg.txDetailEntry("OtherAccount", fmt.Sprint(txs.OtherAccount), "DocBg", false),
  44  					}
  45  					le := func(gtx l.Context, index int) l.Dimensions {
  46  						return out[index](gtx)
  47  					}
  48  					return wg.VFlex().AlignStart().
  49  						Rigid(
  50  							wg.recentTxCardSummaryButton(&txs, wg.clickables["txPageBack"], "Primary", true),
  51  							// wg.H6(wg.openTxID.Load()).Fn,
  52  						).
  53  						Rigid(
  54  							wg.lists["txdetail"].
  55  								Vertical().
  56  								Length(len(out)).
  57  								ListElement(le).
  58  								Fn,
  59  						).
  60  						Fn(gtx)
  61  					
  62  					// return wg.Flex().Flexed(
  63  					// 	1,
  64  					// 	wg.H3(wg.openTxID.Load()).Fn,
  65  					// ).Fn(gtx)
  66  				}
  67  			}
  68  			// if we got to here, the tx was not found
  69  			if wg.originTxDetail != "" {
  70  				wg.MainApp.ActivePage(wg.originTxDetail)
  71  				wg.originTxDetail = ""
  72  			}
  73  		}
  74  		return wg.VFlex().
  75  			Rigid(
  76  				// wg.Fill("DocBg", l.Center, 0, 0,
  77  				// 	wg.Inset(0.25,
  78  				wg.Responsive(
  79  					wg.Size.Load(), gel.Widgets{
  80  						{
  81  							Widget: wg.VFlex().
  82  								Flexed(1, wg.HistoryPageView()).
  83  								// Rigid(
  84  								// 	// 	wg.Fill("DocBg",
  85  								// 	wg.Flex().AlignMiddle().SpaceBetween().
  86  								// 		Flexed(0.5, gel.EmptyMaxWidth()).
  87  								// 		Rigid(wg.HistoryPageStatusFilter()).
  88  								// 		Flexed(0.5, gel.EmptyMaxWidth()).
  89  								// 		Fn,
  90  								// 	// 	).Fn,
  91  								// ).
  92  								// Rigid(
  93  								// 	wg.Fill("DocBg",
  94  								// 		wg.Flex().AlignMiddle().SpaceBetween().
  95  								// 			Rigid(wg.HistoryPager()).
  96  								// 			Rigid(wg.HistoryPagePerPageCount()).
  97  								// 			Fn,
  98  								// 	).Fn,
  99  								// ).
 100  								Fn,
 101  						},
 102  						{
 103  							Size: 64,
 104  							Widget: wg.VFlex().
 105  								Flexed(1, wg.HistoryPageView()).
 106  								// Rigid(
 107  								// 	// 	wg.Fill("DocBg",
 108  								// 	wg.Flex().AlignMiddle().SpaceBetween().
 109  								// 		// 			Rigid(wg.HistoryPager()).
 110  								// 		Flexed(0.5, gel.EmptyMaxWidth()).
 111  								// 		Rigid(wg.HistoryPageStatusFilter()).
 112  								// 		Flexed(0.5, gel.EmptyMaxWidth()).
 113  								// 		// 			Rigid(wg.HistoryPagePerPageCount()).
 114  								// 		Fn,
 115  								// 	// 	).Fn,
 116  								// ).
 117  								Fn,
 118  						},
 119  					},
 120  				).Fn,
 121  				// ).Fn,
 122  				// ).Fn,
 123  			).Fn(gtx)
 124  	}
 125  }
 126  
 127  func (wg *WalletGUI) HistoryPageView() l.Widget {
 128  	return wg.VFlex().
 129  		Rigid(
 130  			// wg.Fill("DocBg", l.Center, wg.TextSize.True, 0,
 131  			// 	wg.Inset(0.25,
 132  			wg.TxHistoryWidget,
 133  			// ).Fn,
 134  			// ).Fn,
 135  		).Fn
 136  }
 137  
 138  func (wg *WalletGUI) HistoryPageStatusFilter() l.Widget {
 139  	return wg.Flex().AlignMiddle().
 140  		Rigid(
 141  			wg.Inset(
 142  				0.25,
 143  				wg.Caption("show").Fn,
 144  			).Fn,
 145  		).
 146  		Rigid(
 147  			wg.Inset(
 148  				0.25,
 149  				func(gtx l.Context) l.Dimensions {
 150  					return wg.CheckBox(wg.bools["showGenerate"]).
 151  						TextColor("DocText").
 152  						TextScale(1).
 153  						Text("generate").
 154  						IconScale(1).
 155  						Fn(gtx)
 156  				},
 157  			).Fn,
 158  		).
 159  		Rigid(
 160  			wg.Inset(
 161  				0.25,
 162  				func(gtx l.Context) l.Dimensions {
 163  					return wg.CheckBox(wg.bools["showSent"]).
 164  						TextColor("DocText").
 165  						TextScale(1).
 166  						Text("sent").
 167  						IconScale(1).
 168  						Fn(gtx)
 169  				},
 170  			).Fn,
 171  		).
 172  		Rigid(
 173  			wg.Inset(
 174  				0.25,
 175  				func(gtx l.Context) l.Dimensions {
 176  					return wg.CheckBox(wg.bools["showReceived"]).
 177  						TextColor("DocText").
 178  						TextScale(1).
 179  						Text("received").
 180  						IconScale(1).
 181  						Fn(gtx)
 182  				},
 183  			).Fn,
 184  		).
 185  		Rigid(
 186  			wg.Inset(
 187  				0.25,
 188  				func(gtx l.Context) l.Dimensions {
 189  					return wg.CheckBox(wg.bools["showImmature"]).
 190  						TextColor("DocText").
 191  						TextScale(1).
 192  						Text("immature").
 193  						IconScale(1).
 194  						Fn(gtx)
 195  				},
 196  			).Fn,
 197  		).
 198  		Fn
 199  }
 200