2020-01-04 19:31:52 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
|
|
|
|
import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
|
2020-02-11 20:50:10 +00:00
|
|
|
import 'package:cake_wallet/src/domain/common/format_amount.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
part 'trade.g.dart';
|
|
|
|
|
2020-05-26 15:27:10 +00:00
|
|
|
@HiveType(typeId: 3)
|
2020-01-04 19:31:52 +00:00
|
|
|
class Trade extends HiveObject {
|
2020-01-08 12:26:34 +00:00
|
|
|
Trade(
|
|
|
|
{this.id,
|
|
|
|
ExchangeProviderDescription provider,
|
|
|
|
CryptoCurrency from,
|
|
|
|
CryptoCurrency to,
|
|
|
|
TradeState state,
|
|
|
|
this.createdAt,
|
|
|
|
this.expiredAt,
|
|
|
|
this.amount,
|
|
|
|
this.inputAddress,
|
|
|
|
this.extraId,
|
|
|
|
this.outputTransaction,
|
|
|
|
this.refundAddress,
|
|
|
|
this.walletId})
|
|
|
|
: providerRaw = provider?.raw,
|
|
|
|
fromRaw = from?.raw,
|
|
|
|
toRaw = to?.raw,
|
|
|
|
stateRaw = state?.raw;
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
static const boxName = 'Trades';
|
|
|
|
|
|
|
|
@HiveField(0)
|
|
|
|
String id;
|
|
|
|
|
|
|
|
@HiveField(1)
|
|
|
|
int providerRaw;
|
|
|
|
|
|
|
|
ExchangeProviderDescription get provider =>
|
|
|
|
ExchangeProviderDescription.deserialize(raw: providerRaw);
|
|
|
|
|
|
|
|
@HiveField(2)
|
|
|
|
int fromRaw;
|
|
|
|
|
|
|
|
CryptoCurrency get from => CryptoCurrency.deserialize(raw: fromRaw);
|
|
|
|
|
|
|
|
@HiveField(3)
|
|
|
|
int toRaw;
|
|
|
|
|
|
|
|
CryptoCurrency get to => CryptoCurrency.deserialize(raw: toRaw);
|
|
|
|
|
|
|
|
@HiveField(4)
|
|
|
|
String stateRaw;
|
|
|
|
|
|
|
|
TradeState get state => TradeState.deserialize(raw: stateRaw);
|
|
|
|
|
|
|
|
@HiveField(5)
|
|
|
|
DateTime createdAt;
|
|
|
|
|
|
|
|
@HiveField(6)
|
|
|
|
DateTime expiredAt;
|
|
|
|
|
|
|
|
@HiveField(7)
|
|
|
|
String amount;
|
|
|
|
|
|
|
|
@HiveField(8)
|
|
|
|
String inputAddress;
|
|
|
|
|
|
|
|
@HiveField(9)
|
|
|
|
String extraId;
|
|
|
|
|
|
|
|
@HiveField(10)
|
|
|
|
String outputTransaction;
|
|
|
|
|
|
|
|
@HiveField(11)
|
|
|
|
String refundAddress;
|
|
|
|
|
|
|
|
@HiveField(12)
|
|
|
|
String walletId;
|
|
|
|
|
|
|
|
static Trade fromMap(Map map) {
|
|
|
|
return Trade(
|
2020-01-08 12:26:34 +00:00
|
|
|
id: map['id'] as String,
|
|
|
|
provider: ExchangeProviderDescription.deserialize(
|
|
|
|
raw: map['provider'] as int),
|
|
|
|
from: CryptoCurrency.deserialize(raw: map['input'] as int),
|
|
|
|
to: CryptoCurrency.deserialize(raw: map['output'] as int),
|
2020-01-04 19:31:52 +00:00
|
|
|
createdAt: map['date'] != null
|
2020-01-08 12:26:34 +00:00
|
|
|
? DateTime.fromMillisecondsSinceEpoch(map['date'] as int)
|
2020-01-04 19:31:52 +00:00
|
|
|
: null,
|
2020-01-08 12:26:34 +00:00
|
|
|
amount: map['amount'] as String,
|
|
|
|
walletId: map['wallet_id'] as String);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
2020-01-08 12:26:34 +00:00
|
|
|
return <String, dynamic>{
|
2020-01-04 19:31:52 +00:00
|
|
|
'id': id,
|
|
|
|
'provider': provider.serialize(),
|
|
|
|
'input': from.serialize(),
|
|
|
|
'output': to.serialize(),
|
|
|
|
'date': createdAt != null ? createdAt.millisecondsSinceEpoch : null,
|
|
|
|
'amount': amount,
|
|
|
|
'wallet_id': walletId
|
|
|
|
};
|
|
|
|
}
|
2020-02-07 12:06:15 +00:00
|
|
|
|
2020-02-11 20:50:10 +00:00
|
|
|
String amountFormatted() => formatAmount(amount);
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|