2021-04-12 18:22:22 +00:00
|
|
|
import 'package:cake_wallet/buy/buy_provider_description.dart';
|
2021-03-12 19:04:37 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:cake_wallet/exchange/trade_state.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/format_amount.dart';
|
2021-03-12 19:04:37 +00:00
|
|
|
|
|
|
|
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,
|
2021-03-12 19:04:37 +00:00
|
|
|
this.from,
|
2022-10-12 17:09:57 +00:00
|
|
|
this.to}) {
|
|
|
|
if (provider != null) {
|
|
|
|
providerRaw = provider.raw;
|
|
|
|
}
|
|
|
|
if (state != null) {
|
|
|
|
stateRaw = state.raw;
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 19:04:37 +00:00
|
|
|
|
|
|
|
static const typeId = 8;
|
|
|
|
static const boxName = 'Orders';
|
|
|
|
static const boxKey = 'ordersBoxKey';
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(0, defaultValue: '')
|
2021-03-12 19:04:37 +00:00
|
|
|
String id;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(1, defaultValue: '')
|
2021-03-12 19:04:37 +00:00
|
|
|
String transferId;
|
|
|
|
|
|
|
|
@HiveField(2)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? from;
|
2021-03-12 19:04:37 +00:00
|
|
|
|
|
|
|
@HiveField(3)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? to;
|
2021-03-12 19:04:37 +00:00
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(4, defaultValue: '')
|
2022-10-12 17:09:57 +00:00
|
|
|
late String stateRaw;
|
2021-03-12 19:04:37 +00:00
|
|
|
|
|
|
|
TradeState get state => TradeState.deserialize(raw: stateRaw);
|
|
|
|
|
|
|
|
@HiveField(5)
|
|
|
|
DateTime createdAt;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(6, defaultValue: '')
|
2021-03-12 19:04:37 +00:00
|
|
|
String amount;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(7, defaultValue: '')
|
2021-03-12 19:04:37 +00:00
|
|
|
String receiveAddress;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(8, defaultValue: '')
|
2021-03-12 19:04:37 +00:00
|
|
|
String walletId;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(9, defaultValue: 0)
|
2022-10-12 17:09:57 +00:00
|
|
|
late int providerRaw;
|
2021-04-12 18:22:22 +00:00
|
|
|
|
|
|
|
BuyProviderDescription get provider =>
|
|
|
|
BuyProviderDescription.deserialize(raw: providerRaw);
|
|
|
|
|
2021-03-12 19:04:37 +00:00
|
|
|
String amountFormatted() => formatAmount(amount);
|
|
|
|
}
|