mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
refactor InscriptionLink factory, casting
TODO replace casting throughout ordinals DTOs with refactored validation
This commit is contained in:
parent
697f40fce1
commit
afbf818ab5
4 changed files with 29 additions and 37 deletions
|
@ -1,4 +1,4 @@
|
|||
import 'package:stackwallet/dto/ordinals/inscription_response.dart';
|
||||
import 'package:stackwallet/dto/ordinals/inscription_link.dart';
|
||||
|
||||
class AddressResponse {
|
||||
final AddressLinks links;
|
||||
|
@ -48,14 +48,3 @@ class AddressLink {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:stackwallet/dto/ordinals/inscription_link.dart';
|
||||
|
||||
class FeedResponse {
|
||||
final List<InscriptionLink> inscriptions;
|
||||
|
||||
|
@ -12,17 +14,3 @@ class FeedResponse {
|
|||
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 ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
13
lib/dto/ordinals/inscription_link.dart
Normal file
13
lib/dto/ordinals/inscription_link.dart
Normal 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 ?? '',
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:stackwallet/dto/ordinals/inscription_link.dart';
|
||||
|
||||
class TransactionResponse {
|
||||
final TransactionLinks links;
|
||||
final List<OutputLink> inputs;
|
||||
|
@ -18,21 +20,21 @@ class TransactionResponse {
|
|||
factory TransactionResponse.fromJson(Map<String, dynamic> json) {
|
||||
final inputsJson = json['_links']['inputs'] as List;
|
||||
final inputs = inputsJson
|
||||
.map((inputJson) => OutputLink.fromJson(inputJson))
|
||||
.map((inputJson) => OutputLink.fromJson(inputJson as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
final outputsJson = json['_links']['outputs'] as List;
|
||||
final outputs = outputsJson
|
||||
.map((outputJson) => OutputLink.fromJson(outputJson))
|
||||
.map((outputJson) => OutputLink.fromJson(outputJson as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
return TransactionResponse(
|
||||
links: TransactionLinks.fromJson(json['_links']),
|
||||
links: TransactionLinks.fromJson(json['_links'] as Map<String, dynamic>),
|
||||
inputs: inputs,
|
||||
inscription: InscriptionLink.fromJson(json['_links']['inscription']),
|
||||
inscription: InscriptionLink.fromJson(json['_links']['inscription'] as Map<String, dynamic>),
|
||||
outputs: outputs,
|
||||
self: TransactionLink.fromJson(json['_links']['self']),
|
||||
transaction: json['transaction'],
|
||||
self: TransactionLink.fromJson(json['_links']['self'] as Map<String, dynamic>),
|
||||
transaction: json['transaction'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -50,9 +52,9 @@ class TransactionLinks {
|
|||
|
||||
factory TransactionLinks.fromJson(Map<String, dynamic> json) {
|
||||
return TransactionLinks(
|
||||
block: TransactionLink.fromJson(json['block']),
|
||||
inscription: InscriptionLink.fromJson(json['inscription']),
|
||||
self: TransactionLink.fromJson(json['self']),
|
||||
block: TransactionLink.fromJson(json['block'] as Map<String, dynamic>),
|
||||
inscription: InscriptionLink.fromJson(json['inscription'] as Map<String, dynamic>),
|
||||
self: TransactionLink.fromJson(json['self'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +65,7 @@ class TransactionLink {
|
|||
TransactionLink({required this.href});
|
||||
|
||||
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});
|
||||
|
||||
factory OutputLink.fromJson(Map<String, dynamic> json) {
|
||||
return OutputLink(href: json['href']);
|
||||
return OutputLink(href: json['href'] as String);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue