Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 0 additions & 53 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
tauri-build = { version = "1.2", features = [] }

[dependencies]
tauri = { version = "1.2", features = ["shell-all", "system-tray"] }
tauri = { version = "1.2", features = ["fs-exists", "fs-read-file", "path-all", "shell-sidecar"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

Expand Down
49 changes: 24 additions & 25 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ use std::{
process::{Command, Stdio},
thread
};
use tauri::{
// api::process::{Command, CommandChild, Output},
AppHandle, CustomMenuItem, SystemTray, SystemTrayEvent,
SystemTrayMenu, SystemTrayMenuItem,
Manager,
/* use tauri::{
api::process::{Command, CommandChild, Output},
AppHandle, Manager
};
*/

#[tauri::command]
fn stop_testnet(process: u32) {
Expand Down Expand Up @@ -42,7 +41,7 @@ async fn start_testnet(
}

fn main() {
let tray_menu = SystemTrayMenu::new()
/* let tray_menu = SystemTrayMenu::new()
.add_item(CustomMenuItem::new(
"visibility-toggle".to_string(),
"Hide"))
Expand All @@ -51,7 +50,7 @@ fn main() {
"quit".to_string(),
"Quit"
));
let _tray = SystemTray::new().with_menu(tray_menu);
let _tray = SystemTray::new().with_menu(tray_menu); */

/* .setup(|app| {
// the default value is `main`. note that it must be unique
Expand All @@ -71,22 +70,22 @@ fn main() {


let app = tauri::Builder::default()
// .setup(|app| {
// https://tauri.app/v1/guides/features/events
// let id = app.listen_global("event-name", |event| {
// println!("got event-name with payload {:?}", event.payload());
// });
// // unlisten to the event using the `id` returned on the `listen_global` function
// // an `once_global` API is also exposed on the `App` struct
// app.unlisten(id);
/* .setup(|app| {
https://tauri.app/v1/guides/features/events
let id = app.listen_global("event-name", |event| {
println!("got event-name with payload {:?}", event.payload());
});
// unlisten to the event using the `id` returned on the `listen_global` function
// an `once_global` API is also exposed on the `App` struct
app.unlisten(id);

// // emit the `event-name` event to all webview windows on the frontend
// app.emit_all("event-name", Payload { message: "Tauri is awesome!".into() }).unwrap();
// Ok(())
// })
// .system_tray(tray)
// .on_system_tray_event(on_tray_event)
// .manage(AppState {anvil_output: Default::default()})
// emit the `event-name` event to all webview windows on the frontend
app.emit_all("event-name", Payload { message: "Tauri is awesome!".into() }).unwrap();
Ok(())
})
.system_tray(tray)
.on_system_tray_event(on_tray_event)
.manage(AppState {anvil_output: Default::default()}) */
.invoke_handler(tauri::generate_handler![stop_testnet, start_testnet])
.build(tauri::generate_context!())
.expect("error while running tauri application");
Expand All @@ -102,10 +101,10 @@ fn main() {

}

/**
/*
* Limbo till I figure out where to listen for window close outside before clicking on a menuitem
*/
fn _on_tray_event(
/* fn _on_tray_event(
app: &AppHandle,
event: SystemTrayEvent,
) {
Expand Down Expand Up @@ -151,4 +150,4 @@ fn _on_tray_event(
}
_ => {}
}
}
} */
17 changes: 9 additions & 8 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@
"version": "0.0.1"
},
"tauri": {
"systemTray": {
"iconPath": "icons/icon.png",
"menuOnLeftClick": false,
"iconAsTemplate": true
},
"allowlist": {
"all": false,
"shell": {
"all": true,
"open": true,
"sidecar": true,
"scope": [
{
Expand All @@ -29,6 +22,14 @@
"args": true
}
]
},
"fs": {
"scope": ["$APPLOCALDATA/config.json"],
"readFile": true,
"exists": true
},
"path": {
"all": true
}
},
"bundle": {
Expand All @@ -41,7 +42,7 @@
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "anvil.sameold.lab",
"identifier": "com.sameoldlab.anvil-ui",
"targets": "all"
},
"security": {
Expand Down
14 changes: 7 additions & 7 deletions src/anvil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ export const killTestnet = () => {
return _child.kill()
}

import { appLocalDataDir } from "@tauri-apps/api/path"

export async function startTestnet(args: string[] = []) {
// args = ["--config-out", "~/.anvil-ui/anvil.json", ...args]
const appLocalDataDirPath = await appLocalDataDir()
args = ["--config-out", `${appLocalDataDirPath}config.json`, ...args]
const cmd = Command.sidecar("../public/bin/anvil", args)
let i = 0

const unwatch = client.watchBlocks({
onBlock: (block) => {
block_number.update((current) => {
// Check if current block has changed then update block_number and blocks.
// Check if current block has changed then update block_number and blocks.
// Avoids double check and unnecessary updates on block store
if (block.number === null) return current
if (current === block.number.toString()) return current
Expand Down Expand Up @@ -66,17 +68,15 @@ export async function startTestnet(args: string[] = []) {
})

cmd.on("error", (line: string) => {
console.error("on err: ", line)
live.set(false)
console.error("on err: ", line)
testnet_log.update((state) => state + `${line}\n`)
})

// Assigning after don't accidentally get a running process when commnd fails
_child = await cmd.spawn()

cmd.stdout.on("data", (line: string) => {
console.info("stdout: ", line)
live.set(true)
testnet_log.update((state) => {
if (state.includes("command finished with code")) {
blocks.set([]) // save output until next run
Expand All @@ -85,9 +85,9 @@ export async function startTestnet(args: string[] = []) {
return state + `${line}<br/>`
}
})
live.set(true)
})

// Not needed. Errors already handled by listen events
cmd.stderr.on("data", (line) => {
console.debug("stderr: ", line)
testnet_log.update((state) => state + `${line}<br/>`)
Expand Down
15 changes: 12 additions & 3 deletions src/lib/ConfigData.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<script lang="ts">
import { block_number } from "../anvil"
import configJson from "$lib/anvil.json"
import getConfig from "$lib/getConfig"
import Stat from "$lib/Stat.svelte"
import { onMount } from "svelte"

let { base_fee, gas_limit, genesis_timestamp, gas_price } = configJson //check if these change when integrating test client
let base_fee: string, gas_limit: string, genesis_timestamp: string, gas_price: string

onMount(async () => {
// Read the text file in the `$APPCONFIG/app.conf` path
const configJson = await getConfig()
if (!configJson) return
;({ base_fee, gas_limit, genesis_timestamp, gas_price } = configJson) //check if these change when integrating test client

})

let network_id = "31337" //get from viem
let rpc = "localhost:8545" //get from config
let rpc = "localhost:8545" //get from settings config

$: chain_state = [
{ title: "Block #", data: $block_number, grow: false },
Expand Down
12 changes: 10 additions & 2 deletions src/lib/MainNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<NavItem name={route} {active} />
</a>
{/each}
<a
class="nav-item"
href="./tweaks"
> 🧪
</a>
</div>

<div class="nav--end">
Expand Down Expand Up @@ -48,12 +53,15 @@
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}

.nav--main {
// padding: 10px 0;
flex-direction: column;
display: flex;
flex-direction: inherit;
display: inherit;
align-items: inherit;

}

.nav--end {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/clients/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createTestClient, http } from "viem";
import { foundry } from "viem/chains";

const test_client = createTestClient({
chain: foundry,
mode: "anvil",
pollingInterval: 4_000,
transport: http()
});

export const isAutomining = await test_client.getAutomine();

// Delay on adding all of these as anvil should still work with cast.
// Though to avoid breaking GUI best to assume anything might be updated randomly.
25 changes: 25 additions & 0 deletions src/lib/getConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { exists, readTextFile, BaseDirectory } from "@tauri-apps/api/fs"
import type { Address } from "viem"

const getConfig = async () => {
const exist = await exists("config.json", {
dir: BaseDirectory.AppLocalData,
})
if (!exist) throw new Error("config file does not exist")

const config = await readTextFile("config.json", {
dir: BaseDirectory.AppLocalData,
})

return (JSON.parse(config) as {
available_accounts: Address[]
base_fee: string
gas_limit: string
gas_price: string
genesis_timestamp: string
private_keys: Address[]
wallet: { mnemonic: string; derivation_path: string }
})
}

export default getConfig
Loading