Merge pull request #6 from zcash-hackworks/ui-zec

Render zatoshi amounts in UI as ZEC
This commit is contained in:
str4d 2023-09-07 21:19:02 +01:00 committed by GitHub
commit ef2fb68e9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 11 deletions

View File

@ -5,7 +5,7 @@ use zcash_client_backend::data_api::WalletRead;
use zcash_client_sqlite::WalletDb;
use zcash_primitives::{consensus::Parameters, zip32::AccountId};
use crate::{data::get_db_paths, error, MIN_CONFIRMATIONS};
use crate::{data::get_db_paths, error, ui::format_zec, MIN_CONFIRMATIONS};
// Options accepted for the `balance` command
#[derive(Debug, Options)]
@ -38,8 +38,8 @@ impl Command {
println!("{}", address.encode(&params));
println!(" Height: {}", height);
println!(" Balance: {} zatoshis", u64::from(balance));
println!(" Verified: {} zatoshis", u64::from(verified_balance));
println!(" Balance: {}", format_zec(balance));
println!(" Verified: {}", format_zec(verified_balance));
Ok(())
}

View File

@ -4,13 +4,10 @@ use gumdrop::Options;
use rusqlite::{named_params, Connection};
use zcash_primitives::{
consensus::BlockHeight,
transaction::{
components::{amount::NonNegativeAmount, Amount},
TxId,
},
transaction::{components::amount::NonNegativeAmount, TxId},
};
use crate::data::get_db_paths;
use crate::{data::get_db_paths, ui::format_zec};
// Options accepted for the `list` command
#[derive(Debug, Options)]
@ -128,7 +125,7 @@ impl Transaction {
println!(
" Fee paid: {}",
self.fee_paid
.map(|v| format!("{} zatoshis", u64::from(Amount::from(v))))
.map(|v| format_zec(v.into()))
.as_ref()
.map(|s| s.as_str())
.unwrap_or("Unknown"),

View File

@ -5,7 +5,7 @@ use zcash_client_backend::data_api::WalletRead;
use zcash_client_sqlite::WalletDb;
use zcash_primitives::{consensus::Parameters, zip32::AccountId};
use crate::{data::get_db_paths, error, MIN_CONFIRMATIONS};
use crate::{data::get_db_paths, error, ui::format_zec, MIN_CONFIRMATIONS};
// Options accepted for the `balance` command
#[derive(Debug, Options)]
@ -29,7 +29,7 @@ impl Command {
let notes = db_data.get_spendable_sapling_notes(account, target_height, &[])?;
for note in notes {
println!("{}: {} zatoshis", note.note_id, u64::from(note.note_value));
println!("{}: {}", note.note_id, format_zec(note.note_value));
}
Ok(())

View File

@ -14,6 +14,7 @@ mod commands;
mod data;
mod error;
mod remote;
mod ui;
const MIN_CONFIRMATIONS: u32 = 3;

10
src/ui.rs Normal file
View File

@ -0,0 +1,10 @@
use zcash_primitives::transaction::components::Amount;
const COIN: u64 = 1_0000_0000;
pub(crate) fn format_zec(value: Amount) -> String {
let value = u64::from(value);
let zec = value / COIN;
let frac = value % COIN;
format!("{:3}.{:08} ZEC", zec, frac)
}