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 // @override
// Widget build(BuildContext context) { // Widget body(BuildContext context) {
// return BaseSendWidget(sendViewModel: sendViewModel); // 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 // @override
// Widget build(BuildContext context) { // Widget build(BuildContext context) {
// _setEffects(context); // _setEffects(context);

View file

@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/generated/i18n.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'; import 'package:cake_wallet/src/screens/send/widgets/base_send_widget.dart';
class SendTemplatePage extends BasePage { class SendTemplatePage extends BasePage {
@ -26,22 +26,17 @@ class SendTemplatePage extends BasePage {
bool get resizeToAvoidBottomPadding => false; bool get resizeToAvoidBottomPadding => false;
@override @override
Widget body(BuildContext context) => Widget body(BuildContext context) => BaseSendWidget(
BaseSendWidget( sendViewModel: sendViewModel,
sendViewModel: sendViewModel, leading: leading(context),
leading: leading(context), middle: middle(context),
middle: middle(context), isTemplate: true);
isTemplate: true
);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding, resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
body: Container( body: Container(
color: Theme.of(context).backgroundColor, color: Theme.of(context).backgroundColor, child: body(context)));
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); sharedPreferences.getBool(shouldSaveRecipientAddressKey);
final allowBiometricalAuthentication = final allowBiometricalAuthentication =
sharedPreferences.getBool(allowBiometricalAuthenticationKey) ?? false; sharedPreferences.getBool(allowBiometricalAuthenticationKey) ?? false;
final savedDarkTheme = sharedPreferences.getBool(currentDarkTheme) ?? true; final savedDarkTheme = sharedPreferences.getBool(currentDarkTheme) ?? false;
final actionListDisplayMode = ObservableList<ActionListDisplayMode>(); final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
actionListDisplayMode.addAll(deserializeActionlistDisplayModes( actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
sharedPreferences.getInt(displayActionListModeKey) ?? sharedPreferences.getInt(displayActionListModeKey) ??

View file

@ -1,5 +1,6 @@
import 'package:cake_wallet/core/wallet_base.dart'; 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/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/exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart'; import 'package:cake_wallet/src/domain/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.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; class ExchangeViewModel = ExchangeViewModelBase with _$ExchangeViewModel;
abstract class ExchangeViewModelBase with Store { abstract class ExchangeViewModelBase with Store {
ExchangeViewModelBase({ ExchangeViewModelBase(
this.wallet, {this.wallet,
this.trades, this.trades,
this.exchangeTemplateStore, this.exchangeTemplateStore,
this.tradesStore}) { this.tradesStore}) {
providerList = [ providerList = [
XMRTOExchangeProvider(), XMRTOExchangeProvider(),
ChangeNowExchangeProvider(), ChangeNowExchangeProvider(),
MorphTokenExchangeProvider(trades: trades) MorphTokenExchangeProvider(trades: trades)
]; ];
provider = providerList[ 0 ]; _initialPairBasedOnWallet();
depositCurrency = CryptoCurrency.xmr;
receiveCurrency = CryptoCurrency.btc;
isDepositAddressEnabled = !(depositCurrency == wallet.currency); isDepositAddressEnabled = !(depositCurrency == wallet.currency);
isReceiveAddressEnabled = !(receiveCurrency == wallet.currency); isReceiveAddressEnabled = !(receiveCurrency == wallet.currency);
depositAmount = ''; depositAmount = '';
@ -50,6 +47,7 @@ abstract class ExchangeViewModelBase with Store {
limitsState = LimitsInitialState(); limitsState = LimitsInitialState();
tradeState = ExchangeTradeStateInitial(); tradeState = ExchangeTradeStateInitial();
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12; _cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12;
provider = providersForCurrentPair().first;
loadLimits(); loadLimits();
} }
@ -140,8 +138,11 @@ abstract class ExchangeViewModelBase with Store {
provider provider
.calculateAmount( .calculateAmount(
from: depositCurrency, to: receiveCurrency, amount: _amount) from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), "")) .then((amount) => _cryptoNumberFormat
.format(amount)
.toString()
.replaceAll(RegExp('\\,'), ''))
.then((amount) => depositAmount = amount); .then((amount) => depositAmount = amount);
} }
@ -158,8 +159,11 @@ abstract class ExchangeViewModelBase with Store {
final _amount = double.parse(amount); final _amount = double.parse(amount);
provider provider
.calculateAmount( .calculateAmount(
from: depositCurrency, to: receiveCurrency, amount: _amount) from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), "")) .then((amount) => _cryptoNumberFormat
.format(amount)
.toString()
.replaceAll(RegExp('\\,'), ''))
.then((amount) => receiveAmount = amount); .then((amount) => receiveAmount = amount);
} }
@ -217,11 +221,13 @@ abstract class ExchangeViewModelBase with Store {
if (limitsState is LimitsLoadedSuccessfully && amount != null) { if (limitsState is LimitsLoadedSuccessfully && amount != null) {
if (double.parse(amount) < limits.min) { if (double.parse(amount) < limits.min) {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_minimal_limit('${provider.description}', tradeState = TradeIsCreatedFailure(
'${limits.min}', currency.toString())); error: S.current.error_text_minimal_limit('${provider.description}',
'${limits.min}', currency.toString()));
} else if (limits.max != null && double.parse(amount) > limits.max) { } else if (limits.max != null && double.parse(amount) > limits.max) {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_maximum_limit('${provider.description}', tradeState = TradeIsCreatedFailure(
'${limits.max}', currency.toString())); error: S.current.error_text_maximum_limit('${provider.description}',
'${limits.max}', currency.toString()));
} else { } else {
try { try {
tradeState = TradeIsCreating(); tradeState = TradeIsCreating();
@ -235,9 +241,10 @@ abstract class ExchangeViewModelBase with Store {
} }
} }
} else { } 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 @action
@ -261,9 +268,9 @@ abstract class ExchangeViewModelBase with Store {
{CryptoCurrency from, CryptoCurrency to}) { {CryptoCurrency from, CryptoCurrency to}) {
final providers = providerList final providers = providerList
.where((provider) => provider.pairList .where((provider) => provider.pairList
.where((pair) => .where((pair) =>
pair.from == depositCurrency && pair.to == receiveCurrency) pair.from == depositCurrency && pair.to == receiveCurrency)
.isNotEmpty) .isNotEmpty)
.toList(); .toList();
return providers; return providers;
@ -272,12 +279,12 @@ abstract class ExchangeViewModelBase with Store {
void _onPairChange() { void _onPairChange() {
final isPairExist = provider.pairList final isPairExist = provider.pairList
.where((pair) => .where((pair) =>
pair.from == depositCurrency && pair.to == receiveCurrency) pair.from == depositCurrency && pair.to == receiveCurrency)
.isNotEmpty; .isNotEmpty;
if (!isPairExist) { if (!isPairExist) {
final provider = final provider =
_providerForPair(from: depositCurrency, to: receiveCurrency); _providerForPair(from: depositCurrency, to: receiveCurrency);
if (provider != null) { if (provider != null) {
changeProvider(provider: provider); changeProvider(provider: provider);
@ -295,4 +302,18 @@ abstract class ExchangeViewModelBase with Store {
return providers.isNotEmpty ? providers[0] : null; 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:intl/intl.dart';
import 'package:mobx/mobx.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/address_validator.dart';
import 'package:cake_wallet/core/amount_validator.dart'; import 'package:cake_wallet/core/amount_validator.dart';
import 'package:cake_wallet/core/pending_transaction.dart'; import 'package:cake_wallet/core/pending_transaction.dart';
@ -28,7 +29,7 @@ abstract class SendViewModelBase with Store {
: state = InitialSendViewModelState(), : state = InitialSendViewModelState(),
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12, _cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12,
// FIXME: need to be based on wallet type. // FIXME: need to be based on wallet type.
all = false; sendAll = false;
@observable @observable
SendViewModelState state; SendViewModelState state;
@ -43,7 +44,7 @@ abstract class SendViewModelBase with Store {
String address; String address;
@observable @observable
bool all; bool sendAll;
FiatCurrency get fiat => _settingsStore.fiatCurrency; FiatCurrency get fiat => _settingsStore.fiatCurrency;
@ -59,6 +60,8 @@ abstract class SendViewModelBase with Store {
Validator get addressValidator => AddressValidator(type: _wallet.currency); Validator get addressValidator => AddressValidator(type: _wallet.currency);
Validator get templateValidator => TemplateValidator();
PendingTransaction pendingTransaction; PendingTransaction pendingTransaction;
@computed @computed
@ -83,7 +86,7 @@ abstract class SendViewModelBase with Store {
final NumberFormat _cryptoNumberFormat; final NumberFormat _cryptoNumberFormat;
@action @action
void setAll() => all = true; void setSendAll() => sendAll = true;
@action @action
void reset() { void reset() {
@ -118,7 +121,7 @@ abstract class SendViewModelBase with Store {
void setCryptoAmount(String amount) { void setCryptoAmount(String amount) {
// FIXME: hardcoded value. // FIXME: hardcoded value.
if (amount.toUpperCase() != 'ALL') { if (amount.toUpperCase() != 'ALL') {
all = false; sendAll = false;
} }
cryptoAmount = amount; cryptoAmount = amount;
@ -162,7 +165,7 @@ abstract class SendViewModelBase with Store {
Object _credentials() { Object _credentials() {
final amount = final amount =
!all ? double.parse(cryptoAmount.replaceAll(',', '.')) : null; !sendAll ? double.parse(cryptoAmount.replaceAll(',', '.')) : null;
switch (_wallet.type) { switch (_wallet.type) {
case WalletType.bitcoin: case WalletType.bitcoin: