@@ -43,6 +43,7 @@ class WalletViewModel extends ViewModel with StringMixin {
43
43
final GlobalKey <ExpansionTileCardState > tileKeyXmr = GlobalKey ();
44
44
45
45
late final StreamSubscription <List <WalletBalanceModel >> _balanceSubcription;
46
+ late final StreamSubscription <List <double >> _assetsPricesSubcription;
46
47
47
48
String _balanceBtc = '' ;
48
49
String _addressBtc = '' ;
@@ -53,7 +54,7 @@ class WalletViewModel extends ViewModel with StringMixin {
53
54
String _addressXmr = '' ;
54
55
bool _loadingBalance = false ;
55
56
bool _afterBuildCalled = false ;
56
- bool _loadingPrices = false ;
57
+ // bool _loadingPrices = false;
57
58
Asset _asset = Asset .BTC ;
58
59
late bool isGuestMode;
59
60
final List <TransactionModel > transactions = [];
@@ -92,6 +93,7 @@ class WalletViewModel extends ViewModel with StringMixin {
92
93
void init () {
93
94
//todo - refactor me (maybe with AutoRoute)
94
95
isGuestMode = _authService.authState == AuthState .guest;
96
+
95
97
_authService.onAuthStateChange.listen ((e) {
96
98
isGuestMode = e == AuthState .guest;
97
99
if (e == AuthState .loggedIn) {
@@ -102,6 +104,9 @@ class WalletViewModel extends ViewModel with StringMixin {
102
104
_balanceSubcription = _appState.balanceController.listen ((event) {
103
105
_updateBalance ();
104
106
});
107
+ _assetsPricesSubcription = _appState.assetPriceController.listen ((event) {
108
+ _updateBalance ();
109
+ });
105
110
super .init ();
106
111
}
107
112
@@ -111,6 +116,7 @@ class WalletViewModel extends ViewModel with StringMixin {
111
116
_afterBuildCalled = true ;
112
117
_tabsRouter = context.tabsRouter;
113
118
_tabsRouter.addListener (_routerListener);
119
+ _updateBalance ();
114
120
// if (_authService.isAuthenticated) {
115
121
// indicatorKey.currentState?.show();
116
122
// }
@@ -120,9 +126,8 @@ class WalletViewModel extends ViewModel with StringMixin {
120
126
121
127
Future getInitalData () async {
122
128
fiatName = _appState.currencyCode;
123
- await calcAssetsPrices ();
124
129
await getBalances ();
125
-
130
+ // await calcAssetsPrices();
126
131
getIncomingDeposits ();
127
132
}
128
133
@@ -149,12 +154,18 @@ class WalletViewModel extends ViewModel with StringMixin {
149
154
// _balanceXmr = _appState.balance[0].balance.toDouble().bankerRound(digitsXmr).toString();
150
155
_balanceXmr = _appState.balance[0 ].balance.toString ();
151
156
_addressXmr = _appState.balance[0 ].receivingAddress;
157
+ if (_appState.assetPrice.isNotEmpty) {
158
+ xmrPrice = _appState.assetPrice[0 ];
159
+ }
152
160
}
153
161
if (_appState.balance.length > 1 ) {
154
162
// final int digitsBtc = getBankersDigits(Asset.BTC.name);
155
163
// _balanceBtc = _appState.balance[1].balance.toDouble().bankerRound(digitsBtc).toString();
156
164
_balanceBtc = _appState.balance[1 ].balance.toString ();
157
165
_addressBtc = _appState.balance[1 ].receivingAddress;
166
+ if (_appState.assetPrice.length > 1 ) {
167
+ btcPrice = _appState.assetPrice[1 ];
168
+ }
158
169
}
159
170
}
160
171
@@ -314,28 +325,28 @@ class WalletViewModel extends ViewModel with StringMixin {
314
325
return '${(_xmrPrice ! * (double .tryParse (_balanceXmr ) ?? 0 )).toStringAsFixed (2 )} ${_appState .currencyCode }' ;
315
326
}
316
327
317
- Future calcAssetsPrices () async {
318
- if (! _loadingPrices) {
319
- _loadingPrices = true ;
320
- for (final asset in Asset .values) {
321
- String usdToCurrency = '' ;
322
- if (_appState.currencyCode != 'USD' ) {
323
- usdToCurrency = '*usd${_appState .currencyCode .toLowerCase ()}' ;
324
- }
325
-
326
- if (asset == Asset .BTC ) {
327
- btcPrice = await calcPrice (
328
- priceEquation: 'coingecko${asset .key ().toLowerCase ()}usd$usdToCurrency ' ,
329
- currency: _appState.currencyCode);
330
- } else {
331
- xmrPrice = await calcPrice (
332
- priceEquation: 'coingecko${asset .key ().toLowerCase ()}usd$usdToCurrency ' ,
333
- currency: _appState.currencyCode);
334
- }
335
- }
336
- _loadingPrices = false ;
337
- }
338
- }
328
+ // Future calcAssetsPrices() async {
329
+ // if (!_loadingPrices) {
330
+ // _loadingPrices = true;
331
+ // for (final asset in Asset.values) {
332
+ // String usdToCurrency = '';
333
+ // if (_appState.currencyCode != 'USD') {
334
+ // usdToCurrency = '*usd${_appState.currencyCode.toLowerCase()}';
335
+ // }
336
+
337
+ // if (asset == Asset.BTC) {
338
+ // btcPrice = await calcPrice(
339
+ // priceEquation: 'coingecko${asset.key().toLowerCase()}usd$usdToCurrency',
340
+ // currency: _appState.currencyCode);
341
+ // } else {
342
+ // xmrPrice = await calcPrice(
343
+ // priceEquation: 'coingecko${asset.key().toLowerCase()}usd$usdToCurrency',
344
+ // currency: _appState.currencyCode);
345
+ // }
346
+ // }
347
+ // _loadingPrices = false;
348
+ // }
349
+ // }
339
350
340
351
Future <double ?> calcPrice ({required String priceEquation, required String currency}) async {
341
352
final res = await _adsRepository.calcPrice (priceEquation, currency);
@@ -377,6 +388,7 @@ class WalletViewModel extends ViewModel with StringMixin {
377
388
@override
378
389
void dispose () {
379
390
_balanceSubcription.cancel ();
391
+ _assetsPricesSubcription.cancel ();
380
392
_tabsRouter.removeListener (_routerListener);
381
393
super .dispose ();
382
394
}
0 commit comments