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

View file

@ -85,7 +85,7 @@ class DashboardPage extends BasePage {
final DashboardViewModel walletViewModel;
final WalletAddressListViewModel addressListViewModel;
final controller = PageController(initialPage: 1);
final controller = PageController(initialPage: 0);
var pages = <Widget>[];
bool _isEffectsInstalled = false;
@ -101,21 +101,10 @@ class DashboardPage extends BasePage {
height: 24,
width: 24,
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);
return SafeArea(
minimum: EdgeInsets.only(bottom: 24),
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
@ -140,49 +129,89 @@ class DashboardPage extends BasePage {
.display1
.backgroundColor),
)),
ClipRect(
child:Container(
margin: const EdgeInsets.only(left: 16, right: 16),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0),
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
),
child: Container(
padding: EdgeInsets.only(left: 32, right: 32, bottom: 14, top: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
if (!isMoneroOnly && !isHaven)
Observer(builder: (_) {
return ClipRect(
child:Container(
margin: const EdgeInsets.only(left: 16, right: 16),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0),
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),
child: Container(
padding: EdgeInsets.only(left: 32, right: 32),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
if (walletViewModel.hasBuyAction)
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(
image: buyImage,
title: S.of(context).buy,
onClick: () async => await _onClickBuyButton(context),
),
ActionButton(
image: receiveImage,
title: S.of(context).receive,
route: Routes.receive),
if (!isHaven)
image: receiveImage,
title: S.of(context).receive,
route: Routes.receive),
if (walletViewModel.hasExchangeAction)
ActionButton(
image: Image.asset('assets/images/transfer.png',
height: 24,
width: 24,
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(
image: exchangeImage,
title: S.of(context).exchange,
route: Routes.exchange),
ActionButton(
image: sendImage,
title: S.of(context).send,
route: Routes.send),
if (!isMoneroOnly && !isHaven)
ActionButton(
image: sellImage,
title: S.of(context).sell,
onClick: () async => await _onClickSellButton(context),
),
],
),),
),),),
image: sendImage,
title: S.of(context).send,
route: Routes.send),
if (walletViewModel.hasSellAction)
ActionButton(
image: Image.asset('assets/images/sell.png',
height: 24,
width: 24,
color: !walletViewModel.isEnabledSellAction
? Theme.of(context)
.accentTextTheme
.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;
}
pages.add(AddressPage(
addressListViewModel: addressListViewModel,
walletViewModel: walletViewModel));
pages.add(balancePage);
pages.add(TransactionsPage(dashboardViewModel: walletViewModel));
_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,
this.route,
this.onClick,
this.alignment = Alignment.center});
this.alignment = Alignment.center,
this.textColor});
final Image image;
final String title;
final String route;
final Alignment alignment;
final void Function() onClick;
final Color textColor;
@override
Widget build(BuildContext context) {
var _textColor = textColor ?? Theme.of(context)
.accentTextTheme
.display3
.backgroundColor;
return Container(
padding: EdgeInsets.only(top: 14, bottom: 16, left: 10, right: 10),
alignment: alignment,
child: Column(
mainAxisSize: MainAxisSize.max,
@ -42,8 +50,7 @@ class ActionButton extends StatelessWidget {
title,
style: TextStyle(
fontSize: 10,
color: Theme.of(context).accentTextTheme.display3
.backgroundColor),
color: _textColor),
)
],
),

View file

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

View file

@ -64,7 +64,13 @@ abstract class BalanceViewModelBase with Store {
@computed
String get asset {
final typeFormatted = walletTypeToString(appStore.wallet.type);
return '$typeFormatted Asset';
switch(wallet.type) {
case WalletType.haven:
return '$typeFormatted Asset';
default:
return typeFormatted;
}
}
@computed
@ -253,7 +259,7 @@ abstract class BalanceViewModelBase with Store {
case WalletType.haven:
final assetStringified = asset.toString();
if (assetStringified[0].toUpperCase() == 'X') {
if (asset != CryptoCurrency.xhv && assetStringified[0].toUpperCase() == '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/balance.dart';
import 'package:cake_wallet/buy/order.dart';
@ -78,6 +79,13 @@ abstract class DashboardViewModelBase with Store {
isShowFirstYatIntroduction = false;
isShowSecondYatIntroduction = 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;
if (_wallet.type == WalletType.monero) {
@ -229,6 +237,24 @@ abstract class DashboardViewModelBase with Store {
void furtherShowYatPopup(bool 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 _onMoneroBalanceChangeReaction;
@ -251,6 +277,12 @@ abstract class DashboardViewModelBase with Store {
name = wallet.name;
isOutdatedElectrumWallet =
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) {
subname = monero.getCurrentAccount(wallet)?.label;