57 lines
1.8 KiB
Dart
57 lines
1.8 KiB
Dart
/// Data model for wallet transactions returned by the API.
|
|
///
|
|
/// Maps deposit, withdraw, and transfer records with blockchain metadata.
|
|
class TransactionModel {
|
|
const TransactionModel({
|
|
required this.id,
|
|
required this.walletTypeId,
|
|
required this.type,
|
|
required this.amount,
|
|
required this.fee,
|
|
required this.status,
|
|
this.blockchainTxId,
|
|
this.fromAddress,
|
|
this.toAddress,
|
|
this.confirmations,
|
|
this.requiredConfirmations,
|
|
required this.createdAt,
|
|
this.metadata,
|
|
});
|
|
|
|
final String id;
|
|
final int walletTypeId;
|
|
/// Transaction kind (e.g. deposit, withdraw, transfer).
|
|
final String type;
|
|
/// Amount in smallest units as a string.
|
|
final String amount;
|
|
final String fee;
|
|
final String status;
|
|
final String? blockchainTxId;
|
|
final String? fromAddress;
|
|
final String? toAddress;
|
|
final int? confirmations;
|
|
final int? requiredConfirmations;
|
|
final String createdAt;
|
|
final Map<String, dynamic>? metadata;
|
|
|
|
/// Parses a transaction from backend JSON (snake_case keys).
|
|
factory TransactionModel.fromJson(Map<String, dynamic> json) {
|
|
final meta = json['metadata'];
|
|
return TransactionModel(
|
|
id: json['id'] as String,
|
|
walletTypeId: json['wallet_type_id'] as int,
|
|
type: json['type'] as String,
|
|
amount: (json['amount'] ?? '0').toString(),
|
|
fee: (json['fee'] ?? '0').toString(),
|
|
status: json['status'] as String,
|
|
blockchainTxId: json['blockchain_tx_id'] as String?,
|
|
fromAddress: json['from_address'] as String?,
|
|
toAddress: json['to_address'] as String?,
|
|
confirmations: json['confirmations'] as int?,
|
|
requiredConfirmations: json['required_confirmations'] as int?,
|
|
createdAt: json['created_at'] as String,
|
|
metadata: meta is Map<String, dynamic> ? meta : null,
|
|
);
|
|
}
|
|
}
|