Skip to content

Commit

Permalink
enable float support for sending
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelaced committed Sep 11, 2024
1 parent b901551 commit 8b4ec16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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!(
"{}: {}",
Expand Down

0 comments on commit 8b4ec16

Please sign in to comment.