From 2243a08a3df04a0983884381f73f65998a6a495c Mon Sep 17 00:00:00 2001 From: Kirill Bubochkin Date: Mon, 2 Oct 2023 22:42:55 +0200 Subject: [PATCH] fix: kado order status (#1089) --- .../ramp/kado/src/data/kado_api_client.dart | 16 +++++++++++++++- .../src/services/kado_on_ramp_order_watcher.dart | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/espressocash_app/lib/features/ramp/kado/src/data/kado_api_client.dart b/packages/espressocash_app/lib/features/ramp/kado/src/data/kado_api_client.dart index 85dec949ca..3ed69248bc 100644 --- a/packages/espressocash_app/lib/features/ramp/kado/src/data/kado_api_client.dart +++ b/packages/espressocash_app/lib/features/ramp/kado/src/data/kado_api_client.dart @@ -1,3 +1,5 @@ +// ignore_for_file: invalid_annotation_target + import 'package:dio/dio.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -24,7 +26,8 @@ abstract class KadoApiClient { class OrderDataDto with _$OrderDataDto { const factory OrderDataDto({ required String humanStatusField, - required String machineStatusField, + @JsonKey(unknownEnumValue: MachineStatus.unknown) + required MachineStatus machineStatusField, required QuoteDto quote, required AmountDto totalFee, required AmountDto payAmount, @@ -34,6 +37,17 @@ class OrderDataDto with _$OrderDataDto { _$OrderDataDtoFromJson(json); } +@JsonEnum(fieldRename: FieldRename.screamingSnake) +enum MachineStatus { + settled, + cardPaymentFailed, + achPaymentFailed, + wireTransferPending, + pendingPayment, + delayedSettlement, + unknown, +} + @Freezed(toJson: false) class QuoteDto with _$QuoteDto { const factory QuoteDto({ diff --git a/packages/espressocash_app/lib/features/ramp/kado/src/services/kado_on_ramp_order_watcher.dart b/packages/espressocash_app/lib/features/ramp/kado/src/services/kado_on_ramp_order_watcher.dart index dd6028ddb7..a7fb7ebeb7 100644 --- a/packages/espressocash_app/lib/features/ramp/kado/src/services/kado_on_ramp_order_watcher.dart +++ b/packages/espressocash_app/lib/features/ramp/kado/src/services/kado_on_ramp_order_watcher.dart @@ -41,14 +41,14 @@ class KadoOnRampOrderWatcher { ); final isCompleted = - data.machineStatusField.toLowerCase() == 'success'; + data.machineStatusField == MachineStatus.settled; if (isCompleted) await _subscription?.cancel(); await statement.write( OnRampOrderRowsCompanion( humanStatus: Value(data.humanStatusField), - machineStatus: Value(data.machineStatusField), + machineStatus: Value(data.machineStatusField.name), isCompleted: Value(isCompleted), receiveAmount: Value( ((data.payAmount.amount - data.totalFee.amount) /