From 9569fdb83ee6b16e6a1377e8a37d38d26b48e5af Mon Sep 17 00:00:00 2001 From: Gabriel Comte Date: Fri, 27 Dec 2024 15:58:11 +0100 Subject: [PATCH] Discontinue differentiation between offer kinds --- examples/node/cli.rs | 124 ++++++++++++------------------ src/actions_required.rs | 2 +- src/activities.rs | 4 +- src/activity.rs | 4 +- src/data_store.rs | 160 +++++++++++++++++---------------------- src/fiat_topup.rs | 28 +++---- src/lib.rs | 48 +++--------- src/lipalightninglib.udl | 25 +++--- src/offer.rs | 43 +++++------ src/support.rs | 6 +- tests/topup_test.rs | 15 ++-- 11 files changed, 184 insertions(+), 275 deletions(-) diff --git a/examples/node/cli.rs b/examples/node/cli.rs index 6bf9cd261..dae2e24bf 100644 --- a/examples/node/cli.rs +++ b/examples/node/cli.rs @@ -19,10 +19,10 @@ use std::path::Path; use std::time::SystemTime; use uniffi_lipalightninglib::{ ActionRequiredItem, Activity, Amount, ChannelCloseInfo, ChannelCloseState, DecodedData, - ExchangeRate, FailedSwapInfo, FeatureFlag, FiatValue, IncomingPaymentInfo, - InvoiceCreationMetadata, InvoiceDetails, LightningNode, LiquidityLimit, LnUrlPayDetails, - LnUrlWithdrawDetails, MaxRoutingFeeMode, OfferInfo, OfferKind, OutgoingPaymentInfo, - PaymentInfo, PaymentMetadata, RangeHit, Recipient, TzConfig, + FailedSwapInfo, FeatureFlag, FiatValue, IncomingPaymentInfo, InvoiceCreationMetadata, + InvoiceDetails, LightningNode, LiquidityLimit, LnUrlPayDetails, LnUrlWithdrawDetails, + MaxRoutingFeeMode, Offer, OfferInfo, OutgoingPaymentInfo, PaymentInfo, PaymentMetadata, + RangeHit, Recipient, TzConfig, }; pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) { @@ -1176,56 +1176,42 @@ fn collect_last_offer(node: &LightningNode) -> Result<()> { } fn print_offer(offer: &OfferInfo) { - let kind = match offer.offer_kind { - OfferKind::Pocket { .. } => "Pocket", - }; - let created_at: DateTime = offer.created_at.into(); let expires_at: Option> = offer.expires_at.map(Into::into); - println!("{kind} offer created at {created_at}:"); + println!("Offer created at {created_at}:"); println!(" Expires at: {expires_at:?}"); println!( " Amount: {}", amount_to_string(&offer.amount) ); println!(" LNURL-w: {:?}", offer.lnurlw); - match &offer.offer_kind { - OfferKind::Pocket { - id, - exchange_rate, - topup_value_minor_units, - exchange_fee_minor_units, - exchange_fee_rate_permyriad, - error, - .. - } => { - println!(" ID: {id}"); - println!( - " Value exchanged: {:.2} {}", - *topup_value_minor_units as f64 / 100f64, - exchange_rate.currency_code, - ); - println!( - " Exchange fee rate: {}%", - *exchange_fee_rate_permyriad as f64 / 100_f64 - ); - println!( - " Exchange fee value: {:.2} {}", - *exchange_fee_minor_units as f64 / 100f64, - exchange_rate.currency_code, - ); - let exchanged_at: DateTime = exchange_rate.updated_at.into(); - println!( - " Exchanged at: {}", - exchanged_at.format("%d/%m/%Y %T UTC"), - ); - if let Some(e) = error { - println!(" Failure reason: {e:?}"); - } - } + println!(" ID: {}", offer.offer.id); + println!( + " Value exchanged: {:.2} {}", + offer.offer.topup_value_minor_units as f64 / 100f64, + offer.offer.exchange_rate.currency_code, + ); + println!( + " Exchange fee rate: {}%", + offer.offer.exchange_fee_rate_permyriad as f64 / 100_f64 + ); + println!( + " Exchange fee value: {:.2} {}", + offer.offer.exchange_fee_minor_units as f64 / 100f64, + offer.offer.exchange_rate.currency_code, + ); + let exchanged_at: DateTime = offer.offer.exchange_rate.updated_at.into(); + println!( + " Exchanged at: {}", + exchanged_at.format("%d/%m/%Y %T UTC"), + ); + + if let Some(e) = &offer.offer.error { + println!(" Failure reason: {e:?}"); } + println!(" Status: {:?}", offer.status); } @@ -1309,10 +1295,10 @@ fn print_activity(activity: Activity) -> Result<()> { } => print_outgoing_payment(outgoing_payment_info), Activity::OfferClaim { incoming_payment_info, - offer_kind, + offer, } => { print_incoming_payment(incoming_payment_info)?; - println!(" Offer: {}", offer_to_string(offer_kind)); + println!(" Offer: {}", offer_to_string(offer)); Ok(()) } Activity::Swap { @@ -1520,35 +1506,21 @@ fn clear_wallet(node: &LightningNode, words: &mut dyn Iterator) -> Ok(()) } -fn offer_to_string(offer: OfferKind) -> String { - match offer { - OfferKind::Pocket { - id, - exchange_rate: - ExchangeRate { - currency_code, - rate, - updated_at, - }, - topup_value_minor_units, - exchange_fee_minor_units, - exchange_fee_rate_permyriad, - lightning_payout_fee, - .. - } => { - let updated_at: DateTime = updated_at.into(); - format!( - "Pocket exchange ({id}) of {:.2} {currency_code} at {} at rate {rate} SATS per {currency_code}, fee was {:.2}% or {:.2}, payout fee charged {} {currency_code}", - topup_value_minor_units as f64 / 100f64, - updated_at.format("%d/%m/%Y %T UTC"), - exchange_fee_rate_permyriad as f64 / 100f64, - exchange_fee_minor_units as f64 / 100f64, - lightning_payout_fee - .map(|f| amount_to_string(&f)) - .unwrap_or("N/A".to_string()), - ) - } - } +fn offer_to_string(offer: Offer) -> String { + let updated_at: DateTime = offer.exchange_rate.updated_at.into(); + let currency_code = offer.exchange_rate.currency_code; + let rate = offer.exchange_rate.rate; + + format!("Pocket exchange ({}) of {:.2} {currency_code} at {} at rate {rate} SATS per {currency_code}, fee was {:.2}% or {:.2}, payout fee charged {} {currency_code}", + offer.id, + offer.topup_value_minor_units as f64 / 100f64, + updated_at.format("%d/%m/%Y %T UTC"), + offer.exchange_fee_rate_permyriad as f64 / 100f64, + offer.exchange_fee_minor_units as f64 / 100f64, + offer.lightning_payout_fee + .map(|f| amount_to_string(&f)) + .unwrap_or("N/A".to_string()), + ) } fn fiat_value_to_string(value: &FiatValue) -> String { @@ -1591,9 +1563,7 @@ fn calculate_lightning_payout_fee( let offer = uncompleted_offers .into_iter() - .find(|o| match &o.offer_kind { - OfferKind::Pocket { id, .. } => id == offer_id, - }) + .find(|o| o.offer.id == offer_id) .ok_or(anyhow!("Couldn't find offer with id: {offer_id}"))?; let lightning_payout_fee = node.fiat_topup().calculate_payout_fee(offer)?; diff --git a/src/actions_required.rs b/src/actions_required.rs index 2ffdd1a6d..3b795073b 100644 --- a/src/actions_required.rs +++ b/src/actions_required.rs @@ -124,7 +124,7 @@ impl ActionsRequired { /// Hides the topup with the given id. Can be called on expired topups so that they stop being returned /// by [`ActionsRequired::list`]. /// - /// Topup id can be obtained from [`OfferKind::Pocket`](crate::OfferKind::Pocket). + /// Topup id can be obtained from [`Offer`](crate::Offer). /// /// Requires network: **yes** pub fn dismiss_topup(&self, id: String) -> Result<()> { diff --git a/src/activities.rs b/src/activities.rs index dcb7da88e..0b8059a54 100644 --- a/src/activities.rs +++ b/src/activities.rs @@ -357,14 +357,14 @@ impl Activities { .remote_services_config .lipa_lightning_domain, )?; - let offer_kind = fill_payout_fee( + let offer = fill_payout_fee( offer, incoming_payment_info.requested_amount.sats.as_msats(), &exchange_rate, ); Ok(Activity::OfferClaim { incoming_payment_info, - offer_kind, + offer, }) } else if let Some(ref s) = payment_details.swap_info { let swap_info = SwapInfo { diff --git a/src/activity.rs b/src/activity.rs index 42d5c1d0e..b4536a54b 100644 --- a/src/activity.rs +++ b/src/activity.rs @@ -1,5 +1,5 @@ use crate::payment::{IncomingPaymentInfo, OutgoingPaymentInfo, PaymentInfo}; -use crate::{Amount, OfferKind, SwapInfo, TzTime}; +use crate::{Amount, Offer, SwapInfo, TzTime}; use crate::reverse_swap::ReverseSwapInfo; use breez_sdk_core::ReverseSwapStatus; @@ -23,7 +23,7 @@ pub enum Activity { // Topup, referrals. OfferClaim { incoming_payment_info: IncomingPaymentInfo, - offer_kind: OfferKind, + offer: Offer, }, /// An On-chain to Lightning swap. /// diff --git a/src/data_store.rs b/src/data_store.rs index bf05ab4f5..116114842 100644 --- a/src/data_store.rs +++ b/src/data_store.rs @@ -1,7 +1,7 @@ use crate::analytics::AnalyticsConfig; use crate::errors::Result; use crate::migrations::migrate; -use crate::{EnableStatus, ExchangeRate, OfferKind, PocketOfferError, TzConfig, UserPreferences}; +use crate::{EnableStatus, ExchangeRate, Offer, PocketOfferError, TzConfig, UserPreferences}; use chrono::{DateTime, Utc}; use crow::FiatTopupSetupInfo; @@ -16,7 +16,7 @@ pub(crate) const BACKUP_DB_FILENAME_SUFFIX: &str = ".backup"; pub(crate) struct LocalPaymentData { pub user_preferences: UserPreferences, pub exchange_rate: ExchangeRate, - pub offer: Option, + pub offer: Option, pub personal_note: Option, pub received_on: Option, pub received_lnurl_comment: Option, @@ -59,7 +59,7 @@ impl DataStore { payment_hash: &str, user_preferences: UserPreferences, exchange_rates: Vec, - offer: Option, + offer: Option, received_on: Option, received_lnurl_comment: Option, ) -> Result<()> { @@ -89,7 +89,7 @@ impl DataStore { ) .map_to_permanent_failure("Failed to add payment info to db")?; - if let Some(OfferKind::Pocket { + if let Some(Offer { id: pocket_id, exchange_rate: ExchangeRate { @@ -556,8 +556,8 @@ fn exchange_rate_from_row(row: &Row) -> rusqlite::Result { }) } -fn offer_kind_from_row(row: &Row) -> rusqlite::Result> { - if let Some(pocket_id) = row.get(5)? { +fn offer_from_row(row: &Row) -> rusqlite::Result> { + if let Some(id) = row.get(5)? { let fiat_currency: String = row.get(6)?; let rate: u32 = row.get(7)?; let exchanged_at: chrono::DateTime = row.get(8)?; @@ -573,8 +573,8 @@ fn offer_kind_from_row(row: &Row) -> rusqlite::Result> { updated_at: exchanged_at, }; - return Ok(Some(OfferKind::Pocket { - id: pocket_id, + return Ok(Some(Offer { + id, exchange_rate: exchange_rate.clone(), topup_value_minor_units, topup_value_sats, @@ -594,7 +594,7 @@ fn local_payment_data_from_row(row: &Row) -> rusqlite::Result let fiat_currency: String = row.get(2)?; let rate: u32 = row.get(3)?; let updated_at: chrono::DateTime = row.get(4)?; - let offer = offer_kind_from_row(row)?; + let offer = offer_from_row(row)?; let personal_note = row.get(14)?; let received_on = row.get(15)?; let received_lnurl_comment = row.get(16)?; @@ -706,7 +706,7 @@ fn fiat_topup_info_from_row(row: &Row) -> rusqlite::Result OfferKind { + fn build_offer_with_error(error: PocketOfferError) -> Offer { let exchange_rate = ExchangeRate { currency_code: "EUR".to_string(), rate: 5123, updated_at: SystemTime::now(), }; - OfferKind::Pocket { + Offer { id: "id".to_string(), exchange_rate: exchange_rate.clone(), topup_value_minor_units: 51245, @@ -1043,7 +1021,7 @@ mod tests { } } - fn store_payment_with_offer_and_test(offer: OfferKind, data_store: &mut DataStore, hash: &str) { + fn store_payment_with_offer_and_test(offer: Offer, data_store: &mut DataStore, hash: &str) { let user_preferences = UserPreferences { fiat_currency: "EUR".to_string(), timezone_config: TzConfig { diff --git a/src/fiat_topup.rs b/src/fiat_topup.rs index 110ef1f3e..e1995de44 100644 --- a/src/fiat_topup.rs +++ b/src/fiat_topup.rs @@ -3,7 +3,7 @@ use crate::errors::Result; use crate::locker::Locker; use crate::support::Support; use crate::{ - filter_out_and_log_corrupted_activities, Activities, Activity, Amount, OfferInfo, OfferKind, + filter_out_and_log_corrupted_activities, Activities, Activity, Amount, Offer, OfferInfo, OfferStatus, PaymentState, RuntimeErrorCode, }; use breez_sdk_core::{ @@ -278,15 +278,12 @@ impl FiatTopup { description: None, })) { Ok(breez_sdk_core::LnUrlWithdrawResult::Ok { data }) => { - match offer.offer_kind.clone() { - OfferKind::Pocket { id, .. } => self - .support - .offer_manager - .hide_topup(id) - .map_runtime_error_to(RuntimeErrorCode::OfferServiceUnavailable)?, - }; self.support - .store_payment_info(&data.invoice.payment_hash, Some(offer.offer_kind.clone())); + .offer_manager + .hide_topup(offer.offer.id.clone()) + .map_runtime_error_to(RuntimeErrorCode::OfferServiceUnavailable)?; + self.support + .store_payment_info(&data.invoice.payment_hash, Some(offer.offer.clone())); let channel_opening_fee_msat = if let Some(payment_amount_msat) = data.invoice.amount_msat { @@ -353,8 +350,7 @@ impl FiatTopup { } }; - self.support - .store_payment_info(&hash, Some(offer.offer_kind)); + self.support.store_payment_info(&hash, Some(offer.offer)); Ok(hash) } @@ -367,7 +363,7 @@ fn filter_out_recently_claimed_topups( let pocket_id = |a: Activity| match a { Activity::OfferClaim { incoming_payment_info: _, - offer_kind: OfferKind::Pocket { id, .. }, + offer: Offer { id, .. }, } => Some(id), _ => None, }; @@ -387,8 +383,8 @@ mod tests { use crate::fiat_topup::filter_out_recently_claimed_topups; use crate::node_config::WithTimezone; use crate::{ - Activity, Amount, ExchangeRate, IncomingPaymentInfo, InvoiceDetails, OfferKind, - PaymentInfo, PaymentState, TzConfig, + Activity, Amount, ExchangeRate, IncomingPaymentInfo, InvoiceDetails, Offer, PaymentInfo, + PaymentState, TzConfig, }; use crow::{TopupInfo, TopupStatus}; use std::time::SystemTime; @@ -469,7 +465,7 @@ mod tests { received_on: None, received_lnurl_comment: None, }, - offer_kind: OfferKind::Pocket { + offer: Offer { id: "123".to_string(), exchange_rate: ExchangeRate { currency_code: "".to_string(), @@ -495,7 +491,7 @@ mod tests { received_on: None, received_lnurl_comment: None, }, - offer_kind: OfferKind::Pocket { + offer: Offer { id: "234".to_string(), exchange_rate: ExchangeRate { currency_code: "".to_string(), diff --git a/src/lib.rs b/src/lib.rs index d6267de24..e59a0110b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ pub use crate::node_config::{ RemoteServicesConfig, TzConfig, TzTime, }; pub use crate::notification_handling::{handle_notification, Notification, NotificationToggles}; -pub use crate::offer::{OfferInfo, OfferKind, OfferStatus}; +pub use crate::offer::{Offer, OfferInfo, OfferStatus}; pub use crate::payment::{ IncomingPaymentInfo, OutgoingPaymentInfo, PaymentInfo, PaymentState, Recipient, }; @@ -1042,7 +1042,7 @@ impl LightningNode { /// Hides the topup with the given id. Can be called on expired topups so that they stop being returned /// by [`LightningNode::query_uncompleted_offers`]. /// - /// Topup id can be obtained from [`OfferKind::Pocket`]. + /// Topup id can be obtained from [`Offer`]. /// /// Requires network: **yes** #[deprecated = "actions_required().dismiss_topup() should be used instead"] @@ -1684,40 +1684,16 @@ pub(crate) fn enable_backtrace() { env::set_var("RUST_BACKTRACE", "1"); } -fn fill_payout_fee( - offer: OfferKind, - requested_amount: Msats, - rate: &Option, -) -> OfferKind { - match offer { - OfferKind::Pocket { - id, - exchange_rate, - topup_value_minor_units, - topup_value_sats, - exchange_fee_minor_units, - exchange_fee_rate_permyriad, - lightning_payout_fee: _, - error, - } => { - let lightning_payout_fee = topup_value_sats.map(|v| { - (v.as_sats().msats - requested_amount.msats) - .as_msats() - .to_amount_up(rate) - }); - - OfferKind::Pocket { - id, - exchange_rate, - topup_value_minor_units, - topup_value_sats, - exchange_fee_minor_units, - exchange_fee_rate_permyriad, - lightning_payout_fee, - error, - } - } - } +fn fill_payout_fee(offer: Offer, requested_amount: Msats, rate: &Option) -> Offer { + let lightning_payout_fee = offer.topup_value_sats.map(|v| { + (v.as_sats().msats - requested_amount.msats) + .as_msats() + .to_amount_up(rate) + }); + + let mut offer = offer.clone(); + offer.lightning_payout_fee = lightning_payout_fee; + offer } // TODO provide corrupted acticity information partially instead of hiding it diff --git a/src/lipalightninglib.udl b/src/lipalightninglib.udl index 19febf1bb..79e4e2ff0 100644 --- a/src/lipalightninglib.udl +++ b/src/lipalightninglib.udl @@ -640,7 +640,7 @@ interface MaxRoutingFeeMode { interface Activity { IncomingPayment(IncomingPaymentInfo incoming_payment_info); OutgoingPayment(OutgoingPaymentInfo outgoing_payment_info); - OfferClaim(IncomingPaymentInfo incoming_payment_info, OfferKind offer_kind); + OfferClaim(IncomingPaymentInfo incoming_payment_info, Offer offer); Swap(IncomingPaymentInfo? incoming_payment_info, SwapInfo swap_info); ReverseSwap(OutgoingPaymentInfo outgoing_payment_info, ReverseSwapInfo reverse_swap_info); ChannelClose(ChannelCloseInfo channel_close_info); @@ -748,7 +748,7 @@ interface ActionRequiredItem { }; dictionary OfferInfo { - OfferKind offer_kind; + Offer offer; Amount amount; string? lnurlw; timestamp created_at; @@ -787,18 +787,15 @@ interface PocketOfferError { ); }; -[Enum] -interface OfferKind { - Pocket( - string id, - ExchangeRate exchange_rate, - u64 topup_value_minor_units, - u64? topup_value_sats, - u64 exchange_fee_minor_units, - u16 exchange_fee_rate_permyriad, - Amount? lightning_payout_fee, - PocketOfferError? error - ); +dictionary Offer { + string id; + ExchangeRate exchange_rate; + u64 topup_value_minor_units; + u64? topup_value_sats; + u64 exchange_fee_minor_units; + u16 exchange_fee_rate_permyriad; + Amount? lightning_payout_fee; + PocketOfferError? error; }; enum OfferStatus { diff --git a/src/offer.rs b/src/offer.rs index a791400f0..01c21a296 100644 --- a/src/offer.rs +++ b/src/offer.rs @@ -18,35 +18,32 @@ pub enum OfferStatus { SETTLED, } +/// Values are denominated in the fiat currency the user sent to the exchange. +/// The currency code can be found in `exchange_rate`. #[derive(PartialEq, Eq, Debug, Clone)] -pub enum OfferKind { - /// An offer related to a topup using the Pocket exchange - /// Values are denominated in the fiat currency the user sent to the exchange. - /// The currency code can be found in `exchange_rate`. - Pocket { - id: String, - /// The exchange rate used by the exchange to exchange fiat to sats. - exchange_rate: ExchangeRate, - /// The original fiat amount sent to the exchange. - topup_value_minor_units: u64, - /// The sat amount after the exchange. Isn't available for topups collected before version v0.30.0-beta. - topup_value_sats: Option, - /// The fee paid to perform the exchange from fiat to sats. - exchange_fee_minor_units: u64, - /// The rate of the fee expressed in permyriad (e.g. 1.5% would be 150). - exchange_fee_rate_permyriad: u16, - /// Optional payout fees collected by pocket. - lightning_payout_fee: Option, - /// The optional error that might have occurred in the offer withdrawal process. - error: Option, - }, +pub struct Offer { + pub id: String, + /// The exchange rate used by the exchange to exchange fiat to sats. + pub exchange_rate: ExchangeRate, + /// The original fiat amount sent to the exchange. + pub topup_value_minor_units: u64, + /// The sat amount after the exchange. Isn't available for topups collected before version v0.30.0-beta. + pub topup_value_sats: Option, + /// The fee paid to perform the exchange from fiat to sats. + pub exchange_fee_minor_units: u64, + /// The rate of the fee expressed in permyriad (e.g. 1.5% would be 150). + pub exchange_fee_rate_permyriad: u16, + /// Optional payout fees collected by pocket. + pub lightning_payout_fee: Option, + /// The optional error that might have occurred in the offer withdrawal process. + pub error: Option, } /// Information on a funds offer that can be claimed /// using [`crate::LightningNode::request_offer_collection`]. #[derive(Debug, PartialEq, Clone, Eq)] pub struct OfferInfo { - pub offer_kind: OfferKind, + pub offer: Offer, /// Amount available for withdrawal pub amount: Amount, /// The lnurlw string that will be used to withdraw this offer. Can be empty if the offer isn't @@ -75,7 +72,7 @@ impl OfferInfo { }; OfferInfo { - offer_kind: OfferKind::Pocket { + offer: Offer { id: topup_info.id, exchange_rate, topup_value_minor_units: topup_info.topup_value_minor_units, diff --git a/src/support.rs b/src/support.rs index b4c356e66..864dfb8de 100644 --- a/src/support.rs +++ b/src/support.rs @@ -8,8 +8,8 @@ use crate::phone_number::PhoneNumberPrefixParser; use crate::task_manager::TaskManager; use crate::util::LogIgnoreError; use crate::{ - CalculateLspFeeResponseV2, ChannelsInfo, ExchangeRate, LightningNodeConfig, NodeInfo, - OfferKind, RuntimeErrorCode, UserPreferences, + CalculateLspFeeResponseV2, ChannelsInfo, ExchangeRate, LightningNodeConfig, NodeInfo, Offer, + RuntimeErrorCode, UserPreferences, }; use breez_sdk_core::{ BreezServices, OpeningFeeParams, ReportIssueRequest, ReportPaymentFailureDetails, @@ -170,7 +170,7 @@ impl Support { .log_ignore_error(Level::Warn, "Failed to report issue"); } - pub fn store_payment_info(&self, hash: &str, offer: Option) { + pub fn store_payment_info(&self, hash: &str, offer: Option) { let user_preferences = self.user_preferences.lock_unwrap().clone(); let exchange_rates = self.get_exchange_rates(); self.data_store diff --git a/tests/topup_test.rs b/tests/topup_test.rs index 02a179725..96831b571 100644 --- a/tests/topup_test.rs +++ b/tests/topup_test.rs @@ -6,7 +6,7 @@ use perro::Error::InvalidInput; use std::time::Duration; use serial_test::file_serial; -use uniffi_lipalightninglib::{ActionRequiredItem, OfferInfo, OfferKind, OfferStatus}; +use uniffi_lipalightninglib::{ActionRequiredItem, OfferInfo, OfferStatus}; #[test] #[file_serial(key, path => "/tmp/3l-int-tests-lock")] @@ -113,7 +113,6 @@ fn test_topup() { assert!(matches!( uncompleted_offers.first().unwrap(), OfferInfo { - offer_kind: OfferKind::Pocket { .. }, status: OfferStatus::READY, .. } @@ -147,25 +146,21 @@ fn test_topup() { assert!(matches!( uncompleted_offers.first().unwrap(), OfferInfo { - offer_kind: OfferKind::Pocket { .. }, status: OfferStatus::REFUNDED, .. } )); - let refunded_topup_id = match &uncompleted_offers.first().unwrap().offer_kind { - OfferKind::Pocket { id, .. } => id.to_string(), - }; - + let refunded_topup_id = &uncompleted_offers.first().unwrap().offer.id.to_string(); node.actions_required() .dismiss_topup(refunded_topup_id.clone()) .unwrap(); let uncompleted_offers = offer_info_from_actions_required_list(&node.actions_required().list().unwrap()); - uncompleted_offers.iter().find(|o| match &o.offer_kind { - OfferKind::Pocket { id, .. } => id.to_string(), - } == refunded_topup_id); + uncompleted_offers + .iter() + .find(|o| &o.offer.id.to_string() == refunded_topup_id); } fn offer_info_from_actions_required_list(list: &[ActionRequiredItem]) -> Vec {