Skip to content

Commit 8f2b0e4

Browse files
refactor(amount): use Amount wrapper in payment request structs
1 parent a429e5e commit 8f2b0e4

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

crates/portal-rest/src/handlers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub async fn request_recurring_payment(
326326

327327
let payment_request = RecurringPaymentRequestContent {
328328
description: req.payment_request.description,
329-
amount: req.payment_request.amount,
329+
amount: Amount::new(req.payment_request.amount),
330330
currency: req.payment_request.currency,
331331
auth_token: req.payment_request.auth_token,
332332
recurrence: req.payment_request.recurrence,
@@ -399,7 +399,7 @@ pub async fn request_single_payment(
399399
let request_id = req.payment_request.request_id.clone().unwrap_or_else(|| Uuid::new_v4().to_string());
400400
let expires_at = Timestamp::now_plus_seconds(300);
401401
let payment_request = SinglePaymentRequestContent {
402-
amount,
402+
amount: Amount::new(amount),
403403
currency: req.payment_request.currency,
404404
expires_at,
405405
invoice: invoice.clone(),
@@ -585,7 +585,7 @@ pub async fn request_invoice(
585585

586586
let sdk_content = InvoiceRequestContent {
587587
request_id,
588-
amount: req.content.amount,
588+
amount: Amount::new(req.content.amount),
589589
currency: req.content.currency.clone(),
590590
current_exchange_rate,
591591
expires_at: req.content.expires_at,
@@ -727,7 +727,7 @@ pub async fn request_cashu(
727727
let content = CashuRequestContent {
728728
mint_url: req.mint_url,
729729
unit: req.unit,
730-
amount: req.amount,
730+
amount: Amount::new(req.amount),
731731
request_id: Uuid::new_v4().to_string(),
732732
expires_at,
733733
};
@@ -1057,7 +1057,7 @@ async fn spawn_verification_token_request(
10571057
let content = CashuRequestContent {
10581058
mint_url: VERIFICATION_MINT_URL.to_string(),
10591059
unit: VERIFICATION_TICKET_UNIT.to_string(),
1060-
amount: VERIFICATION_TOKEN_AMOUNT,
1060+
amount: Amount::new(VERIFICATION_TOKEN_AMOUNT),
10611061
request_id: Uuid::new_v4().to_string(),
10621062
expires_at,
10631063
};

crates/portal/src/conversation/app/payments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ impl PaymentRequestContent {
133133

134134
pub fn amount(&self) -> u64 {
135135
match self {
136-
Self::Single(content) => content.amount,
137-
Self::Recurring(content) => content.amount,
136+
Self::Single(content) => content.amount.as_u64(),
137+
Self::Recurring(content) => content.amount.as_u64(),
138138
}
139139
}
140140
}

crates/portal/src/conversation/sdk/payments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl RecurringPaymentRequestSenderConversation {
3232
subkey_proof: Option<SubkeyProof>,
3333
payment_request: RecurringPaymentRequestContent,
3434
) -> Result<Self, String> {
35-
if payment_request.amount == 0 {
35+
if payment_request.amount.as_u64() == 0 {
3636
return Err("Recurring payment amount must be greater than zero".to_string());
3737
}
3838

@@ -125,7 +125,7 @@ impl SinglePaymentRequestSenderConversation {
125125
subkey_proof: Option<SubkeyProof>,
126126
payment_request: SinglePaymentRequestContent,
127127
) -> Result<Self, String> {
128-
if payment_request.amount == 0 {
128+
if payment_request.amount.as_u64() == 0 {
129129
return Err("Payment amount must be greater than zero".to_string());
130130
}
131131

crates/portal/src/protocol/model.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub mod payment {
289289
#[derive(Debug, Clone, Serialize, Deserialize)]
290290
#[cfg_attr(feature = "bindings", derive(uniffi::Record))]
291291
pub struct SinglePaymentRequestContent {
292-
pub amount: u64,
292+
pub amount: Amount,
293293
pub currency: Currency,
294294
pub current_exchange_rate: Option<ExchangeRate>,
295295
pub invoice: String,
@@ -338,7 +338,7 @@ pub mod payment {
338338
#[derive(Debug, Clone, Serialize, Deserialize)]
339339
#[cfg_attr(feature = "bindings", derive(uniffi::Record))]
340340
pub struct RecurringPaymentRequestContent {
341-
pub amount: u64,
341+
pub amount: Amount,
342342
pub currency: Currency,
343343
pub recurrence: RecurrenceInfo,
344344
pub current_exchange_rate: Option<ExchangeRate>,
@@ -379,7 +379,7 @@ pub mod payment {
379379
pub enum RecurringPaymentStatus {
380380
Confirmed {
381381
subscription_id: String,
382-
authorized_amount: u64,
382+
authorized_amount: Amount,
383383
authorized_currency: Currency,
384384
authorized_recurrence: RecurrenceInfo,
385385
},
@@ -414,7 +414,7 @@ pub mod payment {
414414
#[cfg_attr(feature = "bindings", derive(uniffi::Record))]
415415
pub struct InvoiceRequestContent {
416416
pub request_id: String,
417-
pub amount: u64,
417+
pub amount: Amount,
418418
pub currency: Currency,
419419
pub current_exchange_rate: Option<ExchangeRate>,
420420
pub expires_at: Timestamp,
@@ -444,7 +444,7 @@ pub mod payment {
444444
pub request_id: String,
445445
pub mint_url: String,
446446
pub unit: String,
447-
pub amount: u64,
447+
pub amount: Amount,
448448
pub expires_at: Timestamp,
449449
}
450450

0 commit comments

Comments
 (0)