cake_wallet/lib/buy/order.dart

71 lines
1.6 KiB
Dart
Raw Permalink Normal View History

import 'package:cake_wallet/buy/buy_provider_description.dart';
import 'package:cake_wallet/exchange/trade_state.dart';
2021-12-24 12:37:24 +00:00
import 'package:cw_core/format_amount.dart';
import 'package:cw_core/hive_type_ids.dart';
import 'package:hive/hive.dart';
part 'order.g.dart';
@HiveType(typeId: Order.typeId)
class Order extends HiveObject {
Order(
2022-10-12 17:09:57 +00:00
{required this.id,
required this.transferId,
required this.createdAt,
required this.amount,
required this.receiveAddress,
required this.walletId,
BuyProviderDescription? provider,
TradeState? state,
this.from,
2022-10-12 17:09:57 +00:00
this.to}) {
if (provider != null) {
providerRaw = provider.raw;
}
if (state != null) {
stateRaw = state.raw;
}
}
static const typeId = ORDER_TYPE_ID;
static const boxName = 'Orders';
static const boxKey = 'ordersBoxKey';
@HiveField(0, defaultValue: '')
String id;
@HiveField(1, defaultValue: '')
String transferId;
@HiveField(2)
2022-10-12 17:09:57 +00:00
String? from;
@HiveField(3)
2022-10-12 17:09:57 +00:00
String? to;
@HiveField(4, defaultValue: '')
2022-10-12 17:09:57 +00:00
late String stateRaw;
TradeState get state => TradeState.deserialize(raw: stateRaw);
@HiveField(5)
DateTime createdAt;
@HiveField(6, defaultValue: '')
String amount;
@HiveField(7, defaultValue: '')
String receiveAddress;
@HiveField(8, defaultValue: '')
String walletId;
@HiveField(9, defaultValue: 0)
2022-10-12 17:09:57 +00:00
late int providerRaw;
BuyProviderDescription get provider =>
BuyProviderDescription.deserialize(raw: providerRaw);
String amountFormatted() => formatAmount(amount);
}