From 8b4ec1683cf317e62eb91ae74a4bc519989077bd Mon Sep 17 00:00:00 2001 From: Erin Grasmick Date: Wed, 11 Sep 2024 17:08:21 +0100 Subject: [PATCH] enable float support for sending --- README.md | 3 ++- src/cli.rs | 2 +- src/commands/send.rs | 11 ++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5c89af5..429155b 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ Before using PolkaCLI, configure your account and RPC URL: ### NFT Minting Workflow -*It is recommended to use Pinata for pinning. Please add `pinata_jwt = "yourJWTsecret"` to `~/.polkacli/config`.* +*It is recommended to use [Pinata](https://pinata.cloud/) for pinning.* +To enable this, please add `pinata_jwt = "yourJWTsecret"` to `~/.polkacli/config`. When minting NFTs, PolkaCLI allows you to include metadata and images, either directly or inferred from filenames: diff --git a/src/cli.rs b/src/cli.rs index 058b40e..0479fce 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -93,7 +93,7 @@ pub enum Commands { address: String, #[arg(value_name = "AMOUNT")] - amount: u128, + amount: f64, }, /// Print the balance of the configured account or a provided address diff --git a/src/commands/send.rs b/src/commands/send.rs index 07ea8be..d0e6a90 100644 --- a/src/commands/send.rs +++ b/src/commands/send.rs @@ -10,7 +10,7 @@ use tokio::time::sleep; use crate::commands::assethub; use crate::client::get_client; -pub async fn send(recipient: String, amount: u128) -> Result<()> { +pub async fn send(recipient: String, amount: f64) -> Result<()> { // Establish a connection to the parachain let api = get_client().await?; println!("{}", "🚀 Connection with parachain established.".green().bold()); @@ -22,8 +22,9 @@ pub async fn send(recipient: String, amount: u128) -> Result<()> { let account_signer = crate::config::load_account_from_config()?; let from: AccountId32 = account_signer.public_key().into(); - // Convert amount to Planck (1 PAS = 10^10 Plancks) - let amount_in_plancks = amount * 10u128.pow(10); + // Convert PAS to Planck (1 PAS = 10^10 Plancks) + let plancks_per_pas = 10u128.pow(10) as f64; + let amount_in_plancks = (amount * plancks_per_pas).round() as u128; // Create transfer payload let payload = assethub::tx().balances().transfer_keep_alive(MultiAddress::Id(recipient.clone()), amount_in_plancks); @@ -62,9 +63,9 @@ pub async fn send(recipient: String, amount: u128) -> Result<()> { recipient.to_string().bright_white() ); println!( - "{}: {} PAS", + "{}: {:.10} PAS", "💰 Amount".cyan().bold(), - amount.to_string().bright_white() + amount ); println!( "{}: {}",