From 64dd855a1a8f0e6c45e788c680fdf690d7a413a9 Mon Sep 17 00:00:00 2001 From: Thomas Jay Rush Date: Sun, 21 Jul 2024 23:24:04 -0400 Subject: [PATCH] Best Version Yet --- app/history.go | 40 ++++++++++++++++++++-- frontend/src/views/History/HistoryView.tsx | 22 ++++++------ frontend/wailsjs/go/app/App.d.ts | 6 ++-- frontend/wailsjs/go/app/App.js | 12 ++++--- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/app/history.go b/app/history.go index d4803d5..95aeb7b 100644 --- a/app/history.go +++ b/app/history.go @@ -1,6 +1,7 @@ package app import ( + "strings" "sync" "github.com/TrueBlocks/trueblocks-core/sdk/v3" @@ -12,15 +13,16 @@ import ( var addrToHistoryMap = map[base.Address][]TransactionEx{} var m = sync.Mutex{} -func (a *App) GetHistory(addr string, first, pageSize int) []TransactionEx { +func (a *App) GetHistoryPage(addr string, first, pageSize int) []TransactionEx { address := base.HexToAddress(addr) m.Lock() defer m.Unlock() if len(addrToHistoryMap[address]) == 0 { + rCtx := output.NewStreamingContext() opts := sdk.ExportOptions{ Addrs: []string{addr}, - RenderCtx: output.NewStreamingContext(), + RenderCtx: rCtx, Globals: sdk.Globals{ Cache: true, Ether: true, @@ -69,15 +71,47 @@ func (a *App) GetHistory(addr string, first, pageSize int) []TransactionEx { } func (a *App) GetHistoryCnt(addr string) int64 { + address := base.HexToAddress(addr) + opts := sdk.ListOptions{ Addrs: []string{addr}, } monitors, _, err := opts.ListCount() if err != nil { - // EventEmitter.Emit("error", err) + a.SendMessage(address, Error, err.Error()) return 0 } else if len(monitors) == 0 { return 0 } return monitors[0].NRecords } + +func (a *App) ConvertToAddress(addr string) (base.Address, bool) { + if !strings.HasSuffix(addr, ".eth") { + ret := base.HexToAddress(addr) + return ret, ret != base.ZeroAddr + } + + m.Lock() + defer m.Unlock() + if ensAddr, exists := a.ensMap[addr]; exists { + return ensAddr, true + } + + // Try to get an ENS or return the same input + opts := sdk.NamesOptions{ + Terms: []string{addr}, + } + if names, _, err := opts.Names(); err != nil { + a.SendMessage(base.ZeroAddr, Error, err.Error()) + return base.ZeroAddr, false + } else { + if len(names) > 0 { + a.ensMap[addr] = names[0].Address + return names[0].Address, true + } else { + ret := base.HexToAddress(addr) + return ret, ret != base.ZeroAddr + } + } +} diff --git a/frontend/src/views/History/HistoryView.tsx b/frontend/src/views/History/HistoryView.tsx index 7a60992..3d5c8ca 100644 --- a/frontend/src/views/History/HistoryView.tsx +++ b/frontend/src/views/History/HistoryView.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from "react"; import classes from "@/App.module.css"; import lClasses from "./HistoryView.module.css"; -import { GetHistory, GetHistoryCnt } from "@gocode/app/App"; +import { GetHistoryPage, GetHistoryCnt } from "@gocode/app/App"; import { app } from "@gocode/models"; import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"; import { useHotkeys } from "react-hotkeys-hook"; @@ -19,29 +19,31 @@ export function HistoryView() { // const [address, setAddress] = useState("0x1db3439a222c519ab44bb1144fc28167b4fa6ee6"); // const [address, setAddress] = useState("0xd8da6bf26964af9d7eed9e03e53415d37aa96045"); // const [address, setAddress] = useState("0x9531c059098e3d194ff87febb587ab07b30b1306"); - const [address, setAddress] = useState("0xf503017d7baf7fbc0fff7492b751025c6a78179b"); + // const [address, setAddress] = useState("0xf503017d7baf7fbc0fff7492b751025c6a78179b"); + const [address, setAddress] = useState("trueblocks.eth"); const [count, setCount] = useState(0); const [loading, setLoading] = useState(false); const [loaded, setLoaded] = useState(false); const [items, setItems] = useState([]); const { curItem, perPage } = useKeyboardPaging2(items, count, [address]); - const fetch = async (addr: string, currentItem: number, itemsPerPage: number) => { - const cnt = await GetHistoryCnt(addr); - setCount(cnt); - const newItems = await GetHistory(addr, currentItem, itemsPerPage); - setItems(newItems); - }; - useEffect(() => { if (loaded && !loading) { + const fetch = async (addr: string, currentItem: number, itemsPerPage: number) => { + const newItems = await GetHistoryPage(addr, currentItem, itemsPerPage); + setItems(newItems); + }; fetch(address, curItem, perPage); } - }, [curItem, perPage]); + }, [count, curItem, perPage]); useEffect(() => { try { setLoading(true); + const fetch = async (addr: string, currentItem: number, itemsPerPage: number) => { + const cnt = await GetHistoryCnt(addr); + setCount(cnt); + }; fetch(address, curItem, perPage); setLoaded(true); } finally { diff --git a/frontend/wailsjs/go/app/App.d.ts b/frontend/wailsjs/go/app/App.d.ts index 4dd9748..32adf28 100755 --- a/frontend/wailsjs/go/app/App.d.ts +++ b/frontend/wailsjs/go/app/App.d.ts @@ -9,6 +9,8 @@ import {output} from '../models'; export function Cancel(arg1:base.Address):Promise; +export function ConvertToAddress(arg1:string):Promise; + export function GenerateEnhanced(arg1:string):Promise; export function GenerateImage(arg1:string):Promise; @@ -23,10 +25,10 @@ export function GetFilelist(arg1:string):Promise>; export function GetFilename(arg1:string):Promise; -export function GetHistory(arg1:string,arg2:number,arg3:number):Promise>; - export function GetHistoryCnt(arg1:string):Promise; +export function GetHistoryPage(arg1:string,arg2:number,arg3:number):Promise>; + export function GetJson(arg1:string):Promise; export function GetLast(arg1:string):Promise; diff --git a/frontend/wailsjs/go/app/App.js b/frontend/wailsjs/go/app/App.js index 6e5c3b0..db9bbe3 100755 --- a/frontend/wailsjs/go/app/App.js +++ b/frontend/wailsjs/go/app/App.js @@ -6,6 +6,10 @@ export function Cancel(arg1) { return window['go']['app']['App']['Cancel'](arg1); } +export function ConvertToAddress(arg1) { + return window['go']['app']['App']['ConvertToAddress'](arg1); +} + export function GenerateEnhanced(arg1) { return window['go']['app']['App']['GenerateEnhanced'](arg1); } @@ -34,14 +38,14 @@ export function GetFilename(arg1) { return window['go']['app']['App']['GetFilename'](arg1); } -export function GetHistory(arg1, arg2, arg3) { - return window['go']['app']['App']['GetHistory'](arg1, arg2, arg3); -} - export function GetHistoryCnt(arg1) { return window['go']['app']['App']['GetHistoryCnt'](arg1); } +export function GetHistoryPage(arg1, arg2, arg3) { + return window['go']['app']['App']['GetHistoryPage'](arg1, arg2, arg3); +} + export function GetJson(arg1) { return window['go']['app']['App']['GetJson'](arg1); }