2023-07-27 15:28:01 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-09-08 22:53:09 +00:00
|
|
|
import 'package:stackwallet/networking/http.dart';
|
|
|
|
import 'package:stackwallet/services/tor_service.dart';
|
2023-07-27 15:28:01 +00:00
|
|
|
import 'package:stackwallet/utilities/logger.dart';
|
2023-09-08 22:53:09 +00:00
|
|
|
import 'package:stackwallet/utilities/prefs.dart';
|
2023-07-27 15:28:01 +00:00
|
|
|
|
|
|
|
final pMonKeyService = Provider((ref) => MonKeyService());
|
|
|
|
|
|
|
|
class MonKeyService {
|
|
|
|
static const baseURL = "https://monkey.banano.cc/api/v1/monkey/";
|
2023-09-08 22:53:09 +00:00
|
|
|
HTTP client = HTTP();
|
2023-07-27 15:28:01 +00:00
|
|
|
|
|
|
|
Future<Uint8List> fetchMonKey({
|
|
|
|
required String address,
|
|
|
|
bool png = false,
|
|
|
|
}) async {
|
|
|
|
try {
|
|
|
|
String url = "https://monkey.banano.cc/api/v1/monkey/$address";
|
|
|
|
|
|
|
|
if (png) {
|
|
|
|
url += '?format=png&size=512&background=false';
|
|
|
|
}
|
|
|
|
|
2023-09-08 22:53:09 +00:00
|
|
|
final response = await client.get(
|
|
|
|
url: Uri.parse(url),
|
2023-09-15 19:51:20 +00:00
|
|
|
proxyInfo: Prefs.instance.useTor
|
|
|
|
? TorService.sharedInstance.getProxyInfo()
|
|
|
|
: null,
|
2023-09-08 22:53:09 +00:00
|
|
|
);
|
2023-07-27 15:28:01 +00:00
|
|
|
|
2023-09-08 22:53:09 +00:00
|
|
|
if (response.code == 200) {
|
|
|
|
return Uint8List.fromList(response.bodyBytes);
|
2023-07-27 15:28:01 +00:00
|
|
|
} else {
|
|
|
|
throw Exception(
|
2023-09-08 22:53:09 +00:00
|
|
|
"statusCode=${response.code} body=${response.body}",
|
2023-07-27 15:28:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log(
|
|
|
|
"Failed fetchMonKey($address): $e\n$s",
|
|
|
|
level: LogLevel.Error,
|
|
|
|
);
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|