| 1 | import 'dart:async'; |
| 2 | import 'package:cake_wallet/anonpay/anonpay_invoice_info.dart'; |
| 3 | import 'package:cake_wallet/view_model/dashboard/anonpay_transaction_list_item.dart'; |
| 4 | import 'package:flutter/foundation.dart'; |
| 5 | import 'package:hive/hive.dart'; |
| 6 | import 'package:mobx/mobx.dart'; |
| 7 | |
| 8 | part 'anonpay_transactions_store.g.dart'; |
| 9 | |
| 10 | class AnonpayTransactionsStore = AnonpayTransactionsStoreBase with _$AnonpayTransactionsStore; |
| 11 | |
| 12 | abstract class AnonpayTransactionsStoreBase with Store { |
| 13 | AnonpayTransactionsStoreBase({ |
| 14 | required this.anonpayInvoiceInfoSource, |
| 15 | }) : transactions = <AnonpayTransactionListItem>[] { |
| 16 | anonpayInvoiceInfoSource.watch().listen( |
| 17 | (_) async => await updateTransactionList(), |
| 18 | ); |
| 19 | updateTransactionList(); |
| 20 | } |
| 21 | |
| 22 | Box<AnonpayInvoiceInfo> anonpayInvoiceInfoSource; |
| 23 | |
| 24 | @observable |
| 25 | List<AnonpayTransactionListItem> transactions; |
| 26 | |
| 27 | @action |
| 28 | Future<void> updateTransactionList() async { |
| 29 | transactions = anonpayInvoiceInfoSource.values |
| 30 | .map( |
| 31 | (transaction) => AnonpayTransactionListItem( |
| 32 | transaction: transaction, |
| 33 | key: ValueKey('anonpay_invoice_transaction_list_item_${transaction.invoiceId}_key'), |
| 34 | ), |
| 35 | ) |
| 36 | .toList(); |
| 37 | } |
| 38 | } |