From b773811eac6007dd878b4337711e7b2df963cdaa Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 20 Jul 2023 16:49:26 -0500 Subject: [PATCH] working proof of concept --- lib/pages/ordinals/ordinals_view.dart | 10 +++++----- lib/services/litescribe_api.dart | 11 ++++++++--- lib/services/mixins/ordinals_interface.dart | 7 ++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/pages/ordinals/ordinals_view.dart b/lib/pages/ordinals/ordinals_view.dart index f5f3ca23a..8993ed4e7 100644 --- a/lib/pages/ordinals/ordinals_view.dart +++ b/lib/pages/ordinals/ordinals_view.dart @@ -15,8 +15,6 @@ import 'package:stackwallet/models/ordinal.dart'; import 'package:stackwallet/pages/ordinals/ordinals_filter_view.dart'; import 'package:stackwallet/pages/ordinals/widgets/ordinals_list.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; -// import 'package:stackwallet/services/litescribe_api.dart'; -// import 'package:stackwallet/services/ordinals_api.dart'; import 'package:stackwallet/services/mixins/ordinals_interface.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/assets.dart'; @@ -29,7 +27,6 @@ import 'package:stackwallet/widgets/icon_widgets/x_icon.dart'; import 'package:stackwallet/widgets/stack_text_field.dart'; import 'package:stackwallet/widgets/textfield_icon_button.dart'; - class OrdinalsView extends ConsumerStatefulWidget { const OrdinalsView({ super.key, @@ -44,7 +41,7 @@ class OrdinalsView extends ConsumerStatefulWidget { ConsumerState createState() => _OrdinalsViewState(); } -class _OrdinalsViewState extends ConsumerState with OrdinalsInterface { +class _OrdinalsViewState extends ConsumerState { late final TextEditingController searchController; late final FocusNode searchFocus; @@ -94,7 +91,10 @@ class _OrdinalsViewState extends ConsumerState with OrdinalsInterf .topNavIconPrimary, ), onPressed: () async { - refreshInscriptions(); + final manager = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(widget.walletId))); + + (manager.wallet as OrdinalsInterface).refreshInscriptions(); }, ), ), diff --git a/lib/services/litescribe_api.dart b/lib/services/litescribe_api.dart index f7634b387..7fc92910d 100644 --- a/lib/services/litescribe_api.dart +++ b/lib/services/litescribe_api.dart @@ -42,7 +42,7 @@ class LitescribeAPI { final response = await _getResponse('/address/inscriptions?address=$address&cursor=$cursor&size=$size'); // Check if the number of returned inscriptions equals the limit - final list = response.data['result']['list'] as List; + final list = response.data['result']['list']; final int total = response.data['result']['total'] as int; final int currentSize = list.length; @@ -51,10 +51,15 @@ class LitescribeAPI { // increment the cursor and make the next API call to fetch the remaining inscriptions. final int newCursor = cursor + size; return getInscriptionsByAddress(address, cursor: newCursor, size: size); - // TODO test logic with smaller size "pagination" + } else { try { - return list; + // Iterate through the list and create InscriptionData objects from each element + final List inscriptions = (list as List) + .map((json) => InscriptionData.fromJson(json as Map)) + .toList(); + + return inscriptions; } catch (e) { throw const FormatException('LitescribeAPI getInscriptionsByAddress exception: AddressInscriptionResponse.fromJson failure'); } diff --git a/lib/services/mixins/ordinals_interface.dart b/lib/services/mixins/ordinals_interface.dart index fbd41d80b..a04b6522c 100644 --- a/lib/services/mixins/ordinals_interface.dart +++ b/lib/services/mixins/ordinals_interface.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:isar/isar.dart'; import 'package:stackwallet/db/isar/main_db.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart'; @@ -18,7 +20,6 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/services/litescribe_api.dart'; import 'package:stackwallet/dto/ordinals/inscription_data.dart'; - mixin OrdinalsInterface { late final String _walletId; late final Coin _coin; @@ -50,7 +51,7 @@ mixin OrdinalsInterface { List _inscriptions; final utxos = await _db.getUTXOs(_walletId).findAll(); final uniqueAddresses = getUniqueAddressesFromUTXOs(utxos); - _inscriptions = await getAllInscriptionsFromAddresses(uniqueAddresses); + _inscriptions = await getInscriptionsFromAddresses(uniqueAddresses); // TODO save inscriptions to isar which gets watched by a StreamBuilder } @@ -64,7 +65,7 @@ mixin OrdinalsInterface { return uniqueAddresses.toList(); } - Future> getAllInscriptionsFromAddresses(List addresses) async { + Future> getInscriptionsFromAddresses(List addresses) async { List allInscriptions = []; for (String address in addresses) { try {