Skip to content

Commit

Permalink
fix: moneygram offramp bridge amount (#1556)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinenerio authored Sep 2, 2024
1 parent d5b0865 commit b3c3265
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ class MoneygramOffRampOrderService implements Disposable {
.watchSingle()
.asyncExpand<OffRampOrderRowsCompanion?>((order) {
logMessage(
message: 'Moneygram off ramp order status update',
data: {
'orderId': orderId,
'status': order.status.name,
},
message: 'MGOffRampOrderStatusChange',
data: order.toSentry,
);

switch (order.status) {
Expand Down Expand Up @@ -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),
),
);

Expand Down Expand Up @@ -828,3 +829,18 @@ class MoneygramOffRampOrderService implements Disposable {
}

const _minimumInitBalance = 1.5; // 1.5 XLM

extension on OffRampOrderRow {
Map<String, dynamic> get toSentry {
final json = toJson();

const filter = ['transaction', 'slot'];

json.removeWhere(
(key, value) =>
value == null || value == '' || filter.contains(key) || value == 0.0,
);

return json;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ class MoneygramOnRampOrderService implements Disposable {
.whereNotNull()
.asyncExpand<OnRampOrderRowsCompanion?>((order) {
logMessage(
message: 'Moneygram on ramp order status update',
data: {
'orderId': orderId,
'status': order.status.name,
},
message: 'MGOnRampOrderStatusChange',
data: order.toSentry,
);

switch (order.status) {
Expand Down Expand Up @@ -483,3 +480,10 @@ class MoneygramOnRampOrderService implements Disposable {
}

const _minimumInitBalance = 1.5; // 1.5 XLM

extension on OnRampOrderRow {
Map<String, dynamic> get toSentry => toJson()
..removeWhere(
(key, value) => value == null || value == '' || value == 0.0,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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),
Expand Down Expand Up @@ -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 =>
Expand Down
6 changes: 5 additions & 1 deletion packages/espressocash_app/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}

0 comments on commit b3c3265

Please sign in to comment.