Skip to content

Commit

Permalink
rusty kaspa PR compatibility; market rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Dec 20, 2023
1 parent e11fa7b commit 5318750
Show file tree
Hide file tree
Showing 35 changed files with 336 additions and 202 deletions.
17 changes: 10 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,22 @@ kaspad = { path = "../rusty-kaspa/kaspad" }
# |_|_| |__| | \ | \_ | |___ |__| |_|_| | \ ___]
# _________________________________________________________

# workflow-chrome = "0.9.0"
# workflow-dom = "0.9.0"
# workflow-http = "0.9.0"
# workflow-log = "0.9.0"
# workflow-store = "0.9.0"
# workflow-core = { version = "0.9.0", features = ["no-unsafe-eval"] }
# workflow-i18n = { version = "0.9.0", features = ["preserve-order"] }
# workflow-chrome = "0.10.1"
# workflow-dom = "0.10.1"
# workflow-http = "0.10.1"
# workflow-log = "0.10.1"
# workflow-store = "0.10.1"
# workflow-core = { version = "0.10.1", features = ["no-unsafe-eval"] }
# workflow-i18n = { version = "0.10.1", features = ["preserve-order"] }

workflow-chrome = { path = "../workflow-rs/chrome" }
workflow-dom = { path = "../workflow-rs/dom" }
workflow-http = { path = "../workflow-rs/http" }
workflow-log = { path = "../workflow-rs/log" }
workflow-store = { path = "../workflow-rs/store" }
workflow-core = { path = "../workflow-rs/core", features = ["no-unsafe-eval"] }
workflow-i18n = { path = "../workflow-rs/i18n", features = ["preserve-order"] }

# workflow-chrome = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-dom = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
# workflow-http = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" }
Expand All @@ -126,6 +128,7 @@ cfg-if = "1.0.0"
chrome-sys = "0.1.0"
# chrome-sys = {path = "../chrome-sys"}
chrono = "0.4.31"
convert_case = "0.6.0"
clap = { version = "4.4.7", features = ["derive", "string", "cargo"] }
ctrlc = { version = "3.2", features = ["termination"] }
derivative = "2.2.0"
Expand Down
9 changes: 0 additions & 9 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
<!-- this is the base url relative to which other urls will be constructed. trunk will insert this from the public-url option -->
<base data-trunk-public-url />

<script>
console.log("window.adaptor 1:", window.adaptor);
(async () => {
console.log("window.adaptor 2:", window.adaptor);

// await start_app();
})();
</script>

<link data-trunk rel="copy-dir" href="../resources/icons" />
<link data-trunk rel="icon" href="../resources/icons/favicon.ico">

Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ workflow-i18n.workspace = true
ahash.workspace = true
async-trait.workspace = true
cfg-if.workspace = true
convert_case.workspace = true
derivative.workspace = true
downcast-rs.workspace = true
downcast.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use cfg_if::cfg_if;
use kaspa_ng_core::runtime;
use kaspa_ng_core::settings::Settings;
use kaspa_wallet_core::api::WalletApi;
use std::iter::once;
use std::sync::Arc;
use workflow_i18n::*;
use workflow_log::*;
Expand Down Expand Up @@ -60,6 +59,7 @@ cfg_if! {
#[allow(unused)]
use clap::{arg, command, Arg, Command};
use std::env::{args,var};
use std::iter::once;

if args().any(|arg| arg == "--daemon") || var("KASPA_NG_DAEMON").is_ok() {
let args = once("kaspad".to_string()).chain(args().skip(1).filter(|arg| arg != "--daemon"));//.collect::<Vec<String>>();
Expand Down
20 changes: 13 additions & 7 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct Core {
pub release: Option<Release>,

pub device: Device,
pub market: Market,
pub market: Option<Market>,
pub debug: bool,
}

Expand Down Expand Up @@ -179,7 +179,7 @@ impl Core {
release: None,

device: Device::default(),
market: Market::default(),
market: None,
debug: false,
};

Expand Down Expand Up @@ -582,12 +582,18 @@ impl Core {
_frame: &mut eframe::Frame,
) -> Result<()> {
match event {
Events::Market(update) => match update {
MarketUpdate::Price(price) => {
self.market.price.replace(price);
Events::Market(update) => {
if self.market.is_none() {
self.market = Some(Market::default());
}
MarketUpdate::Ohlc(ohlc) => {
self.market.ohlc.replace(ohlc);

match update {
MarketUpdate::Price(price) => {
self.market.as_mut().unwrap().price.replace(price);
}
MarketUpdate::Ohlc(ohlc) => {
self.market.as_mut().unwrap().ohlc.replace(ohlc);
}
}
},
Events::ThemeChange => {
Expand Down
1 change: 0 additions & 1 deletion core/src/egui/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ impl<'panel, Context> Panel<'panel, Context> {
ui.horizontal(|ui| {
match self.back {
Some(back) if self.back_enabled => {
println!("Back is enabled");
let icon = CompositeIcon::new(egui_phosphor::bold::ARROW_BEND_UP_LEFT)
.icon_size(icon_size.inner.x)
.padding(Some(icon_padding));
Expand Down
9 changes: 9 additions & 0 deletions core/src/egui/theme/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub struct ThemeColor {
pub icon_color_default: Color32,
pub ack_color: Color32,
pub nack_color: Color32,
pub market_default_color: Color32,
pub market_up_color: Color32,
pub market_down_color: Color32,

pub raised_text_color: Color32,
pub raised_text_shadow: Color32,
Expand Down Expand Up @@ -86,6 +89,9 @@ impl ThemeColor {
icon_color_default: Color32::from_rgb(240, 240, 240),
ack_color: Color32::from_rgb(100, 200, 100),
nack_color: Color32::from_rgb(200, 100, 100),
market_default_color: Color32::from_rgb(240,240,240),
market_up_color: Color32::from_rgb(136, 255, 136),
market_down_color: Color32::from_rgb(255, 136, 136),

raised_text_color: Color32::from_rgb(255, 255, 255),
raised_text_shadow: Color32::from_rgb(0, 0, 0),
Expand Down Expand Up @@ -150,6 +156,9 @@ impl ThemeColor {
icon_color_default: Color32::from_rgb(32, 32, 32),
ack_color: Color32::from_rgb(100, 200, 100),
nack_color: Color32::from_rgb(200, 100, 100),
market_default_color: Color32::from_rgb(20,20,20),
market_up_color: Color32::from_rgb(41, 77, 41),
market_down_color: Color32::from_rgb(77, 41, 41),

raised_text_color: Color32::from_rgb(0, 0, 0),
raised_text_shadow: Color32::from_rgb(255, 255, 255),
Expand Down
18 changes: 7 additions & 11 deletions core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ pub use kaspa_consensus_core::Hash as KaspaHash;
pub use kaspa_rpc_core::api::rpc::RpcApi;
pub use kaspa_utils::hex::{FromHex, ToHex};
pub use kaspa_utils::{hashmap::GroupExtension, networking::ContextualNetAddress};
pub use kaspa_wallet_core::api;
pub use kaspa_wallet_core::api::WalletApi;
pub use kaspa_wallet_core::events::SyncState;
pub use kaspa_wallet_core::prelude::Address;
pub use kaspa_wallet_core::rpc::DynRpcApi;
pub use kaspa_wallet_core::runtime::{Account as KaspaAccount, Wallet as KaspaWallet};
pub use kaspa_wallet_core::runtime::{AccountDescriptor, AccountId, Balance};
pub use kaspa_wallet_core::secret::Secret;
pub use kaspa_wallet_core::storage::{
IdT, PrvKeyDataId, TransactionId, TransactionRecord, WalletDescriptor,
pub use kaspa_wallet_core::prelude::{
Account as CoreAccount, AccountCreateArgs, AccountCreateArgsBip32, AccountDescriptor,
AccountId, AccountKind, Address, Balance, DynRpcApi, IdT, KaspaRpcClient, Language, Mnemonic,
PrvKeyDataArgs, PrvKeyDataCreateArgs, PrvKeyDataId, PrvKeyDataInfo, Secret, SyncState,
TransactionId, TransactionRecord, Wallet as CoreWallet, WalletApi, WalletCreateArgs,
WalletDescriptor, WordCount, WrpcEncoding,
};
pub use kaspa_wallet_core::utils::*;
pub use kaspa_wrpc_client::{KaspaRpcClient, WrpcEncoding};

pub use async_trait::async_trait;
pub use futures::{pin_mut, select, FutureExt, StreamExt};
Expand Down Expand Up @@ -69,6 +64,7 @@ pub use crate::events::{ApplicationEventsChannel, Events};
pub use crate::menu::Menu;
pub use crate::modules;
pub use crate::modules::{Module, ModuleCaps, ModuleStyle, ModuleT};
pub use crate::market::MarketData;
pub use crate::network::Network;
pub use crate::notifications::{UserNotification, UserNotifyKind};
pub use crate::primitives::{
Expand Down
24 changes: 19 additions & 5 deletions core/src/market.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
use crate::imports::*;

#[derive(Default, Debug)]
#[derive(Debug)]
pub struct MarketData {
pub price: Option<f64>,
pub market_cap: Option<f64>,
pub volume: Option<f64>,
pub change: Option<f64>,
pub price: f64,
pub market_cap: f64,
pub volume: f64,
pub change: f64,
pub precision : usize,
}

impl MarketData {
pub fn new(symbol : &str) -> Self {
let precision = precision_from_symbol(symbol);
Self {
price : 0.0,
market_cap : 0.0,
volume : 0.0,
change : 0.0,
precision,
}
}
}

pub type MarketDataMap = AHashMap<String, MarketData>;
Expand Down
28 changes: 8 additions & 20 deletions core/src/modules/account_create.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![allow(unused_imports)]

use crate::imports::*;
use kaspa_bip32::Mnemonic;
use kaspa_wallet_core::api::AccountsCreateRequest;
use kaspa_wallet_core::runtime::wallet::AccountCreateArgsBip32;
use kaspa_wallet_core::runtime::{AccountCreateArgs, PrvKeyDataCreateArgs, WalletCreateArgs, PrvKeyDataArgs};
use kaspa_wallet_core::storage::{AccountKind, PrvKeyDataInfo};
// use kaspa_bip32::Mnemonic;
// use kaspa_wallet_core::api::AccountsCreateRequest;
// use kaspa_wallet_core::wallet::AccountCreateArgsBip32;
// use kaspa_wallet_core::wallet::args::{AccountCreateArgs, PrvKeyDataCreateArgs, WalletCreateArgs, PrvKeyDataArgs};
// use kaspa_wallet_core::storage::{AccountKind, PrvKeyDataInfo};
// use kaspa_wallet_core::prelude::{AccountKind, PrvKeyDataInfo};


#[derive(Clone)]
Expand All @@ -32,7 +33,7 @@ pub enum State {
AccountError(Arc<Error>),
PresentMnemonic(Arc<CreationData>),
ConfirmMnemonic(Arc<CreationData>),
Finish(Arc<dyn KaspaAccount>),
Finish(Arc<dyn CoreAccount>),
}

#[derive(Clone)]
Expand All @@ -42,28 +43,15 @@ pub enum CreationData {
},
Bip32 {
mnemonic: Option<Mnemonic>,
// account: Arc<dyn KaspaAccount>,
},
Keypair {
private_key: Secret,
// account: Arc<dyn KaspaAccount>,
},
MultiSig {
mnemonics: Vec<Mnemonic>,
// account: Arc<dyn KaspaAccount>,
},
}

// impl CreationData {
// pub fn account(&self) -> Arc<dyn KaspaAccount> {
// match self {
// Self::Bip32 { account, .. } => account.clone(),
// Self::Keypair { account, .. } => account.clone(),
// Self::MultiSig { account, .. } => account.clone(),
// }
// }
// }

#[derive(Default, Debug, Clone, Copy, Eq, PartialEq)]
enum Focus {
#[default]
Expand Down Expand Up @@ -380,7 +368,7 @@ impl ModuleT for AccountCreate {

if let Some(result) = account_create_result.take() {
match result {
Ok(descriptor) => {
Ok(_descriptor) => {
println!("Account created successfully");
// let account = Account::from(descriptor);
// core.account_collection.as_mut().expect("account collection").push_unchecked(account.clone());
Expand Down
18 changes: 12 additions & 6 deletions core/src/modules/account_manager/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ impl<'context> BalancePane<'context> {
);
}

if let Some(price_list) = core.market.price.as_ref() {
for (symbol, data) in price_list.iter() {
if let Some(price) = data.price {
let text = format!("{:.8} {}", sompi_to_kaspa(balance.mature) * price, symbol.to_uppercase());
ui.label(RichText::new(text).font(FontId::proportional(16.)));
}
if let Some(market) = core.market.as_ref() {
if let Some(price_list) = market.price.as_ref() {
let mut symbols = price_list.keys().collect::<Vec<_>>();
symbols.sort();
symbols.into_iter().for_each(|symbol| {
if let Some(data) = price_list.get(symbol) {
let symbol = symbol.to_uppercase();
let MarketData { price, change : _, .. } = data;
let text = format!("{:.8} {}", sompi_to_kaspa(balance.mature) * (*price), symbol.as_str());
ui.label(RichText::new(text).font(FontId::proportional(16.)));
}
});
}
}

Expand Down
59 changes: 26 additions & 33 deletions core/src/modules/account_manager/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,33 @@ impl Details {

let descriptor = account.descriptor();

match &*descriptor {
AccountDescriptor::Bip32(descriptor) => {
descriptor.render(ui);
ui.add_space(8.);

let mut address_kind : Option<NewAddressKind> = None;

ui.horizontal(|ui|{
if ui.medium_button("Generate New Receive Address").clicked() {
address_kind = Some(NewAddressKind::Receive);
}
if ui.medium_button("Generate New Change Address").clicked() {
address_kind = Some(NewAddressKind::Change);
}
});

if let Some(address_kind) = address_kind {
let account_id = account.id();
spawn(async move {
runtime()
.wallet()
.accounts_create_new_address(account_id, address_kind)
.await
.map_err(|err|Error::custom(format!("Failed to create new address\n{err}")))?;

runtime().request_repaint();

Ok(())
});
}
},
_ => {
ui.label("Unknown descriptor type");
descriptor.render(ui);
ui.add_space(8.);

let mut address_kind : Option<NewAddressKind> = None;

ui.horizontal(|ui|{
if ui.medium_button("Generate New Receive Address").clicked() {
address_kind = Some(NewAddressKind::Receive);
}
if ui.medium_button("Generate New Change Address").clicked() {
address_kind = Some(NewAddressKind::Change);
}
});

if let Some(address_kind) = address_kind {
let account_id = account.id();
spawn(async move {
runtime()
.wallet()
.accounts_create_new_address(account_id, address_kind)
.await
.map_err(|err|Error::custom(format!("Failed to create new address\n{err}")))?;

runtime().request_repaint();

Ok(())
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/account_manager/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl AccountMenu {
.show(ui, |ui| {

account_list.retain(|selectable_account|{
if selectable_account.descriptor().prv_key_data_id() == Some(&prv_key_data_info.id) {
if selectable_account.descriptor().prv_key_data_ids().contains(&prv_key_data_info.id) {

if ui.account_selector_button(selectable_account, network_type, account.id() == selectable_account.id(), core.balance_padding()).clicked() {
account_manager.request_estimate();
Expand Down
2 changes: 1 addition & 1 deletion core/src/modules/account_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::borrow::Cow;
use egui_phosphor::thin::{CLOUD_ARROW_DOWN, CLOUD_SLASH};
use kaspa_wallet_core::tx::{GeneratorSummary, PaymentOutput, Fees};
use kaspa_wallet_core::api::*;
use crate::primitives::descriptors::*;
use crate::primitives::descriptor::*;

mod address;
mod balance;
Expand Down
Loading

0 comments on commit 5318750

Please sign in to comment.