mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 02:24:30 +00:00
fetch paynym bot image over Tor
hard to test, as I cannot claim/generate nor detect a previously-claimed/generated nym over Tor due to ``` flutter: Log: [Info][2024-04-25 20:28:22.609Z]: HTTP.post() rethrew: Exception: Command handling failed. With error: serverError flutter: #0 SocksSocket._handleCommandResponse (package:socks5_proxy/src/client/socks_client.dart:196:7) flutter: <asynchronous suspension> flutter: #1 SocksSocket.initialize (package:socks5_proxy/src/client/socks_client.dart:74:22) flutter: <asynchronous suspension> flutter: #2 SocksTCPClient.connect (package:socks5_proxy/src/client/socks_tcp_client.dart:70:20) flutter: <asynchronous suspension> flutter: #3 SocksTCPClient.assignToHttpClientWithSecureOptions.<anonymous closure> (package:socks5_proxy/src/client/socks_tcp_client.dart:46:40) flutter: <asynchronous suspension> flutter: #4 _ConnectionTarget.connect.<anonymous closure> (dart:_http/http_impl.dart:2490:32) flutter: <asynchronous suspension> flutter: #5 _HttpClient._openUrl.<anonymous closure> (dart:_http/http_impl.dart:2787:15) flutter: <asynchronous suspension> flutter: #6 HTTP.post (package:stackwallet/networking/http.dart:85:41) flutter: <asynchronous suspension> flutter: #7 PaynymIsApi._post (package:stackwallet/utilities/paynym_is_api.dart:54:22) flutter: <asynchronous suspension> flutter: #8 PaynymIsApi.nym (package:stackwallet/utilities/paynym_is_api.dart:267:22) flutter: <asynchronous suspension> flutter: #9 Wallet.refresh (package:stackwallet/wallets/wallet/wallet.dart:511:21) flutter: <asynchronous suspension> ```
This commit is contained in:
parent
81fd642735
commit
01de393521
1 changed files with 34 additions and 9 deletions
|
@ -8,8 +8,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||
import 'package:stackwallet/networking/http.dart';
|
||||
import 'package:stackwallet/services/tor_service.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
|
||||
class PayNymBot extends StatelessWidget {
|
||||
const PayNymBot({
|
||||
|
@ -28,16 +32,37 @@ class PayNymBot extends StatelessWidget {
|
|||
child: SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: Image.network(
|
||||
"https://paynym.is/$paymentCodeString/avatar",
|
||||
loadingBuilder: (context, child, loadingProgress) =>
|
||||
loadingProgress == null
|
||||
? child
|
||||
: const Center(
|
||||
child: LoadingIndicator(),
|
||||
),
|
||||
child: FutureBuilder<Uint8List>(
|
||||
future: _fetchImage(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Image.memory(snapshot.data!);
|
||||
} else if (snapshot.hasError) {
|
||||
return const Center(child: Icon(Icons.error));
|
||||
} else {
|
||||
return const Center(); // TODO [prio=low]: Make better loading indicator.
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Uint8List> _fetchImage() async {
|
||||
final HTTP client = HTTP();
|
||||
final Uri uri = Uri.parse("https://paynym.is/$paymentCodeString/avatar");
|
||||
|
||||
final response = await client.get(
|
||||
url: uri,
|
||||
proxyInfo: Prefs.instance.useTor
|
||||
? TorService.sharedInstance.getProxyInfo()
|
||||
: null,
|
||||
);
|
||||
|
||||
if (response.code == 200) {
|
||||
return Uint8List.fromList(response.bodyBytes);
|
||||
} else {
|
||||
throw Exception('Failed to load image');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue