working proof of concept

This commit is contained in:
sneurlax 2023-07-20 16:49:26 -05:00
parent 4db0328c73
commit b773811eac
3 changed files with 17 additions and 11 deletions

View file

@ -15,8 +15,6 @@ import 'package:stackwallet/models/ordinal.dart';
import 'package:stackwallet/pages/ordinals/ordinals_filter_view.dart'; import 'package:stackwallet/pages/ordinals/ordinals_filter_view.dart';
import 'package:stackwallet/pages/ordinals/widgets/ordinals_list.dart'; import 'package:stackwallet/pages/ordinals/widgets/ordinals_list.dart';
import 'package:stackwallet/providers/global/wallets_provider.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/services/mixins/ordinals_interface.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.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/stack_text_field.dart';
import 'package:stackwallet/widgets/textfield_icon_button.dart'; import 'package:stackwallet/widgets/textfield_icon_button.dart';
class OrdinalsView extends ConsumerStatefulWidget { class OrdinalsView extends ConsumerStatefulWidget {
const OrdinalsView({ const OrdinalsView({
super.key, super.key,
@ -44,7 +41,7 @@ class OrdinalsView extends ConsumerStatefulWidget {
ConsumerState<OrdinalsView> createState() => _OrdinalsViewState(); ConsumerState<OrdinalsView> createState() => _OrdinalsViewState();
} }
class _OrdinalsViewState extends ConsumerState<OrdinalsView> with OrdinalsInterface { class _OrdinalsViewState extends ConsumerState<OrdinalsView> {
late final TextEditingController searchController; late final TextEditingController searchController;
late final FocusNode searchFocus; late final FocusNode searchFocus;
@ -94,7 +91,10 @@ class _OrdinalsViewState extends ConsumerState<OrdinalsView> with OrdinalsInterf
.topNavIconPrimary, .topNavIconPrimary,
), ),
onPressed: () async { onPressed: () async {
refreshInscriptions(); final manager = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId)));
(manager.wallet as OrdinalsInterface).refreshInscriptions();
}, },
), ),
), ),

View file

@ -42,7 +42,7 @@ class LitescribeAPI {
final response = await _getResponse('/address/inscriptions?address=$address&cursor=$cursor&size=$size'); final response = await _getResponse('/address/inscriptions?address=$address&cursor=$cursor&size=$size');
// Check if the number of returned inscriptions equals the limit // Check if the number of returned inscriptions equals the limit
final list = response.data['result']['list'] as List<InscriptionData>; final list = response.data['result']['list'];
final int total = response.data['result']['total'] as int; final int total = response.data['result']['total'] as int;
final int currentSize = list.length; 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. // increment the cursor and make the next API call to fetch the remaining inscriptions.
final int newCursor = cursor + size; final int newCursor = cursor + size;
return getInscriptionsByAddress(address, cursor: newCursor, size: size); return getInscriptionsByAddress(address, cursor: newCursor, size: size);
// TODO test logic with smaller size "pagination"
} else { } else {
try { try {
return list; // Iterate through the list and create InscriptionData objects from each element
final List<InscriptionData> inscriptions = (list as List<dynamic>)
.map((json) => InscriptionData.fromJson(json as Map<String, dynamic>))
.toList();
return inscriptions;
} catch (e) { } catch (e) {
throw const FormatException('LitescribeAPI getInscriptionsByAddress exception: AddressInscriptionResponse.fromJson failure'); throw const FormatException('LitescribeAPI getInscriptionsByAddress exception: AddressInscriptionResponse.fromJson failure');
} }

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:stackwallet/db/isar/main_db.dart'; import 'package:stackwallet/db/isar/main_db.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.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/services/litescribe_api.dart';
import 'package:stackwallet/dto/ordinals/inscription_data.dart'; import 'package:stackwallet/dto/ordinals/inscription_data.dart';
mixin OrdinalsInterface { mixin OrdinalsInterface {
late final String _walletId; late final String _walletId;
late final Coin _coin; late final Coin _coin;
@ -50,7 +51,7 @@ mixin OrdinalsInterface {
List<dynamic> _inscriptions; List<dynamic> _inscriptions;
final utxos = await _db.getUTXOs(_walletId).findAll(); final utxos = await _db.getUTXOs(_walletId).findAll();
final uniqueAddresses = getUniqueAddressesFromUTXOs(utxos); final uniqueAddresses = getUniqueAddressesFromUTXOs(utxos);
_inscriptions = await getAllInscriptionsFromAddresses(uniqueAddresses); _inscriptions = await getInscriptionsFromAddresses(uniqueAddresses);
// TODO save inscriptions to isar which gets watched by a StreamBuilder // TODO save inscriptions to isar which gets watched by a StreamBuilder
} }
@ -64,7 +65,7 @@ mixin OrdinalsInterface {
return uniqueAddresses.toList(); return uniqueAddresses.toList();
} }
Future<List<InscriptionData>> getAllInscriptionsFromAddresses(List<String> addresses) async { Future<List<InscriptionData>> getInscriptionsFromAddresses(List<String> addresses) async {
List<InscriptionData> allInscriptions = []; List<InscriptionData> allInscriptions = [];
for (String address in addresses) { for (String address in addresses) {
try { try {