WIP desktop token view

This commit is contained in:
julian 2023-04-03 17:05:48 -06:00
parent f10db8306a
commit 728909399c
4 changed files with 272 additions and 10 deletions

View file

@ -0,0 +1,228 @@
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/pages/token_view/sub_widgets/token_summary.dart';
import 'package:stackwallet/pages/token_view/sub_widgets/token_transaction_list_widget.dart';
import 'package:stackwallet/pages/token_view/token_view.dart';
import 'package:stackwallet/pages/wallet_view/transaction_views/all_transactions_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_summary.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/my_wallet.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/icon_widgets/eth_token_icon.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
/// [eventBus] should only be set during testing
class DesktopTokenView extends ConsumerStatefulWidget {
const DesktopTokenView({
Key? key,
required this.walletId,
this.eventBus,
}) : super(key: key);
static const String routeName = "/desktopTokenView";
final String walletId;
final EventBus? eventBus;
@override
ConsumerState<DesktopTokenView> createState() => _DesktopTokenViewState();
}
class _DesktopTokenViewState extends ConsumerState<DesktopTokenView> {
late final WalletSyncStatus initialSyncStatus;
@override
void initState() {
initialSyncStatus = ref.read(tokenServiceProvider)!.isRefreshing
? WalletSyncStatus.syncing
: WalletSyncStatus.synced;
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");
return DesktopScaffold(
appBar: DesktopAppBar(
background: Theme.of(context).extension<StackColors>()!.popupBG,
leading: Expanded(
flex: 3,
child: Row(
children: [
const SizedBox(
width: 32,
),
SecondaryButton(
padding: const EdgeInsets.only(
left: 12,
right: 18,
),
buttonHeight: ButtonHeight.s,
label: ref.watch(
walletsChangeNotifierProvider.select(
(value) => value.getManager(widget.walletId).walletName,
),
),
icon: SvgPicture.asset(
Assets.svg.arrowLeft,
width: 18,
height: 18,
color: Theme.of(context)
.extension<StackColors>()!
.topNavIconPrimary,
),
onPressed: Navigator.of(context).pop,
),
const SizedBox(
width: 15,
),
],
),
),
center: Expanded(
flex: 4,
child: Row(
children: [
EthTokenIcon(
contractAddress: ref.watch(
tokenServiceProvider.select(
(value) => value!.tokenContract.address,
),
),
size: 32,
),
const SizedBox(
width: 12,
),
Text(
ref.watch(
tokenServiceProvider.select(
(value) => value!.tokenContract.name,
),
),
style: STextStyles.desktopH3(context),
),
const SizedBox(
width: 12,
),
CoinTickerTag(
walletId: widget.walletId,
),
],
),
),
useSpacers: false,
isCompactHeight: true,
),
body: Padding(
padding: const EdgeInsets.all(24),
child: Column(
children: [
RoundedWhiteContainer(
padding: const EdgeInsets.all(20),
child: Row(
children: [
EthTokenIcon(
contractAddress: ref.watch(
tokenServiceProvider.select(
(value) => value!.tokenContract.address,
),
),
size: 40,
),
const SizedBox(
width: 10,
),
DesktopWalletSummary(
walletId: widget.walletId,
isToken: true,
initialSyncStatus: ref.watch(
walletsChangeNotifierProvider.select((value) =>
value.getManager(widget.walletId).isRefreshing))
? WalletSyncStatus.syncing
: WalletSyncStatus.synced,
),
const Spacer(),
DesktopWalletFeatures(
walletId: widget.walletId,
),
],
),
),
const SizedBox(
height: 24,
),
Expanded(
child: Row(
children: [
SizedBox(
width: 450,
child: MyWallet(
walletId: widget.walletId,
),
),
const SizedBox(
width: 16,
),
Expanded(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Recent transactions",
style: STextStyles.desktopTextExtraSmall(context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textFieldActiveSearchIconLeft,
),
),
CustomTextButton(
text: "See all",
onTap: () {
Navigator.of(context).pushNamed(
AllTransactionsView.routeName,
arguments: widget.walletId,
);
},
),
],
),
const SizedBox(
height: 16,
),
Expanded(
child: TokenTransactionsList(
walletId: widget.walletId,
),
),
],
),
),
],
),
),
],
),
),
);
}
}

View file

@ -2,6 +2,7 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/pages/token_view/token_view.dart';
import 'package:stackwallet/pages/wallet_view/sub_widgets/wallet_refresh_button.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/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/providers.dart';
@ -19,10 +20,12 @@ class DesktopWalletSummary extends ConsumerStatefulWidget {
Key? key, Key? key,
required this.walletId, required this.walletId,
required this.initialSyncStatus, required this.initialSyncStatus,
this.isToken = false,
}) : super(key: key); }) : super(key: key);
final String walletId; final String walletId;
final WalletSyncStatus initialSyncStatus; final WalletSyncStatus initialSyncStatus;
final bool isToken;
@override @override
ConsumerState<DesktopWalletSummary> createState() => ConsumerState<DesktopWalletSummary> createState() =>
@ -58,14 +61,29 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
final baseCurrency = ref final baseCurrency = ref
.watch(prefsChangeNotifierProvider.select((value) => value.currency)); .watch(prefsChangeNotifierProvider.select((value) => value.currency));
final priceTuple = ref.watch(priceAnd24hChangeNotifierProvider final priceTuple = widget.isToken
? ref.watch(priceAnd24hChangeNotifierProvider.select((value) =>
value.getTokenPrice(ref.watch(tokenServiceProvider
.select((value) => value!.tokenContract.address)))))
: ref.watch(priceAnd24hChangeNotifierProvider
.select((value) => value.getPrice(coin))); .select((value) => value.getPrice(coin)));
final _showAvailable = final _showAvailable =
ref.watch(walletBalanceToggleStateProvider.state).state == ref.watch(walletBalanceToggleStateProvider.state).state ==
WalletBalanceToggleState.available; WalletBalanceToggleState.available;
Balance balance = ref.watch(walletsChangeNotifierProvider final unit = widget.isToken
? ref.watch(
tokenServiceProvider.select((value) => value!.tokenContract.symbol))
: coin.ticker;
final decimalPlaces = widget.isToken
? ref.watch(tokenServiceProvider
.select((value) => value!.tokenContract.decimals))
: coin.decimals;
Balance balance = widget.isToken
? ref.watch(tokenServiceProvider.select((value) => value!.balance))
: ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(walletId).balance)); .select((value) => value.getManager(walletId).balance));
Decimal balanceToShow; Decimal balanceToShow;
@ -112,8 +130,8 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
"${Format.localizedStringAsFixed( "${Format.localizedStringAsFixed(
value: balanceToShow, value: balanceToShow,
locale: locale, locale: locale,
decimalPlaces: 8, decimalPlaces: decimalPlaces,
)} ${coin.ticker}", )} $unit",
style: STextStyles.desktopH3(context), style: STextStyles.desktopH3(context),
), ),
), ),

View file

@ -117,6 +117,7 @@ import 'package:stackwallet/pages_desktop_specific/desktop_exchange/desktop_all_
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/desktop_exchange_view.dart'; import 'package:stackwallet/pages_desktop_specific/desktop_exchange/desktop_exchange_view.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart'; import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/my_stack_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/my_stack_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_token_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart';
@ -230,6 +231,20 @@ class RouteGenerator {
} }
return _routeError("${settings.name} invalid args: ${args.toString()}"); return _routeError("${settings.name} invalid args: ${args.toString()}");
case DesktopTokenView.routeName:
if (args is String) {
return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => DesktopTokenView(
walletId: args,
),
settings: RouteSettings(
name: settings.name,
),
);
}
return _routeError("${settings.name} invalid args: ${args.toString()}");
case SelectWalletForTokenView.routeName: case SelectWalletForTokenView.routeName:
if (args is EthTokenEntity) { if (args is EthTokenEntity) {
return getRoute( return getRoute(

View file

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages/token_view/token_view.dart'; import 'package:stackwallet/pages/token_view/token_view.dart';
import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_token_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart';
import 'package:stackwallet/providers/db/main_db_provider.dart'; import 'package:stackwallet/providers/db/main_db_provider.dart';
import 'package:stackwallet/providers/global/secure_store_provider.dart'; import 'package:stackwallet/providers/global/secure_store_provider.dart';
@ -89,10 +90,10 @@ class WalletSheetCard extends ConsumerWidget {
nav.pop(); nav.pop();
if (desktopNavigatorState != null) { if (desktopNavigatorState != null) {
// await desktopNavigatorState !.pushNamed( await desktopNavigatorState!.pushNamed(
// DesktopTokenView.routeName, DesktopTokenView.routeName,
// arguments: walletId, arguments: walletId,
// ); );
} else { } else {
await nav.pushNamed( await nav.pushNamed(
TokenView.routeName, TokenView.routeName,