Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: List Transactions #191

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/app/operations/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ impl App {
Ok(())
}

pub async fn list_transactions(
&self,
// after: Option<String>,
// before: Option<String>,
last: Option<i64>,
first: Option<i64>,
// wallet_ids: Option<Vec<Option<String>>>,
all: bool,
) -> anyhow::Result<()> {
let result = self
.client
.list_transactions()
.await
.context("Error occurred while fetching transactions")?;

if let Some(transactions) = result {
let selected_transactions: Vec<_> = if all {
transactions.iter().collect()
} else if let Some(first) = first {
let total_transactions = transactions.len();
transactions
.iter()
.skip(total_transactions.saturating_sub(first.try_into().unwrap()))
.collect()
} else if let Some(last) = last {
transactions.iter().take(last.try_into().unwrap()).collect()
} else {
transactions.iter().collect()
};

println!(
"{}",
serde_json::to_string_pretty(&selected_transactions)
.context("Failed to serialize JSON")?
);
}
Ok(())
}

pub async fn set_username(&self, username: String) -> anyhow::Result<()> {
self.client
.set_username(username)
Expand Down
15 changes: 15 additions & 0 deletions src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ pub enum Command {
Logout,
/// Execute Me query
Me,
// Lists all transactions of user
Transactions {
// #[clap(short, long)]
// after: Option<String>,
// #[clap(short, long)]
// before: Option<String>,
#[clap(short, long, default_value("5"), conflicts_with("first"))]
last: Option<i64>,
#[clap(short, long)]
first: Option<i64>,
// #[clap(long, use_value_delimiter = true)]
// wallet_ids: Option<Vec<Option<String>>>,
#[clap(long, conflicts_with_all(["first", "last"]))]
all: bool,
},
/// Get WalletId for an account
DefaultWallet {
#[clap(value_parser)]
Expand Down
10 changes: 10 additions & 0 deletions src/cli/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ pub async fn run() -> anyhow::Result<()> {
Command::Me => {
app.me().await?;
}
Command::Transactions {
// after,
// before,
last,
first,
// wallet_ids,
all,
} => {
app.list_transactions(last, first, all).await?;
}
Command::DefaultWallet { username } => {
app.default_wallet(username).await?;
}
Expand Down
2 changes: 2 additions & 0 deletions src/client/errors/me_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ use thiserror::Error;
pub enum MeError {
#[error("Failed to unwrap .me")]
FailedToUnwrapMe,
#[error("Failed to unwrap transactions")]
FailedToUnwrapTransactions,
}
59 changes: 59 additions & 0 deletions src/client/gql/queries/transactions.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
query Transactions {
me {
defaultAccount {
__typename
transactions {
edges {
cursor
node {
createdAt
direction
id
initiationVia {
__typename
... on InitiationViaIntraLedger {
counterPartyUsername
counterPartyWalletId
}
... on InitiationViaLn {
paymentHash
}
... on InitiationViaOnChain {
address
}
}
memo
settlementAmount
settlementCurrency
settlementDisplayAmount
settlementDisplayCurrency
settlementDisplayFee
settlementFee
settlementPrice {
base
currencyUnit
formattedAmount
offset
}
settlementVia {
__typename
... on SettlementViaIntraLedger {
counterPartyUsername
counterPartyWalletId
}
... on SettlementViaLn {
preImage
paymentSecret
}
... on SettlementViaOnChain {
transactionHash
vout
}
}
status
}
}
}
}
}
}
Loading