stack_wallet/lib/pages/token_view/token_view.dart

222 lines
7.8 KiB
Dart
Raw Normal View History

2023-01-20 17:24:19 +00:00
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';
2023-02-27 16:37:41 +00:00
import 'package:stackwallet/pages/token_view/sub_widgets/token_summary.dart';
import 'package:stackwallet/pages/token_view/sub_widgets/token_transaction_list_widget.dart';
2023-03-23 22:53:40 +00:00
import 'package:stackwallet/pages/token_view/token_contract_details_view.dart';
import 'package:stackwallet/pages/wallet_view/sub_widgets/wallet_refresh_button.dart';
2023-01-20 17:24:19 +00:00
import 'package:stackwallet/pages/wallet_view/transaction_views/all_transactions_view.dart';
2023-02-23 22:59:58 +00:00
import 'package:stackwallet/services/ethereum/ethereum_token_service.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
2023-01-20 17:24:19 +00:00
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
2023-03-23 22:53:40 +00:00
import 'package:tuple/tuple.dart';
2023-01-20 17:24:19 +00:00
2023-03-03 14:36:56 +00:00
final tokenServiceStateProvider = StateProvider<EthTokenWallet?>((ref) => null);
final tokenServiceProvider = ChangeNotifierProvider<EthTokenWallet?>(
(ref) => ref.watch(tokenServiceStateProvider));
2023-01-20 17:24:19 +00:00
/// [eventBus] should only be set during testing
class TokenView extends ConsumerStatefulWidget {
const TokenView({
Key? key,
2023-01-25 16:08:27 +00:00
required this.walletId,
this.eventBus,
2023-01-20 17:24:19 +00:00
}) : super(key: key);
static const String routeName = "/token";
2023-01-25 16:08:27 +00:00
final String walletId;
final EventBus? eventBus;
2023-01-20 17:24:19 +00:00
@override
ConsumerState<TokenView> createState() => _TokenViewState();
}
class _TokenViewState extends ConsumerState<TokenView> {
late final WalletSyncStatus initialSyncStatus;
2023-01-20 17:24:19 +00:00
@override
void initState() {
initialSyncStatus = ref.read(tokenServiceProvider)!.isRefreshing
? WalletSyncStatus.syncing
: WalletSyncStatus.synced;
2023-01-20 17:24:19 +00:00
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");
2023-01-25 16:08:27 +00:00
2023-02-24 16:23:39 +00:00
return Background(
child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () {
Navigator.of(context).pop();
},
),
2023-03-23 22:28:56 +00:00
// centerTitle: true
2023-02-24 16:23:39 +00:00
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
2023-02-24 16:23:39 +00:00
children: [
2023-03-23 22:28:56 +00:00
const SizedBox(
width: 5,
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
Assets.svg.iconForToken(
contractAddress: ref.watch(
tokenServiceProvider.select(
(value) => value!.tokenContract.address))),
width: 24,
height: 24,
),
const SizedBox(
width: 10,
),
Flexible(
child: Text(
ref.watch(tokenServiceProvider
.select((value) => value!.tokenContract.name)),
style: STextStyles.navBarTitle(context),
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
),
],
),
2023-02-24 16:23:39 +00:00
),
const SizedBox(
2023-03-23 22:28:56 +00:00
width: 28,
2023-02-24 16:23:39 +00:00
),
2023-03-23 22:28:56 +00:00
WalletRefreshButton(
walletId: widget.walletId,
initialSyncStatus: initialSyncStatus,
tokenContractAddress: ref.watch(tokenServiceProvider
.select((value) => value!.tokenContract.address)),
2023-02-24 16:23:39 +00:00
),
const SizedBox(
width: 6,
),
2023-03-23 22:28:56 +00:00
AppBarIconButton(
icon: SvgPicture.asset(
Assets.svg.verticalEllipsis,
),
2023-03-23 22:28:56 +00:00
onPressed: () {
2023-03-23 22:53:40 +00:00
// todo: context menu
Navigator.of(context).pushNamed(
TokenContractDetailsView.routeName,
arguments: Tuple2(
ref.watch(tokenServiceProvider
.select((value) => value!.tokenContract.address)),
widget.walletId,
),
);
2023-03-23 22:28:56 +00:00
},
),
2023-02-24 16:23:39 +00:00
],
2023-01-25 16:08:27 +00:00
),
2023-02-24 16:23:39 +00:00
),
body: Container(
color: Theme.of(context).extension<StackColors>()!.background,
child: Column(
children: [
const SizedBox(
height: 10,
),
2023-02-27 16:37:41 +00:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: TokenSummary(
walletId: widget.walletId,
),
),
2023-02-24 16:23:39 +00:00
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Transactions",
style: STextStyles.itemSubtitle(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark3,
2023-01-25 16:08:27 +00:00
),
),
2023-02-24 16:23:39 +00:00
CustomTextButton(
text: "See all",
onTap: () {
Navigator.of(context).pushNamed(
AllTransactionsView.routeName,
arguments: widget.walletId,
);
},
2023-01-25 16:08:27 +00:00
),
2023-02-24 16:23:39 +00:00
],
),
),
const SizedBox(
height: 12,
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ClipRRect(
borderRadius: BorderRadius.vertical(
top: Radius.circular(
Constants.size.circularBorderRadius,
),
bottom: Radius.circular(
// TokenView.navBarHeight / 2.0,
Constants.size.circularBorderRadius,
),
),
child: Container(
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
2023-01-25 16:08:27 +00:00
),
2023-02-24 16:23:39 +00:00
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: TokenTransactionsList(
walletId: widget.walletId,
2023-01-25 16:08:27 +00:00
),
2023-02-24 16:23:39 +00:00
),
],
),
2023-01-25 16:08:27 +00:00
),
),
2023-02-24 16:23:39 +00:00
),
2023-01-25 16:08:27 +00:00
),
2023-02-24 16:23:39 +00:00
],
2023-01-25 16:08:27 +00:00
),
),
),
);
2023-01-20 17:24:19 +00:00
}
}