Fixes for monero transaction history updates.

This commit is contained in:
M 2020-09-22 16:35:23 +03:00
parent 2b05eedfc6
commit c53b6676b2
9 changed files with 66 additions and 17 deletions

View file

@ -1 +0,0 @@
09c81fe0a3d701eb6da3bd2c6fc5ec65

View file

@ -10,15 +10,17 @@ abstract class TransactionHistoryBase<TransactionType extends TransactionInfo> {
bool _isUpdating;
@action
Future<void> update() async {
if (_isUpdating) {
return;
}
try {
_isUpdating = false;
transactions.addAll(await fetchTransactions());
_isUpdating = true;
final _transactions = await fetchTransactions();
_transactions.forEach((key, value) => transactions[key] = value);
_isUpdating = false;
} catch (e) {
_isUpdating = false;
rethrow;

View file

@ -1,6 +1,7 @@
import 'package:cake_wallet/entities/transaction_direction.dart';
import 'package:cake_wallet/utils/mobx.dart';
abstract class TransactionInfo extends Object {
abstract class TransactionInfo extends Object with Keyable {
String id;
int amount;
TransactionDirection direction;
@ -11,4 +12,7 @@ abstract class TransactionInfo extends Object {
String amountFormatted();
String fiatAmount();
void changeFiatAmount(String amount);
@override
dynamic get keyIndex => id;
}

View file

@ -34,6 +34,7 @@ abstract class MoneroTransactionHistoryBase
}
@override
@action
void updateAsync({void Function() onFinished}) {
fetchTransactionsAsync(
(transaction) => transactions[transaction.id] = transaction,

View file

@ -92,6 +92,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
monero_wallet.getFullBalance(accountIndex: account.id));
address = subaddress.address;
_setListeners();
await transactionHistory.update();
}
void close() {
@ -245,7 +246,11 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
}
}
void _askForUpdateTransactionHistory() => transactionHistory.updateAsync();
Future<void> _askForUpdateTransactionHistory() async {
print('start');
await transactionHistory.update();
print('end');
}
int _getFullBalance() =>
monero_wallet.getFullBalance(accountIndex: account.id);

View file

@ -6,7 +6,7 @@ mixin Keyable {
dynamic keyIndex;
}
void connectDifferent<T extends Keyable, Y extends Keyable>(
void connectWithTransform<T extends Keyable, Y extends Keyable>(
ObservableList<T> source, ObservableList<Y> dest, Y Function(T) transform,
{bool Function(T) filter}) {
source.observe((ListChange<T> change) {
@ -36,6 +36,36 @@ void connectDifferent<T extends Keyable, Y extends Keyable>(
});
}
void connectMapToListWithTransform<T extends Keyable, Y extends Keyable>(
ObservableMap<dynamic, T> source,
ObservableList<Y> dest,
Y Function(T) transform,
{bool Function(T) filter}) {
source.observe((MapChange<dynamic, T> change) {
switch (change.type) {
case OperationType.add:
if (filter?.call(change.newValue) ?? true) {
dest.add(transform(change.newValue));
}
break;
case OperationType.remove:
// Hive could has equal index and key
dest.removeWhere(
(elem) => elem.keyIndex == (change.key ?? change.newValue.keyIndex));
break;
case OperationType.update:
for (var i = 0; i < dest.length; i++) {
final item = dest[i];
if (item.keyIndex == change.key) {
dest[i] = transform(change.newValue);
}
}
break;
}
});
}
void connect<T extends Keyable>(
ObservableList<T> source, ObservableList<T> dest) {
source.observe((ListChange<T> change) {

View file

@ -7,6 +7,7 @@ import 'package:cake_wallet/entities/transaction_direction.dart';
import 'package:cake_wallet/entities/transaction_info.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/utils/mobx.dart';
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
@ -82,6 +83,15 @@ abstract class DashboardViewModelBase with Store {
displayMode: balanceDisplayMode)));
_reaction = reaction((_) => appStore.wallet, _onWalletChange);
// FIXME: fixme
connectMapToListWithTransform(
appStore.wallet.transactionHistory.transactions,
transactions,
(TransactionInfo val) => TransactionListItem(
transaction: val,
price: price,
fiatCurrency: appStore.settingsStore.fiatCurrency,
displayMode: balanceDisplayMode));
final _wallet = wallet;

View file

@ -1,6 +1,7 @@
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/entities/transaction_info.dart';
import 'package:cake_wallet/utils/mobx.dart';
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
import 'package:cake_wallet/monero/monero_transaction_info.dart';
@ -8,28 +9,25 @@ import 'package:cake_wallet/monero/monero_amount_format.dart';
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
class TransactionListItem extends ActionListItem {
TransactionListItem({
this.transaction,
this.price,
this.fiatCurrency,
this.displayMode
});
class TransactionListItem extends ActionListItem with Keyable {
TransactionListItem(
{this.transaction, this.price, this.fiatCurrency, this.displayMode});
final TransactionInfo transaction;
final double price;
final FiatCurrency fiatCurrency;
final BalanceDisplayMode displayMode;
String get formattedCryptoAmount {
@override
dynamic get keyIndex => transaction.id;
String get formattedCryptoAmount {
return displayMode == BalanceDisplayMode.hiddenBalance
? '---'
: transaction.amountFormatted();
}
String get formattedFiatAmount {
if (transaction is MoneroTransactionInfo) {
final amount = calculateFiatAmountRaw(
cryptoAmount: moneroAmountToDouble(amount: transaction.amount),
@ -51,4 +49,4 @@ class TransactionListItem extends ActionListItem {
@override
DateTime get date => transaction.date;
}
}

View file

@ -24,7 +24,7 @@ abstract class NodeListViewModelBase with Store {
nodes.addAll(values.where((Node node) => node.type == _wallet.type).map(
(Node val) => ItemCell<Node>(val,
isSelected: val.key == currentNode.key, key: val.key)));
connectDifferent(
connectWithTransform(
_nodeListStore.nodes,
nodes,
(Node val) => ItemCell<Node>(val,