From c3e0b43b8e48776191b3a52ac2ec4708d35af0c1 Mon Sep 17 00:00:00 2001 From: tjayrush Date: Sat, 20 Jul 2024 06:25:40 -0400 Subject: [PATCH] Best version yet --- app/history.go | 41 ++++++++++++++----- frontend/src/components/view/View.tsx | 4 +- .../src/components/view/ViewStatus.module.css | 13 ++++++ frontend/src/components/view/ViewStatus.tsx | 35 ++++++++++++++-- frontend/src/views/Dalle/DalleView.tsx | 2 +- frontend/src/views/History/HistoryView.tsx | 5 ++- frontend/src/views/Home/HomeView.tsx | 2 +- frontend/src/views/Names/NamesView.tsx | 2 +- frontend/src/views/Series/SeriesView.tsx | 2 +- frontend/src/views/Settings/SettingsView.tsx | 2 +- 10 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 frontend/src/components/view/ViewStatus.module.css diff --git a/app/history.go b/app/history.go index 63fe900..76a2dab 100644 --- a/app/history.go +++ b/app/history.go @@ -5,8 +5,9 @@ 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/output" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" + "github.com/wailsapp/wails/v2/pkg/runtime" ) var addrToHistoryMap = map[base.Address][]types.Transaction{} @@ -19,24 +20,42 @@ func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction { if len(addrToHistoryMap[address]) == 0 { opts := sdk.ExportOptions{ - Addrs: []string{addr}, + Addrs: []string{addr}, + RenderCtx: output.NewStreamingContext(), Globals: sdk.Globals{ Cache: true, }, } - monitors, _, err := opts.Export() + + go func() { + for { + select { + case model := <-opts.RenderCtx.ModelChan: + tx, ok := model.(*types.Transaction) + if !ok { + continue + } + addrToHistoryMap[address] = append(addrToHistoryMap[address], *tx) + if len(addrToHistoryMap[address])%pageSize == 0 { + runtime.EventsEmit(a.ctx, "History", len(addrToHistoryMap[address]), 10000) + } + case err := <-opts.RenderCtx.ErrorChan: + runtime.EventsEmit(a.ctx, "Error", err.Error()) + default: + if opts.RenderCtx.WasCanceled() { + return + } + } + } + }() + + _, _, err := opts.Export() if err != nil { - // EventEmitter.Emit("error", err) - logger.Info(err) + runtime.EventsEmit(a.ctx, "Error", err.Error()) 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] diff --git a/frontend/src/components/view/View.tsx b/frontend/src/components/view/View.tsx index f89a606..745d990 100644 --- a/frontend/src/components/view/View.tsx +++ b/frontend/src/components/view/View.tsx @@ -2,6 +2,6 @@ import React, { ReactNode } from "react"; import { Stack } from "@mantine/core"; import classes from "@/App.module.css"; -export function View(params: { title?: string; children: ReactNode }) { - return {params.children}; +export function View({ title, children }: { title?: string; children: ReactNode }) { + return {children}; } diff --git a/frontend/src/components/view/ViewStatus.module.css b/frontend/src/components/view/ViewStatus.module.css new file mode 100644 index 0000000..3402cb9 --- /dev/null +++ b/frontend/src/components/view/ViewStatus.module.css @@ -0,0 +1,13 @@ +.green { + background-color: black; + color: greenyellow; + font-size: 14pt; + font-family: monospace; +} + +.red { + background-color: black; + color: red; + font-size: 14pt; + font-family: monospace; +} diff --git a/frontend/src/components/view/ViewStatus.tsx b/frontend/src/components/view/ViewStatus.tsx index 0653203..7aacd22 100644 --- a/frontend/src/components/view/ViewStatus.tsx +++ b/frontend/src/components/view/ViewStatus.tsx @@ -1,6 +1,35 @@ -import React, { ReactNode } from "react"; +import React, { ReactNode, useState, useEffect } from "react"; +import classes from "./ViewStatus.module.css"; +import { EventsOn, EventsOff } from "@runtime"; import { Text } from "@mantine/core"; -export function ViewStatus({ children }: { children: ReactNode }) { - return {children}; +export function ViewStatus() { + const [statusMessage, setStatusMessage] = useState(""); + const [color, setColor] = useState(classes.green); + + useEffect(() => { + const handleProgress = (x: number, y: number) => { + setStatusMessage(`Progress: ${x}/${y}`); + setColor(classes.green); + }; + + const handleError = (errorStr: string) => { + setStatusMessage(`Error: ${errorStr}`); + setColor(classes.red); + }; + + EventsOn("Progress", handleProgress); + EventsOn("Error", handleError); + + return () => { + EventsOff("Progress"); + EventsOff("Error"); + }; + }, []); + + return ( + +
{statusMessage}
+
+ ); } diff --git a/frontend/src/views/Dalle/DalleView.tsx b/frontend/src/views/Dalle/DalleView.tsx index a4608af..5d19e85 100644 --- a/frontend/src/views/Dalle/DalleView.tsx +++ b/frontend/src/views/Dalle/DalleView.tsx @@ -142,7 +142,7 @@ export function DalleView() { setDialogOpened(false)} success={success} /> - Status / Progress + ); } diff --git a/frontend/src/views/History/HistoryView.tsx b/frontend/src/views/History/HistoryView.tsx index ada1aec..510e96b 100644 --- a/frontend/src/views/History/HistoryView.tsx +++ b/frontend/src/views/History/HistoryView.tsx @@ -10,7 +10,8 @@ import { View, ViewStatus } from "@components"; import { useKeyboardPaging } from "@hooks"; export function HistoryView() { - const [address, setAddress] = useState("0xf503017d7baf7fbc0fff7492b751025c6a78179b"); + const [address, setAddress] = useState("0x9531c059098e3d194ff87febb587ab07b30b1306"); + // const [address, setAddress] = useState("0xf503017d7baf7fbc0fff7492b751025c6a78179b"); const { items, nItems, curItem } = useKeyboardPaging( (curItem, perPage) => GetHistory(address, curItem, perPage), () => GetHistoryCnt(address), @@ -55,7 +56,7 @@ export function HistoryView() { - Status / Progress + ); } diff --git a/frontend/src/views/Home/HomeView.tsx b/frontend/src/views/Home/HomeView.tsx index 7229380..6ad0ca2 100644 --- a/frontend/src/views/Home/HomeView.tsx +++ b/frontend/src/views/Home/HomeView.tsx @@ -10,7 +10,7 @@ export function HomeView() { Home View Content - Status / Progress + ); } diff --git a/frontend/src/views/Names/NamesView.tsx b/frontend/src/views/Names/NamesView.tsx index af6a588..97d4a56 100644 --- a/frontend/src/views/Names/NamesView.tsx +++ b/frontend/src/views/Names/NamesView.tsx @@ -48,7 +48,7 @@ export function NamesView() { - Status / Progress + ); } diff --git a/frontend/src/views/Series/SeriesView.tsx b/frontend/src/views/Series/SeriesView.tsx index de0dfa0..2cdae9c 100644 --- a/frontend/src/views/Series/SeriesView.tsx +++ b/frontend/src/views/Series/SeriesView.tsx @@ -23,7 +23,7 @@ export function SeriesView() { - Status / Progress + ); } diff --git a/frontend/src/views/Settings/SettingsView.tsx b/frontend/src/views/Settings/SettingsView.tsx index f83b489..3fa86ab 100644 --- a/frontend/src/views/Settings/SettingsView.tsx +++ b/frontend/src/views/Settings/SettingsView.tsx @@ -12,7 +12,7 @@ export function SettingsView() { - Status / Progress + ); }