Skip to content

Commit 09dcde6

Browse files
committed
Properly convert breez payment to ours
1 parent dd305c4 commit 09dcde6

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

orange-sdk/src/trusted_wallet/spark.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,8 @@ impl TrustedWalletInterface for Spark {
139139
.list_payments(ListPaymentsRequest { limit: None, offset: None })
140140
.await?;
141141

142-
let payments = resp
143-
.payments
144-
.into_iter()
145-
.map(|p| {
146-
parse_payment_id(&p.id).map(|id| Payment {
147-
id,
148-
amount: Amount::from_sats(p.amount).unwrap(),
149-
fee: Amount::from_sats(p.fees).unwrap(),
150-
status: p.status.into(),
151-
outbound: p.payment_type == PaymentType::Send,
152-
time_since_epoch: Duration::from_secs(p.timestamp),
153-
})
154-
})
155-
.collect::<Result<_, _>>()?;
142+
let payments =
143+
resp.payments.into_iter().map(|p| p.try_into()).collect::<Result<_, _>>()?;
156144

157145
Ok(payments)
158146
})
@@ -614,3 +602,20 @@ impl breez_sdk_spark::Storage for SparkStore {
614602
Ok(())
615603
}
616604
}
605+
606+
impl TryFrom<breez_sdk_spark::Payment> for Payment {
607+
type Error = TrustedError;
608+
609+
fn try_from(value: breez_sdk_spark::Payment) -> Result<Self, Self::Error> {
610+
let id = parse_payment_id(&value.id)?;
611+
612+
Ok(Payment {
613+
id,
614+
amount: Amount::from_sats(value.amount).map_err(|_| TrustedError::AmountError)?,
615+
fee: Amount::from_sats(value.fees).map_err(|_| TrustedError::AmountError)?,
616+
status: value.status.into(),
617+
outbound: value.payment_type == PaymentType::Send,
618+
time_since_epoch: Duration::from_secs(value.timestamp),
619+
})
620+
}
621+
}

0 commit comments

Comments
 (0)