zaps: Implement single-tap zap on profile action sheet and fix zap fallthrough on default settings

This commit implements a single-tap zap on the profile action sheet and fixes an issue where zapping would silently fail on default settings if the user had no lightning wallet installed in their system.

Testing
-------

Configurations:
- iPhone 13 Mini (physical device) on iOS 17.0.2 with NWC wallet attached
- iPhone 15 Pro (simulator) on iOS 17.0.1 with no lightning wallet nor NWC

Damus: This commit

Coverage:
- Zapping using NWC connected wallet: PASS (Zaps and shows UX feedback of the completed action)
- Zapping under default settings and no lightning wallet: PASS (Shows the wallet selector invoice view)
- Long press on zap button brings custom zap view

Regression testing
------------------

Preconditions: iPhone 15 Pro (simulator) on iOS 17.0.1 with no lightning wallet nor NWC

Coverage:
- Zapping user on their full profile shows wallet selector. PASS
- On-post invoice shows wallet selector. PASS

Closes: https://github.com/damus-io/damus/issues/1634
Changelog-Changed: Zap button on profile action sheet now zaps with a single click, while a long press brings custom zap view
Changelog-Fixed: Fixed an issue where zapping would silently fail on default settings if the user does not have a lightning wallet preinstalled on their device.
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino
2023-10-23 23:32:55 +00:00
committed by William Casarin
parent 139df33cb7
commit 692d29942b
8 changed files with 195 additions and 37 deletions
+16 -6
View File
@@ -39,7 +39,12 @@ struct InvoiceView: View {
if settings.show_wallet_selector {
present_sheet(.select_wallet(invoice: invoice.string))
} else {
open_with_wallet(wallet: settings.default_wallet.model, invoice: invoice.string)
do {
try open_with_wallet(wallet: settings.default_wallet.model, invoice: invoice.string)
}
catch {
present_sheet(.select_wallet(invoice: invoice.string))
}
}
} label: {
RoundedRectangle(cornerRadius: 20, style: .circular)
@@ -82,21 +87,26 @@ struct InvoiceView: View {
}
}
func open_with_wallet(wallet: Wallet.Model, invoice: String) {
enum OpenWalletError: Error {
case no_wallet_to_open
case store_link_invalid
case system_cannot_open_store_link
}
func open_with_wallet(wallet: Wallet.Model, invoice: String) throws {
if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
} else {
guard let store_link = wallet.appStoreLink else {
// TODO: do something here if we don't have an appstore link
return
throw OpenWalletError.no_wallet_to_open
}
guard let url = URL(string: store_link) else {
return
throw OpenWalletError.store_link_invalid
}
guard UIApplication.shared.canOpenURL(url) else {
return
throw OpenWalletError.system_cannot_open_store_link
}
UIApplication.shared.open(url)