Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions app/lib/widgets/wallets/send_confirmation.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -178,18 +180,20 @@ class _SendConfirmationWidgetState extends State<SendConfirmationWidget> {
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;
});
Expand All @@ -204,6 +208,15 @@ class _SendConfirmationWidgetState extends State<SendConfirmationWidget> {
Navigator.pop(context);
}

Future<void> _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<void> _showDialog(
String title, String message, IconData icon, DialogType type) async {
showDialog(
Expand Down