Skip to content

Commit

Permalink
tauri bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Feb 18, 2025
1 parent 8656f47 commit 122952f
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 99 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dist
packages/orderbook/cjs.js
packages/orderbook/cjs.d.ts
packages/orderbook/esm.js
packages/orderbook/esm.d.ts
packages/orderbook/esm.d.ts
tauri-app/src/lib/types
1 change: 0 additions & 1 deletion crates/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod remote;
pub mod scenario;
pub mod sentry;
pub mod subgraph;
pub mod tauri;
pub mod token;
pub mod unit_test;
pub mod yaml;
Expand Down
36 changes: 0 additions & 36 deletions crates/settings/src/tauri.rs

This file was deleted.

8 changes: 6 additions & 2 deletions tauri-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
"author": "Rain Open Source Software Ltd",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "npm run build-bindings && vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint --fix src",
"test": "vitest run",
"lint-check": "eslint src",
"format": "prettier --write src",
"format-bindings": "prettier --write src/lib/types",
"format-check": "prettier --list-different src",
"svelte-lint-format-check": "npm run check && npm run lint-check && npm run format-check"
"svelte-lint-format-check": "npm run check && npm run lint-check && npm run format-check",
"build-bindings": "npm run rm-temp && npm run build-wasm && node ./scripts/build.cjs && npm run format-bindings",
"build-wasm": "cd src-tauri && cargo build --target wasm32-unknown-unknown --lib -r && cd ..",
"rm-temp": "rimraf ./temp"
},
"devDependencies": {
"postcss": "^8.4.32",
Expand Down
26 changes: 26 additions & 0 deletions tauri-app/scripts/build.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('node:fs');
const { execSync } = require('node:child_process');

// create dirs
fs.mkdirSync('./temp', { recursive: true });
fs.mkdirSync('./src/lib/types', { recursive: true });

// generate bindgens
execSync(
`wasm-bindgen --target nodejs ./src-tauri/target/wasm32-unknown-unknown/release/tauri_app.wasm --out-dir ./temp --out-name tauriBindings`,
);

// prepare and move to src/lib/types
let dts = fs.readFileSync(`./temp/tauriBindings.d.ts`, {
encoding: 'utf-8',
});
dts = dts.replace(
`/* tslint:disable */
/* eslint-disable */`,
'',
);
dts = '/* this file is auto-generated, do not modify */\n' + dts;
fs.writeFileSync(`./src/lib/types/tauriBindings.ts`, dts);

execSync('npm run rm-temp');
34 changes: 17 additions & 17 deletions tauri-app/src-tauri/Cargo.lock

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

19 changes: 14 additions & 5 deletions tauri-app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ author = "Rain Open Source Software Ltd"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

# for building bindings
[lib]
crate-type = ["cdylib"]

[build-dependencies]
tauri-build = { version = "1.5", features = [] }

[dependencies]
tauri = { version = "1.5", features = [ "os-all", "window-start-dragging", "fs-write-file", "fs-read-file", "dialog-open", "dialog-save", "shell-open"] }
serde = { version = "1.0", features = ["derive"] }
chrono = { version = "0.4.31", features = ["serde"] }
uuid = { version = "1.7.0", features = ["serde"] }
rain-erc = { git = "https://github.com/rainlanguage/rain.erc", rev = "0106e645ebd49334addc698c5aad9a85370eb54d" }
rain-metadata = { path = "../../lib/rain.interpreter/lib/rain.metadata/crates/cli" }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
tauri = { version = "1.5", features = [ "os-all", "window-start-dragging", "fs-write-file", "fs-read-file", "dialog-open", "dialog-save", "shell-open"] }
serde_json = "1.0"
rain_orderbook_common = { path = "../../crates/common" }
rain_orderbook_quote = { path = "../../crates/quote" }
Expand All @@ -23,16 +33,15 @@ rain_orderbook_bindings = { path = "../../crates/bindings" }
alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "65a68f207287d024cba934bf1e3c8b3f63d2834a" }
alloy = { version = "0.1.4", features = ["full", "node-bindings"] }
reqwest = { version = "0.11.22", features = ["json"] }
chrono = { version = "0.4.32", features = ["serde"] }
uuid = { version = "1.7.0", features = ["serde"] }
serde_bytes = "0.11.14"
thiserror = "1.0.56"
url = "2.5.0"
serde_yaml = "0.9.32"
dotrain = "6.0.1-alpha.24"
futures = "0.3.17"
rain-erc = { git = "https://github.com/rainlanguage/rain.erc", rev = "0106e645ebd49334addc698c5aad9a85370eb54d" }
rain-metadata = { path = "../../lib/rain.interpreter/lib/rain.metadata/crates/cli" }

[target.'cfg(target_family = "wasm")'.dependencies]
wasm-bindgen-utils = "0.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
2 changes: 2 additions & 0 deletions tauri-app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(target_family = "wasm")]
pub mod types;
1 change: 1 addition & 0 deletions tauri-app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub mod error;
pub mod toast;
pub mod transaction_status;
pub mod types;

mod commands;
use commands::app::get_app_commit_sha;
Expand Down
11 changes: 2 additions & 9 deletions tauri-app/src-tauri/src/toast.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
use rain_orderbook_app_settings::tauri::ToastMessageType;
use serde::{Deserialize, Serialize};
use crate::types::{ToastMessageType, ToastPayload};
use tauri::{AppHandle, Manager};

#[derive(Serialize, Deserialize, Clone)]
pub struct ToastPayload {
pub message_type: ToastMessageType,
pub text: String,
}

impl ToastPayload {
pub fn emit(&self, app_handle: AppHandle) {
fn emit(&self, app_handle: AppHandle) {
let _ = app_handle.emit_all("toast", self);
}
}
Expand Down
25 changes: 2 additions & 23 deletions tauri-app/src-tauri/src/transaction_status.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
use alloy::sol_types::SolCall;
use alloy_ethers_typecast::transaction::WriteTransactionStatus;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use chrono::Utc;
use crate::types::{TransactionStatus, TransactionStatusNotice};
use std::sync::RwLock;
use tauri::{AppHandle, Manager};
use uuid::Uuid;

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "type", content = "payload")]
pub enum TransactionStatus {
Initialized,
PendingPrepare,
PendingSign,
PendingSend,
Confirmed(String),
Failed(String),
}

impl<T: SolCall + Clone> From<WriteTransactionStatus<T>> for TransactionStatus {
fn from(val: WriteTransactionStatus<T>) -> Self {
match val {
Expand All @@ -30,16 +19,6 @@ impl<T: SolCall + Clone> From<WriteTransactionStatus<T>> for TransactionStatus {
}
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TransactionStatusNotice {
pub id: Uuid,
pub status: TransactionStatus,
pub created_at: DateTime<Utc>,

/// Human-readable label to display in the UI, describing the transaction i.e. "Approving ERC20 Token Spend"
pub label: String,
}

pub struct TransactionStatusNoticeRwLock(RwLock<TransactionStatusNotice>);

impl TransactionStatusNoticeRwLock {
Expand Down
5 changes: 5 additions & 0 deletions tauri-app/src-tauri/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod toast;
mod transaction_status;

pub use toast::*;
pub use transaction_status::*;
21 changes: 21 additions & 0 deletions tauri-app/src-tauri/src/types/toast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use serde::{Deserialize, Serialize};
#[cfg(target_family = "wasm")]
use wasm_bindgen_utils::{impl_wasm_traits, prelude::*};

#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
pub enum ToastMessageType {
Success,
Error,
Warning,
Info,
}

#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
pub struct ToastPayload {
pub message_type: ToastMessageType,
pub text: String,
}
#[cfg(target_family = "wasm")]
impl_wasm_traits!(ToastPayload);
33 changes: 33 additions & 0 deletions tauri-app/src-tauri/src/types/transaction_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[cfg(target_family = "wasm")]
use wasm_bindgen_utils::{impl_wasm_traits, prelude::*};

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "type", content = "payload")]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
pub enum TransactionStatus {
Initialized,
PendingPrepare,
PendingSign,
PendingSend,
Confirmed(String),
Failed(String),
}
#[cfg(target_family = "wasm")]
impl_wasm_traits!(TransactionStatus);

#[derive(Serialize, Deserialize, Clone, Debug)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
pub struct TransactionStatusNotice {
#[cfg_attr(target_family = "wasm", tsify(type = "string"))]
pub id: Uuid,
pub status: TransactionStatus,
#[cfg_attr(target_family = "wasm", tsify(type = "string"))]
pub created_at: DateTime<Utc>,
/// Human-readable label to display in the UI, describing the transaction i.e. "Approving ERC20 Token Spend"
pub label: String,
}
#[cfg(target_family = "wasm")]
impl_wasm_traits!(TransactionStatusNotice);
2 changes: 1 addition & 1 deletion tauri-app/src/lib/components/AppToast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { IconError, IconSuccess, IconWarning, IconInfo } from '@rainlanguage/ui-components';
import CloseSolid from 'flowbite-svelte-icons/CloseSolid.svelte';
import type { ToastData } from '$lib/stores/toasts';
import { ToastMessageType } from '@rainlanguage/orderbook/js_api';
import { ToastMessageType } from '$lib/types/tauriBindings';
export let toast: ToastData;
let toastColor:
Expand Down
Loading

0 comments on commit 122952f

Please sign in to comment.