mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-25 11:03:55 +01:00
Catches up from the May 12 fork point (v6.1.2+23) through v6.5.0: 535 upstream commits, including the Monero silent-open fix, Monero on Trezor, Ledger/Trezor BLE fixes, the new seed and history screens, quick Bitcoin sync, git-pinned dependencies (pubspec_overrides.yaml), frozen Hive adapters (*.part.dart), monero_c v0.18.4.6-RC2 and Flutter 3.41.9. Merged with both sides normalized first (import rename, 100-column format), which took the conflict count from 614 paths to 322. The procedure is now scripts/upstream_sync.sh. Kept from Hash Bags: - WalletType enum order and Hive IDs. SQLite stores WalletType.index and our order differs from upstream's; taking theirs would reread saved wallets as other chains. Our frozen adapter keeps the shipped IDs. - The 1.0.2 legacy PIN and wallet-password decode and self-heal. - Removed chains (Solana, Tron, Zano, Zcash, Decred, Haven) and the new Robinhood chain stay out; Cake Pay and non-Trocador swaps stay out. - Default nodes (node.wownero.org, sethforprivacy, Blockstream, bysh.me), converted to upstream's isDefault node-list key; Wownero is back in the node reset list. - Privacy: address resolvers limited to domain-anchored sources again; prices.neroswap.com for fiat; upstream's charts tab, which reads prices.cakewallet.com, sits behind FeatureFlag.isChartsEnabled = false. - Lightning stays behind FeatureFlag.isLightningEnabled, including upstream's new post-seed Lightning username step. - Our icon pipeline, branding and bundle identifiers. Twelve new upstream widget tests are skipped: test and code are unchanged from v6.5.0 apart from renames (not rerun on a pristine upstream checkout; upstream's top_bar_test does not compile against its own TopBar). flutter analyze lib: 0 errors; flutter test: 345 passed, 12 skipped; flutter build bundle compiles. Built with Flutter 3.41.9.
481 lines
16 KiB
Dart
481 lines
16 KiB
Dart
import "dart:async";
|
|
|
|
import "package:hash_wallet/core/utilities.dart";
|
|
import "package:hash_wallet/generated/i18n.dart";
|
|
import "package:hash_wallet/new-ui/widgets/account_confirmation_content.dart";
|
|
import "package:hash_wallet/new-ui/widgets/modal_page_wrapper.dart";
|
|
import "package:hash_wallet/new-ui/widgets/money/money_text.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_top_bar.dart";
|
|
import "package:hash_wallet/src/widgets/alert_with_two_actions.dart";
|
|
import "package:hash_wallet/src/widgets/base_alert_dialog.dart";
|
|
import "package:hash_wallet/src/widgets/hash_image_widget.dart";
|
|
import "package:hash_wallet/utils/show_pop_up.dart";
|
|
import "package:hash_wallet/view_model/dashboard/dashboard_view_model.dart";
|
|
import "package:hash_wallet/view_model/wallet_account_list/account_list_item.dart";
|
|
import "package:hash_wallet/view_model/wallet_account_list/wallet_account_list_view_model.dart";
|
|
import "package:cw_core/balance_card_layout.dart";
|
|
import "package:cw_core/balance_card_style_settings.dart";
|
|
import "package:flutter/cupertino.dart";
|
|
import "package:flutter/material.dart";
|
|
import "package:flutter_mobx/flutter_mobx.dart";
|
|
|
|
class HiddenAccountsPage extends StatefulWidget {
|
|
const HiddenAccountsPage({
|
|
required this.accountListViewModel,
|
|
required this.dashboardViewModel,
|
|
super.key,
|
|
});
|
|
|
|
final WalletAccountListViewModel accountListViewModel;
|
|
final DashboardViewModel dashboardViewModel;
|
|
|
|
@override
|
|
State<HiddenAccountsPage> createState() => _HiddenAccountsPageState();
|
|
}
|
|
|
|
class _HiddenAccountsPageState extends State<HiddenAccountsPage> {
|
|
final List<AccountListItem> _items = [];
|
|
final Set<int> _accountsBeingRestored = <int>{};
|
|
bool _isLoading = true;
|
|
|
|
int get _walletInfoId => widget.dashboardViewModel.wallet.walletInfo.internalId;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
unawaited(_loadAccounts());
|
|
}
|
|
|
|
Future<BalanceCardLayout> _layout() async => BalanceCardLayout.resolve(
|
|
accountIndices: widget.accountListViewModel.accounts.map((account) => account.id).toList(),
|
|
settings: await BalanceCardStyleSettings.getAll(_walletInfoId),
|
|
);
|
|
|
|
Future<void> _loadAccounts() async {
|
|
final accounts = widget.accountListViewModel.accounts;
|
|
final layout = await _layout();
|
|
final hiddenAccounts = <AccountListItem>[];
|
|
|
|
for (final accountIndex in layout.hidden) {
|
|
final account = accounts.firstWhereOrNull((account) => account.id == accountIndex);
|
|
if (account != null) {
|
|
hiddenAccounts.add(account);
|
|
}
|
|
}
|
|
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
_items
|
|
..clear()
|
|
..addAll(hiddenAccounts);
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
|
|
Future<bool> _confirmUnarchival(AccountListItem account) async {
|
|
final isFunded = account.isFunded;
|
|
|
|
final result = await showPopUp<bool>(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (dialogContext) => AlertWithTwoActions(
|
|
alertTitle: S.of(dialogContext).unarchive_account_title,
|
|
alertContent: "",
|
|
alertContentTextWidget: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
AccountSummary(account: account),
|
|
const SizedBox(height: 20),
|
|
Text(
|
|
isFunded
|
|
? S.of(dialogContext).unarchive_account_funds_description
|
|
: S.of(dialogContext).unarchive_account_description,
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(dialogContext).textTheme.bodyMedium,
|
|
),
|
|
if (isFunded) ...[
|
|
const SizedBox(height: 20),
|
|
AccountFundsSummary(
|
|
account: account,
|
|
fiatBalance: widget.dashboardViewModel.balanceViewModel.accountFiatBalance(account),
|
|
borderColor: Theme.of(dialogContext).colorScheme.primary,
|
|
),
|
|
],
|
|
],
|
|
),
|
|
leftButtonText: S.of(dialogContext).cancel,
|
|
rightButtonText: S.of(dialogContext).continue_text,
|
|
leftAlertButtonStyle: AlertButtonStyle.secondary(dialogContext),
|
|
rightAlertButtonStyle: AlertButtonStyle.primary(dialogContext),
|
|
actionLeftButton: () => Navigator.of(dialogContext).pop(false),
|
|
actionRightButton: () => Navigator.of(dialogContext).pop(true),
|
|
),
|
|
);
|
|
|
|
return result ?? false;
|
|
}
|
|
|
|
Future<void> _unarchive(AccountListItem account) async {
|
|
final accountForConfirmation =
|
|
widget.accountListViewModel.accounts.firstWhereOrNull((item) => item.id == account.id) ??
|
|
account;
|
|
final confirmed = await _confirmUnarchival(accountForConfirmation);
|
|
if (!confirmed || !mounted) {
|
|
return;
|
|
}
|
|
|
|
setState(() => _accountsBeingRestored.add(account.id));
|
|
try {
|
|
final restored = (await _layout()).unhiding(account.id);
|
|
await BalanceCardStyleSettings.setVisibleOrder(_walletInfoId, restored.orders);
|
|
final latestAccount =
|
|
widget.accountListViewModel.accounts.firstWhereOrNull((item) => item.id == account.id) ??
|
|
account;
|
|
await widget.accountListViewModel.select(latestAccount);
|
|
await widget.dashboardViewModel.loadCardDesigns();
|
|
await _loadAccounts();
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() => _accountsBeingRestored.remove(account.id));
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ModalPageWrapper(
|
|
topBar: ModalTopBar(
|
|
title: S.of(context).archived_accounts,
|
|
leadingIcon: const Icon(Icons.arrow_back_ios_new, size: 18),
|
|
leadingSemanticLabel: S.of(context).seed_alert_back,
|
|
onLeadingPressed: Navigator.of(context).pop,
|
|
),
|
|
content: _isLoading
|
|
? const SizedBox(
|
|
height: 320,
|
|
child: Center(child: CupertinoActivityIndicator()),
|
|
)
|
|
: _items.isEmpty
|
|
? const _EmptyArchiveView()
|
|
: _PopulatedArchiveView(
|
|
accounts: _items,
|
|
accountsBeingRestored: _accountsBeingRestored,
|
|
dashboardViewModel: widget.dashboardViewModel,
|
|
onUnarchive: _unarchive,
|
|
),
|
|
);
|
|
}
|
|
|
|
class _EmptyArchiveView extends StatelessWidget {
|
|
const _EmptyArchiveView();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
return SizedBox(
|
|
height: MediaQuery.sizeOf(context).height - 180,
|
|
child: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_ArchiveIcon(size: 50, color: theme.colorScheme.onSurfaceVariant),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
S.of(context).no_archived_accounts,
|
|
textAlign: TextAlign.center,
|
|
style: theme.textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w500),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
S.of(context).no_archived_accounts_description,
|
|
textAlign: TextAlign.center,
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PopulatedArchiveView extends StatelessWidget {
|
|
const _PopulatedArchiveView({
|
|
required this.accounts,
|
|
required this.accountsBeingRestored,
|
|
required this.dashboardViewModel,
|
|
required this.onUnarchive,
|
|
});
|
|
|
|
final List<AccountListItem> accounts;
|
|
final Set<int> accountsBeingRestored;
|
|
final DashboardViewModel dashboardViewModel;
|
|
final Future<void> Function(AccountListItem account) onUnarchive;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final fundedAccounts = accounts.where((account) => account.isFunded).toList(growable: false);
|
|
final emptyAccounts =
|
|
accounts.where((account) => !account.isFunded).toList(growable: false);
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
_ArchiveIcon(size: 50, color: theme.colorScheme.primary),
|
|
const SizedBox(height: 12),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 36),
|
|
child: Text(
|
|
S.of(context).select_account_to_unarchive,
|
|
textAlign: TextAlign.center,
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
if (fundedAccounts.isNotEmpty) ...[
|
|
_ArchiveSectionHeader(
|
|
title: S.of(context).funded_accounts,
|
|
description: S.of(context).funded_accounts_description,
|
|
),
|
|
const SizedBox(height: 12),
|
|
_accountRows(context, fundedAccounts),
|
|
],
|
|
if (fundedAccounts.isNotEmpty && emptyAccounts.isNotEmpty) const SizedBox(height: 28),
|
|
if (emptyAccounts.isNotEmpty) ...[
|
|
_ArchiveSectionHeader(title: S.of(context).empty_accounts),
|
|
const SizedBox(height: 12),
|
|
_accountRows(context, emptyAccounts),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _accountRows(BuildContext context, List<AccountListItem> sectionAccounts) => Container(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
|
borderRadius: BorderRadius.circular(18),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Column(
|
|
children: [
|
|
for (var index = 0; index < sectionAccounts.length; index++) ...[
|
|
_ArchivedAccountRow(
|
|
account: sectionAccounts[index],
|
|
dashboardViewModel: dashboardViewModel,
|
|
isBusy: accountsBeingRestored.contains(sectionAccounts[index].id),
|
|
onTap: accountsBeingRestored.contains(sectionAccounts[index].id)
|
|
? null
|
|
: () => onUnarchive(sectionAccounts[index]),
|
|
),
|
|
if (index < sectionAccounts.length - 1)
|
|
Divider(
|
|
height: 1,
|
|
indent: 48,
|
|
color: Theme.of(context).colorScheme.outlineVariant,
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
class _ArchivedAccountRow extends StatelessWidget {
|
|
const _ArchivedAccountRow({
|
|
required this.account,
|
|
required this.dashboardViewModel,
|
|
required this.isBusy,
|
|
required this.onTap,
|
|
});
|
|
|
|
final AccountListItem account;
|
|
final DashboardViewModel dashboardViewModel;
|
|
final bool isBusy;
|
|
final VoidCallback? onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final label = account.label.trim();
|
|
|
|
return Material(
|
|
color: theme.colorScheme.surfaceContainer,
|
|
child: Semantics(
|
|
button: true,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
|
child: Row(
|
|
children: [
|
|
HashImageWidget(
|
|
imageUrl: "assets/new-ui/account.svg",
|
|
width: 24,
|
|
height: 24,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text.rich(
|
|
TextSpan(
|
|
children: [
|
|
TextSpan(
|
|
text: "${account.id + 1}. ",
|
|
style: TextStyle(color: theme.colorScheme.primary),
|
|
),
|
|
TextSpan(
|
|
text: label.isEmpty ? S.of(context).unnamed_account : label,
|
|
),
|
|
],
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: theme.textTheme.bodyMedium,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_AccountBalanceTrailing(
|
|
account: account,
|
|
dashboardViewModel: dashboardViewModel,
|
|
isBusy: isBusy,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ArchiveSectionHeader extends StatelessWidget {
|
|
const _ArchiveSectionHeader({required this.title, this.description});
|
|
|
|
final String title;
|
|
final String? description;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600),
|
|
),
|
|
if (description != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
description!,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AccountBalanceTrailing extends StatelessWidget {
|
|
const _AccountBalanceTrailing({
|
|
required this.account,
|
|
required this.dashboardViewModel,
|
|
required this.isBusy,
|
|
});
|
|
|
|
final AccountListItem account;
|
|
final DashboardViewModel dashboardViewModel;
|
|
final bool isBusy;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
if (isBusy) {
|
|
return const CupertinoActivityIndicator(radius: 10);
|
|
}
|
|
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (account.isFunded) ...[
|
|
ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 142),
|
|
child: Observer(
|
|
builder: (_) {
|
|
final fiatBalance = dashboardViewModel.balanceViewModel.accountFiatBalance(account);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
MoneyText(
|
|
account.balance,
|
|
fractionalDigits: account.balance.decimals,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: theme.textTheme.bodySmall,
|
|
),
|
|
if (fiatBalance != null) ...[
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
fiatBalance,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
],
|
|
Icon(
|
|
Icons.arrow_forward_ios_rounded,
|
|
size: 14,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ArchiveIcon extends StatelessWidget {
|
|
const _ArchiveIcon({required this.size, required this.color});
|
|
|
|
final double size;
|
|
final Color color;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SizedBox.square(
|
|
dimension: size,
|
|
child: Center(
|
|
child: HashImageWidget(
|
|
imageUrl: "assets/new-ui/archived.svg",
|
|
width: size * 19 / 24,
|
|
height: size * 19 / 24,
|
|
color: color,
|
|
),
|
|
),
|
|
);
|
|
}
|