Fixes for update fiat rate after change of current wallet type. Fixes for change amount for btc transactions. Changed displaying of balance for btc wallet. General fixes.

This commit is contained in:
M 2020-12-15 18:29:10 +02:00
parent eede39ee7a
commit 8cb9bd15cd
29 changed files with 340 additions and 276 deletions

View file

@ -354,7 +354,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -371,7 +371,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Flutter", "$(PROJECT_DIR)/Flutter",
); );
MARKETING_VERSION = 4.0.9; MARKETING_VERSION = 4.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet; PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@ -494,7 +494,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -511,7 +511,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Flutter", "$(PROJECT_DIR)/Flutter",
); );
MARKETING_VERSION = 4.0.9; MARKETING_VERSION = 4.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet; PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@ -528,7 +528,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -545,7 +545,7 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Flutter", "$(PROJECT_DIR)/Flutter",
); );
MARKETING_VERSION = 4.0.9; MARKETING_VERSION = 4.1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet; PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

View file

@ -1,11 +1,13 @@
import 'dart:convert'; import 'dart:convert';
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart'; import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/entities/balance.dart'; import 'package:cake_wallet/entities/balance.dart';
class BitcoinBalance extends Balance { class BitcoinBalance extends Balance {
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed}) : super(); const BitcoinBalance({@required this.confirmed, @required this.unconfirmed})
: super(const [BalanceDisplayMode.availableBalance]);
factory BitcoinBalance.fromJSON(String jsonSource) { factory BitcoinBalance.fromJSON(String jsonSource) {
if (jsonSource == null) { if (jsonSource == null) {
@ -30,6 +32,18 @@ class BitcoinBalance extends Balance {
String get totalFormatted => bitcoinAmountToString(amount: total); String get totalFormatted => bitcoinAmountToString(amount: total);
@override
String formattedBalance(BalanceDisplayMode mode) {
switch (mode) {
case BalanceDisplayMode.fullBalance:
return totalFormatted;
case BalanceDisplayMode.availableBalance:
return totalFormatted;
default:
return null;
}
}
String toJSON() => String toJSON() =>
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed}); json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed});
} }

View file

@ -262,9 +262,8 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
final utxs = await unptsFutures; final utxs = await unptsFutures;
for (final utx in utxs) { for (final utx in utxs) {
final inAmount = utx.value > totalAmount ? totalAmount : utx.value; leftAmount = leftAmount - utx.value;
leftAmount = leftAmount - inAmount; totalInputAmount += utx.value;
totalInputAmount += inAmount;
inputs.add(utx); inputs.add(utx);
if (leftAmount <= 0) { if (leftAmount <= 0) {
@ -348,6 +347,11 @@ abstract class BitcoinWalletBase extends WalletBase<BitcoinBalance> with Store {
// FIXME: Unimplemented // FIXME: Unimplemented
} }
@override
void close() {
}
void _subscribeForUpdates() { void _subscribeForUpdates() {
scriptHashes.forEach((sh) async { scriptHashes.forEach((sh) async {
await _scripthashesUpdateSubject[sh]?.close(); await _scripthashesUpdateSubject[sh]?.close();

View file

@ -75,7 +75,7 @@ class ElectrumClient {
try { try {
final jsoned = final jsoned =
json.decode(utf8.decode(event.toList())) as Map<String, Object>; json.decode(utf8.decode(event.toList())) as Map<String, Object>;
print(jsoned); // print(jsoned);
final method = jsoned['method']; final method = jsoned['method'];
final id = jsoned['id'] as String; final id = jsoned['id'] as String;
final result = jsoned['result']; final result = jsoned['result'];
@ -92,7 +92,9 @@ class ElectrumClient {
}, onError: (Object error) { }, onError: (Object error) {
print(error.toString()); print(error.toString());
_setIsConnected(false); _setIsConnected(false);
}, onDone: () => _setIsConnected(false)); }, onDone: () {
_setIsConnected(false);
});
keepAlive(); keepAlive();
} }
@ -103,7 +105,7 @@ class ElectrumClient {
Future<void> ping() async { Future<void> ping() async {
try { try {
// await callWithTimeout(method: 'server.ping'); await callWithTimeout(method: 'server.ping');
_setIsConnected(true); _setIsConnected(true);
} on RequestFailedTimeoutException catch (_) { } on RequestFailedTimeoutException catch (_) {
_setIsConnected(false); _setIsConnected(false);

View file

@ -52,4 +52,6 @@ abstract class WalletBase<BalaceType> {
Future<void> save(); Future<void> save();
Future<void> rescan({int height}); Future<void> rescan({int height});
void close();
} }

View file

@ -1,3 +1,9 @@
import 'package:cake_wallet/entities/balance_display_mode.dart';
abstract class Balance { abstract class Balance {
const Balance(); const Balance(this.availableModes);
final List<BalanceDisplayMode> availableModes;
String formattedBalance(BalanceDisplayMode mode);
} }

View file

@ -19,5 +19,5 @@ Future<void> loadCurrentWallet() async {
await getIt.get<KeyService>().getWalletPassword(walletName: name); await getIt.get<KeyService>().getWalletPassword(walletName: name);
final _service = getIt.get<WalletService>(param1: type); final _service = getIt.get<WalletService>(param1: type);
final wallet = await _service.openWallet(name, password); final wallet = await _service.openWallet(name, password);
appStore.wallet = wallet; appStore.changeCurrentWallet(wallet);
} }

View file

@ -39,9 +39,9 @@ Future<List<Node>> loadElectrumServerList() async {
Future resetToDefault(Box<Node> nodeSource) async { Future resetToDefault(Box<Node> nodeSource) async {
final moneroNodes = await loadDefaultNodes(); final moneroNodes = await loadDefaultNodes();
// final bitcoinElectrumServerList = await loadElectrumServerList(); final bitcoinElectrumServerList = await loadElectrumServerList();
// final nodes = moneroNodes + bitcoinElectrumServerList; final nodes = moneroNodes + bitcoinElectrumServerList;
await nodeSource.clear(); await nodeSource.clear();
await nodeSource.addAll(moneroNodes); await nodeSource.addAll(nodes);
} }

View file

@ -83,7 +83,6 @@ void main() async {
))))); )))));
} }
} }
Future<void> initialSetup( Future<void> initialSetup(
{@required SharedPreferences sharedPreferences, {@required SharedPreferences sharedPreferences,
@required Box<Node> nodes, @required Box<Node> nodes,

View file

@ -1,20 +1,42 @@
import 'package:cake_wallet/entities/balance.dart';
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:cake_wallet/monero/monero_amount_format.dart'; import 'package:cake_wallet/monero/monero_amount_format.dart';
class MoneroBalance { class MoneroBalance extends Balance {
MoneroBalance({@required this.fullBalance, @required this.unlockedBalance}) MoneroBalance({@required this.fullBalance, @required this.unlockedBalance})
: formattedFullBalance = moneroAmountToString(amount: fullBalance), : formattedFullBalance = moneroAmountToString(amount: fullBalance),
formattedUnlockedBalance = formattedUnlockedBalance =
moneroAmountToString(amount: unlockedBalance); moneroAmountToString(amount: unlockedBalance),
super(const [
BalanceDisplayMode.availableBalance,
BalanceDisplayMode.fullBalance
]);
MoneroBalance.fromString( MoneroBalance.fromString(
{@required this.formattedFullBalance, {@required this.formattedFullBalance,
@required this.formattedUnlockedBalance}) @required this.formattedUnlockedBalance})
: fullBalance = moneroParseAmount(amount: formattedFullBalance), : fullBalance = moneroParseAmount(amount: formattedFullBalance),
unlockedBalance = moneroParseAmount(amount: formattedUnlockedBalance); unlockedBalance = moneroParseAmount(amount: formattedUnlockedBalance),
super(const [
BalanceDisplayMode.availableBalance,
BalanceDisplayMode.fullBalance
]);
final int fullBalance; final int fullBalance;
final int unlockedBalance; final int unlockedBalance;
final String formattedFullBalance; final String formattedFullBalance;
final String formattedUnlockedBalance; final String formattedUnlockedBalance;
}
@override
String formattedBalance(BalanceDisplayMode mode) {
switch (mode) {
case BalanceDisplayMode.fullBalance:
return formattedFullBalance;
case BalanceDisplayMode.availableBalance:
return formattedUnlockedBalance;
default:
return null;
}
}
}

View file

@ -43,7 +43,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
balance = MoneroBalance( balance = MoneroBalance(
fullBalance: monero_wallet.getFullBalance(accountIndex: account.id), fullBalance: monero_wallet.getFullBalance(accountIndex: account.id),
unlockedBalance: unlockedBalance:
monero_wallet.getUnlockedBalance(accountIndex: account.id)); monero_wallet.getUnlockedBalance(accountIndex: account.id));
subaddressList.update(accountIndex: account.id); subaddressList.update(accountIndex: account.id);
subaddress = subaddressList.subaddresses.first; subaddress = subaddressList.subaddresses.first;
address = subaddress.address; address = subaddress.address;
@ -120,6 +120,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
} }
} }
@override
void close() { void close() {
_listener?.stop(); _listener?.stop();
_onAccountChangeReaction?.reaction?.dispose(); _onAccountChangeReaction?.reaction?.dispose();
@ -315,9 +316,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
} }
} }
Future<void> _askForUpdateTransactionHistory() async { Future<void> _askForUpdateTransactionHistory() async =>
await transactionHistory.update(); await transactionHistory.update();
}
int _getFullBalance() => int _getFullBalance() =>
monero_wallet.getFullBalance(accountIndex: account.id); monero_wallet.getFullBalance(accountIndex: account.id);
@ -326,13 +326,13 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
monero_wallet.getUnlockedBalance(accountIndex: account.id); monero_wallet.getUnlockedBalance(accountIndex: account.id);
Future<void> _afterSyncSave() async { Future<void> _afterSyncSave() async {
if (_isSavingAfterSync) {
return;
}
_isSavingAfterSync = true;
try { try {
if (_isSavingAfterSync) {
return;
}
_isSavingAfterSync = true;
final nowTimestamp = DateTime.now().millisecondsSinceEpoch; final nowTimestamp = DateTime.now().millisecondsSinceEpoch;
final sum = _lastAutosaveTimestamp + _autoAfterSyncSaveInterval; final sum = _lastAutosaveTimestamp + _autoAfterSyncSaveInterval;
@ -350,13 +350,13 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
} }
Future<void> _afterNewTransactionSave() async { Future<void> _afterNewTransactionSave() async {
if (_isSavingAfterNewTransaction) {
return;
}
_isSavingAfterNewTransaction = true;
try { try {
if (_isSavingAfterNewTransaction) {
return;
}
_isSavingAfterNewTransaction = true;
await save(); await save();
} catch (e) { } catch (e) {
print(e.toString()); print(e.toString());
@ -366,30 +366,38 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
} }
void _onNewBlock(int height, int blocksLeft, double ptc) async { void _onNewBlock(int height, int blocksLeft, double ptc) async {
if (walletInfo.isRecovery) { try {
await _askForUpdateTransactionHistory();
_askForUpdateBalance();
accountList.update();
}
if (blocksLeft < 100) {
await _askForUpdateTransactionHistory();
_askForUpdateBalance();
accountList.update();
syncStatus = SyncedSyncStatus();
await _afterSyncSave();
if (walletInfo.isRecovery) { if (walletInfo.isRecovery) {
await setAsRecovered(); await _askForUpdateTransactionHistory();
_askForUpdateBalance();
accountList.update();
} }
} else {
syncStatus = SyncingSyncStatus(blocksLeft, ptc); if (blocksLeft < 100) {
await _askForUpdateTransactionHistory();
_askForUpdateBalance();
accountList.update();
syncStatus = SyncedSyncStatus();
await _afterSyncSave();
if (walletInfo.isRecovery) {
await setAsRecovered();
}
} else {
syncStatus = SyncingSyncStatus(blocksLeft, ptc);
}
} catch (e) {
print(e.toString());
} }
} }
void _onNewTransaction() { void _onNewTransaction() {
_askForUpdateTransactionHistory(); try {
_askForUpdateBalance(); _askForUpdateTransactionHistory();
Timer(Duration(seconds: 1), () => _afterNewTransactionSave()); _askForUpdateBalance();
Timer(Duration(seconds: 1), () => _afterNewTransactionSave());
} catch (e) {
print(e.toString());
}
} }
} }

View file

@ -12,12 +12,13 @@ Future<void> startFiatRateUpdate(AppStore appStore, SettingsStore settingsStore,
return; return;
} }
fiatConversionStore.price = await FiatConversionService.fetchPrice( fiatConversionStore.prices[appStore.wallet.currency] =
appStore.wallet.currency, settingsStore.fiatCurrency); await FiatConversionService.fetchPrice(
appStore.wallet.currency, settingsStore.fiatCurrency);
_timer = Timer.periodic( _timer = Timer.periodic(
Duration(seconds: 30), Duration(seconds: 30),
(_) async => fiatConversionStore.price = (_) async => fiatConversionStore.prices[appStore.wallet.currency] =
await FiatConversionService.fetchPrice( await FiatConversionService.fetchPrice(
appStore.wallet.currency, settingsStore.fiatCurrency)); appStore.wallet.currency, settingsStore.fiatCurrency));
} }

View file

@ -7,12 +7,13 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
ReactionDisposer _onCurrentFiatCurrencyChangeDisposer; ReactionDisposer _onCurrentFiatCurrencyChangeDisposer;
void startCurrentFiatChangeReaction(AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { void startCurrentFiatChangeReaction(AppStore appStore,
SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
_onCurrentFiatCurrencyChangeDisposer?.reaction?.dispose(); _onCurrentFiatCurrencyChangeDisposer?.reaction?.dispose();
_onCurrentFiatCurrencyChangeDisposer = reaction( _onCurrentFiatCurrencyChangeDisposer = reaction(
(_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async { (_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async {
final cryptoCurrency = appStore.wallet.currency; final cryptoCurrency = appStore.wallet.currency;
fiatConversionStore.price = await FiatConversionService.fetchPrice( fiatConversionStore.prices[appStore.wallet.currency] =
cryptoCurrency, fiatCurrency); await FiatConversionService.fetchPrice(cryptoCurrency, fiatCurrency);
}); });
} }

View file

@ -6,10 +6,9 @@ ReactionDisposer _onCurrentNodeChangeReaction;
void startOnCurrentNodeChangeReaction(AppStore appStore) { void startOnCurrentNodeChangeReaction(AppStore appStore) {
_onCurrentNodeChangeReaction?.reaction?.dispose(); _onCurrentNodeChangeReaction?.reaction?.dispose();
_onCurrentNodeChangeReaction = appStore.settingsStore.nodes.observe((change) async {
reaction((_) => appStore.settingsStore.currentNode, (Node node) async {
try { try {
await appStore.wallet.connectToNode(node: node); await appStore.wallet.connectToNode(node: change.newValue);
} catch (e) { } catch (e) {
print(e.toString()); print(e.toString());
} }

View file

@ -12,6 +12,7 @@ import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
ReactionDisposer _onCurrentWalletChangeReaction; ReactionDisposer _onCurrentWalletChangeReaction;
ReactionDisposer _onCurrentWalletChangeFiatRateUpdateReaction;
void startCurrentWalletChangeReaction(AppStore appStore, void startCurrentWalletChangeReaction(AppStore appStore,
SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
@ -29,8 +30,16 @@ void startCurrentWalletChangeReaction(AppStore appStore,
await getIt.get<SharedPreferences>().setInt( await getIt.get<SharedPreferences>().setInt(
PreferencesKey.currentWalletType, serializeToInt(wallet.type)); PreferencesKey.currentWalletType, serializeToInt(wallet.type));
await wallet.connectToNode(node: node); await wallet.connectToNode(node: node);
} catch (e) {
print(e.toString());
}
});
fiatConversionStore.price = await FiatConversionService.fetchPrice( _onCurrentWalletChangeFiatRateUpdateReaction =
reaction((_) => appStore.wallet, (WalletBase wallet) async {
try {
fiatConversionStore.prices[wallet.currency] = 0;
fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice(
wallet.currency, settingsStore.fiatCurrency); wallet.currency, settingsStore.fiatCurrency);
} catch (e) { } catch (e) {
print(e.toString()); print(e.toString());

View file

@ -11,58 +11,66 @@ class BalancePage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.all(24), padding: EdgeInsets.all(24),
child: GestureDetector( child: GestureDetector(
onTapUp: (_) => dashboardViewModel.balanceViewModel.isReversing = false, onTapUp: (_) {
onTapDown: (_) => dashboardViewModel.balanceViewModel.isReversing = true, if (dashboardViewModel.balanceViewModel.canReverse) {
child: Column( dashboardViewModel.balanceViewModel.isReversing = false;
mainAxisAlignment: MainAxisAlignment.center, }
crossAxisAlignment: CrossAxisAlignment.center, },
children: <Widget>[ onTapDown: (_) {
Observer(builder: (_) { if (dashboardViewModel.balanceViewModel.canReverse) {
return Text( dashboardViewModel.balanceViewModel.isReversing = true;
dashboardViewModel.balanceViewModel.currency.toString(), }
style: TextStyle( },
fontSize: 40, child: Column(
fontWeight: FontWeight.bold, mainAxisAlignment: MainAxisAlignment.center,
color: Theme.of(context).indicatorColor, crossAxisAlignment: CrossAxisAlignment.center,
height: 1), children: <Widget>[
); Observer(builder: (_) {
}), return Text(
Observer(builder: (_) { dashboardViewModel.balanceViewModel.currency.toString(),
return Text(
dashboardViewModel.balanceViewModel.displayMode.toString(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Theme.of(context).indicatorColor,
height: 1),
);
}),
SizedBox(height: 10),
Observer(builder: (_) {
return AutoSizeText(dashboardViewModel.balanceViewModel.cryptoBalance,
style: TextStyle( style: TextStyle(
fontSize: 54, fontSize: 40,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.white,
height: 1),
maxLines: 1,
textAlign: TextAlign.center);
}),
SizedBox(height: 10),
Observer(builder: (_) {
return Text(dashboardViewModel.balanceViewModel.fiatBalance,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Theme.of(context).indicatorColor, color: Theme.of(context).indicatorColor,
height: 1), height: 1),
textAlign: TextAlign.center); );
}), }),
], Observer(builder: (_) {
), return Text(
) dashboardViewModel.balanceViewModel.displayMode.toString(),
); style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Theme.of(context).indicatorColor,
height: 1),
);
}),
SizedBox(height: 10),
Observer(builder: (_) {
return AutoSizeText(
dashboardViewModel.balanceViewModel.cryptoBalance,
style: TextStyle(
fontSize: 54,
fontWeight: FontWeight.bold,
color: Colors.white,
height: 1),
maxLines: 1,
textAlign: TextAlign.center);
}),
SizedBox(height: 10),
Observer(builder: (_) {
return Text(dashboardViewModel.balanceViewModel.fiatBalance,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Theme.of(context).indicatorColor,
height: 1),
textAlign: TextAlign.center);
}),
],
),
));
} }
} }

View file

@ -46,7 +46,8 @@ class TransactionsPage extends StatelessWidget {
if (item is TransactionListItem) { if (item is TransactionListItem) {
final transaction = item.transaction; final transaction = item.transaction;
return TransactionRow( return Observer(
builder: (_) => TransactionRow(
onTap: () => Navigator.of(context).pushNamed( onTap: () => Navigator.of(context).pushNamed(
Routes.transactionDetails, Routes.transactionDetails,
arguments: transaction), arguments: transaction),
@ -55,7 +56,7 @@ class TransactionsPage extends StatelessWidget {
.format(transaction.date), .format(transaction.date),
formattedAmount: item.formattedCryptoAmount, formattedAmount: item.formattedCryptoAmount,
formattedFiatAmount: item.formattedFiatAmount, formattedFiatAmount: item.formattedFiatAmount,
isPending: transaction.isPending); isPending: transaction.isPending));
} }
if (item is TradeListItem) { if (item is TradeListItem) {

View file

@ -65,98 +65,90 @@ class NodeListPage extends BasePage {
padding: EdgeInsets.only(top: 10), padding: EdgeInsets.only(top: 10),
child: Observer( child: Observer(
builder: (BuildContext context) { builder: (BuildContext context) {
return nodeListViewModel.nodes.isNotEmpty return SectionStandardList(
? SectionStandardList( sectionCount: 2,
sectionCount: 2, context: context,
context: context, itemCounter: (int sectionIndex) {
itemCounter: (int sectionIndex) { if (sectionIndex == 0) {
if (sectionIndex == 0) { return 1;
return 1; }
}
return nodeListViewModel.nodes.length; return nodeListViewModel.nodes.length;
}, },
itemBuilder: (_, sectionIndex, index) { itemBuilder: (_, sectionIndex, index) {
if (sectionIndex == 0) { if (sectionIndex == 0) {
return NodeHeaderListRow( return NodeHeaderListRow(
title: S.of(context).add_new_node, title: S.of(context).add_new_node,
onTap: (_) async => await Navigator.of(context) onTap: (_) async => await Navigator.of(context)
.pushNamed(Routes.newNode)); .pushNamed(Routes.newNode));
} }
final node = nodeListViewModel.nodes[index]; final node = nodeListViewModel.nodes[index];
final isSelected = node.keyIndex == final isSelected =
nodeListViewModel.settingsStore.currentNode.keyIndex; node.keyIndex == nodeListViewModel.currentNode?.keyIndex;
final nodeListRow = NodeListRow( final nodeListRow = NodeListRow(
title: node.uri, title: node.uri,
isSelected: isSelected, isSelected: isSelected,
isAlive: node.requestNode(), isAlive: node.requestNode(),
onTap: (_) async { onTap: (_) async {
if (isSelected) { if (isSelected) {
return; return;
}
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle:
S.of(context).change_current_node_title,
alertContent:
S.of(context).change_current_node(node.uri),
leftButtonText: S.of(context).cancel,
rightButtonText: S.of(context).change,
actionLeftButton: () =>
Navigator.of(context).pop(),
actionRightButton: () async {
await nodeListViewModel.setAsCurrent(node);
Navigator.of(context).pop();
});
});
});
final dismissibleRow = Slidable(
key: Key('${node.keyIndex}'),
actionPane: SlidableDrawerActionPane(),
child: nodeListRow,
secondaryActions: <Widget>[
IconSlideAction(
caption: S.of(context).delete,
color: Colors.red,
icon: CupertinoIcons.delete,
onTap: () async {
final confirmed = await showPopUp<bool>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).remove_node,
alertContent:
S.of(context).remove_node_message,
rightButtonText: S.of(context).remove,
leftButtonText: S.of(context).cancel,
actionRightButton: () =>
Navigator.pop(context, true),
actionLeftButton: () =>
Navigator.pop(context, false));
}) ??
false;
if (confirmed) {
await nodeListViewModel.delete(node);
} }
},
),
]);
await showPopUp<void>( return isSelected ? nodeListRow : dismissibleRow;
context: context, });
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context)
.change_current_node_title,
alertContent: S
.of(context)
.change_current_node(node.uri),
leftButtonText: S.of(context).cancel,
rightButtonText: S.of(context).change,
actionLeftButton: () =>
Navigator.of(context).pop(),
actionRightButton: () async {
await nodeListViewModel
.setAsCurrent(node);
Navigator.of(context).pop();
});
});
});
final dismissibleRow = Slidable(
key: Key('${node.keyIndex}'),
actionPane: SlidableDrawerActionPane(),
child: nodeListRow,
secondaryActions: <Widget>[
IconSlideAction(
caption: S.of(context).delete,
color: Colors.red,
icon: CupertinoIcons.delete,
onTap: () async {
final confirmed = await showPopUp<bool>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle:
S.of(context).remove_node,
alertContent: S
.of(context)
.remove_node_message,
rightButtonText:
S.of(context).remove,
leftButtonText:
S.of(context).cancel,
actionRightButton: () =>
Navigator.pop(context, true),
actionLeftButton: () =>
Navigator.pop(context, false));
}) ??
false;
if (confirmed) {
await nodeListViewModel.delete(node);
}
},
),
]);
return isSelected ? nodeListRow : dismissibleRow;
})
: Container();
}, },
), ),
); );

View file

@ -204,7 +204,7 @@ class AddressTextField extends StatelessWidget {
onURIScanned(uri); onURIScanned(uri);
} }
} catch (e) { } catch (e) {
print('Error $e'); print(e.toString());
} }
} }

View file

@ -26,4 +26,10 @@ abstract class AppStoreBase with Store {
SettingsStore settingsStore; SettingsStore settingsStore;
NodeListStore nodeListStore; NodeListStore nodeListStore;
@action
void changeCurrentWallet(WalletBase wallet) {
this.wallet?.close();
this.wallet = wallet;
}
} }

View file

@ -1,13 +1,13 @@
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
part 'fiat_conversion_store.g.dart'; part 'fiat_conversion_store.g.dart';
class FiatConversionStore = FiatConversionStoreBase class FiatConversionStore = FiatConversionStoreBase with _$FiatConversionStore;
with _$FiatConversionStore;
abstract class FiatConversionStoreBase with Store { abstract class FiatConversionStoreBase with Store {
FiatConversionStoreBase() : price = 0.0; FiatConversionStoreBase() : prices = ObservableMap<CryptoCurrency, double>();
@observable @observable
double price; ObservableMap<CryptoCurrency, double> prices;
} }

View file

@ -43,7 +43,6 @@ abstract class SettingsStoreBase with Store {
isDarkTheme = initialDarkTheme; isDarkTheme = initialDarkTheme;
pinCodeLength = initialPinLength; pinCodeLength = initialPinLength;
languageCode = initialLanguageCode; languageCode = initialLanguageCode;
currentNode = nodes[WalletType.monero];
this.nodes = ObservableMap<WalletType, Node>.of(nodes); this.nodes = ObservableMap<WalletType, Node>.of(nodes);
_sharedPreferences = sharedPreferences; _sharedPreferences = sharedPreferences;
@ -80,13 +79,14 @@ abstract class SettingsStoreBase with Store {
(int pinLength) => sharedPreferences.setInt( (int pinLength) => sharedPreferences.setInt(
PreferencesKey.currentPinLength, pinLength)); PreferencesKey.currentPinLength, pinLength));
reaction((_) => currentNode,
(Node node) => _saveCurrentNode(node, WalletType.monero));
reaction( reaction(
(_) => languageCode, (_) => languageCode,
(String languageCode) => sharedPreferences.setString( (String languageCode) => sharedPreferences.setString(
PreferencesKey.currentLanguageCode, languageCode)); PreferencesKey.currentLanguageCode, languageCode));
this
.nodes
.observe((change) => _saveCurrentNode(change.newValue, change.key));
} }
static const defaultPinLength = 4; static const defaultPinLength = 4;
@ -116,9 +116,6 @@ abstract class SettingsStoreBase with Store {
@observable @observable
int pinCodeLength; int pinCodeLength;
@observable
Node currentNode;
@computed @computed
ThemeData get theme => isDarkTheme ? Themes.darkTheme : Themes.lightTheme; ThemeData get theme => isDarkTheme ? Themes.darkTheme : Themes.lightTheme;

View file

@ -57,7 +57,8 @@ extension MobxBindable<T extends Keyable> on Box<T> {
Filter<T> filter, Filter<T> filter,
}) { }) {
if (initialFire) { if (initialFire) {
dest.addAll(values); final res = filter != null ? values.where(filter) : values;
dest.addAll(res);
} }
return watch().listen((event) { return watch().listen((event) {

View file

@ -15,31 +15,34 @@ part 'balance_view_model.g.dart';
class BalanceViewModel = BalanceViewModelBase with _$BalanceViewModel; class BalanceViewModel = BalanceViewModelBase with _$BalanceViewModel;
abstract class BalanceViewModelBase with Store { abstract class BalanceViewModelBase with Store {
BalanceViewModelBase({ BalanceViewModelBase(
@required this.appStore, {@required this.appStore,
@required this.settingsStore, @required this.settingsStore,
@required this.fiatConvertationStore @required this.fiatConvertationStore})
}) : isReversing = false; : isReversing = false;
final AppStore appStore; final AppStore appStore;
final SettingsStore settingsStore; final SettingsStore settingsStore;
final FiatConversionStore fiatConvertationStore; final FiatConversionStore fiatConvertationStore;
bool get canReverse =>
(appStore.wallet.balance.availableModes as List).length > 1;
@observable @observable
bool isReversing; bool isReversing;
@computed
double get price => fiatConvertationStore.prices[appStore.wallet.currency];
@computed @computed
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode; BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
@computed @computed
BalanceDisplayMode get displayMode => isReversing BalanceDisplayMode get displayMode => isReversing
? (savedDisplayMode == BalanceDisplayMode.availableBalance ? (savedDisplayMode == BalanceDisplayMode.availableBalance
? BalanceDisplayMode.fullBalance ? BalanceDisplayMode.fullBalance
: BalanceDisplayMode.availableBalance) : BalanceDisplayMode.availableBalance)
: savedDisplayMode; : savedDisplayMode;
@computed
double get price => fiatConvertationStore.price;
@computed @computed
String get cryptoBalance { String get cryptoBalance {
@ -63,15 +66,11 @@ abstract class BalanceViewModelBase with Store {
final fiatCurrency = settingsStore.fiatCurrency; final fiatCurrency = settingsStore.fiatCurrency;
var balance = '---'; var balance = '---';
final totalBalance = _getFiatBalance( final totalBalance =
price: price, _getFiatBalance(price: price, cryptoAmount: walletBalance.totalBalance);
cryptoAmount: walletBalance.totalBalance
);
final unlockedBalance = _getFiatBalance( final unlockedBalance = _getFiatBalance(
price: price, price: price, cryptoAmount: walletBalance.unlockedBalance);
cryptoAmount: walletBalance.unlockedBalance
);
if (displayMode == BalanceDisplayMode.availableBalance) { if (displayMode == BalanceDisplayMode.availableBalance) {
balance = fiatCurrency.toString() + ' ' + unlockedBalance ?? '0.00'; balance = fiatCurrency.toString() + ' ' + unlockedBalance ?? '0.00';
@ -89,7 +88,7 @@ abstract class BalanceViewModelBase with Store {
final _wallet = appStore.wallet; final _wallet = appStore.wallet;
if (_wallet is MoneroWallet) { if (_wallet is MoneroWallet) {
return WalletBalance( return WalletBalance(
unlockedBalance: _wallet.balance.formattedUnlockedBalance, unlockedBalance: _wallet.balance.formattedUnlockedBalance,
totalBalance: _wallet.balance.formattedFullBalance); totalBalance: _wallet.balance.formattedFullBalance);
} }
@ -113,4 +112,4 @@ abstract class BalanceViewModelBase with Store {
return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount); return calculateFiatAmount(price: price, cryptoAmount: cryptoAmount);
} }
} }

View file

@ -13,16 +13,18 @@ part 'node_list_view_model.g.dart';
class NodeListViewModel = NodeListViewModelBase with _$NodeListViewModel; class NodeListViewModel = NodeListViewModelBase with _$NodeListViewModel;
abstract class NodeListViewModelBase with Store { abstract class NodeListViewModelBase with Store {
NodeListViewModelBase(this._nodeSource, this._wallet, this.settingsStore) NodeListViewModelBase(this._nodeSource, this.wallet, this.settingsStore)
: nodes = ObservableList<Node>() { : nodes = ObservableList<Node>() {
_nodeSource.bindToList(nodes, _nodeSource.bindToList(nodes,
filter: (Node val) => val?.type == _wallet.type, initialFire: true); filter: (Node val) => val?.type == wallet.type, initialFire: true);
} }
@computed
Node get currentNode => settingsStore.nodes[wallet.type];
final ObservableList<Node> nodes; final ObservableList<Node> nodes;
final SettingsStore settingsStore; final SettingsStore settingsStore;
final WalletBase wallet;
final WalletBase _wallet;
final Box<Node> _nodeSource; final Box<Node> _nodeSource;
Future<void> reset() async { Future<void> reset() async {
@ -30,14 +32,12 @@ abstract class NodeListViewModelBase with Store {
Node node; Node node;
switch (_wallet.type) { switch (wallet.type) {
case WalletType.bitcoin: case WalletType.bitcoin:
node = getBitcoinDefaultElectrumServer(nodes: _nodeSource); node = getBitcoinDefaultElectrumServer(nodes: _nodeSource);
break; break;
case WalletType.monero: case WalletType.monero:
node = getMoneroDefaultNode( node = getMoneroDefaultNode(nodes: _nodeSource);
nodes: _nodeSource,
);
break; break;
default: default:
break; break;
@ -50,5 +50,5 @@ abstract class NodeListViewModelBase with Store {
Future<void> delete(Node node) async => node.delete(); Future<void> delete(Node node) async => node.delete();
Future<void> setAsCurrent(Node node) async => Future<void> setAsCurrent(Node node) async =>
settingsStore.currentNode = node; settingsStore.nodes[wallet.type] = node;
} }

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/balance_display_mode.dart';
import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/transaction_description.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
@ -77,19 +78,9 @@ abstract class SendViewModelBase with Store {
PendingTransaction pendingTransaction; PendingTransaction pendingTransaction;
@computed @computed
String get balance { String get balance =>
String balance = '0.0'; _wallet.balance.formattedBalance(BalanceDisplayMode.availableBalance)
as String ?? '0.0';
if (_wallet is MoneroWallet) {
balance = _wallet.balance.formattedUnlockedBalance as String ?? '';
}
if (_wallet is BitcoinWallet) {
balance = _wallet.balance.confirmedFormatted as String ?? '';
}
return balance;
}
@computed @computed
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus; bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
@ -176,7 +167,7 @@ abstract class SendViewModelBase with Store {
void _updateFiatAmount() { void _updateFiatAmount() {
try { try {
final fiat = calculateFiatAmount( final fiat = calculateFiatAmount(
price: _fiatConversationStore.price, price: _fiatConversationStore.prices[_wallet.currency],
cryptoAmount: cryptoAmount.replaceAll(',', '.')); cryptoAmount: cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) { if (fiatAmount != fiat) {
fiatAmount = fiat; fiatAmount = fiat;
@ -190,7 +181,7 @@ abstract class SendViewModelBase with Store {
void _updateCryptoAmount() { void _updateCryptoAmount() {
try { try {
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) / final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
_fiatConversationStore.price; _fiatConversationStore.prices[_wallet.currency];
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto); final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
if (cryptoAmount != cryptoAmountTmp) { if (cryptoAmount != cryptoAmountTmp) {

View file

@ -35,12 +35,13 @@ abstract class SettingsViewModelBase with Store {
(PackageInfo packageInfo) => currentVersion = packageInfo.version); (PackageInfo packageInfo) => currentVersion = packageInfo.version);
sections = [ sections = [
[ [
PickerListItem( if ((wallet.balance.availableModes as List).length > 1)
title: S.current.settings_display_balance_as, PickerListItem(
items: BalanceDisplayMode.all, title: S.current.settings_display_balance_as,
selectedItem: () => balanceDisplayMode, items: BalanceDisplayMode.all,
onItemSelected: (BalanceDisplayMode mode) => selectedItem: () => balanceDisplayMode,
_settingsStore.balanceDisplayMode = mode), onItemSelected: (BalanceDisplayMode mode) =>
_settingsStore.balanceDisplayMode = mode),
PickerListItem( PickerListItem(
title: S.current.settings_currency, title: S.current.settings_currency,
items: FiatCurrency.all, items: FiatCurrency.all,

View file

@ -51,7 +51,7 @@ abstract class WalletCreationVMBase with Store {
credentials.walletInfo = walletInfo; credentials.walletInfo = walletInfo;
final wallet = await process(credentials); final wallet = await process(credentials);
await _walletInfoSource.add(walletInfo); await _walletInfoSource.add(walletInfo);
_appStore.wallet = wallet; _appStore.changeCurrentWallet(wallet);
_appStore.authenticationStore.allowed(); _appStore.authenticationStore.allowed();
state = ExecutedSuccessfullyState(); state = ExecutedSuccessfullyState();
} catch (e) { } catch (e) {

View file

@ -32,7 +32,8 @@ abstract class WalletListViewModelBase with Store {
final password = final password =
await _keyService.getWalletPassword(walletName: wallet.name); await _keyService.getWalletPassword(walletName: wallet.name);
final walletService = getIt.get<WalletService>(param1: wallet.type); final walletService = getIt.get<WalletService>(param1: wallet.type);
_appStore.wallet = await walletService.openWallet(wallet.name, password); final loadedWallet = await walletService.openWallet(wallet.name, password);
_appStore.changeCurrentWallet(loadedWallet);
_updateList(); _updateList();
} }