mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
48 lines
1.2 KiB
Dart
48 lines
1.2 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../networking/http.dart';
|
|
import 'tor_service.dart';
|
|
import '../utilities/logger.dart';
|
|
import '../utilities/prefs.dart';
|
|
|
|
final pMonKeyService = Provider((ref) => MonKeyService());
|
|
|
|
class MonKeyService {
|
|
static const baseURL = "https://monkey.banano.cc/api/v1/monkey/";
|
|
HTTP client = HTTP();
|
|
|
|
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';
|
|
}
|
|
|
|
final response = await client.get(
|
|
url: Uri.parse(url),
|
|
proxyInfo: Prefs.instance.useTor
|
|
? TorService.sharedInstance.getProxyInfo()
|
|
: null,
|
|
);
|
|
|
|
if (response.code == 200) {
|
|
return Uint8List.fromList(response.bodyBytes);
|
|
} else {
|
|
throw Exception(
|
|
"statusCode=${response.code} body=${response.body}",
|
|
);
|
|
}
|
|
} catch (e, s) {
|
|
Logging.instance.log(
|
|
"Failed fetchMonKey($address): $e\n$s",
|
|
level: LogLevel.Error,
|
|
);
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|