@marcos_feitoza/personal-finance-frontend-feature-dashboard 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.1.2](https://github.com/MarcosOps/personal-finance-frontend-feature-dashboard/compare/v1.1.1...v1.1.2) (2025-12-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Criação do `DashboardViewModel ([ee9447a](https://github.com/MarcosOps/personal-finance-frontend-feature-dashboard/commit/ee9447abe8b99ecbd92d9ce61afa0c4492a8b70c))
7
+
1
8
  ## [1.1.1](https://github.com/MarcosOps/personal-finance-frontend-feature-dashboard/compare/v1.1.0...v1.1.1) (2025-12-06)
2
9
 
3
10
 
@@ -0,0 +1,124 @@
1
+ import 'package:flutter/material.dart';
2
+ import 'package:personal_finance_frontend_core_services/services/transaction_service.dart';
3
+ import 'package:personal_finance_frontend_core_ui/utils/currency_input_formatter.dart';
4
+
5
+ class DashboardViewModel extends ChangeNotifier {
6
+ final TransactionService _transactionService = TransactionService();
7
+ String? _token;
8
+
9
+ // Controllers
10
+ final rbcCashController = TextEditingController();
11
+ final wealthsimpleCashController = TextEditingController();
12
+ final rbcCardController = TextEditingController();
13
+ final bmoCardController = TextEditingController();
14
+
15
+ // State variables
16
+ bool _isLoading = true;
17
+ String? _selectedMenu;
18
+ Map<String, double> _accountBalances = {};
19
+ double _rbcUnpaidExpenses = 0.0;
20
+ double _bmoUnpaidExpenses = 0.0;
21
+ List<Map<String, dynamic>> _cashTransactions = [];
22
+ List<Map<String, dynamic>> _rbcTransactions = [];
23
+ List<Map<String, dynamic>> _bmoTransactions = [];
24
+
25
+ final List<String> _investmentAccountNames = const [
26
+ 'TFSA',
27
+ 'RRSP Wealthsimple',
28
+ 'Non-Registered',
29
+ 'Crypto'
30
+ ];
31
+
32
+ // Getters
33
+ bool get isLoading => _isLoading;
34
+ String? get selectedMenu => _selectedMenu;
35
+ Map<String, double> get accountBalances => _accountBalances;
36
+ List<String> get investmentAccountNames => _investmentAccountNames;
37
+ double get rbcUnpaidExpenses => _rbcUnpaidExpenses;
38
+ double get bmoUnpaidExpenses => _bmoUnpaidExpenses;
39
+ List<Map<String, dynamic>> get cashTransactions => _cashTransactions;
40
+ List<Map<String, dynamic>> get rbcTransactions => _rbcTransactions;
41
+ List<Map<String, dynamic>> get bmoTransactions => _bmoTransactions;
42
+
43
+ double get totalUserCash =>
44
+ CurrencyInputFormatter.unformat(rbcCashController.text) +
45
+ CurrencyInputFormatter.unformat(wealthsimpleCashController.text);
46
+
47
+ double get appCalculatedCash => _accountBalances['CASH'] ?? 0.0;
48
+
49
+ DashboardViewModel(this._token) {
50
+ // Add listeners to controllers to notify UI changes
51
+ rbcCashController.addListener(notifyListeners);
52
+ wealthsimpleCashController.addListener(notifyListeners);
53
+ rbcCardController.addListener(notifyListeners);
54
+ bmoCardController.addListener(notifyListeners);
55
+
56
+ fetchData();
57
+ }
58
+
59
+ @override
60
+ void dispose() {
61
+ rbcCashController.dispose();
62
+ wealthsimpleCashController.dispose();
63
+ rbcCardController.dispose();
64
+ bmoCardController.dispose();
65
+ super.dispose();
66
+ }
67
+
68
+ void setMenu(String? menu) {
69
+ _selectedMenu = menu;
70
+ notifyListeners();
71
+ }
72
+
73
+ Future<void> fetchData() async {
74
+ _isLoading = true;
75
+ notifyListeners();
76
+
77
+ try {
78
+ final cashBalanceFuture = _transactionService.getAccountBalance('CASH', token: _token);
79
+ final investmentBalanceFutures = _investmentAccountNames
80
+ .map((name) => _transactionService.getAccountBalance(name, token: _token))
81
+ .toList();
82
+
83
+ final otherFutures = <Future<dynamic>>[
84
+ _transactionService.getSummaryByPaymentMethod(token: _token),
85
+ _transactionService.fetchTransactions(paymentMethod: 'CASH', limit: 10, token: _token),
86
+ _transactionService.fetchTransactions(paymentMethod: 'RBC', limit: 10, token: _token),
87
+ _transactionService.fetchTransactions(paymentMethod: 'BMO', limit: 10, token: _token),
88
+ ];
89
+
90
+ final allInvestmentBalances = await Future.wait(investmentBalanceFutures);
91
+ final cashBalance = await cashBalanceFuture;
92
+ final otherResults = await Future.wait(otherFutures);
93
+
94
+ _accountBalances = {'CASH': cashBalance};
95
+ for (int i = 0; i < _investmentAccountNames.length; i++) {
96
+ _accountBalances[_investmentAccountNames[i]] = allInvestmentBalances[i];
97
+ }
98
+
99
+ final pmSummary = otherResults[0] as List<Map<String, dynamic>>;
100
+ double tempRbcUnpaid = 0.0;
101
+ double tempBmoUnpaid = 0.0;
102
+ for (var item in pmSummary) {
103
+ final paymentMethod = (item['payment_method'] as String?)?.toUpperCase();
104
+ if (paymentMethod == 'RBC') {
105
+ tempRbcUnpaid += double.tryParse(item['unpaid_amount']?.toString() ?? '0.0') ?? 0.0;
106
+ } else if (paymentMethod == 'BMO') {
107
+ tempBmoUnpaid += double.tryParse(item['unpaid_amount']?.toString() ?? '0.0') ?? 0.0;
108
+ }
109
+ }
110
+ _rbcUnpaidExpenses = tempRbcUnpaid;
111
+ _bmoUnpaidExpenses = tempBmoUnpaid;
112
+
113
+ _cashTransactions = otherResults[1] as List<Map<String, dynamic>>;
114
+ _rbcTransactions = otherResults[2] as List<Map<String, dynamic>>;
115
+ _bmoTransactions = otherResults[3] as List<Map<String, dynamic>>;
116
+
117
+ } catch (e) {
118
+ debugPrint('Error fetching dashboard data: $e');
119
+ } finally {
120
+ _isLoading = false;
121
+ notifyListeners();
122
+ }
123
+ }
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marcos_feitoza/personal-finance-frontend-feature-dashboard",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },