From a87df27a4188cf893e6d8f4d0e23bf285a6c50c3 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Fri, 19 Jul 2024 12:06:04 -0400 Subject: [PATCH] Best version yet --- app/history.go | 57 +++++++++-------- frontend/src/views/History/HistoryView.tsx | 73 +++++++++++++++++----- frontend/src/views/Names/NamesView.tsx | 51 ++++++++------- frontend/wailsjs/go/types/Appearance.d.ts | 15 +++++ frontend/wailsjs/go/types/Appearance.js | 27 ++++++++ go.mod | 2 +- go.sum | 2 - main.go | 1 + 8 files changed, 161 insertions(+), 67 deletions(-) create mode 100755 frontend/wailsjs/go/types/Appearance.d.ts create mode 100755 frontend/wailsjs/go/types/Appearance.js diff --git a/app/history.go b/app/history.go index cbc8961..6284da1 100644 --- a/app/history.go +++ b/app/history.go @@ -1,7 +1,9 @@ package app import ( + "github.com/TrueBlocks/trueblocks-core/sdk/v3" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) @@ -9,39 +11,42 @@ var addrToHistoryMap = map[base.Address][]types.Transaction{} func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction { address := base.HexToAddress(addr) - if address.IsZero() { - return []types.Transaction{ - { - TransactionIndex: 1, - BlockNumber: 1, - BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db01"), - }, - { - TransactionIndex: 2, - BlockNumber: 2, - BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db02"), - }, - { - TransactionIndex: 3, - BlockNumber: 3, - BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db03"), + if len(addrToHistoryMap[address]) == 0 { + opts := sdk.ExportOptions{ + Addrs: []string{addr}, + Articulate: true, + Globals: sdk.Globals{ + Cache: true, }, } - } - - var ret []types.Transaction - if len(addrToHistoryMap[address]) == 0 { - return ret + monitors, _, err := opts.Export() + if err != nil { + // EventEmitter.Emit("error", err) + logger.Info(err) + return []types.Transaction{} + } else if len(monitors) == 0 { + logger.Info("none") + return []types.Transaction{} + } else { + logger.Info("got em", len(monitors)) + addrToHistoryMap[address] = monitors + } } first = base.Max(0, base.Min(first, len(addrToHistoryMap[address])-1)) last := base.Min(len(addrToHistoryMap[address]), first+pageSize) return addrToHistoryMap[address][first:last] } -func (a *App) GetHistoryCnt(addr string) int { - address := base.HexToAddress(addr) - if address.IsZero() { - return 3 +func (a *App) GetHistoryCnt(addr string) int64 { + opts := sdk.ListOptions{ + Addrs: []string{addr}, + } + monitors, _, err := opts.ListCount() + if err != nil { + // EventEmitter.Emit("error", err) + return 0 + } else if len(monitors) == 0 { + return 0 } - return len(addrToHistoryMap[address]) + return monitors[0].NRecords } diff --git a/frontend/src/views/History/HistoryView.tsx b/frontend/src/views/History/HistoryView.tsx index 5ebb6a1..8c1e2f5 100644 --- a/frontend/src/views/History/HistoryView.tsx +++ b/frontend/src/views/History/HistoryView.tsx @@ -2,31 +2,74 @@ import React, { useState, useEffect } from "react"; import { GetHistory, GetHistoryCnt } from "@gocode/app/App"; import classes from "@/App.module.css"; import { View, ViewStatus } from "@/components/view"; -import { Stack, Title } from "@mantine/core"; +import { Group, Stack, Title, Text } from "@mantine/core"; import { types } from "@gocode/models"; +import { useHotkeys } from "react-hotkeys-hook"; export function HistoryView() { - const [address, setAddress] = useState(""); - const [cnt, setCnt] = useState(0); - const [txs, setTxs] = useState([]); + const [address, setAddress] = useState("0x054993ab0f2b1acc0fdc65405ee203b4271bebe6"); + const [items, setItems] = useState([]); + const [nItems, setNItems] = useState(0); + const [curItem, setCurItem] = useState(0); + const perPage = 20; + + useHotkeys("left", (event) => { + setCurItem((cur) => Math.max(cur - 1, 0)); + event.preventDefault(); + }); + useHotkeys("up", (event) => { + setCurItem((cur) => Math.max(cur - perPage, 0)); + event.preventDefault(); + }); + useHotkeys("home", (event) => { + setCurItem(0); + event.preventDefault(); + }); + + useHotkeys("right", (event) => { + var max = Math.max(nItems - perPage, 0); + setCurItem((cur) => Math.min(max, cur + 1)); + event.preventDefault(); + }); + useHotkeys("down", (event) => { + var max = Math.max(nItems - perPage, 0); + setCurItem((cur) => Math.min(max, cur + perPage)); + event.preventDefault(); + }); + useHotkeys("end", (event) => { + var max = Math.max(nItems - perPage, 0); + setCurItem(max); + event.preventDefault(); + }); + + useEffect(() => { + const fetchHistory = async () => { + const fetchedItems = await GetHistory(address, curItem, perPage); + setItems(fetchedItems); + const cnt = await GetHistoryCnt(address); + setNItems(cnt); + }; + fetchHistory(); + }, [address, curItem, perPage]); useEffect(() => { - setAddress("0xf503017d7baf7fbc0fff7492b751025c6a78179b"); - GetHistoryCnt(address).then((cnt: number) => { - setCnt(cnt); - }); - GetHistory(address, 0, 20).then((txs: types.Transaction[]) => { - setTxs(txs); - }); - }, []); + setCurItem(0); + }, [address]); return ( History Title -
{address}
-
{cnt}
-
{JSON.stringify(txs)}
+ + {address} at record {curItem} of {nItems} records + + + {items.map((item, idx) => ( + + {item.blockNumber} {item.from} {item.to} {item.value} + + ))} +
Status / Progress
diff --git a/frontend/src/views/Names/NamesView.tsx b/frontend/src/views/Names/NamesView.tsx index d73c283..d8db01e 100644 --- a/frontend/src/views/Names/NamesView.tsx +++ b/frontend/src/views/Names/NamesView.tsx @@ -11,51 +11,56 @@ import { View, ViewStatus } from "@/components/view"; const columnHelper = createColumnHelper(); export function NamesView() { - const [names, _setData] = React.useState(() => []); - const [nNames, setNamesCount] = useState(0); - const [curName, setCurName] = useState(-1); - const [perPage, setPerPage] = useState(20); + const [items, setItems] = useState([]); + const [nItems, setNItems] = useState(0); + const [curItem, setCurItem] = useState(0); + const perPage = 20; useHotkeys("left", (event) => { - setCurName(curName - 1 < 0 ? 0 : curName - 1); + setCurItem((cur) => Math.max(cur - 1, 0)); event.preventDefault(); }); useHotkeys("up", (event) => { - setCurName(curName - 20 < 0 ? 0 : curName - 20); + setCurItem((cur) => Math.max(cur - perPage, 0)); event.preventDefault(); }); - useHotkeys("right", (event) => { - setCurName(curName + 1 >= nNames ? nNames : curName + 1); + useHotkeys("home", (event) => { + setCurItem(0); event.preventDefault(); }); - useHotkeys("down", (event) => { - setCurName(curName + 20 >= nNames ? nNames - 20 : curName + 20); + + useHotkeys("right", (event) => { + var max = Math.max(nItems - perPage, 0); + setCurItem((cur) => Math.min(max, cur + 1)); event.preventDefault(); }); - useHotkeys("home", (event) => { - setCurName(0); + useHotkeys("down", (event) => { + var max = Math.max(nItems - perPage, 0); + setCurItem((cur) => Math.min(max, cur + perPage)); event.preventDefault(); }); useHotkeys("end", (event) => { - setCurName(nNames <= 20 ? 20 : nNames - 20); + var max = Math.max(nItems - perPage, 0); + setCurItem(max); event.preventDefault(); }); useEffect(() => { - GetNames(curName, perPage).then((names: types.Name[]) => { - _setData(names); - GetNamesCnt().then((cnt) => { - setNamesCount(cnt); - }); - }); - }, [curName]); + const fetchHistory = async () => { + const fetchedItems = await GetNames(curItem, perPage); + setItems(fetchedItems); + const cnt = await GetNamesCnt(); + setNItems(cnt); + }; + fetchHistory(); + }, [curItem, perPage]); useEffect(() => { - setCurName(0); + setCurItem(0); }, []); const table = useReactTable({ - data: names, + data: items, columns: namesColumns, getCoreRowModel: getCoreRowModel(), }); @@ -63,7 +68,7 @@ export function NamesView() { return ( - Names Title {curName} + Names Title {curItem} {table.getHeaderGroups().map((headerGroup) => ( diff --git a/frontend/wailsjs/go/types/Appearance.d.ts b/frontend/wailsjs/go/types/Appearance.d.ts new file mode 100755 index 0000000..759e134 --- /dev/null +++ b/frontend/wailsjs/go/types/Appearance.d.ts @@ -0,0 +1,15 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT +import {types} from '../models'; + +export function Date():Promise; + +export function FinishUnmarshal():Promise; + +export function GetKey():Promise; + +export function Model(arg1:string,arg2:string,arg3:boolean,arg4:{[key: string]: any}):Promise; + +export function Orig():Promise; + +export function String():Promise; diff --git a/frontend/wailsjs/go/types/Appearance.js b/frontend/wailsjs/go/types/Appearance.js new file mode 100755 index 0000000..a1930f8 --- /dev/null +++ b/frontend/wailsjs/go/types/Appearance.js @@ -0,0 +1,27 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export function Date() { + return window['go']['types']['Appearance']['Date'](); +} + +export function FinishUnmarshal() { + return window['go']['types']['Appearance']['FinishUnmarshal'](); +} + +export function GetKey() { + return window['go']['types']['Appearance']['GetKey'](); +} + +export function Model(arg1, arg2, arg3, arg4) { + return window['go']['types']['Appearance']['Model'](arg1, arg2, arg3, arg4); +} + +export function Orig() { + return window['go']['types']['Appearance']['Orig'](); +} + +export function String() { + return window['go']['types']['Appearance']['String'](); +} diff --git a/go.mod b/go.mod index 109bbff..63d1954 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 toolchain go1.22.0 replace ( - github.com/TrueBlocks/trueblocks-core/sdk => ../trueblocks-core/sdk + github.com/TrueBlocks/trueblocks-core/sdk/v3 => ../trueblocks-core/sdk github.com/TrueBlocks/trueblocks-core/src/apps/chifra => ../trueblocks-core/src/apps/chifra ) diff --git a/go.sum b/go.sum index 17394b7..b5bb404 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,6 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/TrueBlocks/trueblocks-core/sdk/v3 v3.0.0-20240718213142-3cffd1bf17f0 h1:wWeaGbu8mv+NLwDJ3EKPNpoX4UxYxL8jjtFNQdhP2tg= -github.com/TrueBlocks/trueblocks-core/sdk/v3 v3.0.0-20240718213142-3cffd1bf17f0/go.mod h1:r01Zts5Fl/rEdb5iU94jg5cMu+fPn8msgiAL3u1MIxg= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40= github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o= diff --git a/main.go b/main.go index 4ef8414..7d859f8 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,7 @@ func main() { a, &types.Name{}, &types.Transaction{}, + &types.Appearance{}, }, StartHidden: true, AssetServer: &assetserver.Options{