Skip to content
Open
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
27 changes: 14 additions & 13 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ ahash = "0.8.6"
async-trait = "0.1.73"
borsh = { version = "0.9.1", features = ["rc"] } # please keep this fixed
cfg-if = "1.0.0"
chrome-sys = "0.1.0"
# chrome-sys = {path = "../chrome-sys"}
# chrome-sys = "0.1.0"
chrome-sys = {path = "../chrome-sys"}
chrono = "0.4.31"
clap = { version = "4.4.7", features = ["derive", "string", "cargo"] }
convert_case = "0.6.0"
Expand Down Expand Up @@ -201,7 +201,7 @@ thiserror = "1.0.50"
tokio = { version = "1", features = ["sync", "rt-multi-thread", "process"] }
toml = "0.8.8"
walkdir = "2.4.0"
wasm-bindgen = "0.2.87"
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3.64", features = ['Window'] }
xxhash-rust = { version = "0.8.7", features = ["xxh3"] }
Expand Down
20 changes: 20 additions & 0 deletions build-adapter
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# !/bin/bash

# trunk build --config extensions/chrome/Chrome.toml

rm -rf ./dist-chrome
mkdir ./dist-chrome
mkdir ./dist-chrome/icons

cp -r ./core/resources/icons ./dist-chrome/
cp ./extensions/chrome/style.css ./dist-chrome/
cp ./extensions/chrome/manifest.json ./dist-chrome/
cp ./extensions/chrome/popup.html ./dist-chrome/
cp ./extensions/chrome/popup.js ./dist-chrome/
cp ./extensions/chrome/background.js ./dist-chrome/

wasm-pack build --dev --target web --out-name kaspa-ng --out-dir ../../dist-chrome ./extensions/chrome/

# wasm-pack build --target web --out-name background --out-dir ../../dist-chrome ./extensions/chrome/


2 changes: 2 additions & 0 deletions build-chrome
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ cp ./extensions/chrome/manifest.json ./dist-chrome/
cp ./extensions/chrome/popup.html ./dist-chrome/
cp ./extensions/chrome/popup.js ./dist-chrome/
cp ./extensions/chrome/background.js ./dist-chrome/
cp ./extensions/chrome/content-script.js ./dist-chrome/
cp ./extensions/chrome/api.js ./dist-chrome/

wasm-pack build $@ --target web --out-name kaspa-ng --out-dir ../../dist-chrome ./extensions/chrome/ --features browser-extension
4 changes: 2 additions & 2 deletions core/resources/images/kaspa-node-transparent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 4 additions & 32 deletions core/src/adaptor.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
// Chrome Extension Wallet Adaptor

use crate::imports::*;
use wasm_bindgen::prelude::*;

struct Inner {
#[allow(dead_code)]
runtime: Runtime,
pub enum WebEvent {
AccountSelection(AccountId),
}

impl Inner {
pub fn new(runtime: Runtime) -> Self {
Self { runtime }
}
pub trait AdaptorApi: Sync + Send {
fn post_to_server(&self, event: WebEvent);
}

#[wasm_bindgen]
pub struct Adaptor {
#[allow(dead_code)]
inner: Arc<Inner>,
}

impl Adaptor {
pub fn new(runtime: Runtime) -> Self {
Self {
inner: Arc::new(Inner::new(runtime.clone())),
}
}
}

#[wasm_bindgen]
impl Adaptor {
#[wasm_bindgen(js_name = "sendTransaction")]
pub fn send_transaction(&self) -> Result<()> {
Ok(())
}
}

// static mut ADAPTOR : Option<Adaptor> = None;
24 changes: 13 additions & 11 deletions core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ cfg_if! {
"Kaspa NG",
native_options,
Box::new(move |cc| {
let runtime = runtime::Runtime::new(&cc.egui_ctx, &settings, wallet_api, application_events);
let runtime = runtime::Runtime::new(&cc.egui_ctx, &settings, wallet_api, application_events, None);
delegate.lock().unwrap().replace(runtime.clone());
runtime::signals::Signals::bind(&runtime);
runtime.start();
Expand All @@ -279,9 +279,9 @@ cfg_if! {
} else {

// use crate::result::Result;
use crate::adaptor::AdaptorApi;

pub async fn kaspa_ng_main(wallet_api : Option<Arc<dyn WalletApi>>, application_events : Option<ApplicationEventsChannel>) -> Result<()> {
use wasm_bindgen::prelude::*;
pub async fn kaspa_ng_main(wallet_api : Option<Arc<dyn WalletApi>>, application_events : Option<ApplicationEventsChannel>, adaptor: Option<Arc<dyn AdaptorApi>>) -> Result<()> {
use workflow_dom::utils::document;

// ------------------------------------------------------------
Expand Down Expand Up @@ -330,16 +330,18 @@ cfg_if! {

// wallet_api.ping()

let runtime = runtime::Runtime::new(&cc.egui_ctx, &settings, wallet_api, application_events);
// let adaptor = kaspa_ng_core::adaptor::Adaptor::new(runtime.clone());
// let window = web_sys::window().expect("no global `window` exists");
// js_sys::Reflect::set(
// &window,
// &JsValue::from_str("adaptor"),
// &JsValue::from(adaptor),
// ).expect("failed to set adaptor");

let runtime = runtime::Runtime::new(&cc.egui_ctx, &settings, wallet_api, application_events, adaptor);
runtime.start();

let adaptor = kaspa_ng_core::adaptor::Adaptor::new(runtime.clone());
let window = web_sys::window().expect("no global `window` exists");
js_sys::Reflect::set(
&window,
&JsValue::from_str("adaptor"),
&JsValue::from(adaptor),
).expect("failed to set adaptor");


Box::new(kaspa_ng_core::Core::new(cc, runtime, settings, false))
}),
Expand Down
7 changes: 5 additions & 2 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ impl Core {
) -> Result<()> {
// println!("event: {:?}", event);
match event {
// Events::WebMessage(msg)=>{
// log_info!("Events::WebMessage msg: {msg}");
// }
Events::NetworkChange(network) => {
self.modules.clone().values().for_each(|module| {
module.network_change(self, network);
Expand Down Expand Up @@ -757,8 +760,8 @@ impl Core {
// println!("event: {:?}", event);
match *event {
CoreWallet::WalletPing => {
// log_info!("KASPA NG RECEIVED WALLET START EVENT");
crate::runtime::runtime().notify(UserNotification::info("Wallet ping"));
log_info!("KASPA NG RECEIVED WALLET START EVENT");
// crate::runtime::runtime().notify(UserNotification::info("Wallet ping"));
}
CoreWallet::Error { message } => {
// runtime().notify(UserNotification::error(message.as_str()));
Expand Down
1 change: 1 addition & 0 deletions core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub type ApplicationEventsChannel = crate::runtime::channel::Channel<Events>;

#[derive(Clone, Debug)]
pub enum Events {
// WebMessage(String),
NetworkChange(Network),
UpdateStorage(StorageUpdateOptions),
VisibilityChange(VisibilityState),
Expand Down
2 changes: 1 addition & 1 deletion core/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'core> Menu<'core> {
if ui
.add(
Label::new(
RichText::new(format!("{}", egui_phosphor::light::WALLET))
RichText::new(egui_phosphor::light::WALLET.to_string())
.size(device.top_icon_size()),
)
.sense(Sense::click()),
Expand Down
6 changes: 5 additions & 1 deletion core/src/modules/account_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ impl AccountManager {
}
}).render(ui);
} else if account_collection.len() == 1 {
self.select(Some(account_collection.first().unwrap().clone()), core.device().clone());
let account = account_collection.first().unwrap();
self.select(Some(account.clone()), core.device().clone());
} else {
Panel::new(self)
.with_caption(i18n("Select Account"))
Expand Down Expand Up @@ -362,6 +363,9 @@ impl AccountManager {
account_collection.iter().for_each(|account_select| {
if ui.account_selector_button(account_select, &network_type, false, core.balance_padding()).clicked() {
this.select(Some(account_select.clone()), core.device().clone());
let id = account_select.id();
// let _ = core.sender().try_send(Events::Wallet { event: Box::new(kaspa_wallet_core::events::Events::AccountSelection{id: Some(id)}) });
runtime().post_to_server(crate::adaptor::WebEvent::AccountSelection(id));
if core.device().single_pane() {
this.section = AccountManagerSection::Overview;
} else {
Expand Down
15 changes: 15 additions & 0 deletions core/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod channel;
pub mod payload;
pub mod services;
pub mod system;
use crate::adaptor::{AdaptorApi, WebEvent};
pub use payload::Payload;
pub use services::Service;
use services::*;
Expand All @@ -27,6 +28,8 @@ pub struct Inner {
start_time: Instant,
system: Option<System>,

adaptor: Option<Arc<dyn AdaptorApi>>,

kaspa: Arc<KaspaService>,
peer_monitor_service: Arc<PeerMonitorService>,
update_monitor_service: Arc<UpdateMonitorService>,
Expand All @@ -52,6 +55,7 @@ impl Runtime {
settings: &Settings,
wallet_api: Option<Arc<dyn WalletApi>>,
application_events: Option<ApplicationEventsChannel>,
adaptor: Option<Arc<dyn AdaptorApi>>,
) -> Self {
let system = System::new();

Expand Down Expand Up @@ -113,6 +117,7 @@ impl Runtime {
is_running: Arc::new(AtomicBool::new(false)),
start_time: Instant::now(),
system: Some(system),
adaptor,
// #[cfg(not(feature = "lean"))]
metrics_service,
#[cfg(not(feature = "lean"))]
Expand All @@ -125,6 +130,16 @@ impl Runtime {
runtime
}

// pub fn set_adaptor(&self, adapter:Adaptor){
// self.inner.adaptor.lock().unwrap().adaptor = Some(adapter);
// }

pub fn post_to_server(&self, event: WebEvent) {
if let Some(adaptor) = self.inner.adaptor.as_ref() {
adaptor.post_to_server(event);
}
}

pub fn uptime(&self) -> Duration {
self.inner.start_time.elapsed()
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/runtime/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,11 @@ cfg_if! {

}
}

impl Default for System {
fn default() -> Self {
Self::new()
}
}
}
}
4 changes: 2 additions & 2 deletions core/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ async fn fetch_public_servers() -> Result<Arc<HashMap<Network, Vec<Server>>>> {
} else {
href
};
let url = format!("{}/Servers.toml", location.trim_end_matches("/"));
let url = format!("{}/Servers.toml", location.trim_end_matches('/'));
let servers_toml = http::get(url).await?;
Ok(try_parse_servers(&servers_toml)?)
try_parse_servers(&servers_toml)
} else {
// TODO - parse local Servers.toml file
Ok(parse_default_servers().clone())
Expand Down
Loading