From 96f1c1ea6e21229b64c244532507aab75cc1f596 Mon Sep 17 00:00:00 2001 From: AlaaElattar Date: Wed, 12 Feb 2025 13:52:28 +0200 Subject: [PATCH] added timeout to transfer function --- .../widgets/wallets/send_confirmation.dart | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/lib/widgets/wallets/send_confirmation.dart b/app/lib/widgets/wallets/send_confirmation.dart index bc0c469f..a5330184 100644 --- a/app/lib/widgets/wallets/send_confirmation.dart +++ b/app/lib/widgets/wallets/send_confirmation.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:threebotlogin/helpers/transaction_helpers.dart'; import 'package:threebotlogin/models/wallet.dart'; @@ -178,18 +180,20 @@ class _SendConfirmationWidgetState extends State { loading = true; }); try { - if (widget.chainType == ChainType.Stellar) { - await Stellar.transfer( - widget.secret, widget.to, widget.amount, widget.memo); - } else { - await TFChain.transfer(widget.secret, widget.to, widget.amount); - } + await Future.any([ + _performTransfer(), + Future.delayed(const Duration(minutes: 1), () { + throw TimeoutException('Transfer operation timed out.'); + }) + ]); await _showDialog('Success!', 'Tokens have been transferred successfully', Icons.check, DialogType.Info); Navigator.pop(context); } catch (e) { - _showDialog('Error', 'Failed to transfer. Please try again.', Icons.error, - DialogType.Error); + String errorMessage = e is TimeoutException + ? 'Transfer took too long. Please try again.' + : 'Failed to transfer. Please try again.'; + _showDialog('Error', errorMessage, Icons.error, DialogType.Error); setState(() { loading = false; }); @@ -204,6 +208,15 @@ class _SendConfirmationWidgetState extends State { Navigator.pop(context); } + Future _performTransfer() async { + if (widget.chainType == ChainType.Stellar) { + await Stellar.transfer( + widget.secret, widget.to, widget.amount, widget.memo); + } else { + await TFChain.transfer(widget.secret, widget.to, widget.amount); + } + } + Future _showDialog( String title, String message, IconData icon, DialogType type) async { showDialog(