stack_wallet/lib/pages/token_view/token_view.dart

249 lines
8.7 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
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';
2024-01-10 22:53:12 +00:00
import 'package:stackwallet/pages/wallet_view/transaction_views/tx_v2/all_transactions_v2_view.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
import 'package:stackwallet/themes/stack_colors.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';
2024-01-10 22:53:12 +00:00
import 'package:stackwallet/wallets/isar/providers/eth/current_token_wallet_provider.dart';
2023-01-20 17:24:19 +00:00
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-04-03 22:38:48 +00:00
import 'package:stackwallet/widgets/icon_widgets/eth_token_icon.dart';
2023-03-23 22:53:40 +00:00
import 'package:tuple/tuple.dart';
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,
2023-10-17 17:21:53 +00:00
this.popPrevious = false,
2023-01-25 16:08:27 +00:00
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;
2023-10-17 17:21:53 +00:00
final bool popPrevious;
2023-01-25 16:08:27 +00:00
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() {
2024-01-10 22:53:12 +00:00
initialSyncStatus = ref.read(pCurrentTokenWallet)!.refreshMutex.isLocked
? 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-10-17 17:21:53 +00:00
return WillPopScope(
onWillPop: () async {
final nav = Navigator.of(context);
if (widget.popPrevious) {
nav.pop();
}
nav.pop();
return false;
},
child: Background(
child: Scaffold(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () {
final nav = Navigator.of(context);
if (widget.popPrevious) {
nav.pop();
}
nav.pop();
},
),
centerTitle: true,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
EthTokenIcon(
contractAddress: ref.watch(
2024-01-10 22:53:12 +00:00
pCurrentTokenWallet.select(
2023-10-17 17:21:53 +00:00
(value) => value!.tokenContract.address,
),
2023-04-03 22:38:48 +00:00
),
2023-10-17 17:21:53 +00:00
size: 24,
2023-04-03 22:38:48 +00:00
),
2023-10-17 17:21:53 +00:00
const SizedBox(
width: 10,
2023-03-23 22:28:56 +00:00
),
2023-10-17 17:21:53 +00:00
Flexible(
child: Text(
2024-01-10 22:53:12 +00:00
ref.watch(pCurrentTokenWallet
2023-10-17 17:21:53 +00:00
.select((value) => value!.tokenContract.name)),
style: STextStyles.navBarTitle(context),
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
),
],
),
),
],
),
actions: [
Padding(
padding: const EdgeInsets.only(right: 2),
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
icon: SvgPicture.asset(
Assets.svg.verticalEllipsis,
color: Theme.of(context)
.extension<StackColors>()!
.topNavIconPrimary,
2023-03-23 22:28:56 +00:00
),
2023-10-17 17:21:53 +00:00
onPressed: () {
// todo: context menu
Navigator.of(context).pushNamed(
TokenContractDetailsView.routeName,
arguments: Tuple2(
2024-01-10 22:53:12 +00:00
ref.watch(pCurrentTokenWallet
2023-10-17 17:21:53 +00:00
.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-10-17 17:21:53 +00:00
body: Container(
color: Theme.of(context).extension<StackColors>()!.background,
child: Column(
children: [
const SizedBox(
height: 10,
2023-03-29 21:29:27 +00:00
),
2023-10-17 17:21:53 +00:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: TokenSummary(
walletId: widget.walletId,
initialSyncStatus: initialSyncStatus,
),
2023-02-27 16:37:41 +00:00
),
2023-10-17 17:21:53 +00:00
const SizedBox(
height: 20,
2023-02-24 16:23:39 +00:00
),
2023-10-17 17:21:53 +00:00
Padding(
2023-02-24 16:23:39 +00:00
padding: const EdgeInsets.symmetric(horizontal: 16),
2023-10-17 17:21:53 +00:00
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Transactions",
style: STextStyles.itemSubtitle(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark3,
),
2023-02-24 16:23:39 +00:00
),
2023-10-17 17:21:53 +00:00
CustomTextButton(
text: "See all",
onTap: () {
Navigator.of(context).pushNamed(
2024-01-10 22:53:12 +00:00
AllTransactionsV2View.routeName,
2023-10-18 19:58:56 +00:00
arguments: (
walletId: widget.walletId,
contractAddress: ref.watch(
pCurrentTokenWallet.select(
(value) => value!.tokenContract.address,
),
),
2023-10-18 19:58:56 +00:00
),
2023-10-17 17:21:53 +00:00
);
},
2023-02-24 16:23:39 +00:00
),
2023-10-17 17:21:53 +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,
2023-02-24 16:23:39 +00:00
Constants.size.circularBorderRadius,
2023-01-25 16:08:27 +00:00
),
2023-02-24 16:23:39 +00:00
),
2023-10-17 17:21:53 +00:00
child: Container(
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
2023-02-24 16:23:39 +00:00
),
2023-10-17 17:21:53 +00:00
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: TokenTransactionsList(
walletId: widget.walletId,
),
),
],
),
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-10-17 17:21:53 +00:00
],
),
2023-01-25 16:08:27 +00:00
),
),
),
);
2023-01-20 17:24:19 +00:00
}
}