Skip to content

Commit 2a0885d

Browse files
Merge pull request #71 from getlipa/feature/update-schema
Update topup type in schema
2 parents 0f4c10d + 5c6470b commit 2a0885d

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

crow/src/lib.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub struct TopupInfo {
5757
pub exchange_fee_minor_units: u64,
5858
pub exchange_rate: ExchangeRate,
5959

60-
pub expires_at: SystemTime,
61-
pub lnurlw: String,
60+
pub expires_at: Option<SystemTime>,
61+
pub lnurlw: Option<String>,
6262
pub error: Option<TopupError>,
6363
}
6464

@@ -148,7 +148,10 @@ fn to_topup_info(topup: ListUncompletedTopupsTopup) -> graphql::Result<TopupInfo
148148
let exchange_fee_rate_permyriad = (topup.exchange_fee_rate * 10_000_f64).round() as u16;
149149
let exchange_fee_minor_units = (topup.exchange_fee_user_currency * 100_f64).round() as u64;
150150
let expires_at = topup.expires_at;
151-
let expires_at = parse_from_rfc3339(&expires_at)?;
151+
let expires_at = match expires_at {
152+
Some(e) => Some(parse_from_rfc3339(&e)?),
153+
None => None,
154+
};
152155
let lnurlw = topup.lnurl;
153156

154157
let status = match topup.status {
@@ -258,10 +261,10 @@ mod tests {
258261
exchange_fee_rate: 0.014999999664723873,
259262
exchange_fee_user_currency: 0.11999999731779099,
260263
exchange_rate: 18507.0,
261-
expires_at: "2023-09-21T16:39:21.919+00:00".to_string(),
264+
expires_at: Some("2023-09-21T16:39:21.919+00:00".to_string()),
262265
id: "1707e09e-ebe1-4004-abd7-7a64604501b3".to_string(),
263266
lightning_fee_user_currency: 0.0,
264-
lnurl: LNURL.to_string(),
267+
lnurl: Some(LNURL.to_string()),
265268
node_pub_key: "0233786a3f5c79d25508ed973e7a37506ddab49d41a07fcb3d341ab638000d69cf"
266269
.to_string(),
267270
status: topup_status_enum::READY,
@@ -286,11 +289,12 @@ mod tests {
286289

287290
let expires_at = topup_info
288291
.expires_at
292+
.unwrap()
289293
.duration_since(SystemTime::UNIX_EPOCH)
290294
.unwrap()
291295
.as_secs();
292296
assert_eq!(expires_at, 1695314361);
293-
assert_eq!(topup_info.lnurlw, LNURL);
297+
assert_eq!(topup_info.lnurlw.unwrap(), LNURL);
294298

295299
assert_eq!(topup_info.status, TopupStatus::READY);
296300

@@ -302,10 +306,10 @@ mod tests {
302306
exchange_fee_rate: 0.014999999664723873,
303307
exchange_fee_user_currency: 0.11999999731779099,
304308
exchange_rate: 18507.0,
305-
expires_at: "2023-09-21T16:39:21.919+00:00".to_string(),
309+
expires_at: None,
306310
id: "1707e09e-ebe1-4004-abd7-7a64604501b3".to_string(),
307311
lightning_fee_user_currency: 0.0,
308-
lnurl: LNURL.to_string(),
312+
lnurl: None,
309313
node_pub_key: "0233786a3f5c79d25508ed973e7a37506ddab49d41a07fcb3d341ab638000d69cf"
310314
.to_string(),
311315
status: topup_status_enum::FAILED,
@@ -320,6 +324,8 @@ mod tests {
320324
code: TemporaryFailureCode::NoRoute
321325
})
322326
));
327+
assert!(topup_info.expires_at.is_none());
328+
assert!(topup_info.lnurlw.is_none());
323329

324330
let topup = ListUncompletedTopupsTopup {
325331
additional_info: Some("customer_requested".to_string()),
@@ -329,10 +335,10 @@ mod tests {
329335
exchange_fee_rate: 0.014999999664723873,
330336
exchange_fee_user_currency: 0.11999999731779099,
331337
exchange_rate: 18507.0,
332-
expires_at: "2023-09-21T16:39:21.919+00:00".to_string(),
338+
expires_at: Some("2023-09-21T16:39:21.919+00:00".to_string()),
333339
id: "1707e09e-ebe1-4004-abd7-7a64604501b3".to_string(),
334340
lightning_fee_user_currency: 0.0,
335-
lnurl: LNURL.to_string(),
341+
lnurl: None,
336342
node_pub_key: "0233786a3f5c79d25508ed973e7a37506ddab49d41a07fcb3d341ab638000d69cf"
337343
.to_string(),
338344
status: topup_status_enum::REFUNDED,
@@ -347,5 +353,7 @@ mod tests {
347353
code: PermanentFailureCode::CustomerRequested
348354
})
349355
));
356+
assert!(topup_info.expires_at.is_some());
357+
assert!(topup_info.lnurlw.is_none());
350358
}
351359
}

graphql/schemas/schema_wallet_read.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,10 +1545,10 @@ type topup {
15451545
exchangeFeeRate: float8!
15461546
exchangeFeeUserCurrency: float8!
15471547
exchangeRate: float8!
1548-
expiresAt: timestamptz!
1548+
expiresAt: timestamptz
15491549
id: uuid!
15501550
lightningFeeUserCurrency: float8!
1551-
lnurl: String!
1551+
lnurl: String
15521552
nodePubKey: String!
15531553
status: topup_status_enum!
15541554
userCurrency: String!

0 commit comments

Comments
 (0)