refactor InscriptionLink factory, casting

TODO replace casting throughout ordinals DTOs with refactored validation
This commit is contained in:
sneurlax 2023-07-19 11:04:19 -05:00
parent 697f40fce1
commit afbf818ab5
4 changed files with 29 additions and 37 deletions

View file

@ -1,4 +1,4 @@
import 'package:stackwallet/dto/ordinals/inscription_response.dart'; import 'package:stackwallet/dto/ordinals/inscription_link.dart';
class AddressResponse { class AddressResponse {
final AddressLinks links; final AddressLinks links;
@ -48,14 +48,3 @@ class AddressLink {
return AddressLink(href: json['href'] as String); return AddressLink(href: json['href'] as String);
} }
} }
class InscriptionLink {
final String href;
final String title;
InscriptionLink(this.href, this.title);
factory InscriptionLink.fromJson(Map<String, dynamic> json) {
return InscriptionLink(json['href'] as String, json['title'] as String);
}
}

View file

@ -1,3 +1,5 @@
import 'package:stackwallet/dto/ordinals/inscription_link.dart';
class FeedResponse { class FeedResponse {
final List<InscriptionLink> inscriptions; final List<InscriptionLink> inscriptions;
@ -12,17 +14,3 @@ class FeedResponse {
return FeedResponse(inscriptions: inscriptions); return FeedResponse(inscriptions: inscriptions);
} }
} }
class InscriptionLink {
final String href;
final String title;
InscriptionLink({required this.href, required this.title});
factory InscriptionLink.fromJson(Map<String, dynamic> json) {
return InscriptionLink(
href: json['href'] as String ?? '',
title: json['title'] as String ?? '',
);
}
}

View file

@ -0,0 +1,13 @@
class InscriptionLink {
final String href;
final String title;
InscriptionLink({required this.href, required this.title});
factory InscriptionLink.fromJson(Map<String, dynamic> json) {
return InscriptionLink(
href: json['href'] as String ?? '',
title: json['title'] as String ?? '',
);
}
}

View file

@ -1,3 +1,5 @@
import 'package:stackwallet/dto/ordinals/inscription_link.dart';
class TransactionResponse { class TransactionResponse {
final TransactionLinks links; final TransactionLinks links;
final List<OutputLink> inputs; final List<OutputLink> inputs;
@ -18,21 +20,21 @@ class TransactionResponse {
factory TransactionResponse.fromJson(Map<String, dynamic> json) { factory TransactionResponse.fromJson(Map<String, dynamic> json) {
final inputsJson = json['_links']['inputs'] as List; final inputsJson = json['_links']['inputs'] as List;
final inputs = inputsJson final inputs = inputsJson
.map((inputJson) => OutputLink.fromJson(inputJson)) .map((inputJson) => OutputLink.fromJson(inputJson as Map<String, dynamic>))
.toList(); .toList();
final outputsJson = json['_links']['outputs'] as List; final outputsJson = json['_links']['outputs'] as List;
final outputs = outputsJson final outputs = outputsJson
.map((outputJson) => OutputLink.fromJson(outputJson)) .map((outputJson) => OutputLink.fromJson(outputJson as Map<String, dynamic>))
.toList(); .toList();
return TransactionResponse( return TransactionResponse(
links: TransactionLinks.fromJson(json['_links']), links: TransactionLinks.fromJson(json['_links'] as Map<String, dynamic>),
inputs: inputs, inputs: inputs,
inscription: InscriptionLink.fromJson(json['_links']['inscription']), inscription: InscriptionLink.fromJson(json['_links']['inscription'] as Map<String, dynamic>),
outputs: outputs, outputs: outputs,
self: TransactionLink.fromJson(json['_links']['self']), self: TransactionLink.fromJson(json['_links']['self'] as Map<String, dynamic>),
transaction: json['transaction'], transaction: json['transaction'] as String,
); );
} }
} }
@ -50,9 +52,9 @@ class TransactionLinks {
factory TransactionLinks.fromJson(Map<String, dynamic> json) { factory TransactionLinks.fromJson(Map<String, dynamic> json) {
return TransactionLinks( return TransactionLinks(
block: TransactionLink.fromJson(json['block']), block: TransactionLink.fromJson(json['block'] as Map<String, dynamic>),
inscription: InscriptionLink.fromJson(json['inscription']), inscription: InscriptionLink.fromJson(json['inscription'] as Map<String, dynamic>),
self: TransactionLink.fromJson(json['self']), self: TransactionLink.fromJson(json['self'] as Map<String, dynamic>),
); );
} }
} }
@ -63,7 +65,7 @@ class TransactionLink {
TransactionLink({required this.href}); TransactionLink({required this.href});
factory TransactionLink.fromJson(Map<String, dynamic> json) { factory TransactionLink.fromJson(Map<String, dynamic> json) {
return TransactionLink(href: json['href']); return TransactionLink(href: json['href'] as String);
} }
} }
@ -73,6 +75,6 @@ class OutputLink {
OutputLink({required this.href}); OutputLink({required this.href});
factory OutputLink.fromJson(Map<String, dynamic> json) { factory OutputLink.fromJson(Map<String, dynamic> json) {
return OutputLink(href: json['href']); return OutputLink(href: json['href'] as String);
} }
} }