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.
350 lines
16 KiB
Dart
350 lines
16 KiB
Dart
import "package:hash_wallet/anonpay/anonpay_donation_link_info.dart";
|
|
import "package:hash_wallet/bitcoin/bitcoin.dart";
|
|
import "package:hash_wallet/core/utilities.dart";
|
|
import "package:hash_wallet/di.dart";
|
|
import "package:hash_wallet/entities/auto_generate_subaddress_status.dart";
|
|
import "package:hash_wallet/entities/preferences_key.dart";
|
|
import "package:hash_wallet/generated/i18n.dart";
|
|
import "package:hash_wallet/new-ui/widgets/modern_button.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/payjoin_copy_modal.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_address_type.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_address_widget.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_amount_display.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_amount_modal.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_bottom_buttons.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_info_box.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_label_modal.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_label_widget.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_large_amount_preview.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_qr_code.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_token_display.dart";
|
|
import "package:hash_wallet/new-ui/widgets/receive_page/receive_top_bar.dart";
|
|
import "package:hash_wallet/routes.dart";
|
|
import "package:hash_wallet/utils/share_util.dart";
|
|
import "package:hash_wallet/view_model/dashboard/dashboard_view_model.dart";
|
|
import "package:hash_wallet/view_model/dashboard/receive_option_view_model.dart";
|
|
import "package:hash_wallet/view_model/wallet_address_list/wallet_address_list_item.dart";
|
|
import "package:hash_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart";
|
|
import "package:cw_core/crypto_currency.dart";
|
|
import "package:cw_core/payment_uris.dart";
|
|
import "package:cw_core/receive_page_option.dart";
|
|
import "package:cw_core/utils/print_verbose.dart";
|
|
import "package:cw_core/wallet_type.dart";
|
|
import "package:flutter/cupertino.dart";
|
|
import "package:flutter/material.dart";
|
|
import "package:flutter/services.dart";
|
|
import "package:flutter_mobx/flutter_mobx.dart";
|
|
import "package:mobx/mobx.dart";
|
|
import "package:modal_bottom_sheet/modal_bottom_sheet.dart";
|
|
import "package:shared_preferences/shared_preferences.dart";
|
|
|
|
class NewReceivePage extends StatefulWidget {
|
|
NewReceivePage({
|
|
required this.addressListViewModel,
|
|
required this.receiveOptionViewModel,
|
|
required this.dashboardViewModel,
|
|
required this.lightningMode,
|
|
super.key,
|
|
CryptoCurrency? initialCurrency,
|
|
}) {
|
|
if (initialCurrency != null && initialCurrency != addressListViewModel.selectedCurrency) {
|
|
addressListViewModel.setTokenCurrency(initialCurrency);
|
|
}
|
|
}
|
|
|
|
final WalletAddressListViewModel addressListViewModel;
|
|
final ReceiveOptionViewModel receiveOptionViewModel;
|
|
final DashboardViewModel dashboardViewModel;
|
|
final bool lightningMode;
|
|
|
|
@override
|
|
State<NewReceivePage> createState() => _NewReceivePageState();
|
|
}
|
|
|
|
class _NewReceivePageState extends State<NewReceivePage> {
|
|
bool _largeQrMode = false;
|
|
late WalletAddressListItem? _addressItemWithLabel;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (widget.lightningMode) {
|
|
widget.addressListViewModel.setTokenCurrency(CryptoCurrency.btcln);
|
|
widget.receiveOptionViewModel.selectReceiveOption(
|
|
widget.receiveOptionViewModel.options
|
|
.firstWhereOrNull((item) => item.value.contains("Lightning")) ??
|
|
ReceivePageOption.mainnet,
|
|
);
|
|
widget.addressListViewModel.selectedCurrency = CryptoCurrency.btcln;
|
|
} else if (widget.addressListViewModel.wallet.type == WalletType.bitcoin) {
|
|
widget.receiveOptionViewModel.selectReceiveOption(
|
|
widget.receiveOptionViewModel.options
|
|
.firstWhereOrNull((item) => item.value.contains("Standard")) ??
|
|
ReceivePageOption.mainnet,
|
|
);
|
|
widget.addressListViewModel.selectedCurrency = CryptoCurrency.btc;
|
|
}
|
|
});
|
|
|
|
reaction((_) => widget.addressListViewModel.uri, _reloadAddressWithLabel);
|
|
|
|
_addressItemWithLabel = widget.addressListViewModel.forceRecomputeItems.firstWhereOrNull(
|
|
(item) =>
|
|
item is WalletAddressListItem && item.address == widget.addressListViewModel.uri.address,
|
|
) as WalletAddressListItem?;
|
|
|
|
reaction((_) => widget.receiveOptionViewModel.selectedReceiveOption, (option) {
|
|
// The infobox depends on the selected address type, so the page has to be
|
|
// rebuilt when it changes.
|
|
if (mounted) setState(() {});
|
|
|
|
if (widget.dashboardViewModel.type == WalletType.bitcoin &&
|
|
bitcoin!.isBitcoinReceivePageOption(option)) {
|
|
widget.addressListViewModel.setAddressType(bitcoin!.getOptionToType(option));
|
|
if (option.value.contains("Lightning")) {
|
|
widget.addressListViewModel.selectedCurrency = CryptoCurrency.btcln;
|
|
} else {
|
|
widget.addressListViewModel.selectedCurrency = CryptoCurrency.btc;
|
|
}
|
|
return;
|
|
}
|
|
|
|
if ([WalletType.bitcoin, WalletType.litecoin]
|
|
.contains(widget.addressListViewModel.type)) {
|
|
widget.addressListViewModel.setAddressType(bitcoin!.getBitcoinAddressType(option));
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final hasAddressTypeSelector = widget.receiveOptionViewModel.options.length > 1;
|
|
final hasLabel = _addressItemWithLabel?.name != null && _addressItemWithLabel!.name!.isNotEmpty;
|
|
final infoboxDismissed = widget.addressListViewModel.wallet.walletInfo.receiveInfoboxDismissed;
|
|
final infobox = ReceiveInfoBox.forWalletType(
|
|
widget.addressListViewModel.type,
|
|
supportedCurrencies:
|
|
widget.addressListViewModel.tokenCurrencies.whereType<CryptoCurrency>().toList(),
|
|
onDismissed: () {
|
|
widget.addressListViewModel.dismissInfobox();
|
|
setState(() {});
|
|
},
|
|
autoGenerateSubaddressStatus: widget.lightningMode
|
|
? AutoGenerateSubaddressStatus.disabled
|
|
: widget.dashboardViewModel.settingsStore.autoGenerateSubaddressStatus,
|
|
addressRotates: _selectedAddressRotates,
|
|
);
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [
|
|
Theme.of(context).colorScheme.surfaceBright,
|
|
Theme.of(context).colorScheme.surface,
|
|
],
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
),
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
|
|
),
|
|
child: SafeArea(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
ModalTopBar(
|
|
title: _largeQrMode ? "" : S.of(context).receive,
|
|
leadingIcon: const Icon(Icons.close),
|
|
leadingSemanticLabel: S.of(context).close,
|
|
onLeadingPressed: () {
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
},
|
|
trailingWidget: Observer(
|
|
builder: (_) => AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 300),
|
|
child: _largeQrMode ||
|
|
widget.addressListViewModel.hasAddressRotation
|
|
/* TODO rotating is broken on mweb, disabling for now, fix after mvp*/
|
|
&&
|
|
!(widget.receiveOptionViewModel.selectedReceiveOption.description ??
|
|
"")
|
|
.toLowerCase()
|
|
.contains("mweb")
|
|
? ModernButton(
|
|
key: ValueKey(_largeQrMode),
|
|
size: 36,
|
|
icon: _largeQrMode
|
|
? const Icon(Icons.share)
|
|
: widget.addressListViewModel.isRotatingAddress
|
|
? const CupertinoActivityIndicator()
|
|
: const Icon(Icons.refresh),
|
|
semanticLabel: _largeQrMode
|
|
? S.of(context).share_address
|
|
: S.of(context).rotate_address,
|
|
onPressed: () {
|
|
if (_largeQrMode) {
|
|
ShareUtil.share(
|
|
text: widget.addressListViewModel.uri.toString(),
|
|
context: context,
|
|
);
|
|
} else {
|
|
if (widget.addressListViewModel.hasAddressRotation) {
|
|
widget.addressListViewModel.rotateAddress();
|
|
}
|
|
}
|
|
},
|
|
)
|
|
: const SizedBox.shrink(),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
ReceiveAmountDisplay(
|
|
walletAddressListViewModel: widget.addressListViewModel,
|
|
largeQrMode: _largeQrMode,
|
|
),
|
|
ReceiveQrCode(
|
|
addressListViewModel: widget.addressListViewModel,
|
|
onTap: () {
|
|
setState(() {
|
|
_largeQrMode = !_largeQrMode;
|
|
// _infoboxDimissed = true;
|
|
widget.addressListViewModel.dismissInfobox();
|
|
});
|
|
},
|
|
largeQrMode: _largeQrMode,
|
|
),
|
|
if (widget.addressListViewModel.tokenCurrency != null)
|
|
ReceiveTokenDisplay(addressListViewModel: widget.addressListViewModel),
|
|
if (hasAddressTypeSelector)
|
|
ReceiveAddressTypeDisplay(
|
|
lightningMode: widget.lightningMode,
|
|
receiveOptionViewModel: widget.receiveOptionViewModel,
|
|
largeQrMode: _largeQrMode,
|
|
),
|
|
ReceiveAddressWidget(
|
|
addressListViewModel: widget.addressListViewModel,
|
|
),
|
|
// The label chip animates to zero height when there is no
|
|
// label (or in large QR mode); keep it out of the semantics
|
|
// tree entirely while it is collapsed.
|
|
ExcludeSemantics(
|
|
excluding: _largeQrMode || !hasLabel,
|
|
child: MergeSemantics(
|
|
child: Semantics(
|
|
button: true,
|
|
hint: S.of(context).set_label,
|
|
child: GestureDetector(
|
|
onTap: _showLabelModal,
|
|
child: ReceiveLabelWidget(
|
|
name: _addressItemWithLabel?.name ?? "",
|
|
largeQrMode: _largeQrMode,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Observer(
|
|
builder: (_) => ReceiveBottomButtons(
|
|
key: const ValueKey(0),
|
|
largeQrMode: _largeQrMode,
|
|
showAccountsButton: widget.addressListViewModel.hasAddressList,
|
|
showLabelButton: widget.addressListViewModel.hasAddressList && !hasLabel,
|
|
copyData: widget.addressListViewModel.hasPayjoin
|
|
? null
|
|
: ClipboardData(
|
|
text: widget.addressListViewModel.displayAmount.isEmpty
|
|
? widget.addressListViewModel.uri.address
|
|
: widget.addressListViewModel.uri.toString(),
|
|
),
|
|
onCopyButtonPressed: () {
|
|
if (widget.addressListViewModel.hasPayjoin) {
|
|
showModalBottomSheet(
|
|
isScrollControlled: true,
|
|
context: context,
|
|
builder: (context) =>
|
|
PayjoinCopyModal(uri: widget.addressListViewModel.uri),
|
|
);
|
|
}
|
|
},
|
|
onAmountButtonPressed: () {
|
|
showMaterialModalBottomSheet(
|
|
context: context,
|
|
backgroundColor: Colors.transparent,
|
|
barrierColor: Colors.black.withAlpha(80),
|
|
builder: (context) => ReceiveAmountModal(
|
|
walletAddressListViewModel: widget.addressListViewModel,
|
|
onSubmitted: (amount) {},
|
|
),
|
|
);
|
|
},
|
|
onLabelButtonPressed: _showLabelModal,
|
|
onAccountsButtonPressed: () {
|
|
Navigator.of(context).pushNamed(
|
|
Routes.receiveAddresses,
|
|
arguments: false,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
ReceiveLargeAmountPreview(
|
|
amount: widget.addressListViewModel.displayAmount,
|
|
currency: widget.addressListViewModel.cryptoCurrencySymbol,
|
|
largeQrMode: _largeQrMode,
|
|
),
|
|
if (infobox != null && !widget.addressListViewModel.isLightning)
|
|
ClipRect(
|
|
child: AnimatedAlign(
|
|
duration: const Duration(milliseconds: 200),
|
|
curve: Curves.easeOutCubic,
|
|
heightFactor: infoboxDismissed ? 0 : 1,
|
|
alignment: Alignment.center,
|
|
child: AnimatedOpacity(
|
|
duration: const Duration(milliseconds: 200),
|
|
opacity: infoboxDismissed ? 0 : 1,
|
|
curve: Curves.easeOutCubic,
|
|
child: infobox,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Zcash is the only wallet type that also offers static address types, so
|
|
/// the rotation notice must not be shown for it unless the disposable
|
|
/// transparent type is the one currently selected.
|
|
bool get _selectedAddressRotates => true;
|
|
|
|
void _showLabelModal() {
|
|
showMaterialModalBottomSheet(
|
|
context: context,
|
|
backgroundColor: Colors.transparent,
|
|
barrierColor: Colors.black.withAlpha(80),
|
|
builder: (_) => getIt.get<ReceiveLabelModal>(param1: _addressItemWithLabel),
|
|
).then((value) {
|
|
_reloadAddressWithLabel(widget.addressListViewModel.uri);
|
|
});
|
|
}
|
|
|
|
void _reloadAddressWithLabel(PaymentURI newAddress) {
|
|
// FIXME: viewmodel doesn't want to load address name here, so we make it. investigate why later
|
|
setState(() {
|
|
_addressItemWithLabel = widget.addressListViewModel.forceRecomputeItems.firstWhereOrNull(
|
|
(item) => item is WalletAddressListItem && item.address == newAddress.address,
|
|
) as WalletAddressListItem?;
|
|
});
|
|
}
|
|
}
|