From b3c32652655d2d3b3abf3ba12d2c7d1b3a571402 Mon Sep 17 00:00:00 2001 From: Justin Enerio Date: Tue, 3 Sep 2024 04:53:52 +0800 Subject: [PATCH] fix: moneygram offramp bridge amount (#1556) --- .../lib/features/currency/models/amount.dart | 2 ++ .../service/moneygram_off_ramp_service.dart | 30 ++++++++++++++----- .../service/moneygram_on_ramp_service.dart | 14 +++++---- .../ramp/screens/off_ramp_order_screen.dart | 22 ++++++++------ .../espressocash_app/lib/l10n/intl_en.arb | 6 +++- 5 files changed, 52 insertions(+), 22 deletions(-) diff --git a/packages/espressocash_app/lib/features/currency/models/amount.dart b/packages/espressocash_app/lib/features/currency/models/amount.dart index 65c2a6e114..fb98660fbf 100644 --- a/packages/espressocash_app/lib/features/currency/models/amount.dart +++ b/packages/espressocash_app/lib/features/currency/models/amount.dart @@ -109,6 +109,8 @@ extension CryptoAmountExt on CryptoAmount { copyWith(value: currency.decimalToInt(decimal)); CryptoAmount round(int scale) => copyWithDecimal(decimal.round(scale: scale)); + + CryptoAmount floor(int scale) => copyWithDecimal(decimal.floor(scale: scale)); } extension FiatAmountExt on FiatAmount { diff --git a/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_off_ramp_service.dart b/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_off_ramp_service.dart index c7b59a834f..af3cee99a2 100644 --- a/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_off_ramp_service.dart +++ b/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_off_ramp_service.dart @@ -104,11 +104,8 @@ class MoneygramOffRampOrderService implements Disposable { .watchSingle() .asyncExpand((order) { logMessage( - message: 'Moneygram off ramp order status update', - data: { - 'orderId': orderId, - 'status': order.status.name, - }, + message: 'MGOffRampOrderStatusChange', + data: order.toSentry, ); switch (order.status) { @@ -573,12 +570,16 @@ class MoneygramOffRampOrderService implements Disposable { return; } - final bridgeAmount = int.parse(destination.amount) ~/ 10; + final amount = int.parse(destination.amount) ~/ 10; + + final bridgeAmount = + CryptoAmount(value: amount, cryptoCurrency: Currency.usdc) + .floor(Currency.usd.decimals); await statement.write( OffRampOrderRowsCompanion( status: const Value(OffRampOrderStatus.ready), - bridgeAmount: Value(bridgeAmount), + bridgeAmount: Value(bridgeAmount.value), ), ); @@ -828,3 +829,18 @@ class MoneygramOffRampOrderService implements Disposable { } const _minimumInitBalance = 1.5; // 1.5 XLM + +extension on OffRampOrderRow { + Map get toSentry { + final json = toJson(); + + const filter = ['transaction', 'slot']; + + json.removeWhere( + (key, value) => + value == null || value == '' || filter.contains(key) || value == 0.0, + ); + + return json; + } +} diff --git a/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_on_ramp_service.dart b/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_on_ramp_service.dart index 05fe51d42f..cb370a5fa3 100644 --- a/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_on_ramp_service.dart +++ b/packages/espressocash_app/lib/features/ramp/partners/moneygram/service/moneygram_on_ramp_service.dart @@ -91,11 +91,8 @@ class MoneygramOnRampOrderService implements Disposable { .whereNotNull() .asyncExpand((order) { logMessage( - message: 'Moneygram on ramp order status update', - data: { - 'orderId': orderId, - 'status': order.status.name, - }, + message: 'MGOnRampOrderStatusChange', + data: order.toSentry, ); switch (order.status) { @@ -483,3 +480,10 @@ class MoneygramOnRampOrderService implements Disposable { } const _minimumInitBalance = 1.5; // 1.5 XLM + +extension on OnRampOrderRow { + Map get toSentry => toJson() + ..removeWhere( + (key, value) => value == null || value == '' || value == 0.0, + ); +} diff --git a/packages/espressocash_app/lib/features/ramp/screens/off_ramp_order_screen.dart b/packages/espressocash_app/lib/features/ramp/screens/off_ramp_order_screen.dart index acbb966e59..c940bc8e6f 100644 --- a/packages/espressocash_app/lib/features/ramp/screens/off_ramp_order_screen.dart +++ b/packages/espressocash_app/lib/features/ramp/screens/off_ramp_order_screen.dart @@ -128,8 +128,9 @@ class OffRampOrderScreenContent extends StatelessWidget { context.l10n.offRampWithdrawOngoing( totalAmount.format(locale), ), - OffRampOrderStatus.waitingForPartner => - context.l10n.offRampWaitingForPartner, + OffRampOrderStatus.waitingForPartner => isMoneygramOrder + ? context.l10n.offRampWithdrawalInProgress + : context.l10n.offRampWaitingForPartner, OffRampOrderStatus.depositTxConfirmError || OffRampOrderStatus.depositError => context.l10n.offRampDepositError, @@ -383,8 +384,11 @@ class _Timeline extends StatelessWidget { Widget build(BuildContext context) { final isMoneygramOrder = order.partner == RampPartner.moneygram; final CpTimelineStatus timelineStatus = order.status.toTimelineStatus(); - final animated = timelineStatus == CpTimelineStatus.inProgress && - order.status != OffRampOrderStatus.ready; + final animatedForMoneygram = (order.status != OffRampOrderStatus.ready && + order.status != OffRampOrderStatus.waitingForPartner) || + !isMoneygramOrder; + final animated = + timelineStatus == CpTimelineStatus.inProgress && animatedForMoneygram; final int activeItem = isMoneygramOrder ? order.status.toActiveItemForMoneygram() @@ -400,7 +404,9 @@ class _Timeline extends StatelessWidget { title: context.l10n.bridgingText, ); final amountSent = CpTimelineItem( - title: context.l10n.offRampWithdrawSent, + title: isMoneygramOrder + ? context.l10n.moneygramCashAvailable + : context.l10n.offRampWithdrawSent, trailing: isMoneygramOrder ? order.bridgeAmount?.let( (e) => e.isZero ? null : e.format(context.locale, maxDecimals: 2), @@ -545,12 +551,10 @@ extension on OffRampOrderStatus { OffRampOrderStatus.depositTxReady || OffRampOrderStatus.waitingForRefundBridge || OffRampOrderStatus.sendingDepositTx || + OffRampOrderStatus.waitingForPartner || OffRampOrderStatus.refunded => 2, - OffRampOrderStatus.waitingForPartner || - OffRampOrderStatus.failure || - OffRampOrderStatus.completed => - 3, + OffRampOrderStatus.failure || OffRampOrderStatus.completed => 3, }; bool get isRefunding => diff --git a/packages/espressocash_app/lib/l10n/intl_en.arb b/packages/espressocash_app/lib/l10n/intl_en.arb index 82bb89b7d0..2dcdc84fce 100644 --- a/packages/espressocash_app/lib/l10n/intl_en.arb +++ b/packages/espressocash_app/lib/l10n/intl_en.arb @@ -859,5 +859,9 @@ "onRampCancelTitle": "Cancel Deposit", "@onRampCancelTitle": {}, "onRampCancelSubtitle": "Are you sure you want to cancel this deposit?", - "@onRampCancelSubtitle": {} + "@onRampCancelSubtitle": {}, + "offRampWithdrawalInProgress": "Withdrawing in progress...", + "@offRampWithdrawalInProgress": {}, + "moneygramCashAvailable": "Cash is available at Moneygram location", + "@moneygramCashAvailable": {} }