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 21, 2024
1 parent 40a9360 commit 8af5cb8
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 597 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type App struct {
titleTemplate *template.Template
Series dalle.Series `json:"series"`
names []types.Name
namesMap map[base.Address]types.Name
dalleCache map[string]*dalle.DalleDress
renderCtxs map[base.Address][]output.RenderCtx
}
Expand Down
75 changes: 66 additions & 9 deletions app/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,64 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"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{}
type TransactionEx struct {
BlockNumber base.Blknum `json:"blockNumber"`
TransactionIndex base.Txnum `json:"transactionIndex"`
Timestamp base.Timestamp `json:"timestamp"`
Date string `json:"date"`
From base.Address `json:"from"`
FromName string `json:"fromName"`
To base.Address `json:"to"`
ToName string `json:"toName"`
Wei base.Wei `json:"wei"`
Ether string `json:"ether"`
Function string `json:"function"`
HasToken bool `json:"hasToken"`
IsError bool `json:"isError"`
}

func NewTransactionEx(a *App, tx *types.Transaction) *TransactionEx {
fromName := a.namesMap[tx.From].Name
if len(fromName) == 0 {
fromName = tx.From.String()
} else if len(fromName) > 39 {
fromName = fromName[:39] + "..."
}
toName := a.namesMap[tx.To].Name
if len(toName) == 0 {
toName = tx.To.String()
} else if len(toName) > 39 {
toName = toName[:39] + "..."
}
ether := tx.Value.ToEtherStr(18)
if tx.Value.IsZero() {
ether = "-"
} else if len(ether) > 5 {
ether = ether[:5]
}
return &TransactionEx{
BlockNumber: tx.BlockNumber,
TransactionIndex: tx.TransactionIndex,
Timestamp: tx.Timestamp,
Date: tx.Date(),
From: tx.From,
FromName: fromName,
To: tx.To,
ToName: toName,
Wei: tx.Value,
Ether: ether,
HasToken: tx.HasToken,
IsError: tx.IsError,
// Function: tx.Function(),
}
}

var addrToHistoryMap = map[base.Address][]TransactionEx{}
var m = sync.Mutex{}

func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction {
func (a *App) GetHistory(addr string, first, pageSize int) []TransactionEx {
address := base.HexToAddress(addr)
m.Lock()
defer m.Unlock()
Expand All @@ -37,12 +88,18 @@ func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction {
if !ok {
continue
}
addrToHistoryMap[address] = append(addrToHistoryMap[address], *tx)
txEx := NewTransactionEx(a, tx)
// if strings.HasPrefix(txEx.ToName, "0x") {
addrToHistoryMap[address] = append(addrToHistoryMap[address], *txEx)
if len(addrToHistoryMap[address])%pageSize == 0 {
runtime.EventsEmit(a.ctx, "Progress", len(addrToHistoryMap[address]), nItems)
a.SendMessage(address, Progress, &ProgressMsg{
Have: int64(len(addrToHistoryMap[address])),
Want: nItems,
})
}
// }
case err := <-opts.RenderCtx.ErrorChan:
runtime.EventsEmit(a.ctx, "Error", err.Error())
a.SendMessage(address, Error, err.Error())
default:
if opts.RenderCtx.WasCanceled() {
return
Expand All @@ -53,11 +110,11 @@ func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction {

_, _, err := opts.Export()
if err != nil {
runtime.EventsEmit(a.ctx, "Error", err.Error())
return []types.Transaction{}
a.SendMessage(address, Error, err.Error())
return []TransactionEx{}
}

runtime.EventsEmit(a.ctx, "Done")
a.SendMessage(address, Completed, "")
}

first = base.Max(0, base.Min(first, len(addrToHistoryMap[address])-1))
Expand Down
32 changes: 32 additions & 0 deletions app/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package app

import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/wailsapp/wails/v2/pkg/runtime"
)

type Message int

const (
Completed Message = iota
Error
Progress
)

type ProgressMsg struct {
Have int64 `json:"have"`
Want int64 `json:"want"`
}

func (a *App) MessageType(msg Message) string {
m := map[Message]string{
Completed: "Completed",
Error: "Error",
Progress: "Progress",
}
return m[msg]
}

func (a *App) SendMessage(addr base.Address, msg Message, data interface{}) {
runtime.EventsEmit(a.ctx, a.MessageType(msg), data)
}
10 changes: 9 additions & 1 deletion app/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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/names"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
)

Expand All @@ -21,15 +22,22 @@ func (a *App) GetNamesCnt() int {
}

func (a *App) loadNames() error {
var err error

types := names.Regular | names.Custom | names.Prefund | names.Baddress
if a.namesMap, err = names.LoadNamesMap("mainnet", types, nil); err != nil {
return err
}

opts := sdk.NamesOptions{
Regular: true,
// Custom: true,
// Prefund: true,
Globals: sdk.Globals{
Chain: "mainnet",
},
}

var err error
if a.names, _, err = opts.Names(); err != nil {
return err
} else {
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/global/Aside.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect } from "react";
import { EventsOn, EventsOff } from "@runtime";
import { Text } from "@mantine/core";

export function Aside() {
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/components/view/ViewStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React, { ReactNode, useState, useEffect } from "react";
import classes from "./ViewStatus.module.css";
import { EventsOn, EventsOff } from "@runtime";
import { Text } from "@mantine/core";
import { MessageType } from "@gocode/app/App";

type Progress = {
have: number;
want: number;
};

export function ViewStatus() {
const [statusMessage, setStatusMessage] = useState<string>("");
Expand All @@ -13,8 +19,8 @@ export function ViewStatus() {
setColor(classes.green);
};

const handleProgress = (x: number, y: number) => {
setStatusMessage(`Progress: ${x}/${y}`);
const handleProgress = (p: Progress) => {
setStatusMessage(`Progress: ${p.have}/${p.want}`);
setColor(classes.green);
};

Expand All @@ -23,7 +29,7 @@ export function ViewStatus() {
setColor(classes.red);
};

EventsOn("Done", handleDone);
EventsOn("Completed", handleDone);
EventsOn("Progress", handleProgress);
EventsOn("Error", handleError);

Expand Down
16 changes: 8 additions & 8 deletions frontend/src/views/History/HistoryTable.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { IconCircleCheck } from "@tabler/icons-react";
import { types } from "@gocode/models";
import { app } from "@gocode/models";
import { createColumnHelper } from "@tanstack/react-table";

const txColumnHelper = createColumnHelper<types.Transaction>();
const txColumnHelper = createColumnHelper<app.TransactionEx>();

export const txColumns = [
txColumnHelper.accessor("blockNumber", {
Expand All @@ -16,23 +16,23 @@ export const txColumns = [
cell: (info) => info.renderValue(),
size: 100,
}),
txColumnHelper.accessor("timestamp", {
header: () => "Timestamp",
txColumnHelper.accessor("date", {
header: () => "Date",
cell: (info) => info.renderValue(),
size: 100,
}),
txColumnHelper.accessor("from", {
txColumnHelper.accessor("fromName", {
header: () => "From",
cell: (info) => info.renderValue(),
size: 100,
}),
txColumnHelper.accessor("to", {
txColumnHelper.accessor("toName", {
header: () => "To",
cell: (info) => info.renderValue(),
size: 100,
}),
txColumnHelper.accessor("value", {
header: () => "Value",
txColumnHelper.accessor("ether", {
header: () => "Ether",
cell: (info) => info.renderValue(),
size: 100,
}),
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/views/History/HistoryView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from "react";
import classes from "@/App.module.css";
import { GetHistory, GetHistoryCnt } from "@gocode/app/App";
import { types } from "@gocode/models";
import { app } from "@gocode/models";
import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
import { useHotkeys } from "react-hotkeys-hook";
import { Stack, Table, Title } from "@mantine/core";
Expand All @@ -10,16 +10,17 @@ import { View, ViewStatus } from "@components";
import { useKeyboardPaging2 } from "@hooks";

export function HistoryView() {
const [address, setAddress] = useState<string>("0xee906d7d5f1748258174be4cbc38930302ab7b42");
// const [address, setAddress] = useState<string>("0x5088d623ba0fcf0131e0897a91734a4d83596aa0");
// const [address, setAddress] = useState<string>("0xee906d7d5f1748258174be4cbc38930302ab7b42");
// const [address, setAddress] = useState<string>("0x8bae48f227d978d084b009b775222baaf61ed9fe");
// const [address, setAddress] = useState<string>("0x3fb1cd2cd96c6d5c0b5eb3322d807b34482481d4");
// const [address, setAddress] = useState<string>("0x5ed8cee6b63b1c6afce3ad7c92f4fd7e1b8fad9f");
// const [address, setAddress] = useState<string>("0x1db3439a222c519ab44bb1144fc28167b4fa6ee6");
// const [address, setAddress] = useState<string>("0xd8da6bf26964af9d7eed9e03e53415d37aa96045");
// const [address, setAddress] = useState<string>("0x9531c059098e3d194ff87febb587ab07b30b1306");
// const [address, setAddress] = useState<string>("0xf503017d7baf7fbc0fff7492b751025c6a78179b");
const [address, setAddress] = useState<string>("0xf503017d7baf7fbc0fff7492b751025c6a78179b");
const [nItems, setNItems] = useState<number>(0);
const { items, curItem } = useKeyboardPaging2<types.Transaction>(
const { items, curItem } = useKeyboardPaging2<app.TransactionEx>(
(curItem, perPage) => GetHistory(address, curItem, perPage),
nItems,
address,
Expand Down
7 changes: 6 additions & 1 deletion frontend/wailsjs/go/app/App.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {base} from '../models';
import {app} from '../models';
import {types} from '../models';
import {config} from '../models';
import {dalle} from '../models';
Expand All @@ -22,7 +23,7 @@ export function GetFilelist(arg1:string):Promise<Array<string>>;

export function GetFilename(arg1:string):Promise<string>;

export function GetHistory(arg1:string,arg2:number,arg3:number):Promise<Array<types.Transaction>>;
export function GetHistory(arg1:string,arg2:number,arg3:number):Promise<Array<app.TransactionEx>>;

export function GetHistoryCnt(arg1:string):Promise<number>;

Expand Down Expand Up @@ -50,12 +51,16 @@ export function LoadSeries():Promise<dalle.Series>;

export function MakeDalleDress(arg1:string):Promise<dalle.DalleDress>;

export function MessageType(arg1:app.Message):Promise<string>;

export function RegisterRenderCtx(arg1:base.Address,arg2:output.RenderCtx):Promise<void>;

export function ReloadDatabases():Promise<void>;

export function Save(arg1:string):Promise<boolean>;

export function SendMessage(arg1:base.Address,arg2:app.Message,arg3:any):Promise<void>;

export function SetLast(arg1:string,arg2:string):Promise<void>;

export function String():Promise<string>;
8 changes: 8 additions & 0 deletions frontend/wailsjs/go/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export function MakeDalleDress(arg1) {
return window['go']['app']['App']['MakeDalleDress'](arg1);
}

export function MessageType(arg1) {
return window['go']['app']['App']['MessageType'](arg1);
}

export function RegisterRenderCtx(arg1, arg2) {
return window['go']['app']['App']['RegisterRenderCtx'](arg1, arg2);
}
Expand All @@ -102,6 +106,10 @@ export function Save(arg1) {
return window['go']['app']['App']['Save'](arg1);
}

export function SendMessage(arg1, arg2, arg3) {
return window['go']['app']['App']['SendMessage'](arg1, arg2, arg3);
}

export function SetLast(arg1, arg2) {
return window['go']['app']['App']['SetLast'](arg1, arg2);
}
Expand Down
Loading

0 comments on commit 8af5cb8

Please sign in to comment.