Skip to content

Commit

Permalink
Best version yet
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Jul 20, 2024
1 parent 003b82b commit c3e0b43
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 23 deletions.
41 changes: 30 additions & 11 deletions app/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/view/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Stack className={classes.mainContent}>{params.children}</Stack>;
export function View({ title, children }: { title?: string; children: ReactNode }) {
return <Stack className={classes.mainContent}>{children}</Stack>;
}
13 changes: 13 additions & 0 deletions frontend/src/components/view/ViewStatus.module.css
Original file line number Diff line number Diff line change
@@ -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;
}
35 changes: 32 additions & 3 deletions frontend/src/components/view/ViewStatus.tsx
Original file line number Diff line number Diff line change
@@ -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 <Text size="xs">{children}</Text>;
export function ViewStatus() {
const [statusMessage, setStatusMessage] = useState<string>("");
const [color, setColor] = useState<string>(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 (
<Text size="lg">
<div className={color}>{statusMessage}</div>
</Text>
);
}
2 changes: 1 addition & 1 deletion frontend/src/views/Dalle/DalleView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function DalleView() {
</Grid>
<ResultDialog opened={dialogOpened} onClose={() => setDialogOpened(false)} success={success} />
</Stack>
<ViewStatus>Status / Progress</ViewStatus>
<ViewStatus />
</View>
);
}
5 changes: 3 additions & 2 deletions frontend/src/views/History/HistoryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { View, ViewStatus } from "@components";
import { useKeyboardPaging } from "@hooks";

export function HistoryView() {
const [address, setAddress] = useState<string>("0xf503017d7baf7fbc0fff7492b751025c6a78179b");
const [address, setAddress] = useState<string>("0x9531c059098e3d194ff87febb587ab07b30b1306");
// const [address, setAddress] = useState<string>("0xf503017d7baf7fbc0fff7492b751025c6a78179b");
const { items, nItems, curItem } = useKeyboardPaging<types.Transaction>(
(curItem, perPage) => GetHistory(address, curItem, perPage),
() => GetHistoryCnt(address),
Expand Down Expand Up @@ -55,7 +56,7 @@ export function HistoryView() {
</Table.Tbody>
</Table>
</Stack>
<ViewStatus>Status / Progress</ViewStatus>
<ViewStatus />
</View>
);
}
2 changes: 1 addition & 1 deletion frontend/src/views/Home/HomeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function HomeView() {
<Stack className={classes.mainContent}>
<Text>Home View Content</Text>
</Stack>
<ViewStatus>Status / Progress</ViewStatus>
<ViewStatus />
</View>
);
}
2 changes: 1 addition & 1 deletion frontend/src/views/Names/NamesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function NamesView() {
</Table.Tbody>
</Table>
</Stack>
<ViewStatus>Status / Progress</ViewStatus>
<ViewStatus />
</View>
);
}
2 changes: 1 addition & 1 deletion frontend/src/views/Series/SeriesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function SeriesView() {
<Stack className={classes.mainContent}>
<StringTable data={dataItems} />
</Stack>
<ViewStatus>Status / Progress</ViewStatus>
<ViewStatus />
</View>
);
}
2 changes: 1 addition & 1 deletion frontend/src/views/Settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function SettingsView() {
<Checkbox label={"A checkbox"} />
</InputLabel>
</Stack>
<ViewStatus>Status / Progress</ViewStatus>
<ViewStatus />
</View>
);
}

0 comments on commit c3e0b43

Please sign in to comment.