Merge redesign part 2.

This commit is contained in:
M 2020-09-02 11:47:41 +03:00
parent 2627945e00
commit 9074bee6db
6 changed files with 570 additions and 440 deletions

View file

@ -95,16 +95,26 @@ class SendPage extends BasePage {
// }
}
@override
Widget body(BuildContext context) {
return super.build(context);
}
// @override
// Widget build(BuildContext context) {
// return BaseSendWidget(sendViewModel: sendViewModel);
// Widget body(BuildContext context) {
// return super.build(context);
// }
@override
Widget body(BuildContext context) => BaseSendWidget(
sendViewModel: sendViewModel,
leading: leading(context),
middle: middle(context),
);
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
body: Container(
color: Theme.of(context).backgroundColor, child: body(context)));
}
// @override
// Widget build(BuildContext context) {
// _setEffects(context);

View file

@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/view_model/send_view_model.dart';
import 'package:cake_wallet/view_model/send/send_view_model.dart';
import 'package:cake_wallet/src/screens/send/widgets/base_send_widget.dart';
class SendTemplatePage extends BasePage {
@ -26,22 +26,17 @@ class SendTemplatePage extends BasePage {
bool get resizeToAvoidBottomPadding => false;
@override
Widget body(BuildContext context) =>
BaseSendWidget(
sendViewModel: sendViewModel,
leading: leading(context),
middle: middle(context),
isTemplate: true
);
Widget body(BuildContext context) => BaseSendWidget(
sendViewModel: sendViewModel,
leading: leading(context),
middle: middle(context),
isTemplate: true);
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
body: Container(
color: Theme.of(context).backgroundColor,
child: body(context)
)
);
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
body: Container(
color: Theme.of(context).backgroundColor, child: body(context)));
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -138,7 +138,7 @@ abstract class SettingsStoreBase with Store {
sharedPreferences.getBool(shouldSaveRecipientAddressKey);
final allowBiometricalAuthentication =
sharedPreferences.getBool(allowBiometricalAuthenticationKey) ?? false;
final savedDarkTheme = sharedPreferences.getBool(currentDarkTheme) ?? true;
final savedDarkTheme = sharedPreferences.getBool(currentDarkTheme) ?? false;
final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
sharedPreferences.getInt(displayActionListModeKey) ??

View file

@ -1,5 +1,6 @@
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
@ -25,22 +26,18 @@ part 'exchange_view_model.g.dart';
class ExchangeViewModel = ExchangeViewModelBase with _$ExchangeViewModel;
abstract class ExchangeViewModelBase with Store {
ExchangeViewModelBase({
this.wallet,
this.trades,
this.exchangeTemplateStore,
this.tradesStore}) {
ExchangeViewModelBase(
{this.wallet,
this.trades,
this.exchangeTemplateStore,
this.tradesStore}) {
providerList = [
XMRTOExchangeProvider(),
ChangeNowExchangeProvider(),
MorphTokenExchangeProvider(trades: trades)
];
provider = providerList[ 0 ];
depositCurrency = CryptoCurrency.xmr;
receiveCurrency = CryptoCurrency.btc;
_initialPairBasedOnWallet();
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
isReceiveAddressEnabled = !(receiveCurrency == wallet.currency);
depositAmount = '';
@ -50,6 +47,7 @@ abstract class ExchangeViewModelBase with Store {
limitsState = LimitsInitialState();
tradeState = ExchangeTradeStateInitial();
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12;
provider = providersForCurrentPair().first;
loadLimits();
}
@ -140,8 +138,11 @@ abstract class ExchangeViewModelBase with Store {
provider
.calculateAmount(
from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), ""))
from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat
.format(amount)
.toString()
.replaceAll(RegExp('\\,'), ''))
.then((amount) => depositAmount = amount);
}
@ -158,8 +159,11 @@ abstract class ExchangeViewModelBase with Store {
final _amount = double.parse(amount);
provider
.calculateAmount(
from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), ""))
from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat
.format(amount)
.toString()
.replaceAll(RegExp('\\,'), ''))
.then((amount) => receiveAmount = amount);
}
@ -217,11 +221,13 @@ abstract class ExchangeViewModelBase with Store {
if (limitsState is LimitsLoadedSuccessfully && amount != null) {
if (double.parse(amount) < limits.min) {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_minimal_limit('${provider.description}',
'${limits.min}', currency.toString()));
tradeState = TradeIsCreatedFailure(
error: S.current.error_text_minimal_limit('${provider.description}',
'${limits.min}', currency.toString()));
} else if (limits.max != null && double.parse(amount) > limits.max) {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_maximum_limit('${provider.description}',
'${limits.max}', currency.toString()));
tradeState = TradeIsCreatedFailure(
error: S.current.error_text_maximum_limit('${provider.description}',
'${limits.max}', currency.toString()));
} else {
try {
tradeState = TradeIsCreating();
@ -235,9 +241,10 @@ abstract class ExchangeViewModelBase with Store {
}
}
} else {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_limits_loading_failed('${provider.description}'));
tradeState = TradeIsCreatedFailure(
error: S.current
.error_text_limits_loading_failed('${provider.description}'));
}
}
@action
@ -261,9 +268,9 @@ abstract class ExchangeViewModelBase with Store {
{CryptoCurrency from, CryptoCurrency to}) {
final providers = providerList
.where((provider) => provider.pairList
.where((pair) =>
pair.from == depositCurrency && pair.to == receiveCurrency)
.isNotEmpty)
.where((pair) =>
pair.from == depositCurrency && pair.to == receiveCurrency)
.isNotEmpty)
.toList();
return providers;
@ -272,12 +279,12 @@ abstract class ExchangeViewModelBase with Store {
void _onPairChange() {
final isPairExist = provider.pairList
.where((pair) =>
pair.from == depositCurrency && pair.to == receiveCurrency)
pair.from == depositCurrency && pair.to == receiveCurrency)
.isNotEmpty;
if (!isPairExist) {
final provider =
_providerForPair(from: depositCurrency, to: receiveCurrency);
_providerForPair(from: depositCurrency, to: receiveCurrency);
if (provider != null) {
changeProvider(provider: provider);
@ -295,4 +302,18 @@ abstract class ExchangeViewModelBase with Store {
return providers.isNotEmpty ? providers[0] : null;
}
}
void _initialPairBasedOnWallet() {
switch (wallet.type) {
case WalletType.monero:
depositCurrency = CryptoCurrency.xmr;
receiveCurrency = CryptoCurrency.btc;
break;
case WalletType.bitcoin:
depositCurrency = CryptoCurrency.btc;
receiveCurrency = CryptoCurrency.xmr;
break;
default:
break;
}
}
}

View file

@ -1,7 +1,8 @@
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart';
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
import 'package:intl/intl.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/template_validator.dart';
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart';
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/core/amount_validator.dart';
import 'package:cake_wallet/core/pending_transaction.dart';
@ -28,7 +29,7 @@ abstract class SendViewModelBase with Store {
: state = InitialSendViewModelState(),
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12,
// FIXME: need to be based on wallet type.
all = false;
sendAll = false;
@observable
SendViewModelState state;
@ -43,7 +44,7 @@ abstract class SendViewModelBase with Store {
String address;
@observable
bool all;
bool sendAll;
FiatCurrency get fiat => _settingsStore.fiatCurrency;
@ -59,6 +60,8 @@ abstract class SendViewModelBase with Store {
Validator get addressValidator => AddressValidator(type: _wallet.currency);
Validator get templateValidator => TemplateValidator();
PendingTransaction pendingTransaction;
@computed
@ -83,7 +86,7 @@ abstract class SendViewModelBase with Store {
final NumberFormat _cryptoNumberFormat;
@action
void setAll() => all = true;
void setSendAll() => sendAll = true;
@action
void reset() {
@ -118,7 +121,7 @@ abstract class SendViewModelBase with Store {
void setCryptoAmount(String amount) {
// FIXME: hardcoded value.
if (amount.toUpperCase() != 'ALL') {
all = false;
sendAll = false;
}
cryptoAmount = amount;
@ -162,7 +165,7 @@ abstract class SendViewModelBase with Store {
Object _credentials() {
final amount =
!all ? double.parse(cryptoAmount.replaceAll(',', '.')) : null;
!sendAll ? double.parse(cryptoAmount.replaceAll(',', '.')) : null;
switch (_wallet.type) {
case WalletType.bitcoin: