Skip to content

Commit

Permalink
Review sugestion cleanup + more help messages for exit
Browse files Browse the repository at this point in the history
  • Loading branch information
maaktweluit committed Jan 18, 2021
1 parent 2899cad commit 0b26ca8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
34 changes: 28 additions & 6 deletions core/payment/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use crate::accounts::{init_account, Account};
use crate::{wallet, DEFAULT_PAYMENT_DRIVER, DEFAULT_PAYMENT_PLATFORM};
// External crates
use bigdecimal::BigDecimal;
use chrono::Utc;
use std::str::FromStr;
use structopt::*;

// Workspace uses
use ya_core_model::{identity as id_api, payment::local as pay};
use ya_service_api::{CliCtx, CommandOutput, ResponseTable};
use ya_service_bus::{typed as bus, RpcEndpoint};

// Local uses
use crate::accounts::{init_account, Account};
use crate::{wallet, DEFAULT_PAYMENT_DRIVER, DEFAULT_PAYMENT_PLATFORM};

/// Payment management.
#[derive(StructOpt, Debug)]
pub enum PaymentCli {
Expand All @@ -20,7 +27,9 @@ pub enum PaymentCli {
token: Option<String>,
},
Exit {
#[structopt(help = "Optional address to exit to. [default: <DEFAULT_IDENTIDITY>]")]
to: Option<String>,
#[structopt(long, short, help = "Optional amount to exit. [default: <ALL_FUNDS>]")]
amount: Option<String>,
#[structopt(long, default_value = DEFAULT_PAYMENT_DRIVER)]
driver: String,
Expand All @@ -44,8 +53,9 @@ pub enum PaymentCli {
command: InvoiceCommand,
},
Transfer {
amount: String,
to: String,
#[structopt(long, short)]
amount: String,
#[structopt(long, default_value = DEFAULT_PAYMENT_DRIVER)]
driver: String,
#[structopt(long, short)]
Expand Down Expand Up @@ -146,21 +156,33 @@ impl PaymentCli {
driver,
network,
token,
} => CommandOutput::object(wallet::enter(amount, driver, network, token).await?),
} => {
let amount = BigDecimal::from_str(&amount)?;
CommandOutput::object(wallet::enter(amount, driver, network, token).await?)
},
PaymentCli::Exit {
to,
amount,
driver,
network,
token,
} => CommandOutput::object(wallet::exit(to, amount, driver, network, token).await?),
} => {
let amount = match amount {
None => None,
Some(a) => Some(BigDecimal::from_str(&a)?)
};
CommandOutput::object(wallet::exit(to, amount, driver, network, token).await?)
},
PaymentCli::Transfer {
to,
amount,
driver,
network,
token,
} => CommandOutput::object(wallet::transfer(to, amount, driver, network, token).await?),
} => {
let amount = BigDecimal::from_str(&amount)?;
CommandOutput::object(wallet::transfer(to, amount, driver, network, token).await?)
},
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion core/payment/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// External crates
use bigdecimal::BigDecimal;

// Workspace uses
use ya_core_model::driver::{driver_bus_id, Enter, Exit, Transfer};
use ya_service_bus::typed as bus;

Expand Down Expand Up @@ -28,7 +32,7 @@ pub async fn exit(

pub async fn transfer(
to: String,
amount: BigDeciaml,
amount: BigDecimal,
driver: String,
network: Option<String>,
token: Option<String>,
Expand Down

0 comments on commit 0b26ca8

Please sign in to comment.