2020-06-01 18:13:56 +00:00
|
|
|
import 'dart:core';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cw_monero/transaction_history.dart'
|
|
|
|
as monero_transaction_history;
|
|
|
|
import 'package:cake_wallet/core/transaction_history.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/monero/monero_transaction_info.dart';
|
2020-06-01 18:13:56 +00:00
|
|
|
|
|
|
|
part 'monero_transaction_history.g.dart';
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
List<MoneroTransactionInfo> _getAllTransactions(dynamic _) =>
|
2020-06-01 18:13:56 +00:00
|
|
|
monero_transaction_history
|
|
|
|
.getAllTransations()
|
|
|
|
.map((row) => MoneroTransactionInfo.fromRow(row))
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
class MoneroTransactionHistory = MoneroTransactionHistoryBase
|
|
|
|
with _$MoneroTransactionHistory;
|
|
|
|
|
|
|
|
abstract class MoneroTransactionHistoryBase
|
2020-06-20 07:10:00 +00:00
|
|
|
extends TransactionHistoryBase<MoneroTransactionInfo> with Store {
|
|
|
|
MoneroTransactionHistoryBase() {
|
2020-08-25 16:32:40 +00:00
|
|
|
transactions = ObservableMap<String, MoneroTransactionInfo>();
|
2020-06-20 07:10:00 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 18:13:56 +00:00
|
|
|
@override
|
2020-08-25 16:32:40 +00:00
|
|
|
Future<Map<String, MoneroTransactionInfo>> fetchTransactions() async {
|
2020-06-01 18:13:56 +00:00
|
|
|
monero_transaction_history.refreshTransactions();
|
2020-08-25 16:32:40 +00:00
|
|
|
return _getAllTransactions(null).fold<Map<String, MoneroTransactionInfo>>(
|
|
|
|
<String, MoneroTransactionInfo>{},
|
|
|
|
(Map<String, MoneroTransactionInfo> acc, MoneroTransactionInfo tx) {
|
|
|
|
acc[tx.id] = tx;
|
|
|
|
return acc;
|
|
|
|
});
|
2020-06-01 18:13:56 +00:00
|
|
|
}
|
2020-08-25 16:32:40 +00:00
|
|
|
|
|
|
|
@override
|
2020-09-22 13:35:23 +00:00
|
|
|
@action
|
2020-08-25 16:32:40 +00:00
|
|
|
void updateAsync({void Function() onFinished}) {
|
|
|
|
fetchTransactionsAsync(
|
|
|
|
(transaction) => transactions[transaction.id] = transaction,
|
|
|
|
onFinished: onFinished);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void fetchTransactionsAsync(
|
|
|
|
void Function(MoneroTransactionInfo transaction) onTransactionLoaded,
|
2020-09-21 16:56:41 +00:00
|
|
|
{void Function() onFinished}) async {
|
|
|
|
final transactions = await fetchTransactions();
|
|
|
|
transactions.values.forEach((tx) => onTransactionLoaded(tx));
|
|
|
|
onFinished?.call();
|
|
|
|
}
|
2020-06-01 18:13:56 +00:00
|
|
|
}
|