stack_wallet/lib/pages/paynym/subwidgets/paynym_bot.dart

69 lines
1.8 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
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> ```
2024-04-25 20:35:04 +00:00
import 'dart:typed_data';
import 'package:flutter/material.dart';
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> ```
2024-04-25 20:35:04 +00:00
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({
Key? key,
required this.paymentCodeString,
this.size = 60.0,
}) : super(key: key);
final String paymentCodeString;
final double size;
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(size / 2),
2022-12-21 19:46:50 +00:00
child: SizedBox(
width: size,
height: size,
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> ```
2024-04-25 20:35:04 +00:00
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.
}
},
2022-12-21 19:46:50 +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> ```
2024-04-25 20:35:04 +00:00
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');
}
}
}