mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
desktop balance toggle
This commit is contained in:
parent
9e0bd2aa35
commit
e58bdf68c8
5 changed files with 162 additions and 156 deletions
|
@ -240,7 +240,6 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
),
|
||||
DesktopWalletSummary(
|
||||
walletId: widget.walletId,
|
||||
managerProvider: managerProvider,
|
||||
initialSyncStatus: ref.watch(managerProvider
|
||||
.select((value) => value.isRefreshing))
|
||||
? WalletSyncStatus.syncing
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:stackwallet/providers/wallet/wallet_balance_toggle_state_provide
|
|||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
|
||||
class DesktopBalanceToggleButton extends ConsumerWidget {
|
||||
|
@ -18,7 +19,7 @@ class DesktopBalanceToggleButton extends ConsumerWidget {
|
|||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return SizedBox(
|
||||
height: 22,
|
||||
width: 22,
|
||||
width: 80,
|
||||
child: MaterialButton(
|
||||
color: Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
||||
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
||||
|
@ -43,10 +44,63 @@ class DesktopBalanceToggleButton extends ConsumerWidget {
|
|||
Constants.size.circularBorderRadius,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: FittedBox(
|
||||
child: Text(
|
||||
ref.watch(walletBalanceToggleStateProvider.state).state ==
|
||||
WalletBalanceToggleState.available
|
||||
? "AVAILABLE"
|
||||
: "FULL",
|
||||
style: STextStyles.w500_10(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DesktopPrivateBalanceToggleButton extends ConsumerWidget {
|
||||
const DesktopPrivateBalanceToggleButton({
|
||||
Key? key,
|
||||
this.onPressed,
|
||||
}) : super(key: key);
|
||||
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return SizedBox(
|
||||
height: 22,
|
||||
width: 22,
|
||||
child: MaterialButton(
|
||||
color: Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
||||
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
||||
onPressed: () {
|
||||
if (ref.read(walletPrivateBalanceToggleStateProvider.state).state ==
|
||||
WalletBalanceToggleState.available) {
|
||||
ref.read(walletPrivateBalanceToggleStateProvider.state).state =
|
||||
WalletBalanceToggleState.full;
|
||||
} else {
|
||||
ref.read(walletPrivateBalanceToggleStateProvider.state).state =
|
||||
WalletBalanceToggleState.available;
|
||||
}
|
||||
onPressed?.call();
|
||||
},
|
||||
elevation: 0,
|
||||
highlightElevation: 0,
|
||||
hoverElevation: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
Constants.size.circularBorderRadius,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Image(
|
||||
image: AssetImage(
|
||||
ref.watch(walletBalanceToggleStateProvider.state).state ==
|
||||
ref.watch(walletPrivateBalanceToggleStateProvider.state).state ==
|
||||
WalletBalanceToggleState.available
|
||||
? Assets.png.glassesHidden
|
||||
: Assets.png.glasses,
|
||||
|
|
|
@ -43,6 +43,8 @@ class DesktopWalletFeatures extends ConsumerStatefulWidget {
|
|||
}
|
||||
|
||||
class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
|
||||
static const double buttonWidth = 120;
|
||||
|
||||
Future<void> _onSwapPressed() async {
|
||||
// todo
|
||||
}
|
||||
|
@ -311,7 +313,7 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
|
|||
if (Constants.enableExchange)
|
||||
SecondaryButton(
|
||||
label: "Swap",
|
||||
width: 160,
|
||||
width: buttonWidth,
|
||||
buttonHeight: ButtonHeight.l,
|
||||
icon: SvgPicture.asset(
|
||||
Assets.svg.arrowRotate,
|
||||
|
@ -330,7 +332,7 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
|
|||
if (Constants.enableExchange)
|
||||
SecondaryButton(
|
||||
label: "Buy",
|
||||
width: 160,
|
||||
width: buttonWidth,
|
||||
buttonHeight: ButtonHeight.l,
|
||||
icon: SvgPicture.asset(
|
||||
Assets.svg.buy(context),
|
||||
|
@ -348,7 +350,7 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
|
|||
),
|
||||
SecondaryButton(
|
||||
label: "More",
|
||||
width: 160,
|
||||
width: buttonWidth,
|
||||
buttonHeight: ButtonHeight.l,
|
||||
icon: SvgPicture.asset(
|
||||
Assets.svg.bars,
|
||||
|
|
|
@ -1,207 +1,154 @@
|
|||
import 'package:decimal/decimal.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/models/balance.dart';
|
||||
import 'package:stackwallet/pages/wallet_view/sub_widgets/wallet_refresh_button.dart';
|
||||
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_balance_toggle_button.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/providers/wallet/wallet_balance_toggle_state_provider.dart';
|
||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/manager.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart';
|
||||
import 'package:stackwallet/utilities/format.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/widgets/animated_text.dart';
|
||||
|
||||
class DesktopWalletSummary extends StatefulWidget {
|
||||
class DesktopWalletSummary extends ConsumerStatefulWidget {
|
||||
const DesktopWalletSummary({
|
||||
Key? key,
|
||||
required this.walletId,
|
||||
required this.managerProvider,
|
||||
required this.initialSyncStatus,
|
||||
}) : super(key: key);
|
||||
|
||||
final String walletId;
|
||||
final ChangeNotifierProvider<Manager> managerProvider;
|
||||
final WalletSyncStatus initialSyncStatus;
|
||||
|
||||
@override
|
||||
State<DesktopWalletSummary> createState() => _WDesktopWalletSummaryState();
|
||||
ConsumerState<DesktopWalletSummary> createState() =>
|
||||
_WDesktopWalletSummaryState();
|
||||
}
|
||||
|
||||
class _WDesktopWalletSummaryState extends State<DesktopWalletSummary> {
|
||||
class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
|
||||
late final String walletId;
|
||||
late final ChangeNotifierProvider<Manager> managerProvider;
|
||||
|
||||
Decimal? _balanceTotalCached;
|
||||
Decimal? _balanceCached;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
walletId = widget.walletId;
|
||||
managerProvider = widget.managerProvider;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
|
||||
final externalCalls = ref.watch(
|
||||
prefsChangeNotifierProvider.select(
|
||||
(value) => value.externalCalls,
|
||||
),
|
||||
);
|
||||
final coin = ref.watch(
|
||||
walletsChangeNotifierProvider.select(
|
||||
(value) => value.getManager(widget.walletId).coin,
|
||||
),
|
||||
);
|
||||
final locale = ref.watch(
|
||||
localeServiceChangeNotifierProvider.select((value) => value.locale));
|
||||
|
||||
final baseCurrency = ref
|
||||
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
|
||||
|
||||
final priceTuple = ref.watch(priceAnd24hChangeNotifierProvider
|
||||
.select((value) => value.getPrice(coin)));
|
||||
|
||||
final _showAvailable =
|
||||
ref.watch(walletBalanceToggleStateProvider.state).state ==
|
||||
WalletBalanceToggleState.available;
|
||||
|
||||
Balance balance = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManager(walletId).balance));
|
||||
|
||||
Decimal balanceToShow;
|
||||
if (coin == Coin.firo || coin == Coin.firoTestNet) {
|
||||
Balance? balanceSecondary = ref
|
||||
.watch(
|
||||
walletsChangeNotifierProvider.select(
|
||||
(value) =>
|
||||
value.getManager(widget.walletId).wallet as FiroWallet?,
|
||||
),
|
||||
)
|
||||
?.balancePrivate;
|
||||
final showPrivate =
|
||||
ref.watch(walletPrivateBalanceToggleStateProvider.state).state ==
|
||||
WalletBalanceToggleState.available;
|
||||
|
||||
if (_showAvailable) {
|
||||
balanceToShow = showPrivate
|
||||
? balanceSecondary!.getSpendable()
|
||||
: balance.getSpendable();
|
||||
} else {
|
||||
balanceToShow =
|
||||
showPrivate ? balanceSecondary!.getTotal() : balance.getTotal();
|
||||
}
|
||||
} else {
|
||||
if (_showAvailable) {
|
||||
balanceToShow = balance.getSpendable();
|
||||
} else {
|
||||
balanceToShow = balance.getTotal();
|
||||
}
|
||||
}
|
||||
|
||||
return Consumer(
|
||||
builder: (context, ref, __) {
|
||||
final Coin coin =
|
||||
ref.watch(managerProvider.select((value) => value.coin));
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Consumer(
|
||||
builder: (_, ref, __) {
|
||||
final externalCalls = ref.watch(prefsChangeNotifierProvider
|
||||
.select((value) => value.externalCalls));
|
||||
|
||||
Future<Decimal>? totalBalanceFuture;
|
||||
Future<Decimal>? availableBalanceFuture;
|
||||
if (coin == Coin.firo || coin == Coin.firoTestNet) {
|
||||
final firoWallet = ref.watch(
|
||||
managerProvider.select((value) => value.wallet))
|
||||
as FiroWallet;
|
||||
totalBalanceFuture =
|
||||
Future(() => firoWallet.balance.getSpendable());
|
||||
availableBalanceFuture = Future(
|
||||
() => firoWallet.balancePrivate.getSpendable());
|
||||
} else {
|
||||
final manager = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManager(walletId)));
|
||||
totalBalanceFuture =
|
||||
Future(() => manager.balance.getTotal());
|
||||
availableBalanceFuture =
|
||||
Future(() => manager.balance.getSpendable());
|
||||
}
|
||||
|
||||
final locale = ref.watch(localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale));
|
||||
|
||||
final baseCurrency = ref.watch(prefsChangeNotifierProvider
|
||||
.select((value) => value.currency));
|
||||
|
||||
final priceTuple = ref.watch(
|
||||
priceAnd24hChangeNotifierProvider
|
||||
.select((value) => value.getPrice(coin)));
|
||||
|
||||
final _showAvailable = ref
|
||||
.watch(walletBalanceToggleStateProvider.state)
|
||||
.state ==
|
||||
WalletBalanceToggleState.available;
|
||||
|
||||
return FutureBuilder(
|
||||
future: _showAvailable
|
||||
? availableBalanceFuture
|
||||
: totalBalanceFuture,
|
||||
builder: (fbContext, AsyncSnapshot<Decimal> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done &&
|
||||
snapshot.hasData &&
|
||||
snapshot.data != null) {
|
||||
if (_showAvailable) {
|
||||
_balanceCached = snapshot.data!;
|
||||
} else {
|
||||
_balanceTotalCached = snapshot.data!;
|
||||
}
|
||||
}
|
||||
Decimal? balanceToShow = _showAvailable
|
||||
? _balanceCached
|
||||
: _balanceTotalCached;
|
||||
|
||||
if (balanceToShow != null) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
"${Format.localizedStringAsFixed(
|
||||
value: balanceToShow,
|
||||
locale: locale,
|
||||
decimalPlaces: 8,
|
||||
)} ${coin.ticker}",
|
||||
style: STextStyles.desktopH3(context),
|
||||
),
|
||||
),
|
||||
if (externalCalls)
|
||||
Text(
|
||||
"${Format.localizedStringAsFixed(
|
||||
value: priceTuple.item1 * balanceToShow,
|
||||
locale: locale,
|
||||
decimalPlaces: 2,
|
||||
)} $baseCurrency",
|
||||
style:
|
||||
STextStyles.desktopTextExtraSmall(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textSubtitle1,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AnimatedText(
|
||||
stringsToLoopThrough: const [
|
||||
"Loading balance ",
|
||||
"Loading balance. ",
|
||||
"Loading balance.. ",
|
||||
"Loading balance..."
|
||||
],
|
||||
style: STextStyles.desktopH3(context).copyWith(
|
||||
fontSize: 24,
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textDark,
|
||||
),
|
||||
),
|
||||
if (externalCalls)
|
||||
AnimatedText(
|
||||
stringsToLoopThrough: const [
|
||||
"Loading balance ",
|
||||
"Loading balance. ",
|
||||
"Loading balance.. ",
|
||||
"Loading balance..."
|
||||
],
|
||||
style:
|
||||
STextStyles.desktopTextExtraSmall(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textSubtitle1,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
"${Format.localizedStringAsFixed(
|
||||
value: balanceToShow,
|
||||
locale: locale,
|
||||
decimalPlaces: 8,
|
||||
)} ${coin.ticker}",
|
||||
style: STextStyles.desktopH3(context),
|
||||
),
|
||||
),
|
||||
if (externalCalls)
|
||||
Text(
|
||||
"${Format.localizedStringAsFixed(
|
||||
value: priceTuple.item1 * balanceToShow,
|
||||
locale: locale,
|
||||
decimalPlaces: 2,
|
||||
)} $baseCurrency",
|
||||
style: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textSubtitle1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (coin == Coin.firo || coin == Coin.firoTestNet)
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
if (coin == Coin.firo || coin == Coin.firoTestNet)
|
||||
const DesktopBalanceToggleButton(),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
WalletRefreshButton(
|
||||
walletId: walletId,
|
||||
initialSyncStatus: widget.initialSyncStatus,
|
||||
)
|
||||
),
|
||||
if (coin == Coin.firo || coin == Coin.firoTestNet)
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
if (coin == Coin.firo || coin == Coin.firoTestNet)
|
||||
const DesktopPrivateBalanceToggleButton(),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
const DesktopBalanceToggleButton(),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
|
|
@ -4,3 +4,7 @@ import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart';
|
|||
final walletBalanceToggleStateProvider =
|
||||
StateProvider.autoDispose<WalletBalanceToggleState>(
|
||||
(ref) => WalletBalanceToggleState.full);
|
||||
|
||||
final walletPrivateBalanceToggleStateProvider =
|
||||
StateProvider.autoDispose<WalletBalanceToggleState>(
|
||||
(ref) => WalletBalanceToggleState.full);
|
||||
|
|
Loading…
Reference in a new issue