Skip to content

Commit

Permalink
Merge pull request #189 from MXCzkEVM/big_upgrade
Browse files Browse the repository at this point in the history
feat: Get error stream
  • Loading branch information
reasje authored Feb 10, 2025
2 parents dd598bb + 469eb80 commit b7fa626
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/features/common/contract/mxc_websocket_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MXCWebsocketUseCase extends ReactiveUseCase {
late final ValueStream<Stream<dynamic>?> websocketStreamSubscription =
reactive(null);
StreamSubscription<dynamic>? websocketCloseStreamSubscription;
StreamSubscription<dynamic>? websocketErrorStreamSubscription;
late final ValueStream<Stream<dynamic>> addressStream =
reactive(const Stream.empty());
StreamSubscription<dynamic>? addressStreamSubscription;
Expand Down Expand Up @@ -109,6 +110,10 @@ class MXCWebsocketUseCase extends ReactiveUseCase {
return _repository.tokenContract.getCloseStream();
}

Stream<dynamic>? getErrorStream() {
return _repository.tokenContract.getErrorStream();
}

void initializeCloseStream() {
final closeStream = getCloseStream();
websocketCloseStreamSubscription = closeStream!.listen((event) {
Expand All @@ -117,6 +122,15 @@ class MXCWebsocketUseCase extends ReactiveUseCase {
});
}

void initializeErrorStream() {
final errorStream = getErrorStream();
websocketErrorStreamSubscription = errorStream!.listen((event) {
websocketErrorStreamSubscription!.cancel();
initializeWebSocketConnection();
});
}


Future<Stream<dynamic>> subscribeToAddressEvents(String address) async {
final res = await subscribeEvent(
"addresses:$address".toLowerCase(),
Expand All @@ -126,6 +140,9 @@ class MXCWebsocketUseCase extends ReactiveUseCase {

void listenToTopUpEvents(dynamic event) {
switch (event.event.value as String) {
// case "phx_error":
// print('Error in websocket');
// break;
case 'transaction':
final newMXCTx = MoonchainTransactionModel.fromJson(
json.encode(event.payload['transactions'][0]));
Expand Down

0 comments on commit b7fa626

Please sign in to comment.