Skip to content

Commit

Permalink
Develop (#14)
Browse files Browse the repository at this point in the history
* Updates .gitignore

* Best version yet

* Best Version Yet

* Best version yet

* Bump braces from 3.0.2 to 3.0.3 in /frontend (#13)

Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](micromatch/braces@3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thomas Jay Rush <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
tjayrush and dependabot[bot] authored Jul 24, 2024
1 parent b8d0c0d commit 45262b9
Show file tree
Hide file tree
Showing 23 changed files with 827 additions and 1,187 deletions.
34 changes: 33 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"math/rand/v2"
Expand All @@ -23,6 +24,10 @@ import (
"github.com/wailsapp/wails/v2/pkg/runtime"
)

// Since we need App.ctx to display a dialog and we can only get it when Startup method
// is executed, we keep track of the first fatal error that has happened before Startup
var startupError error

type App struct {
ctx context.Context
session config.Session
Expand Down Expand Up @@ -57,7 +62,7 @@ func NewApp() *App {
_ = a.session.Load()

if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
a.Fatal("Error loading .env file")
} else if a.apiKeys["openAi"] = os.Getenv("OPENAI_API_KEY"); a.apiKeys["openAi"] == "" {
log.Fatal("No OPENAI_API_KEY key found")
}
Expand Down Expand Up @@ -94,6 +99,9 @@ func (a App) String() string {

func (a *App) Startup(ctx context.Context) {
a.ctx = ctx
if startupError != nil {
a.Fatal(startupError.Error())
}
if err := a.loadNames(); err != nil {
logger.Panic(err)
}
Expand Down Expand Up @@ -276,3 +284,27 @@ func (a *App) HandleLines() {
}
wg.Wait()
}

func (a *App) Fatal(message string) {
if message == "" {
message = "Fatal error occured. The application cannot continue to run."
}
log.Println(message)

// If a.ctx has not been set yet (i.e. we are before calling Startup), we can't display the
// dialog. Instead, we keep the error and let Startup call this function again when a.ctx is set.
if a.ctx == nil {
// We will only display the first error, since it makes more sense
if startupError == nil {
startupError = errors.New(message)
}
// Return to allow the application to continue starting up, until we get the context
return
}
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "Fatal Error",
Message: message,
})
os.Exit(1)
}
12 changes: 6 additions & 6 deletions app/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func (a *App) loadNames() error {
}
sort.Slice(a.names, func(i, j int) bool {
ti := a.names[i].Type
if ti == names.Regular {
ti = 7
}
tj := a.names[j].Type
if tj == names.Regular {
tj = 7
}
if ti == tj {
if a.names[i].Tags == a.names[j].Tags {
return a.names[i].Address.Hex() < a.names[j].Address.Hex()
}
return a.names[i].Tags < a.names[j].Tags
}
if ti == 4 || ti == 18 {
return true
}
if tj == 4 || tj == 18 {
return false
}
return ti < tj
})
return nil
Expand Down
10 changes: 10 additions & 0 deletions app/names_ex.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ type NameEx struct {
types.Name `json:",inline"`
Type names.Parts `json:"type"`
}

var NameDbParts = []struct {
Value names.Parts
TSName string
}{
{names.Regular, "REGULAR"},
{names.Custom, "CUSTOM"},
{names.Prefund, "PREFUND"},
{names.Baddress, "BADDRESS"},
}
2 changes: 2 additions & 0 deletions databases/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!*.csv
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"serve": "vite preview"
},
"dependencies": {
"@tabler/icons-react": "^2.46.0",
"@tabler/icons-react": "3.11.0",
"@tanstack/react-table": "^8.19.2",
"dirname": "^0.1.0",
"path": "^0.12.7",
Expand All @@ -28,7 +28,7 @@
"@types/react-dom": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"@vitejs/plugin-react": "^2.0.1",
"@vitejs/plugin-react": "4.3.1",
"eslint": "^9.6.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b2847408bf3098df9dcf115aa2c4ab87
2114266d58f44759553ece36602bac3a
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions frontend/src/components/DataTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import lClasses from "./DataTable.module.css";
import { flexRender, Table as ReactTable } from "@tanstack/react-table";
import { Table, Title } from "@mantine/core";
import { CustomMeta } from "./";

export function DataTable<T>({ table, loading }: { table: ReactTable<T>; loading: boolean }) {
if (loading) {
return <Title order={3}>Loading...</Title>;
} else {
return (
<Table>
<Table.Thead>
{table.getHeaderGroups().map((headerGroup) => (
<Table.Tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<Table.Th key={header.id} className={lClasses.centered}>
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
</Table.Th>
))}
</Table.Tr>
))}
</Table.Thead>
<Table.Tbody>
{table.getRowModel().rows.map((row) => (
<Table.Tr key={row.id}>
{row.getVisibleCells().map((cell) => {
const meta = cell.column.columnDef.meta as CustomMeta;
return (
<Table.Td key={cell.id} className={lClasses[meta?.className || ""]}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</Table.Td>
);
})}
</Table.Tr>
))}
</Table.Tbody>
</Table>
);
}
}
2 changes: 2 additions & 0 deletions frontend/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from "./CustomMeta";
export * from "./DataTable";
export * from "./EditableSelect";
export * from "./ImageDisplay";
export * from "./ResultDialog";
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/view/ViewStatus.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
font-size: 14pt;
font-family: monospace;
}

.yellow {
background-color: black;
color: yellow;
font-size: 14pt;
font-family: monospace;
}
11 changes: 9 additions & 2 deletions frontend/src/components/view/ViewStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EventsOn, EventsOff } from "@runtime";
import { Text } from "@mantine/core";
import { MessageType } from "@gocode/app/App";

// TODO: Why is this no availabe in the Wails folders?
// TODO: Why is this not availabe in the Wails folders?
type Progress = {
address: string;
have: number;
Expand All @@ -26,18 +26,25 @@ export function ViewStatus() {
setColor(classes.green);
};

const handleWarning = (warnStr: string) => {
setStatusMessage(`Warning: ${warnStr}`);
setColor(classes.yellow);
};

const handleError = (errorStr: string) => {
setStatusMessage(`Error: ${errorStr}`);
setColor(classes.red);
};

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

return () => {
EventsOff("Done");
EventsOff("Completed");
EventsOff("Progress");
EventsOff("Warning");
EventsOff("Error");
};
}, []);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/History/HistoryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { IconCircleCheck } from "@tabler/icons-react";
import { app } from "@gocode/models";
import { createColumnHelper, ColumnDef } from "@tanstack/react-table";
import { CustomMeta } from "../CustomMeta";
import { CustomMeta } from "@components";

type CustomColumnDef<TData, TValue> = ColumnDef<TData, TValue> & {
meta?: CustomMeta;
Expand All @@ -15,7 +15,7 @@ export const txColumns: CustomColumnDef<app.TransactionEx, any>[] = [
id: "blockTx",
header: () => "Id",
cell: (info) => info.getValue(),
meta: { className: "small" },
meta: { className: "medium-small" },
}),
txColumnHelper.accessor("date", {
header: () => "Date",
Expand Down
45 changes: 4 additions & 41 deletions frontend/src/views/History/HistoryView.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { useState, useEffect } from "react";
import classes from "@/App.module.css";
import lClasses from "../Columns.module.css";
import { GetHistoryPage, GetHistoryCnt } from "@gocode/app/App";
import { app } from "@gocode/models";
import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
import { Stack, Table, Title } from "@mantine/core";
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";
import { Stack, Title } from "@mantine/core";
import { txColumns } from "./HistoryTable";
import { CustomMeta } from "../CustomMeta";
import { EditableSelect, View, ViewStatus } from "@components";
import { useKeyboardPaging } from "@hooks";
import { DataTable } from "@components";

export function HistoryView() {
const [address, setAddress] = useState<string>("trueblocks.eth");
Expand Down Expand Up @@ -48,16 +47,6 @@ export function HistoryView() {
getCoreRowModel: getCoreRowModel(),
});

if (loading) {
return (
<View>
<Stack className={classes.mainContent}>
<Title order={3}>Loading...</Title>
</Stack>
</View>
);
}

return (
<View>
<Stack className={classes.mainContent}>
Expand All @@ -70,33 +59,7 @@ export function HistoryView() {
label="Select or enter an address or ENS name"
placeholder="Enter or select an address"
/>
<Table>
<Table.Thead>
{table.getHeaderGroups().map((headerGroup) => (
<Table.Tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<Table.Th key={header.id} className={lClasses.centered}>
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
</Table.Th>
))}
</Table.Tr>
))}
</Table.Thead>
<Table.Tbody>
{table.getRowModel().rows.map((row) => (
<Table.Tr key={row.id}>
{row.getVisibleCells().map((cell) => {
var meta = cell.column.columnDef.meta as CustomMeta;
return (
<Table.Td key={cell.id} className={lClasses[meta?.className || ""]}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</Table.Td>
);
})}
</Table.Tr>
))}
</Table.Tbody>
</Table>
<DataTable<app.TransactionEx> table={table} loading={loading} />
</Stack>
<ViewStatus />
</View>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/Names/NameTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { IconCircleCheck } from "@tabler/icons-react";
import { app } from "@gocode/models";
import { createColumnHelper, ColumnDef } from "@tanstack/react-table";
import { CustomMeta } from "../CustomMeta";
import { CustomMeta } from "@components";
import { NameTags } from "./NameTag";

type CustomColumnDef<TData, TValue> = ColumnDef<TData, TValue> & {
Expand Down Expand Up @@ -39,7 +39,7 @@ export const nameColumns: CustomColumnDef<app.NameEx, any>[] = [
}),
nameColumnHelper.accessor("decimals", {
header: () => "Decimals",
cell: (info) => info.renderValue(),
cell: (info) => (info.getValue() === 0 ? "-" : info.getValue()),
meta: { className: "small" },
}),
nameColumnHelper.accessor("isContract", {
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/views/Names/NameTag.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React, { ReactNode, useEffect } from "react";
import { Badge } from "@mantine/core";
import { app } from "@gocode/models";
import { app, names } from "@gocode/models";

export const NameTags = ({ name }: { name: app.NameEx }) => {
const [tags, setTags] = React.useState<ReactNode>([]);

useEffect(() => {
var types: ReactNode[] = [];
if (name.type & 2) {
types.push(<Badge color="blue">Reg</Badge>);
if (name.type & names.Parts.REGULAR) {
types.push(<Badge color="blue">R</Badge>);
}
if (name.type & 4) {
types.push(<Badge color="yellow">Cus</Badge>);
if (name.type & names.Parts.CUSTOM) {
types.push(<Badge color="yellow">C</Badge>);
}
if (name.type & 8) {
types.push(<Badge color="green">Pre</Badge>);
if (name.type & names.Parts.PREFUND) {
types.push(<Badge color="green">P</Badge>);
}
if (name.type & 16) {
types.push(<Badge color="pink">Bad</Badge>);
if (name.type & names.Parts.BADDRESS) {
types.push(<Badge color="pink">B</Badge>);
}
setTags(<div>{types.map((tag) => tag)}</div>);
}, [name]);
Expand Down
Loading

0 comments on commit 45262b9

Please sign in to comment.