Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lib/app/routes/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ Route<dynamic>? onGenerateRoute({
),
settings: settings,
);
case LiquidAddressPaymentPage.routeName:
return FadeInRoute<SendPaymentRequest?>(
builder: (BuildContext _) => LiquidAddressPaymentPage(
addressData: settings.arguments as LiquidAddressData,
),
settings: settings,
);
case LnPaymentPage.routeName:
return FadeInRoute<SendPaymentRequest?>(
builder: (BuildContext context) => BlocProvider<PaymentLimitsCubit>(
Expand Down
2 changes: 2 additions & 0 deletions lib/cubit/input/input_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class InputCubit extends Cubit<InputState> {
result = InputState.nodeId(parsedInput.nodeId, source);
} else if (parsedInput is InputType_BitcoinAddress) {
result = InputState.bitcoinAddress(parsedInput.address, source);
} else if (parsedInput is InputType_LiquidAddress) {
result = InputState.liquidAddress(parsedInput.address, source);
} else if (parsedInput is InputType_Url) {
result = InputState.url(parsedInput.url, source);
} else {
Expand Down
28 changes: 28 additions & 0 deletions lib/cubit/input/input_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ typedef TypeCheck = bool Function(InputType);
final List<TypeCheck> unsupportedInputTypeChecks = <TypeCheck>[
(InputType input) => input is InputType_NodeId,
(InputType input) => input is InputType_Url,
// ponytail: Liquid sends are L-BTC only, so an address naming an asset is unsupported.
(InputType input) => input is InputType_LiquidAddress && input.address.assetId != null,
];

const Set<Type> unsupportedInputStates = <Type>{NodeIdInputState, UrlInputState};
Expand Down Expand Up @@ -37,6 +39,9 @@ class InputState {
const factory InputState.bitcoinAddress(BitcoinAddressData data, InputSource source) =
BitcoinAddressInputState;

const factory InputState.liquidAddress(LiquidAddressData data, InputSource source) =
LiquidAddressInputState;

const factory InputState.url(String url, InputSource source) = UrlInputState;
}

Expand Down Expand Up @@ -260,6 +265,29 @@ class BitcoinAddressInputState extends InputState {
int get hashCode => Object.hash(data, source);
}

class LiquidAddressInputState extends InputState {
const LiquidAddressInputState(this.data, this.source) : super._();

final LiquidAddressData data;
final InputSource source;

@override
String toString() {
return 'LiquidAddressInputState{address: ${data.address}, source: $source}';
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is LiquidAddressInputState &&
runtimeType == other.runtimeType &&
data == other.data &&
source == other.source;

@override
int get hashCode => Object.hash(data, source);
}

class UrlInputState extends InputState {
const UrlInputState(this.url, this.source) : super._();

Expand Down
33 changes: 33 additions & 0 deletions lib/handlers/input_handler/src/input_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class InputHandler extends Handler {
throw inputState.data.reason;
} else if (inputState is BitcoinAddressInputState) {
return handleBitcoinAddress(context, inputState);
} else if (inputState is LiquidAddressInputState) {
return handleLiquidAddress(context, inputState);
} else if (unsupportedInputStates.contains(inputState.runtimeType)) {
throw context.texts().payment_info_dialog_error_unsupported_input;
} else if (inputState is EmptyInputState) {
Expand Down Expand Up @@ -187,6 +189,37 @@ class InputHandler extends Handler {
return await Navigator.of(context).pushNamed(SendChainSwapPage.routeName, arguments: inputState.data);
}

Future<dynamic> handleLiquidAddress(BuildContext context, LiquidAddressInputState inputState) async {
_logger.fine('Handle Liquid Address $inputState');
if (inputState.data.assetId != null) {
throw context.texts().payment_info_dialog_error_unsupported_input;
}

final NavigatorState navigator = Navigator.of(context);
final SendPaymentRequest? sendPaymentRequest = await navigator.pushNamed<SendPaymentRequest?>(
LiquidAddressPaymentPage.routeName,
arguments: inputState.data,
);
if (sendPaymentRequest == null || !context.mounted) {
return Future<dynamic>.value();
}

return await showProcessingPaymentSheet(
context,
paymentFunc: () async {
final PaymentsCubit paymentsCubit = context.read<PaymentsCubit>();
return await paymentsCubit.sendPayment(prepareResponse: sendPaymentRequest.prepareResponse);
},
).then((dynamic result) {
if (context.mounted) {
Navigator.of(context).pushNamedAndRemoveUntil(Home.routeName, (Route<dynamic> route) => false);
if (result is String) {
showFlushbar(context, message: result);
}
}
});
}

void handleResult(dynamic result) {
_logger.info('Input state handled: $result');
if (result is LNURLPageResult && result.protocol != null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/enter_payment_info/enter_payment_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class _EnterPaymentInfoPageState extends State<EnterPaymentInfoPage> {
prefixIconConstraints: BoxConstraints.tight(const Size(16, 56)),
prefixIcon: const SizedBox.shrink(),
contentPadding: EdgeInsets.zero,
hintText: 'Invoice | Lightning Address | BTC Address | LNURL',
hintText: 'Invoice | Lightning Address | BTC Address | Liquid Address | LNURL',
hintStyle: FieldTextStyle.labelStyle.copyWith(fontSize: 14.3),
floatingLabelBehavior: FloatingLabelBehavior.never,
helper: Text(
Expand Down
Loading
Loading