Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordinals null issue and re-add to UI #632

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
manager.coin == Coin.firoTestNet ||
manager.hasWhirlpoolSupport ||
manager.coin == Coin.banano ||
manager.hasWhirlpoolSupport;
manager.hasOrdinalsSupport;
return Row(
children: [
if (Constants.enableExchange)
Expand Down
33 changes: 22 additions & 11 deletions lib/services/litescribe_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';
import 'package:http/http.dart' as http;

import 'package:http/http.dart' as http;
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
import 'package:stackwallet/dto/ordinals/litescribe_response.dart';

Expand All @@ -21,7 +21,8 @@ class LitescribeAPI {
if (response.statusCode == 200) {
return LitescribeResponse(data: _validateJson(response.body));
} else {
throw Exception('LitescribeAPI _getResponse exception: Failed to load data');
throw Exception(
'LitescribeAPI _getResponse exception: Failed to load data');
}
}

Expand All @@ -30,39 +31,49 @@ class LitescribeAPI {
if (parsed is Map<String, dynamic>) {
return parsed;
} else {
throw const FormatException('LitescribeAPI _validateJson exception: Invalid JSON format');
throw const FormatException(
'LitescribeAPI _validateJson exception: Invalid JSON format');
}
}

Future<List<InscriptionData>> getInscriptionsByAddress(String address, {int cursor = 0, int size = 1000}) async {
Future<List<InscriptionData>> getInscriptionsByAddress(String address,
{int cursor = 0, int size = 1000}) async {
// size param determines how many inscriptions are returned per response
// default of 1000 is used to cover most addresses (I assume)
// if the total number of inscriptions at the address exceeds the length of the list of inscriptions returned, another call with a higher size is made
final int defaultLimit = 1000;
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
final list = response.data['result']['list'];
final int total = response.data['result']['total'] as int;
final int currentSize = list.length as int;

int currentSize = 0;
if (total == 0) {
return <InscriptionData>[];
}

final list = response.data['result']!['list'];
currentSize = list.length as int;

if (currentSize == size && currentSize < total) {
// If the number of returned inscriptions equals the limit and there are more inscriptions available,
// 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);

} else {
try {
// 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>))
.map((json) =>
InscriptionData.fromJson(json as Map<String, dynamic>))
.toList();

return inscriptions;
} catch (e) {
throw const FormatException('LitescribeAPI getInscriptionsByAddress exception: AddressInscriptionResponse.fromJson failure');
throw const FormatException(
'LitescribeAPI getInscriptionsByAddress exception: AddressInscriptionResponse.fromJson failure');
}
}
}
}
}
5 changes: 5 additions & 0 deletions test/widget_tests/table_view/table_view_row_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,11 @@ class MockManager extends _i1.Mock implements _i6.Manager {
returnValue: false,
) as bool);
@override
bool get hasFusionSupport => (super.noSuchMethod(
Invocation.getter(#hasFusionSupport),
returnValue: false,
) as bool);
@override
bool get hasTokenSupport => (super.noSuchMethod(
Invocation.getter(#hasTokenSupport),
returnValue: false,
Expand Down
Loading