Skip to content

Commit

Permalink
fix UI
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Jul 16, 2024
1 parent 1a08a73 commit 26e67ea
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
async fn get_address(&self, _: Request<tari_rpc::Empty>) -> Result<Response<GetAddressResponse>, Status> {
let address = self
.wallet
.get_wallet_address()
.get_wallet_interactive_address()
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;
Ok(Response::new(GetAddressResponse {
Expand Down Expand Up @@ -662,7 +662,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.map_err(|err| Status::unknown(err.to_string()))?;
let wallet_address = self
.wallet
.get_wallet_address()
.get_wallet_interactive_address()
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;
let transactions = transactions
Expand Down
9 changes: 7 additions & 2 deletions applications/minotari_console_wallet/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ impl<B: Backend> App<B> {
base_node_config: PeerConfig,
notifier: Notifier,
) -> Result<Self, ExitError> {
let wallet_address = wallet.get_wallet_address().await?;
let wallet_id = WalletIdentity::new(wallet.comms.node_identity(), wallet_address);
let wallet_address_interactive = wallet.get_wallet_interactive_address().await?;
let wallet_address_one_sided = wallet.get_wallet_one_sided_address().await?;
let wallet_id = WalletIdentity::new(
wallet.comms.node_identity(),
wallet_address_interactive,
wallet_address_one_sided,
);
let app_state = AppState::new(
&wallet_id,
wallet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl ReceiveTab {

let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(6), Constraint::Length(23)].as_ref())
.constraints([Constraint::Length(8), Constraint::Length(23)].as_ref())
.margin(1)
.split(area);

Expand All @@ -46,6 +46,8 @@ impl ReceiveTab {
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
]
.as_ref(),
)
Expand All @@ -57,54 +59,76 @@ impl ReceiveTab {
.title(Span::styled("Connection Details", Style::default().fg(Color::White)));
f.render_widget(block, chunks[0]);

const ITEM_01: &str = "Tari Address: ";
const ITEM_02: &str = "Node ID: ";
const ITEM_03: &str = "Network Address: ";
const ITEM_04: &str = "Emoji ID: ";
const ITEM_01: &str = "Tari Address interactive: ";
const ITEM_02: &str = "Tari Address one-sided: ";
const ITEM_03: &str = "Node ID: ";
const ITEM_04: &str = "Network Address: ";
const ITEM_05: &str = "Interactive emoji address: ";
const ITEM_06: &str = "One-sided emoji address: ";

// Tari address
let tari_address_text = Spans::from(vec![
let tari_address_interactive_text = Spans::from(vec![
Span::styled(ITEM_01, Style::default().fg(Color::Magenta)),
Span::styled(
app_state.get_identity().tari_address.clone(),
app_state.get_identity().tari_address_interactive.to_base58(),
Style::default().fg(Color::White),
),
]);
let paragraph = Paragraph::new(tari_address_text).block(Block::default());
let paragraph = Paragraph::new(tari_address_interactive_text).block(Block::default());
f.render_widget(paragraph, details_chunks[0]);

let tari_address_one_sided_text = Spans::from(vec![
Span::styled(ITEM_02, Style::default().fg(Color::Magenta)),
Span::styled(
app_state.get_identity().tari_address_one_sided.to_base58(),
Style::default().fg(Color::White),
),
]);
let paragraph = Paragraph::new(tari_address_one_sided_text).block(Block::default());
f.render_widget(paragraph, details_chunks[1]);

// NodeId
let node_id_text = Spans::from(vec![
Span::styled(ITEM_02, Style::default().fg(Color::Magenta)),
Span::styled(ITEM_03, Style::default().fg(Color::Magenta)),
Span::styled(
app_state.get_identity().node_id.clone(),
Style::default().fg(Color::White),
),
]);
let paragraph = Paragraph::new(node_id_text).block(Block::default());
f.render_widget(paragraph, details_chunks[1]);
f.render_widget(paragraph, details_chunks[2]);

// Public Address
let public_address_text = Spans::from(vec![
Span::styled(ITEM_03, Style::default().fg(Color::Magenta)),
Span::styled(ITEM_04, Style::default().fg(Color::Magenta)),
Span::styled(
app_state.get_identity().network_address.clone(),
Style::default().fg(Color::White),
),
]);
let paragraph = Paragraph::new(public_address_text).block(Block::default());
f.render_widget(paragraph, details_chunks[2]);
f.render_widget(paragraph, details_chunks[3]);

// Emoji ID
let emoji_id_text = Spans::from(vec![
Span::styled(ITEM_04, Style::default().fg(Color::Magenta)),
Span::styled(ITEM_05, Style::default().fg(Color::Magenta)),
Span::styled(
app_state.get_identity().emoji_id.clone(),
app_state.get_identity().tari_address_interactive.to_emoji_string(),
Style::default().fg(Color::White),
),
]);
let paragraph = Paragraph::new(emoji_id_text).block(Block::default());
f.render_widget(paragraph, details_chunks[3]);
f.render_widget(paragraph, details_chunks[4]);

let emoji_id_text = Spans::from(vec![
Span::styled(ITEM_06, Style::default().fg(Color::Magenta)),
Span::styled(
app_state.get_identity().tari_address_one_sided.to_emoji_string(),
Style::default().fg(Color::White),
),
]);
let paragraph = Paragraph::new(emoji_id_text).block(Block::default());
f.render_widget(paragraph, details_chunks[5]);
}
}

Expand Down
18 changes: 8 additions & 10 deletions applications/minotari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,11 +897,10 @@ impl AppStateInner {

pub async fn refresh_network_id(&mut self) -> Result<(), UiError> {
let wallet_id = self.wallet.get_wallet_id().await?;
let eid = wallet_id.address.to_emoji_string();
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_id.network(),
wallet_id.address.to_base58()
wallet_id.address_interactive.to_base58()
);
let code = QrCode::new(qr_link).unwrap();
let image = code
Expand All @@ -913,15 +912,15 @@ impl AppStateInner {
.skip(1)
.fold("".to_string(), |acc, l| format!("{}{}\n", acc, l));
let identity = MyIdentity {
tari_address: wallet_id.address.to_base58(),
tari_address_interactive: wallet_id.address_interactive.clone(),
tari_address_one_sided: wallet_id.address_one_sided.clone(),
network_address: wallet_id
.node_identity
.public_addresses()
.iter()
.map(|a| a.to_string())
.collect::<Vec<_>>()
.join(", "),
emoji_id: eid,
qr_code: image,
node_id: wallet_id.node_identity.node_id().to_string(),
};
Expand Down Expand Up @@ -1234,11 +1233,10 @@ pub struct EventListItem {

impl AppStateData {
pub fn new(wallet_identity: &WalletIdentity, base_node_selected: Peer, base_node_config: PeerConfig) -> Self {
let eid = wallet_identity.address.to_emoji_string();
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_identity.network(),
wallet_identity.address.to_base58()
wallet_identity.address_interactive.to_base58()
);
let code = QrCode::new(qr_link).unwrap();
let image = code
Expand All @@ -1251,15 +1249,15 @@ impl AppStateData {
.fold("".to_string(), |acc, l| format!("{}{}\n", acc, l));

let identity = MyIdentity {
tari_address: wallet_identity.address.to_base58(),
tari_address_interactive: wallet_identity.address_interactive.clone(),
tari_address_one_sided: wallet_identity.address_one_sided.clone(),
network_address: wallet_identity
.node_identity
.public_addresses()
.iter()
.map(|a| a.to_string())
.collect::<Vec<_>>()
.join(", "),
emoji_id: eid,
qr_code: image,
node_id: wallet_identity.node_identity.node_id().to_string(),
};
Expand Down Expand Up @@ -1309,9 +1307,9 @@ impl AppStateData {

#[derive(Clone)]
pub struct MyIdentity {
pub tari_address: String,
pub tari_address_interactive: TariAddress,
pub tari_address_one_sided: TariAddress,
pub network_address: String,
pub emoji_id: String,
pub qr_code: String,
pub node_id: String,
}
Expand Down
19 changes: 13 additions & 6 deletions base_layer/wallet/src/util/wallet_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,39 @@ use tari_core::transactions::key_manager::TariKeyId;
#[derive(Clone, Debug)]
pub struct WalletIdentity {
pub node_identity: Arc<NodeIdentity>,
pub address: TariAddress,
pub address_interactive: TariAddress,
pub address_one_sided: TariAddress,
pub wallet_node_key_id: TariKeyId,
}

impl WalletIdentity {
pub fn new(node_identity: Arc<NodeIdentity>, address: TariAddress) -> Self {
pub fn new(
node_identity: Arc<NodeIdentity>,
address_interactive: TariAddress,
address_one_sided: TariAddress,
) -> Self {
let wallet_node_key_id = TariKeyId::Imported {
key: node_identity.public_key().clone(),
};
WalletIdentity {
node_identity,
address,
address_interactive,
address_one_sided,
wallet_node_key_id,
}
}

pub fn network(&self) -> Network {
self.address.network()
self.address_interactive.network()
}
}

impl Display for WalletIdentity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "{}", self.node_identity)?;
writeln!(f, "Tari Address: {}", self.address)?;
writeln!(f, "Network: {:?}", self.address.network())?;
writeln!(f, "Tari Address interactive: {}", self.address_interactive)?;
writeln!(f, "Tari Address one-sided: {}", self.address_one_sided)?;
writeln!(f, "Network: {:?}", self.address_interactive.network())?;
Ok(())
}
}
43 changes: 31 additions & 12 deletions base_layer/wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use log::*;
use rand::rngs::OsRng;
use tari_common::configuration::bootstrap::ApplicationType;
use tari_common_types::{
tari_address::TariAddress,
tari_address::{TariAddress, TariAddressFeatures},
transaction::{ImportStatus, TxId},
types::{ComAndPubSignature, Commitment, PrivateKey, PublicKey, RangeProof, SignatureWithDomain},
wallet_types::WalletType,
Expand Down Expand Up @@ -137,6 +137,7 @@ pub struct Wallet<T, U, V, W, TKeyManagerInterface> {
pub db: WalletDatabase<T>,
pub output_db: OutputManagerDatabase<V>,
pub factories: CryptoFactories,
wallet_type: WalletType,
_u: PhantomData<U>,
_v: PhantomData<V>,
_w: PhantomData<W>,
Expand Down Expand Up @@ -206,7 +207,7 @@ where
key_manager_backend,
master_seed,
factories.clone(),
wallet_type,
wallet_type.clone(),
))
.add_initializer(TransactionServiceInitializer::<U, T, TKeyManagerInterface>::new(
config.transaction_service_config,
Expand Down Expand Up @@ -356,6 +357,7 @@ where
db: wallet_database,
output_db: output_manager_database,
factories,
wallet_type,
_u: PhantomData,
_v: PhantomData,
_w: PhantomData,
Expand Down Expand Up @@ -475,23 +477,40 @@ where
}
}

pub async fn get_wallet_address(&self) -> Result<TariAddress, WalletError> {
pub async fn get_wallet_interactive_address(&self) -> Result<TariAddress, WalletError> {
let (_view_key_id, view_key) = self.key_manager_service.get_view_key().await?;
Ok(TariAddress::new_dual_address_with_default_features(
view_key.clone(),
self.comms.node_identity().public_key().clone(),
let (_comms_key_id, comms_key) = self.key_manager_service.get_comms_key().await?;
let features = match self.wallet_type {
WalletType::Software => TariAddressFeatures::default(),
WalletType::Ledger(_) | WalletType::Imported(_) => TariAddressFeatures::create_interactive_only(),
};
Ok(TariAddress::new_dual_address(
view_key,
comms_key,
self.network.as_network(),
features,
))
}

pub async fn get_wallet_id(&self) -> Result<WalletIdentity, WalletError> {
pub async fn get_wallet_one_sided_address(&self) -> Result<TariAddress, WalletError> {
let (_view_key_id, view_key) = self.key_manager_service.get_view_key().await?;
let address = TariAddress::new_dual_address_with_default_features(
view_key.clone(),
self.comms.node_identity().public_key().clone(),
let (_spend_key_id, spend_key) = self.key_manager_service.get_spend_key().await?;
Ok(TariAddress::new_dual_address(
view_key,
spend_key,
self.network.as_network(),
);
Ok(WalletIdentity::new(self.comms.node_identity(), address))
TariAddressFeatures::create_one_sided_only(),
))
}

pub async fn get_wallet_id(&self) -> Result<WalletIdentity, WalletError> {
let address_interactive = self.get_wallet_interactive_address().await?;
let address_one_sided = self.get_wallet_one_sided_address().await?;
Ok(WalletIdentity::new(
self.comms.node_identity(),
address_interactive,
address_one_sided,
))
}

pub fn get_software_updater(&self) -> Option<SoftwareUpdaterHandle> {
Expand Down
6 changes: 3 additions & 3 deletions base_layer/wallet/tests/transaction_service_tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use tari_common_types::{
tari_address::TariAddress,
transaction::{ImportStatus, TransactionDirection, TransactionStatus, TxId},
types::{FixedHash, PrivateKey, PublicKey, Signature},
wallet_types::WalletType,
wallet_types::{ImportedWallet, WalletType},
};
use tari_comms::{
message::EnvelopeBody,
Expand Down Expand Up @@ -169,7 +169,7 @@ use tokio::{
task,
time::sleep,
};
use tari_common_types::wallet_types::ImportedWallet;

use crate::support::{
base_node_service_mock::MockBaseNodeService,
comms_and_services::{create_dummy_message, setup_comms_services},
Expand Down Expand Up @@ -228,7 +228,7 @@ async fn setup_transaction_service<P: AsRef<Path>>(
let db_cipher = XChaCha20Poly1305::new(key_ga);
let kms_backend = KeyManagerSqliteDatabase::init(connection, db_cipher);
let wallet_type = WalletType::Imported(ImportedWallet {
public_spend_key: PublicKey::from_secret_key(&node_identity.secret_key()),
public_spend_key: PublicKey::from_secret_key(node_identity.secret_key()),
private_spend_key: Some(node_identity.secret_key().clone()),
view_key: SK::random(&mut OsRng),
});
Expand Down
Loading

0 comments on commit 26e67ea

Please sign in to comment.