Skip to content

Commit 0a67db1

Browse files
authored
Merge pull request #128 from MostroP2P/change-payment-method-type
change payment_method type to string array
2 parents 4af104f + 20a66b1 commit 0a67db1

6 files changed

Lines changed: 35 additions & 27 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uuid = { version = "1.3.0", features = [
3939
dotenvy = "0.15.6"
4040
lightning-invoice = { version = "0.32.0", features = ["std"] }
4141
reqwest = { version = "0.12.4", features = ["json"] }
42-
mostro-core = "0.6.40"
42+
mostro-core = "0.6.41"
4343
lnurl-rs = "0.9.0"
4444
pretty_env_logger = "0.5.0"
4545
openssl = { version = "0.10.68", features = ["vendored"] }

src/cli/new_order.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub async fn execute_new_order(
1919
fiat_code: &str,
2020
fiat_amount: &(i64, Option<i64>),
2121
amount: &i64,
22-
payment_method: &String,
22+
payment_method: &str,
2323
premium: &i64,
2424
invoice: &Option<String>,
2525
identity_keys: &Keys,
@@ -57,6 +57,10 @@ pub async fn execute_new_order(
5757
Some(expires_at.timestamp())
5858
}
5959
};
60+
let payment_method = payment_method
61+
.split(',')
62+
.map(|s| s.trim().to_string())
63+
.collect::<Vec<String>>();
6064

6165
// Get the type of neworder
6266
// if both tuple field are valid than it's a range order

src/db.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ impl Order {
233233
Some(id) => id.to_string(),
234234
None => uuid::Uuid::new_v4().to_string(),
235235
};
236+
let payment_method =
237+
serde_json::to_string(order.payment_method.as_ref() as &[String]).unwrap_or_default();
236238
let order = Order {
237239
id: Some(id),
238240
kind: order.kind.as_ref().map(|k| k.to_string()),
@@ -242,7 +244,7 @@ impl Order {
242244
min_amount: order.min_amount,
243245
max_amount: order.max_amount,
244246
fiat_amount: order.fiat_amount,
245-
payment_method: order.payment_method,
247+
payment_method,
246248
premium: order.premium,
247249
trade_keys: Some(trade_keys_hex),
248250
counterparty_pubkey: None,

src/nip33.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,56 @@
11
use anyhow::{Ok, Result};
2+
use mostro_core::order::Kind;
23
use mostro_core::prelude::*;
34
use nostr_sdk::prelude::*;
45
use std::str::FromStr;
56
use uuid::Uuid;
67

78
pub fn order_from_tags(tags: Tags) -> Result<SmallOrder> {
89
let mut order = SmallOrder::default();
10+
911
for tag in tags {
10-
let t = tag.to_vec();
11-
let v = t.get(1).unwrap().as_str();
12-
match t.first().unwrap().as_str() {
12+
let t = tag.to_vec(); // Vec<String>
13+
if t.is_empty() {
14+
continue;
15+
}
16+
17+
let key = t[0].as_str();
18+
let values = &t[1..];
19+
20+
let v = values.first().map(|s| s.as_str()).unwrap_or_default();
21+
22+
match key {
1323
"d" => {
14-
let id = v.parse::<Uuid>();
15-
let id = match id {
16-
core::result::Result::Ok(id) => Some(id),
17-
Err(_) => None,
18-
};
19-
order.id = id;
24+
order.id = Uuid::parse_str(v).ok();
2025
}
2126
"k" => {
22-
order.kind = Some(mostro_core::order::Kind::from_str(v).unwrap());
27+
order.kind = Kind::from_str(v).ok();
2328
}
2429
"f" => {
2530
order.fiat_code = v.to_string();
2631
}
2732
"s" => {
28-
order.status = Some(Status::from_str(v).unwrap_or(Status::Dispute));
33+
order.status = Status::from_str(v).ok().or(Some(Status::Pending));
2934
}
3035
"amt" => {
31-
order.amount = v.parse::<i64>().unwrap();
36+
order.amount = v.parse::<i64>().unwrap_or(0);
3237
}
3338
"fa" => {
3439
if v.contains('.') {
3540
continue;
3641
}
37-
let max = t.get(2);
38-
if max.is_some() {
42+
if let Some(max_str) = values.get(1) {
3943
order.min_amount = v.parse::<i64>().ok();
40-
order.max_amount = max.unwrap().parse::<i64>().ok();
44+
order.max_amount = max_str.parse::<i64>().ok();
4145
} else {
42-
let fa = v.parse::<i64>();
43-
order.fiat_amount = fa.unwrap_or(0);
46+
order.fiat_amount = v.parse::<i64>().unwrap_or(0);
4447
}
4548
}
4649
"pm" => {
47-
order.payment_method = v.to_string();
50+
order.payment_method = values.iter().map(|s| s.to_string()).collect();
4851
}
4952
"premium" => {
50-
order.premium = v.parse::<i64>().unwrap();
53+
order.premium = v.parse::<i64>().unwrap_or(0);
5154
}
5255
_ => {}
5356
}

src/pretty_table.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use comfy_table::presets::UTF8_FULL;
44
use comfy_table::*;
55
use mostro_core::prelude::*;
66

7-
87
pub fn print_order_preview(ord: Payload) -> Result<String, String> {
98
let single_order = match ord {
109
Payload::Order(o) => o,
@@ -69,7 +68,7 @@ pub fn print_order_preview(ord: Payload) -> Result<String, String> {
6968
);
7069
Cell::new(range_str).set_alignment(CellAlignment::Center)
7170
},
72-
Cell::new(single_order.payment_method.to_string()).set_alignment(CellAlignment::Center),
71+
Cell::new(single_order.payment_method.join(", ")).set_alignment(CellAlignment::Center),
7372
Cell::new(single_order.premium.to_string()).set_alignment(CellAlignment::Center),
7473
]);
7574

@@ -174,7 +173,7 @@ pub fn print_orders_table(orders_table: Vec<SmallOrder>) -> Result<String> {
174173
);
175174
Cell::new(range_str).set_alignment(CellAlignment::Center)
176175
},
177-
Cell::new(single_order.payment_method.to_string())
176+
Cell::new(single_order.payment_method.join(", "))
178177
.set_alignment(CellAlignment::Center),
179178
Cell::new(date.unwrap()),
180179
]);

0 commit comments

Comments
 (0)