Skip to content

Commit

Permalink
fix: kado order status (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
ookami-kb authored Oct 2, 2023
1 parent a220e44 commit 2243a08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) /
Expand Down

0 comments on commit 2243a08

Please sign in to comment.