Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Decode requests in dashboard #5621

Merged
merged 90 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
3c07095
bus-client: Connect before publish
Aug 18, 2022
492e8be
dashboard: WorkflowCompileResult message
Aug 25, 2022
ea85d83
dashboard: Add @truffle/decoder dep
Aug 25, 2022
8e77a6d
dashboard: Add @truffle/codec dep
Aug 25, 2022
9549f7a
dashboard: Add object-inspect deps
Aug 18, 2022
5f0c4db
dashboard: Fix bad `tsx` file extension
Aug 24, 2022
4d730f9
dashboard: Add @truffle/compile-common dep
Aug 25, 2022
2f46633
dashboard: Fix naming mistake
Oct 6, 2022
e148f46
dashboard: Update @truffle/ deps
Oct 7, 2022
de901f5
dashboard: Add object-hash deps
Oct 7, 2022
a26c1c7
dashboard: Add idb dep
Oct 7, 2022
985c2af
dashboard: Simplify bus client init logic
Oct 7, 2022
c1cf401
dashboard: State improvements
Oct 7, 2022
1e5c322
dashboard: Extract bus client init logic into its own function
Oct 7, 2022
d2fdc0c
dashboard: IndexedDB setup
Oct 7, 2022
ee54f16
dashboard: Migrate from react-scripts to webpack + babel
Oct 11, 2022
cbdc158
dashboard: Add to and organize existing dev server scripts
Oct 12, 2022
773c684
dashboard: Webpack build directly into destination during `build` com…
Oct 12, 2022
e769b29
dashboard: Remove cpy-cli devDep
Oct 12, 2022
716cc44
dashboard: Add polyfills necessary for web3
Oct 12, 2022
3290e9d
dashboard: Add eslint devDep
Oct 12, 2022
cbde513
dashboard: Add eslint-webpack-plugin devDep
Oct 12, 2022
8aea944
dashboard: Configure eslint webpack plugin
Oct 12, 2022
90971bf
dashboard: Upgrade truffle namespace deps to latest
Oct 14, 2022
c628d8f
dashboard: Remove unnecessary nested build directory level
Oct 14, 2022
1672516
dashboard: Some webpack config for niceness
Oct 14, 2022
1f4a31c
dashboard: Decoder setup
Oct 14, 2022
26856f1
dashboard: Upgrade concurrently devDep
Oct 14, 2022
c44c1e7
dashboard: Use concurrently programmatically to start dev servers
Oct 14, 2022
2427199
dashboard: Webpack log progress
Oct 14, 2022
e79dd61
dashboard: Use only message lifecycle to handle message
Oct 14, 2022
18eb3f4
dashboard: Handle WorkflowCompileResultMessage (partial impl.)
Oct 14, 2022
67285d8
dashboard: Init decoder before bus client
Oct 15, 2022
e0ba804
dashboard: Decode and render in `<RPC />`
Oct 15, 2022
ab18d2e
dashboard: Remove decoding from `<RPC />` state
Oct 15, 2022
2ab9a7b
dashboard: Fix initDecoder bad logic
Oct 16, 2022
7c6536f
dashboard: Handle WorkflowCompileResultMessage (finished impl.)
Oct 16, 2022
a82df2a
dashboard: Remove unnecessary label
Oct 16, 2022
9c261a7
dashboard: Move log and debug message handling outside of reducer
Oct 16, 2022
6c2ff11
dashboard: Tighten SetDecoderAction data property type
Oct 16, 2022
1fb3695
dashboard: Add terser-webpack-plugin devDep
Oct 18, 2022
8dd01b8
dashboard: Properly mute console via webpack
Oct 18, 2022
b74dfcd
dashboard: Update comment on batch insert optimization
Oct 18, 2022
6a316d1
dashboard: Wrap db insert in try-catch
Oct 18, 2022
579f185
dashboard: Webpack only minimize for build
Oct 18, 2022
f9f8f4c
dashboard: Add warning sign when decoding fails.
Oct 18, 2022
bbac26a
dashboard: Change labels
Oct 18, 2022
d7348c2
dashboard: Move eth_signTransaction to array of unsupported methods
Oct 18, 2022
01a7543
dashboard: Only try to decode for eth_sendTransaction
Oct 18, 2022
0b11d89
dashboard: Better `<RPC />` decoding-related logic and display
Oct 18, 2022
a9e3738
dashboard: Use icon when showing decode fail
Oct 18, 2022
9841cf1
dashboard: Notification when transaction decoding fails / recovers
Oct 24, 2022
e4d7c52
dashboard: Fix idb import
Oct 24, 2022
9e37df4
dashboard: Decoder use `window.ethereum`
Oct 25, 2022
f706b70
dashboard: Confirm provider messages using `window.ethereum`
Oct 25, 2022
ce82b14
dashboard: Remove unused provider from state and remove references to it
Oct 25, 2022
cb777f7
dashboard: Remove unnecessary async/await
Oct 25, 2022
9487fbf
dashboard: Remove unnecessary @ts-ignore comment
Oct 25, 2022
e4249e1
dashboard: Prevent prism from crashing when decoding isn't ready
Oct 25, 2022
a04a67b
dashboard: Support decoding personal_sign requests
Oct 25, 2022
0b6b11b
dashboard: Remove unnecessary variable to indicate `<Details />` view
Oct 25, 2022
0e0b473
dashboard: Tighten prop type for inspected decoding
Oct 25, 2022
2e6dc1e
dashboard: Change code highlight language depending on request method
Oct 25, 2022
57473b9
dashboard: Nest some styles in `<Global />`
Oct 25, 2022
22a387c
dashboard: Change some variable / type names from upper to camel / pa…
Oct 25, 2022
f55fa36
dashboard: Minor fix mute error regex pattern
Oct 25, 2022
dd386fe
dashboard: Add missing Buffer import
Oct 25, 2022
63b103a
dashboard: Support decoding eth_signTypedData_v3 + eth_signTypedData_v4
Oct 26, 2022
4552ea4
dashboard: Fix code highlight for decoded typed data
Oct 26, 2022
fb002d9
dashboard: Use latest @truffle deps
Oct 27, 2022
6f0d4ca
dashboard: Stdin accept ^C to stop dev servers
Oct 28, 2022
02d0cab
dashboard: Hide decode notification in effect clean-up
Oct 28, 2022
5c137c5
dashboard: Move hide notification logic into its own effect
Oct 28, 2022
80c780f
dashboard: Add missing dependency in `<RPC />` effects
Oct 28, 2022
1539521
workflow-compile: Wait for "compile:succeed" event handlers
Nov 1, 2022
50c6f14
dashboard: Webpack config use `nosources-source-map`
Nov 14, 2022
d5cf616
dashboard: Switch babel-loader out for ts-loader
Nov 14, 2022
94ee482
dashboard: Remove unused babel deps and config
Nov 14, 2022
fecf7ca
dashboard: Generalize WorkflowCompileResultMessage to be CliEventMessage
Nov 15, 2022
fbfe32b
bus-common: Remove package.json empty dependencies field
Nov 15, 2022
23ea247
dashboard: Remove \.jsx? check in webpack config
Nov 15, 2022
de0ac22
dashboard: Update some deps
Nov 15, 2022
dd6dc4b
dashboard: Change @truffle/compile-common to be devDep
Nov 17, 2022
dd09d96
dashboard: Pass around decoding object
Nov 17, 2022
aa8035b
bus-common: Improve CliEventMessage type
Nov 17, 2022
48b1200
dashboard: Update to latest @truffle deps
Nov 17, 2022
e8618ce
dashboard: Create and use Decoding type
Nov 18, 2022
ecc8ea8
dashboard: Extract getHighlightLanguageForRpcMethod
Nov 18, 2022
98819e3
bus-common: Add generic to isCliEventMessage
Nov 18, 2022
822a619
bus-common: Remove CliEventMessage default generic param
Nov 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/dashboard-message-bus-client/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class DashboardMessageBusClient {
const { type, payload } = options;
let message = createMessage(type, payload);
try {
await this.ready();

const lifecycle = new PublishMessageLifecycle({
message,
connection: this._publishConnection
Expand Down
23 changes: 21 additions & 2 deletions packages/dashboard-message-bus-common/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ export interface Response {
payload: any;
}

export type CliEventMessageType = "cli-event";
export const cliEventMessageType = "cli-event";
/**
* Message to inform subscribers of Truffle CLI event data.
* The message payload label helps identify the type of event data.
*/
export interface CliEventMessage<T> extends Message {
type: CliEventMessageType;
payload: {
label: string;
data: T;
};
}

export type DashboardProviderMessageType = "provider";
export const dashboardProviderMessageType = "provider";
/**
Expand All @@ -27,7 +41,6 @@ export interface DashboardProviderMessage extends Message {

export type LogMessageType = "log";
export const logMessageType = "log";

/**
* Message intended to log messages across the message bus.
* The message payload includes a "debug" namespace as well as a message.
Expand All @@ -43,7 +56,6 @@ export interface LogMessage extends Message {

export type DebugMessageType = "debug";
export const debugMessageType = "debug";

/**
* Message to log in Dashboard browser console
*/
Expand All @@ -66,6 +78,12 @@ export interface InvalidateMessage extends Message {
payload: number;
}

export const isCliEventMessage = <T>(
message: Message
): message is CliEventMessage<T> => {
return message.type === cliEventMessageType;
};

export const isDashboardProviderMessage = (
message: Message
): message is DashboardProviderMessage => {
Expand All @@ -87,6 +105,7 @@ export const isInvalidateMessage = (
};

export type MessageType =
| CliEventMessage<unknown>
| DashboardProviderMessageType
| LogMessageType
| DebugMessageType
Expand Down
48 changes: 48 additions & 0 deletions packages/dashboard/dev-server/all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import concurrently from "concurrently";

function notice(text: string) {
console.log(`\x1b[34m\x1b[1m${text}\x1b[0m`);
}

async function startServers() {
notice("Press ^C or Q to exit\nStarting servers...");

const { commands, result } = concurrently(
[
{
command: "yarn start:server",
name: "dashboard",
prefixColor: "bgMagenta.bold"
},
{
command: "yarn start:react",
name: "webpack",
prefixColor: "cyan.bgBlack.bold"
}
],
{
killOthers: ["success", "failure"],
handleInput: true
}
);

const kill = () => commands.forEach(command => void command.kill("SIGINT"));

process.stdin.setRawMode(true);
process.stdin.on("data", async data => {
const isControlC = data.equals(Buffer.from("\x03"));
const isQ = /^q$/i.test(data.toString().trim());

if (isControlC || isQ) {
notice("Stopping servers...");
kill();
try {
await result;
} catch (err) {
/* We don't really care. */
}
}
});
}
benjamincburns marked this conversation as resolved.
Show resolved Hide resolved

startServers();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ const options = {
rpc: true,
autoOpen: false
};

const dashboardServer = new DashboardServer(options);
dashboardServer.start();

async function startServer() {
await dashboardServer.start();
console.log(
`Dashboard server running at http://${options.host}:${options.port}`
);
benjamincburns marked this conversation as resolved.
Show resolved Hide resolved
}

startServer();
12 changes: 12 additions & 0 deletions packages/dashboard/dev-server/webpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Webpack from "webpack";
import WebpackDevServer from "webpack-dev-server";
import webpackConfig from "../webpack.config";

const compiler = Webpack(webpackConfig);
const server = new WebpackDevServer(webpackConfig.devServer, compiler);

async function startServer() {
await server.start();
}

startServer();
7 changes: 1 addition & 6 deletions packages/dashboard/lib/DashboardServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ export class DashboardServer {
this.rpc = options.rpc ?? true;
this.verbose = options.verbose ?? false;
this.autoOpen = options.autoOpen ?? true;
this.frontendPath = path.join(
__dirname,
".",
"dashboard-frontend",
"build"
);
this.frontendPath = path.join(__dirname, "dashboard-frontend");
benjamincburns marked this conversation as resolved.
Show resolved Hide resolved

this.boundTerminateListener = () => this.stop();
}
Expand Down
52 changes: 35 additions & 17 deletions packages/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
"dist/lib"
],
"scripts": {
"build": "yarn build:react && yarn build:server && yarn copy:react",
"build:react": "react-scripts build",
"build:server": "tsc -p tsconfig.server.json",
"copy:react": "cpy build/** dist/lib/dashboard-frontend/ --parents --dot",
"build": "yarn build:server && yarn build:react --output-path ./dist/lib/dashboard-frontend",
"build:react": "cross-env NODE_ENV=\"production\" webpack",
"build:server": "tsc --project tsconfig.server.json",
"prepare": "yarn build",
"start": "concurrently --kill-others \"yarn start:dev-server\" \"NODE_ENV=\"development\" yarn start:react\"",
"start:dev-server": "ts-node --project tsconfig.server.json bin/start-dev-server.ts",
"start:prebuilt": "node dist/bin/start-dev-server.js",
"start:react": "react-scripts start",
"start": "ts-node --project tsconfig.server.json ./dev-server/all.ts",
"start:react": "ts-node --project tsconfig.server.json ./dev-server/webpack.ts",
"start:server": "ts-node --project tsconfig.server.json ./dev-server/dashboard.ts",
"test": "jest --passWithNoTests"
},
"types": "dist/lib/index.d.ts",
Expand All @@ -39,42 +37,62 @@
"@mantine/hooks": "^5.0.0",
"@mantine/notifications": "^5.0.0",
"@mantine/prism": "^5.0.0",
"@truffle/codec": "^0.14.9",
"@truffle/dashboard-message-bus": "^0.1.8",
"@truffle/dashboard-message-bus-client": "^0.1.8",
"@truffle/dashboard-message-bus-common": "^0.1.4",
"@truffle/decoder": "^5.3.0",
"cors": "^2.8.5",
"debug": "^4.3.2",
"ethers": "^5.6.9",
"express": "^4.17.1",
"get-port": "^5.1.1",
"idb": "^7.1.1",
"isomorphic-ws": "^4.0.1",
"object-hash": "^3.0.0",
"object-inspect": "^1.12.2",
"open": "^8.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-feather": "^2.0.10",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"wagmi": "^0.6.3",
"ws": "^7.2.0"
},
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/core": "^7.20.2",
"@babel/plugin-syntax-flow": "^7.18.6",
"@babel/plugin-transform-react-jsx": "^7.18.10",
"@babel/plugin-transform-react-jsx": "^7.19.0",
"@truffle/compile-common": "^0.9.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/express": "^4.17.14",
"@types/jest": "27.4.1",
"@types/node": "~12.12.0",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/object-hash": "^2.2.1",
"@types/object-inspect": "^1.8.1",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/ws": "^7.2.0",
"concurrently": "^6.5.1",
"cpy-cli": "^3.1.1",
"concurrently": "^7.5.0",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",
"eslint": "^8.25.0",
"eslint-config-react-app": "^7.0.1",
"eslint-webpack-plugin": "^3.2.0",
"html-webpack-plugin": "^5.5.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"terser-webpack-plugin": "^5.3.6",
"ts-jest": "29.0.3",
"ts-loader": "^9.4.1",
"ts-node": "10.7.0",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"vm-browserify": "^1.1.2",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
},
"publishConfig": {
"access": "public"
Expand Down
48 changes: 14 additions & 34 deletions packages/dashboard/public/index.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Truffle Dashboard" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Truffle Dashboard</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Truffle Dashboard" />
<title>Truffle Dashboard</title>
</head>

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
<body>
<div id="root"></div>
<noscript>
JavaScript is disabled in your browser.
Please consider enabling it to run this app.
</noscript>
</body>

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file removed packages/dashboard/public/logo192.png
Binary file not shown.
Binary file removed packages/dashboard/public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions packages/dashboard/public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/dashboard/public/robots.txt

This file was deleted.

35 changes: 19 additions & 16 deletions packages/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Wrappers
import MantineWrapper from "src/components/wrappers/MantineWrapper";
import ColorSchemeWrapper from "src/components/wrappers/ColorSchemeWrapper";
import { NotificationsProvider } from "@mantine/notifications";
import WagmiWrapper from "src/components/wrappers/WagmiWrapper";
import { DashProvider } from "src/contexts/DashContext";
// Router
Expand All @@ -17,22 +18,24 @@ function App(): JSX.Element {
<ColorSchemeWrapper>
<MantineWrapper>
<MantineGlobal /> {/* Set global styles */}
<WagmiWrapper>
<DashProvider>
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Navigate to="/rpcs" replace />} />
<Route path="rpcs" element={<RPCs />} />
</Route>
{process.env.NODE_ENV === "development" && (
<Route path="colors" element={<Palette />} />
)}
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
</BrowserRouter>
</DashProvider>
</WagmiWrapper>
<NotificationsProvider limit={5}>
<WagmiWrapper>
<DashProvider>
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Navigate to="/rpcs" replace />} />
<Route path="rpcs" element={<RPCs />} />
</Route>
{process.env.NODE_ENV === "development" && (
<Route path="colors" element={<Palette />} />
)}
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
</BrowserRouter>
</DashProvider>
</WagmiWrapper>
</NotificationsProvider>
</MantineWrapper>
</ColorSchemeWrapper>
</div>
Expand Down
Loading