2020-08-25 16:32:40 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-06-01 18:13:56 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/transaction_info.dart';
|
2020-06-01 18:13:56 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
abstract class TransactionHistoryBase<TransactionType extends TransactionInfo> {
|
|
|
|
TransactionHistoryBase() : _isUpdating = false;
|
2020-06-01 18:13:56 +00:00
|
|
|
|
|
|
|
@observable
|
2020-08-25 16:32:40 +00:00
|
|
|
ObservableMap<String, TransactionType> transactions;
|
2020-06-01 18:13:56 +00:00
|
|
|
|
|
|
|
bool _isUpdating;
|
|
|
|
|
|
|
|
Future<void> update() async {
|
|
|
|
if (_isUpdating) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
_isUpdating = false;
|
2020-06-20 07:10:00 +00:00
|
|
|
transactions.addAll(await fetchTransactions());
|
2020-06-01 18:13:56 +00:00
|
|
|
_isUpdating = true;
|
|
|
|
} catch (e) {
|
|
|
|
_isUpdating = false;
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
void updateAsync({void Function() onFinished}) {
|
|
|
|
fetchTransactionsAsync(
|
|
|
|
(transaction) => transactions[transaction.id] = transaction,
|
|
|
|
onFinished: onFinished);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fetchTransactionsAsync(
|
|
|
|
void Function(TransactionType transaction) onTransactionLoaded,
|
|
|
|
{void Function() onFinished});
|
|
|
|
|
|
|
|
Future<Map<String, TransactionType>> fetchTransactions();
|
|
|
|
}
|