| 1 | class NanoTransactionModel { |
| 2 | final DateTime? date; |
| 3 | final String hash; |
| 4 | final bool confirmed; |
| 5 | final String account; |
| 6 | final BigInt amount; |
| 7 | final int height; |
| 8 | final String type; |
| 9 | |
| 10 | NanoTransactionModel({ |
| 11 | this.date, |
| 12 | required this.hash, |
| 13 | required this.height, |
| 14 | required this.amount, |
| 15 | required this.confirmed, |
| 16 | required this.type, |
| 17 | required this.account, |
| 18 | }); |
| 19 | |
| 20 | factory NanoTransactionModel.fromJson(dynamic json) { |
| 21 | DateTime? localTimestamp; |
| 22 | try { |
| 23 | localTimestamp = |
| 24 | DateTime.fromMillisecondsSinceEpoch(int.parse(json["local_timestamp"] as String) * 1000); |
| 25 | } catch (e) { |
| 26 | localTimestamp = DateTime.now(); |
| 27 | } |
| 28 | |
| 29 | return NanoTransactionModel( |
| 30 | date: localTimestamp, |
| 31 | hash: json["hash"] as String, |
| 32 | height: int.parse(json["height"] as String), |
| 33 | type: json["type"] as String, |
| 34 | amount: BigInt.parse(json["amount"] as String), |
| 35 | account: json["account"] as String, |
| 36 | confirmed: (json["confirmed"] as String) == "true", |
| 37 | ); |
| 38 | } |
| 39 | } |