mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
3&4 fixes for Payjoin (#2358)
* fix: update Payjoin transaction details list item type to `TransactionDetailsListItem` * fix: add error handling for unrecoverable Payjoin sender sessions * fix: centralize Payjoin connectivity error handling with `_isPayjoinConnectivityError` function
This commit is contained in:
@@ -57,6 +57,9 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S
|
||||
return generateP2WPKHAddress(hd: hd, index: index, network: network);
|
||||
}
|
||||
|
||||
bool _isPayjoinConnectivityError(String error) =>
|
||||
["error sending request for url", "Instance of 'FfiIoError'"].any((e) => error.contains(e));
|
||||
|
||||
@action
|
||||
Future<void> initPayjoin() async {
|
||||
try {
|
||||
@@ -68,7 +71,7 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S
|
||||
} catch (e) {
|
||||
printV(e);
|
||||
// Ignore Connectivity errors
|
||||
if (!e.toString().contains("error sending request for url")) rethrow;
|
||||
if (!_isPayjoinConnectivityError(e.toString())) rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +85,7 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S
|
||||
} catch (e) {
|
||||
printV(e);
|
||||
// Ignore Connectivity errors
|
||||
if (!e.toString().contains("error sending request for url")) rethrow;
|
||||
if (!_isPayjoinConnectivityError(e.toString())) rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'package:payjoin_flutter/common.dart';
|
||||
import 'package:payjoin_flutter/receive.dart';
|
||||
import 'package:payjoin_flutter/send.dart';
|
||||
import 'package:payjoin_flutter/src/config.dart' as pj_config;
|
||||
import 'package:payjoin_flutter/src/generated/api.dart' as pj_api;
|
||||
import 'package:payjoin_flutter/uri.dart' as PayjoinUri;
|
||||
|
||||
class PayjoinManager {
|
||||
@@ -44,17 +45,21 @@ class PayjoinManager {
|
||||
final allSessions = _payjoinStorage.readAllOpenSessions(_wallet.id);
|
||||
|
||||
final spawnedSessions = allSessions.map((session) {
|
||||
if (session.isSenderSession) {
|
||||
printV("Resuming Payjoin Sender Session ${session.pjUri!}");
|
||||
return _spawnSender(
|
||||
sender: Sender.fromJson(json: session.sender!),
|
||||
pjUri: session.pjUri!,
|
||||
);
|
||||
try {
|
||||
if (session.isSenderSession) {
|
||||
printV("Resuming Payjoin Sender Session ${session.pjUri!}");
|
||||
return _spawnSender(
|
||||
sender: Sender.fromJson(json: session.sender!),
|
||||
pjUri: session.pjUri!,
|
||||
);
|
||||
}
|
||||
final receiver = Receiver.fromJson(json: session.receiver!);
|
||||
printV("Resuming Payjoin Receiver Session ${receiver.id()}");
|
||||
return spawnReceiver(receiver: receiver);
|
||||
} on pj_api.FfiSerdeJsonError catch (_) {
|
||||
_payjoinStorage.markSenderSessionUnrecoverable(session.pjUri!, "Outdated Session");
|
||||
}
|
||||
final receiver = Receiver.fromJson(json: session.receiver!);
|
||||
printV("Resuming Payjoin Receiver Session ${receiver.id()}");
|
||||
return spawnReceiver(receiver: receiver);
|
||||
});
|
||||
}).nonNulls;
|
||||
|
||||
printV("Resumed ${spawnedSessions.length} Payjoin Sessions");
|
||||
await Future.wait(spawnedSessions);
|
||||
|
||||
@@ -27,7 +27,7 @@ abstract class PayjoinDetailsViewModelBase with Store {
|
||||
this.transactionInfo, {
|
||||
required this.payjoinSessionSource,
|
||||
required this.themeStore,
|
||||
}) : items = ObservableList<StandartListItem>(),
|
||||
}) : items = ObservableList<TransactionDetailsListItem>(),
|
||||
payjoinSession = payjoinSessionSource.get(payjoinSessionId)! {
|
||||
listener = payjoinSessionSource.watch().listen((e) {
|
||||
if (e.key == payjoinSessionId) _updateItems();
|
||||
|
||||
Reference in New Issue
Block a user