Skip to content

Commit 92b8948

Browse files
committed
feat: work in progress for note on deposit
1 parent bd69450 commit 92b8948

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

src/pots.rs

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use chrono::{Duration, Utc};
12
use monzo::Client;
23

34
use crate::accounts;
@@ -45,27 +46,51 @@ pub async fn deposit(
4546

4647
let found_pot = find_pot(token, pot_name).await?;
4748

48-
match found_pot {
49-
None => {
50-
println!("No pot found with name: {}", pot_name);
51-
return Ok(());
52-
}
53-
54-
Some(pot) => {
55-
let balance = Amount::from(pot.balance);
56-
println!("Found pot. Name: {}, Balance: {}", pot.name, balance,);
57-
58-
let amount_i: u32 = amount.pence.try_into()?;
59-
client
60-
.deposit_into_pot(&pot.id, &pot.current_account_id, amount_i)
61-
.await?;
62-
println!("Completed deposit. Name: {}, Amount: {}", pot.name, amount);
63-
}
49+
if found_pot.is_none() {
50+
println!("No pot found with name: {}", pot_name);
51+
return Ok(());
6452
}
6553

66-
if let Some(_description) = description {
67-
// find transaction
68-
// annotate transaction
54+
let pot = found_pot.expect("none checked above so this is safe");
55+
56+
let balance = Amount::from(pot.balance);
57+
println!("Found pot. Name: {}, Balance: {}", pot.name, balance);
58+
59+
let amount_i: u32 = amount.pence.try_into()?;
60+
client
61+
.deposit_into_pot(&pot.id, &pot.current_account_id, amount_i)
62+
.await?;
63+
println!("Completed deposit. Name: {}, Amount: {}", pot.name, amount);
64+
65+
if let Some(description) = description {
66+
let since = Utc::now() - Duration::minutes(5);
67+
let limit = 10;
68+
69+
let transactions = client
70+
.transactions(&pot.current_account_id)
71+
.since(since)
72+
.limit(limit)
73+
.send()
74+
.await?;
75+
76+
// transactions
77+
// .iter()
78+
// .filter(|tx| tx.metadata.contains_key("pot_id"))
79+
// .find(|tx| tx.metadata.get(k));
80+
81+
// metadata: {
82+
// "ledger_committed_timestamp_earliest": "2024-04-26T21:17:37.867Z",
83+
// "pot_deposit_id": "potdep_0000AhIBZeZKQxtcO5qKSv",
84+
// "ledger_insertion_id": "entryset_0000AhIBZeQSxvHj6Dcsy1",
85+
// "user_id": "user_00009HutzjJh6uIxmYfk6z",
86+
// "external_id": "user_00009HutzjJh6uIxmYfk6z:VG5PeJCYVY",
87+
// "pot_account_id": "acc_0000AgbkY0OhRmP0ooPx69",
88+
// "trigger": "user",
89+
// "ledger_committed_timestamp_latest": "2024-04-26T21:17:37.867Z",
90+
// "pot_id": "pot_0000AgbkY00Euhtjk7z0td",
91+
// },
92+
// let tx_list = transactions::list(token, account_type, since, limit).await?;
93+
// transactions::annotate(token, transaction_id, description).await?
6994
}
7095

7196
Ok(())

src/transactions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub async fn list(
4545
let created = &tx.created.format("%Y-%m-%d").to_string();
4646
let amount = Amount::from(tx.amount);
4747
print_transaction_row(created, &tx.category, &tx.id, &amount.to_string());
48+
dbg!(tx);
4849
}
4950
}
5051
}

0 commit comments

Comments
 (0)