Files
hash-wallet/lib/new-ui/widgets/swap_page/swap_send_external_modal.dart
jwinterm dd449f2594 Merge upstream Cake Wallet v6.5.0
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.
2026-10-24 23:49:29 -04:00

261 lines
12 KiB
Dart

import 'package:hash_wallet/generated/i18n.dart';
import 'package:hash_wallet/new-ui/widgets/copy_wrapper.dart';
import 'package:hash_wallet/new-ui/widgets/new_primary_button.dart';
import 'package:hash_wallet/new-ui/widgets/receive_page/receive_top_bar.dart';
import 'package:hash_wallet/new-ui/widgets/swap_page/swap_modal_header.dart';
import 'package:hash_wallet/src/screens/receive/widgets/qr_image.dart';
import 'package:hash_wallet/utils/address_formatter.dart';
import 'package:hash_wallet/utils/clipboard_util.dart';
import 'package:hash_wallet/view_model/exchange/exchange_trade_view_model.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/payment_uris.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class SwapSendExternalModal extends StatefulWidget {
const SwapSendExternalModal(
{super.key,
required this.amount,
required this.from,
required this.to,
required this.address,
required this.exchangeTradeViewModel});
final String amount;
final ExchangeTradeViewModel exchangeTradeViewModel;
final CryptoCurrency from;
final CryptoCurrency to;
final String address;
@override
State<SwapSendExternalModal> createState() => _SwapSendExternalModalState();
}
class _SwapSendExternalModalState extends State<SwapSendExternalModal> {
PaymentURI? uri;
bool largeQrMode = false;
static const warningTextColor = Color(0xFFFFB84E);
static const warningBackgroundColor = Color(0xFF8E5800);
@override
void initState() {
super.initState();
final newUri = widget.exchangeTradeViewModel.paymentUri;
setState(() {
uri = newUri;
});
}
@override
Widget build(BuildContext context) {
if (widget.address.isEmpty) return SizedBox.shrink();
final resolvedSize = MediaQuery.of(context).size.width * (largeQrMode ? 0.8 : 0.54);
return PopScope(
onPopInvokedWithResult: (didPop, result) {
Navigator.of(context, rootNavigator: true).pop();
},
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ModalTopBar(
title: "",
leadingWidget: SwapModalHeader(
fromIconPath: widget.from.iconPath ?? "", toIconPath: widget.to.iconPath ?? ""),
trailingIcon: Icon(Icons.close),
trailingSemanticLabel: S.of(context).close,
onTrailingPressed: Navigator.of(context).pop,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Column(
spacing: 24,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 12,
children: [
Text(
S.of(context).send_exactly,
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w500),
),
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
spacing: 8,
children: [
Text(
widget.amount,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: Theme.of(context).colorScheme.primary),
),
Text(
widget.from.title,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16,
color: Theme.of(context).colorScheme.primary),
),
],
),
)),
Text("${S.of(context).to}:",
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w500))
],
),
GestureDetector(
onTap: () {
setState(() {
largeQrMode = !largeQrMode;
});
},
child: TweenAnimationBuilder<double>(
duration: const Duration(milliseconds: 400),
curve: Curves.easeOutCubic,
tween: Tween<double>(
begin: resolvedSize,
end: resolvedSize,
),
builder: (context, animatedSize, child) {
return SizedBox(
width: animatedSize,
height: animatedSize,
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: QrImage(
size: animatedSize,
embeddedImagePath: widget.from.iconPath,
data: uri?.toString() ?? widget.address,
),
),
);
},
),
),
AddressFormatter.buildSegmentedAddress(
address: widget.address,
evenTextStyle: TextStyle(color: Theme.of(context).colorScheme.onSurface),
textAlign: TextAlign.center),
Container(
decoration: BoxDecoration(
color: warningBackgroundColor,
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: EdgeInsets.all(20),
child: Text(
S.of(context).send_external_desc,
textAlign: TextAlign.center,
style: TextStyle(
color: warningTextColor, fontSize: 14, fontWeight: FontWeight.w500),
),
)),
if (widget.exchangeTradeViewModel.trade.extraId != null)
CopyWrapper(
data: ClipboardData(
text: widget.exchangeTradeViewModel.trade.extraId!),
builder: (context, copied) => Container(
width: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
spacing: 8,
children: [
Text(
S.of(context).destination_tag,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.onSurfaceVariant),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 8,
children: [
Flexible(
child: Text(
widget.exchangeTradeViewModel.trade.extraId!,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.primary),
),
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: Icon(
copied ? Icons.check : Icons.copy,
key: ValueKey(copied),
// Only the icon changes here, so label
// the copied state for CopyWrapper's
// live region to announce.
semanticLabel: copied ? S.of(context).copied : null,
size: 18,
color: Theme.of(context).colorScheme.primary,
),
),
],
),
],
),
),
),
),
Row(
spacing: 8,
children: [
Flexible(
child: NewPrimaryButton(
onPressed: () =>
ClipboardUtil.copyToClipboard(context, widget.address),
text: S.of(context).copy,
color: Theme.of(context).colorScheme.primary,
textColor: Theme.of(context).colorScheme.onPrimary),
),
Flexible(
child: NewPrimaryButton(
onPressed: Navigator.of(context).pop,
text: S.of(context).sent_the_funds,
color: Theme.of(context).colorScheme.surfaceContainer,
textColor: Theme.of(context).colorScheme.primary),
),
],
),
SizedBox()
],
),
),
],
),
),
),
);
}
}