Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 43 additions & 54 deletions lib/pages/add_wallet_views/select_wallet_for_token_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../models/add_wallet_list_entity/sub_classes/coin_entity.dart';
import '../../models/add_wallet_list_entity/sub_classes/eth_token_entity.dart';
import 'add_token_view/edit_wallet_tokens_view.dart';
Expand All @@ -18,6 +19,7 @@ import 'verify_recovery_phrase_view/verify_recovery_phrase_view.dart';
import '../../themes/stack_colors.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
import '../../providers/global/wallets_provider.dart';
import '../../wallets/isar/providers/all_wallets_info_provider.dart';
import '../../wallets/isar/providers/wallet_info_provider.dart';
import '../../widgets/background.dart';
Expand All @@ -30,16 +32,15 @@ import '../../widgets/eth_wallet_radio.dart';
import '../../widgets/rounded_container.dart';
import '../../widgets/rounded_white_container.dart';
import '../../widgets/wallet_info_row/wallet_info_row.dart';

import 'package:tuple/tuple.dart';

final newEthWalletTriggerTempUntilHiveCompletelyDeleted =
StateProvider((ref) => false);
final newEthWalletTriggerTempUntilHiveCompletelyDeleted = StateProvider(
(ref) => false,
);

class SelectWalletForTokenView extends ConsumerStatefulWidget {
const SelectWalletForTokenView({
super.key,
required this.entity,
});
const SelectWalletForTokenView({super.key, required this.entity});

static const String routeName = "/selectWalletForTokenView";

Expand All @@ -59,10 +60,7 @@ class _SelectWalletForTokenViewState
void _onContinue() {
Navigator.of(context).pushNamed(
EditWalletTokensView.routeName,
arguments: Tuple2(
_selectedWalletId!,
[widget.entity.token.address],
),
arguments: Tuple2(_selectedWalletId!, [widget.entity.token.address]),
);
}

Expand All @@ -83,9 +81,23 @@ class _SelectWalletForTokenViewState

final _hasEthWallets = ethWalletInfos.isNotEmpty;

// The wallet info is written to the db when a new wallet is created, but
// the wallet is only added to pWallets once its flow completes. Rebuild
// when that happens and skip wallets that are not registered yet.
ref.watch(newEthWalletTriggerTempUntilHiveCompletelyDeleted);
final registeredWalletIds = ref
.read(pWallets)
.wallets
.map((e) => e.walletId)
.toSet();

final List<String> ethWalletIds = [];

for (final walletId in ethWalletInfos.map((e) => e.walletId).toList()) {
for (final walletId
in ethWalletInfos
.map((e) => e.walletId)
.where(registeredWalletIds.contains)
.toList()) {
final walletContracts = ref.read(pWalletTokenAddresses(walletId));
if (!walletContracts.contains(widget.entity.token.address)) {
ethWalletIds.add(walletId);
Expand All @@ -101,8 +113,9 @@ class _SelectWalletForTokenViewState
condition: !isDesktop,
builder: (child) => Background(
child: Scaffold(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
backgroundColor: Theme.of(context)
.extension<StackColors>()!
.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () {
Expand All @@ -111,10 +124,7 @@ class _SelectWalletForTokenViewState
),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: child,
),
child: Padding(padding: const EdgeInsets.all(16), child: child),

// child: LayoutBuilder(
// builder: (ctx, constraints) {
Expand All @@ -139,48 +149,36 @@ class _SelectWalletForTokenViewState
isCompactHeight: false,
leading: AppBarBackButton(),
),
body: SizedBox(
width: 500,
child: child,
),
body: SizedBox(width: 500, child: child),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (isDesktop)
const SizedBox(
height: 24,
),
if (isDesktop) const SizedBox(height: 24),
Text(
"Select Ethereum wallet",
textAlign: TextAlign.center,
style: isDesktop
? STextStyles.desktopH2(context)
: STextStyles.pageTitleH1(context),
),
SizedBox(
height: isDesktop ? 16 : 8,
),
SizedBox(height: isDesktop ? 16 : 8),
Text(
"You are adding an ETH token.",
textAlign: TextAlign.center,
style: isDesktop
? STextStyles.desktopSubtitleH2(context)
: STextStyles.subtitle(context),
),
const SizedBox(
height: 8,
),
const SizedBox(height: 8),
Text(
"You must choose an Ethereum wallet in order to use ${widget.entity.name}",
textAlign: TextAlign.center,
style: isDesktop
? STextStyles.desktopSubtitleH2(context)
: STextStyles.subtitle(context),
),
SizedBox(
height: isDesktop ? 60 : 16,
),
SizedBox(height: isDesktop ? 60 : 16),
ethWalletIds.isEmpty
? RoundedWhiteContainer(
padding: EdgeInsets.all(isDesktop ? 16 : 12),
Expand Down Expand Up @@ -208,9 +206,8 @@ class _SelectWalletForTokenViewState
child: ListView.separated(
itemCount: ethWalletIds.length,
shrinkWrap: true,
separatorBuilder: (_, __) => SizedBox(
height: isDesktop ? 12 : 6,
),
separatorBuilder: (_, __) =>
SizedBox(height: isDesktop ? 12 : 6),
itemBuilder: (_, index) {
return RoundedContainer(
padding: EdgeInsets.all(isDesktop ? 16 : 8),
Expand All @@ -221,33 +218,25 @@ class _SelectWalletForTokenViewState
},
color: isDesktop
? Theme.of(context)
.extension<StackColors>()!
.popupBG
.extension<StackColors>()!
.popupBG
: _selectedWalletId == ethWalletIds[index]
? Theme.of(context)
.extension<StackColors>()!
.highlight
: Colors.transparent,
? Theme.of(context)
.extension<StackColors>()!
.highlight
: Colors.transparent,
child: isDesktop
? EthWalletRadio(
walletId: ethWalletIds[index],
selectedWalletId: _selectedWalletId,
)
: WalletInfoRow(
walletId: ethWalletIds[index],
),
: WalletInfoRow(walletId: ethWalletIds[index]),
);
},
),
),
if (ethWalletIds.isEmpty || isDesktop)
const SizedBox(
height: 16,
),
if (isDesktop)
const SizedBox(
height: 16,
),
if (ethWalletIds.isEmpty || isDesktop) const SizedBox(height: 16),
if (isDesktop) const SizedBox(height: 16),
ethWalletIds.isEmpty
? PrimaryButton(
label: "Add new Ethereum wallet",
Expand Down
Loading