2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
|
|
|
import 'package:cake_wallet/exchange/trade_state.dart';
|
2023-10-25 20:58:25 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/format_amount.dart';
|
2023-08-15 00:47:25 +00:00
|
|
|
import 'package:cw_core/hive_type_ids.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
part 'trade.g.dart';
|
|
|
|
|
2021-01-15 17:41:30 +00:00
|
|
|
@HiveType(typeId: Trade.typeId)
|
2020-01-04 19:31:52 +00:00
|
|
|
class Trade extends HiveObject {
|
2023-02-07 17:39:39 +00:00
|
|
|
Trade({
|
|
|
|
required this.id,
|
|
|
|
required this.amount,
|
|
|
|
ExchangeProviderDescription? provider,
|
|
|
|
CryptoCurrency? from,
|
|
|
|
CryptoCurrency? to,
|
|
|
|
TradeState? state,
|
|
|
|
this.createdAt,
|
|
|
|
this.expiredAt,
|
|
|
|
this.inputAddress,
|
|
|
|
this.extraId,
|
|
|
|
this.outputTransaction,
|
|
|
|
this.refundAddress,
|
|
|
|
this.walletId,
|
|
|
|
this.payoutAddress,
|
|
|
|
this.password,
|
|
|
|
this.providerId,
|
|
|
|
this.providerName,
|
2024-01-28 13:02:59 +00:00
|
|
|
this.fromWalletAddress,
|
|
|
|
this.memo,
|
2024-02-04 11:01:01 +00:00
|
|
|
this.txId
|
2023-02-07 17:39:39 +00:00
|
|
|
}) {
|
2023-10-25 20:58:25 +00:00
|
|
|
if (provider != null) providerRaw = provider.raw;
|
|
|
|
|
|
|
|
if (from != null) fromRaw = from.raw;
|
|
|
|
|
|
|
|
if (to != null) toRaw = to.raw;
|
|
|
|
|
|
|
|
if (state != null) stateRaw = state.raw;
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
2020-01-08 12:26:34 +00:00
|
|
|
|
2023-08-15 00:47:25 +00:00
|
|
|
static const typeId = TRADE_TYPE_ID;
|
2020-01-04 19:31:52 +00:00
|
|
|
static const boxName = 'Trades';
|
2020-09-21 11:50:26 +00:00
|
|
|
static const boxKey = 'tradesBoxKey';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(0, defaultValue: '')
|
2020-01-04 19:31:52 +00:00
|
|
|
String id;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(1, defaultValue: 0)
|
2022-10-12 17:09:57 +00:00
|
|
|
late int providerRaw;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
ExchangeProviderDescription get provider =>
|
|
|
|
ExchangeProviderDescription.deserialize(raw: providerRaw);
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(2, defaultValue: 0)
|
2022-10-12 17:09:57 +00:00
|
|
|
late int fromRaw;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
CryptoCurrency get from => CryptoCurrency.deserialize(raw: fromRaw);
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(3, defaultValue: 0)
|
2022-10-12 17:09:57 +00:00
|
|
|
late int toRaw;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
CryptoCurrency get to => CryptoCurrency.deserialize(raw: toRaw);
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(4, defaultValue: '')
|
2022-10-12 17:09:57 +00:00
|
|
|
late String stateRaw;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
TradeState get state => TradeState.deserialize(raw: stateRaw);
|
|
|
|
|
|
|
|
@HiveField(5)
|
2022-10-12 17:09:57 +00:00
|
|
|
DateTime? createdAt;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@HiveField(6)
|
2022-10-12 17:09:57 +00:00
|
|
|
DateTime? expiredAt;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(7, defaultValue: '')
|
2020-01-04 19:31:52 +00:00
|
|
|
String amount;
|
|
|
|
|
|
|
|
@HiveField(8)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? inputAddress;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@HiveField(9)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? extraId;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@HiveField(10)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? outputTransaction;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@HiveField(11)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? refundAddress;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@HiveField(12)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? walletId;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2023-01-16 15:27:49 +00:00
|
|
|
@HiveField(13)
|
|
|
|
String? payoutAddress;
|
|
|
|
|
2023-02-07 17:39:39 +00:00
|
|
|
@HiveField(14)
|
|
|
|
String? password;
|
|
|
|
|
|
|
|
@HiveField(15)
|
|
|
|
String? providerId;
|
|
|
|
|
|
|
|
@HiveField(16)
|
|
|
|
String? providerName;
|
|
|
|
|
2023-11-02 15:52:47 +00:00
|
|
|
@HiveField(17)
|
|
|
|
String? fromWalletAddress;
|
|
|
|
|
2024-01-28 13:02:59 +00:00
|
|
|
@HiveField(18)
|
|
|
|
String? memo;
|
|
|
|
|
2024-02-04 11:01:01 +00:00
|
|
|
@HiveField(19)
|
|
|
|
String? txId;
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
static Trade fromMap(Map<String, Object?> map) {
|
2020-01-04 19:31:52 +00:00
|
|
|
return Trade(
|
2020-01-08 12:26:34 +00:00
|
|
|
id: map['id'] as String,
|
2023-02-07 17:39:39 +00:00
|
|
|
provider: ExchangeProviderDescription.deserialize(raw: map['provider'] as int),
|
2020-01-08 12:26:34 +00:00
|
|
|
from: CryptoCurrency.deserialize(raw: map['input'] as int),
|
|
|
|
to: CryptoCurrency.deserialize(raw: map['output'] as int),
|
2023-02-07 17:39:39 +00:00
|
|
|
createdAt:
|
|
|
|
map['date'] != null ? DateTime.fromMillisecondsSinceEpoch(map['date'] as int) : null,
|
2020-01-08 12:26:34 +00:00
|
|
|
amount: map['amount'] as String,
|
2023-11-02 15:52:47 +00:00
|
|
|
walletId: map['wallet_id'] as String,
|
2024-01-28 13:02:59 +00:00
|
|
|
fromWalletAddress: map['from_wallet_address'] as String?,
|
2024-02-04 11:01:01 +00:00
|
|
|
memo: map['memo'] as String?,
|
|
|
|
txId: map['tx_id'] as String?
|
2023-11-02 15:52:47 +00:00
|
|
|
);
|
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(),
|
2022-10-12 17:09:57 +00:00
|
|
|
'date': createdAt != null ? createdAt!.millisecondsSinceEpoch : null,
|
2020-01-04 19:31:52 +00:00
|
|
|
'amount': amount,
|
2023-11-02 15:52:47 +00:00
|
|
|
'wallet_id': walletId,
|
2024-01-28 13:02:59 +00:00
|
|
|
'from_wallet_address': fromWalletAddress,
|
2024-02-04 11:01:01 +00:00
|
|
|
'memo': memo,
|
|
|
|
'tx_id': txId
|
2020-01-04 19:31:52 +00:00
|
|
|
};
|
|
|
|
}
|
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
|
|
|
}
|