Skip to content
Open
Show file tree
Hide file tree
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
54 changes: 54 additions & 0 deletions lib/pages/send_view/confirm_transaction_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,25 @@ class _ConfirmTransactionViewState
children: [
Text("Send $unit", style: STextStyles.pageTitleH1(context)),
const SizedBox(height: 12),
if (widget.txData.openAlias != null) ...[
RoundedWhiteContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
"OpenAlias",
style: STextStyles.smallMed12(context),
),
const SizedBox(height: 4),
Text(
widget.txData.openAlias!,
style: STextStyles.itemSubtitle12(context),
),
],
),
),
const SizedBox(height: 12),
],
RoundedWhiteContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
Expand Down Expand Up @@ -1125,6 +1144,41 @@ class _ConfirmTransactionViewState
.extension<StackColors>()!
.background,
),
if (widget.txData.openAlias != null) ...[
Padding(
padding: const EdgeInsets.all(12),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"OpenAlias",
style: STextStyles.desktopTextExtraExtraSmall(
context,
),
),
const SizedBox(height: 2),
SelectableText(
widget.txData.openAlias!,
style:
STextStyles.desktopTextExtraExtraSmall(
context,
).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
),
],
),
),
Container(
height: 1,
color: Theme.of(context)
.extension<StackColors>()!
.background,
),
],
Padding(
padding: const EdgeInsets.all(12),
child: Column(
Expand Down
105 changes: 92 additions & 13 deletions lib/pages/send_view/send_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import 'dart:async';
import 'dart:io';

import 'package:cs_openalias/cs_openalias.dart';
import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -30,6 +31,7 @@ import '../../providers/ui/fee_rate_type_state_provider.dart';
import '../../providers/ui/preview_tx_button_state_provider.dart';
import '../../providers/wallet/public_private_balance_state_provider.dart';
import '../../route_generator.dart';
import '../../services/openalias/open_alias_service.dart';
import '../../services/spark_names_service.dart';
import '../../themes/coin_icon_provider.dart';
import '../../themes/stack_colors.dart';
Expand Down Expand Up @@ -150,6 +152,7 @@ class _SendViewState extends ConsumerState<SendView> {

Amount? _cachedAmountToSend;
String? _address;
OpenAliasResolved? _openAlias;

/// The [pRecipient] index of each recipient's form while sending to more
/// than one recipient, otherwise null.
Expand Down Expand Up @@ -237,8 +240,13 @@ class _SendViewState extends ConsumerState<SendView> {
}

void _addRecipientTapped() {
final resolved = _openAlias;
final address =
resolved != null && resolved.alias == openAliasKey(_address ?? "")
? resolved.address
: _address ?? "";
_setMultiRecipients([
(address: _address ?? "", amount: ref.read(pSendAmount), label: null),
(address: address, amount: ref.read(pSendAmount), label: null),
(address: "", amount: null, label: null),
]);
}
Expand Down Expand Up @@ -703,8 +711,9 @@ class _SendViewState extends ConsumerState<SendView> {
}
}

ref.read(pValidSendToAddress.notifier).state = wallet.cryptoCurrency
.validateAddress(address ?? "");
ref.read(pValidSendToAddress.notifier).state =
wallet.cryptoCurrency.validateAddress(address ?? "") ||
(coin.openAliasApplication != null && isOpenAlias(address ?? ""));
}
}

Expand Down Expand Up @@ -1018,11 +1027,73 @@ class _SendViewState extends ConsumerState<SendView> {
}
}

/// Looks up the OpenAlias in the address field. Returns null if the lookup
/// failed or was cancelled.
Future<OpenAliasResolved?> _resolveOpenAlias(String application) async {
final resolution = ref
.read(pOpenAliasService)
.resolve(
_address!,
isValidAddress: coin.validateAddress,
application: application,
coinName: coin.prettyName,
);
unawaited(
showDialog<void>(
context: context,
useSafeArea: false,
barrierDismissible: false,
builder: (context) => BuildingTransactionDialog(
coin: coin,
isSpark: false,
onCancel: () {
resolution.cancel();
Navigator.of(context).pop();
},
),
),
);
final outcome = await resolution.outcome;
if (!mounted) return null;
switch (outcome) {
case OpenAliasCancelled():
return null;
case OpenAliasResolved():
Navigator.of(context, rootNavigator: true).pop();
return outcome;
case OpenAliasFailed(:final title, :final message):
Navigator.of(context, rootNavigator: true).pop();
unawaited(
showDialog<void>(
context: context,
builder: (context) => StackOkDialog(title: title, message: message),
),
);
return null;
}
}

Future<void> _previewTransaction() async {
// wait for keyboard to disappear
FocusScope.of(context).unfocus();
await Future<void>.delayed(const Duration(milliseconds: 100));
final wallet = ref.read(pWallets).getWallet(walletId);
String? openAlias;
String? resolvedAddress;
final application = coin.openAliasApplication;
if (application != null &&
!coin.validateAddress(_address ?? "") &&
isOpenAlias(_address ?? "")) {
var resolved = _openAlias;
if (resolved?.alias != openAliasKey(_address!)) {
resolved = _openAlias = await _resolveOpenAlias(application);
}
if (resolved == null || !mounted) return;
openAlias = resolved.alias;
resolvedAddress = resolved.address;
_setValidAddressProviders(resolvedAddress);
}
late final recipientAddress = resolvedAddress ?? _address!;

final Amount amount = ref.read(pSendAmount)!;
final Amount availableBalance;
Expand Down Expand Up @@ -1166,12 +1237,13 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
sparkRecipients: [
(
address: _address!,
address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
),
],
openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
utxos: (coinControlEnabled && selectedUTXOs.isNotEmpty)
Expand All @@ -1184,14 +1256,15 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
recipients: [
TxRecipient(
address: _address!,
address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
_address!,
recipientAddress,
)!,
),
],
openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
utxos: (coinControlEnabled && selectedUTXOs.isNotEmpty)
Expand All @@ -1210,24 +1283,25 @@ class _SendViewState extends ConsumerState<SendView> {
? null
: [
TxRecipient(
address: _address!,
address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
_address!,
recipientAddress,
)!,
),
],
sparkRecipients: ref.read(pValidSparkSendToAddress)
? [
(
address: _address!,
address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
),
]
: null,
openAlias: openAlias,
),
);
break;
Expand All @@ -1239,12 +1313,15 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
recipients: [
TxRecipient(
address: _address!,
address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(_address!)!,
addressType: wallet.cryptoCurrency.getAddressType(
recipientAddress,
)!,
),
],
openAlias: openAlias,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,

Expand All @@ -1266,14 +1343,15 @@ class _SendViewState extends ConsumerState<SendView> {
_multiRecipients?.toTxRecipients(wallet.cryptoCurrency) ??
[
TxRecipient(
address: _address!,
address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
_address!,
recipientAddress,
)!,
),
],
openAlias: openAlias,
memo: memo,
feeRateType: feeRateType,
satsPerVByte: satsPerVByte,
Expand Down Expand Up @@ -1379,6 +1457,7 @@ class _SendViewState extends ConsumerState<SendView> {
if (!mounted) {
return;
}
_openAlias = null;
sendToController.text = "";
cryptoAmountController.text = "";
baseAmountController.text = "";
Expand Down
Loading
Loading