This commit is contained in:
M 2022-03-21 18:35:33 +01:00
parent 64edf50bbc
commit d9cf0c9255
6 changed files with 181 additions and 91 deletions

View file

@ -50,10 +50,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
@required this.mnemonic, @required this.mnemonic,
ElectrumClient electrumClient, ElectrumClient electrumClient,
ElectrumBalance initialBalance}) ElectrumBalance initialBalance})
: balance = ObservableMap<CryptoCurrency, ElectrumBalance>.of({ : hd = bitcoin.HDWallet.fromSeed(mnemonicToSeedBytes(mnemonic),
CryptoCurrency.btc: initialBalance ??
const ElectrumBalance(confirmed: 0, unconfirmed: 0)}),
hd = bitcoin.HDWallet.fromSeed(mnemonicToSeedBytes(mnemonic),
network: networkType) network: networkType)
.derivePath("m/0'/0"), .derivePath("m/0'/0"),
syncStatus = NotConnectedSyncStatus(), syncStatus = NotConnectedSyncStatus(),
@ -61,6 +58,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
_feeRates = <int>[], _feeRates = <int>[],
_isTransactionUpdating = false, _isTransactionUpdating = false,
super(walletInfo) { super(walletInfo) {
balance = ObservableMap<CryptoCurrency, ElectrumBalance>.of({
currency: initialBalance ?? const ElectrumBalance(confirmed: 0, unconfirmed: 0)});
this.electrumClient = electrumClient ?? ElectrumClient(); this.electrumClient = electrumClient ?? ElectrumClient();
this.walletInfo = walletInfo; this.walletInfo = walletInfo;
this.unspentCoinsInfo = unspentCoinsInfo; this.unspentCoinsInfo = unspentCoinsInfo;

View file

@ -85,7 +85,7 @@ class DashboardPage extends BasePage {
final DashboardViewModel walletViewModel; final DashboardViewModel walletViewModel;
final WalletAddressListViewModel addressListViewModel; final WalletAddressListViewModel addressListViewModel;
final controller = PageController(initialPage: 1); final controller = PageController(initialPage: 0);
var pages = <Widget>[]; var pages = <Widget>[];
bool _isEffectsInstalled = false; bool _isEffectsInstalled = false;
@ -101,21 +101,10 @@ class DashboardPage extends BasePage {
height: 24, height: 24,
width: 24, width: 24,
color: Theme.of(context).accentTextTheme.display3.backgroundColor); color: Theme.of(context).accentTextTheme.display3.backgroundColor);
final exchangeImage = Image.asset('assets/images/transfer.png',
height: 24,
width: 24,
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
final buyImage = Image.asset('assets/images/buy.png',
height: 24,
width: 24,
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
final sellImage = Image.asset('assets/images/sell.png',
height: 24,
width: 24,
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
_setEffects(context); _setEffects(context);
return SafeArea( return SafeArea(
minimum: EdgeInsets.only(bottom: 24),
child: Column( child: Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
@ -140,49 +129,89 @@ class DashboardPage extends BasePage {
.display1 .display1
.backgroundColor), .backgroundColor),
)), )),
Observer(builder: (_) {
ClipRect( return ClipRect(
child:Container( child:Container(
margin: const EdgeInsets.only(left: 16, right: 16), margin: const EdgeInsets.only(left: 16, right: 16),
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0), borderRadius: BorderRadius.circular(50.0),
border: Border.all(color: currentTheme.type == ThemeType.bright ? Color.fromRGBO(255, 255, 255, 0.2): Colors.transparent, width: 1, ), border: Border.all(color: currentTheme.type == ThemeType.bright ? Color.fromRGBO(255, 255, 255, 0.2): Colors.transparent, width: 1, ),
color:Theme.of(context).textTheme.title.backgroundColor color:Theme.of(context).textTheme.title.backgroundColor),
), child: Container(
child: Container( padding: EdgeInsets.only(left: 32, right: 32),
padding: EdgeInsets.only(left: 32, right: 32, bottom: 14, top: 16), child: Row(
child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
children: <Widget>[ if (walletViewModel.hasBuyAction)
if (!isMoneroOnly && !isHaven) ActionButton(
image: Image.asset('assets/images/buy.png',
height: 24,
width: 24,
color: !walletViewModel.isEnabledBuyAction
? Theme.of(context)
.accentTextTheme
.display2
.backgroundColor
: Theme.of(context).accentTextTheme.display3.backgroundColor),
title: S.of(context).buy,
onClick: () async => await _onClickBuyButton(context),
textColor: !walletViewModel.isEnabledBuyAction
? Theme.of(context)
.accentTextTheme
.display2
.backgroundColor
: null),
ActionButton( ActionButton(
image: buyImage, image: receiveImage,
title: S.of(context).buy, title: S.of(context).receive,
onClick: () async => await _onClickBuyButton(context), route: Routes.receive),
), if (walletViewModel.hasExchangeAction)
ActionButton( ActionButton(
image: receiveImage, image: Image.asset('assets/images/transfer.png',
title: S.of(context).receive, height: 24,
route: Routes.receive), width: 24,
if (!isHaven) color: !walletViewModel.isEnabledExchangeAction
? Theme.of(context)
.accentTextTheme
.display2
.backgroundColor
: Theme.of(context).accentTextTheme.display3.backgroundColor),
title: S.of(context).exchange,
onClick: () async => _onClickExchangeButton(context),
textColor: !walletViewModel.isEnabledExchangeAction
? Theme.of(context)
.accentTextTheme
.display2
.backgroundColor
: null),
ActionButton( ActionButton(
image: exchangeImage, image: sendImage,
title: S.of(context).exchange, title: S.of(context).send,
route: Routes.exchange), route: Routes.send),
ActionButton( if (walletViewModel.hasSellAction)
image: sendImage, ActionButton(
title: S.of(context).send, image: Image.asset('assets/images/sell.png',
route: Routes.send), height: 24,
if (!isMoneroOnly && !isHaven) width: 24,
ActionButton( color: !walletViewModel.isEnabledSellAction
image: sellImage, ? Theme.of(context)
title: S.of(context).sell, .accentTextTheme
onClick: () async => await _onClickSellButton(context), .display2
), .backgroundColor
], : Theme.of(context).accentTextTheme.display3.backgroundColor),
),), title: S.of(context).sell,
),),), onClick: () async => await _onClickSellButton(context),
textColor: !walletViewModel.isEnabledSellAction
? Theme.of(context)
.accentTextTheme
.display2
.backgroundColor
: null),
],
),),
),),);
}),
], ],
)); ));
@ -193,9 +222,6 @@ class DashboardPage extends BasePage {
return; return;
} }
pages.add(AddressPage(
addressListViewModel: addressListViewModel,
walletViewModel: walletViewModel));
pages.add(balancePage); pages.add(balancePage);
pages.add(TransactionsPage(dashboardViewModel: walletViewModel)); pages.add(TransactionsPage(dashboardViewModel: walletViewModel));
_isEffectsInstalled = true; _isEffectsInstalled = true;
@ -290,4 +316,24 @@ class DashboardPage extends BasePage {
}); });
} }
} }
Future<void> _onClickExchangeButton(BuildContext context) async {
final walletType = walletViewModel.type;
switch (walletType) {
case WalletType.haven:
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: 'Exchange',
alertContent: 'Exchange for this asset is not supported yet.',
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
break;
default:
await Navigator.of(context).pushNamed(Routes.exchange);
}
}
} }

View file

@ -6,17 +6,25 @@ class ActionButton extends StatelessWidget {
@required this.title, @required this.title,
this.route, this.route,
this.onClick, this.onClick,
this.alignment = Alignment.center}); this.alignment = Alignment.center,
this.textColor});
final Image image; final Image image;
final String title; final String title;
final String route; final String route;
final Alignment alignment; final Alignment alignment;
final void Function() onClick; final void Function() onClick;
final Color textColor;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var _textColor = textColor ?? Theme.of(context)
.accentTextTheme
.display3
.backgroundColor;
return Container( return Container(
padding: EdgeInsets.only(top: 14, bottom: 16, left: 10, right: 10),
alignment: alignment, alignment: alignment,
child: Column( child: Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
@ -42,8 +50,7 @@ class ActionButton extends StatelessWidget {
title, title,
style: TextStyle( style: TextStyle(
fontSize: 10, fontSize: 10,
color: Theme.of(context).accentTextTheme.display3 color: _textColor),
.backgroundColor),
) )
], ],
), ),

View file

@ -30,7 +30,7 @@ class BalancePage extends StatelessWidget{
Container( Container(
margin: const EdgeInsets.only(left: 24, bottom: 16), margin: const EdgeInsets.only(left: 24, bottom: 16),
child: Observer(builder: (_) { child: Observer(builder: (_) {
return AutoSizeText( return Text(
dashboardViewModel.balanceViewModel.asset, dashboardViewModel.balanceViewModel.asset,
style: TextStyle( style: TextStyle(
fontSize: 24, fontSize: 24,
@ -86,20 +86,34 @@ class BalancePage extends StatelessWidget{
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SizedBox(height: 4,), SizedBox(height: 4,),
Row( Text('${availableBalanceLabel}',
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('${availableBalanceLabel}',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontFamily: 'Lato', fontFamily: 'Lato',
fontWeight: FontWeight.w500, fontWeight: FontWeight.w400,
color: Theme.of(context) color: Theme.of(context)
.accentTextTheme .accentTextTheme
.display2 .display2
.backgroundColor, .backgroundColor,
height: 1)), height: 1)),
SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AutoSizeText(
availableBalance,
style: TextStyle(
fontSize: 24,
fontFamily: 'Lato',
fontWeight: FontWeight.w900,
color: Theme.of(context)
.accentTextTheme
.display3
.backgroundColor,
height: 1),
maxLines: 1,
textAlign: TextAlign.center),
Text(currency, Text(currency,
style: TextStyle( style: TextStyle(
fontSize: 28, fontSize: 28,
@ -111,20 +125,6 @@ class BalancePage extends StatelessWidget{
.backgroundColor, .backgroundColor,
height: 1)), height: 1)),
]), ]),
AutoSizeText(
availableBalance,
style: TextStyle(
fontSize: 24,
fontFamily: 'Lato',
fontWeight: FontWeight.w900,
color: Theme.of(context)
.accentTextTheme
.display3
.backgroundColor,
height: 1),
maxLines: 1,
textAlign: TextAlign.center),
SizedBox(height: 4,), SizedBox(height: 4,),
Text('${availableFiatBalance}', Text('${availableFiatBalance}',
textAlign: TextAlign.center, textAlign: TextAlign.center,
@ -143,7 +143,7 @@ class BalancePage extends StatelessWidget{
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontFamily: 'Lato', fontFamily: 'Lato',
fontWeight: FontWeight.w500, fontWeight: FontWeight.w400,
color: Theme.of(context) color: Theme.of(context)
.accentTextTheme .accentTextTheme
.display2 .display2
@ -153,9 +153,9 @@ class BalancePage extends StatelessWidget{
AutoSizeText( AutoSizeText(
additionalBalance, additionalBalance,
style: TextStyle( style: TextStyle(
fontSize: 24, fontSize: 20,
fontFamily: 'Lato', fontFamily: 'Lato',
fontWeight: FontWeight.w900, fontWeight: FontWeight.w400,
color: Theme.of(context) color: Theme.of(context)
.accentTextTheme .accentTextTheme
.display3 .display3
@ -167,9 +167,9 @@ class BalancePage extends StatelessWidget{
Text('${additionalFiatBalance}', Text('${additionalFiatBalance}',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 12,
fontFamily: 'Lato', fontFamily: 'Lato',
fontWeight: FontWeight.w500, fontWeight: FontWeight.w400,
color: Theme.of(context) color: Theme.of(context)
.accentTextTheme .accentTextTheme
.display3 .display3

View file

@ -64,7 +64,13 @@ abstract class BalanceViewModelBase with Store {
@computed @computed
String get asset { String get asset {
final typeFormatted = walletTypeToString(appStore.wallet.type); final typeFormatted = walletTypeToString(appStore.wallet.type);
return '$typeFormatted Asset';
switch(wallet.type) {
case WalletType.haven:
return '$typeFormatted Asset';
default:
return typeFormatted;
}
} }
@computed @computed
@ -253,7 +259,7 @@ abstract class BalanceViewModelBase with Store {
case WalletType.haven: case WalletType.haven:
final assetStringified = asset.toString(); final assetStringified = asset.toString();
if (assetStringified[0].toUpperCase() == 'X') { if (asset != CryptoCurrency.xhv && assetStringified[0].toUpperCase() == 'X') {
return assetStringified.replaceFirst('X', 'x'); return assetStringified.replaceFirst('X', 'x');
} }

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/wallet_type_utils.dart';
import 'package:cw_core/transaction_history.dart'; import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/balance.dart'; import 'package:cw_core/balance.dart';
import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/buy/order.dart';
@ -78,6 +79,13 @@ abstract class DashboardViewModelBase with Store {
isShowFirstYatIntroduction = false; isShowFirstYatIntroduction = false;
isShowSecondYatIntroduction = false; isShowSecondYatIntroduction = false;
isShowThirdYatIntroduction = false; isShowThirdYatIntroduction = false;
isEnabledExchangeAction = wallet.type != WalletType.haven;
hasExchangeAction = !isHaven;
isEnabledBuyAction = wallet.type != WalletType.haven;
hasBuyAction = !isMoneroOnly && !isHaven;
isEnabledSellAction = wallet.type != WalletType.haven;
hasSellAction = !isMoneroOnly && !isHaven;
final _wallet = wallet; final _wallet = wallet;
if (_wallet.type == WalletType.monero) { if (_wallet.type == WalletType.monero) {
@ -229,6 +237,24 @@ abstract class DashboardViewModelBase with Store {
void furtherShowYatPopup(bool shouldShow) => void furtherShowYatPopup(bool shouldShow) =>
settingsStore.shouldShowYatPopup = shouldShow; settingsStore.shouldShowYatPopup = shouldShow;
@observable
bool isEnabledExchangeAction;
@observable
bool hasExchangeAction;
@observable
bool isEnabledBuyAction;
@observable
bool hasBuyAction;
@observable
bool isEnabledSellAction;
@observable
bool hasSellAction;
ReactionDisposer _onMoneroAccountChangeReaction; ReactionDisposer _onMoneroAccountChangeReaction;
ReactionDisposer _onMoneroBalanceChangeReaction; ReactionDisposer _onMoneroBalanceChangeReaction;
@ -251,6 +277,12 @@ abstract class DashboardViewModelBase with Store {
name = wallet.name; name = wallet.name;
isOutdatedElectrumWallet = isOutdatedElectrumWallet =
wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24; wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24;
isEnabledExchangeAction = wallet.type != WalletType.haven;
hasExchangeAction = !isHaven;
isEnabledBuyAction = wallet.type != WalletType.haven;
hasBuyAction = !isMoneroOnly && !isHaven;
isEnabledSellAction = wallet.type != WalletType.haven;
hasSellAction = !isMoneroOnly && !isHaven;
if (wallet.type == WalletType.monero) { if (wallet.type == WalletType.monero) {
subname = monero.getCurrentAccount(wallet)?.label; subname = monero.getCurrentAccount(wallet)?.label;