|
| 1 | +use chrono::{Duration, Utc}; |
1 | 2 | use monzo::Client;
|
2 | 3 |
|
3 | 4 | use crate::accounts;
|
@@ -45,27 +46,51 @@ pub async fn deposit(
|
45 | 46 |
|
46 | 47 | let found_pot = find_pot(token, pot_name).await?;
|
47 | 48 |
|
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(()); |
64 | 52 | }
|
65 | 53 |
|
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? |
69 | 94 | }
|
70 | 95 |
|
71 | 96 | Ok(())
|
|
0 commit comments