Skip to content

Commit

Permalink
(ios) Adding sheet to allow selection of legacy address
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Feb 16, 2024
1 parent 4c3682d commit a55bc15
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 7 deletions.
4 changes: 4 additions & 0 deletions phoenix-ios/phoenix-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
DC355E212A44D838008E8A8E /* NotificationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC355E202A44D838008E8A8E /* NotificationsView.swift */; };
DC355E232A45FAF2008E8A8E /* NestedObservableObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC355E222A45FAF2008E8A8E /* NestedObservableObject.swift */; };
DC355E252A45FDD3008E8A8E /* NoticeMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC355E242A45FDD3008E8A8E /* NoticeMonitor.swift */; };
DC370A892B7FBD7C0093C56F /* BtcAddrOptionsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC370A882B7FBD7C0093C56F /* BtcAddrOptionsSheet.swift */; };
DC384D81265C12B700131772 /* Cache.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC384D80265C12B700131772 /* Cache.swift */; };
DC384D83265C32F100131772 /* TextField+Verbatim.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC384D82265C32F100131772 /* TextField+Verbatim.swift */; };
DC39A2662A12C04D00F59E39 /* LiquidityPolicyHelp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC39A2652A12C04D00F59E39 /* LiquidityPolicyHelp.swift */; };
Expand Down Expand Up @@ -460,6 +461,7 @@
DC355E202A44D838008E8A8E /* NotificationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsView.swift; sourceTree = "<group>"; };
DC355E222A45FAF2008E8A8E /* NestedObservableObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NestedObservableObject.swift; sourceTree = "<group>"; };
DC355E242A45FDD3008E8A8E /* NoticeMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeMonitor.swift; sourceTree = "<group>"; };
DC370A882B7FBD7C0093C56F /* BtcAddrOptionsSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BtcAddrOptionsSheet.swift; sourceTree = "<group>"; };
DC384D7C265BE41900131772 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = fr; path = fr.lproj/about.html; sourceTree = "<group>"; };
DC384D80265C12B700131772 /* Cache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cache.swift; sourceTree = "<group>"; };
DC384D82265C32F100131772 /* TextField+Verbatim.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TextField+Verbatim.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -924,6 +926,7 @@
DC2F431527B6983B0006FCC4 /* CopyOptionsSheet.swift */,
DC2F431727B698E20006FCC4 /* ShareOptionsSheet.swift */,
DC2F431927B699800006FCC4 /* ModifyInvoiceSheet.swift */,
DC370A882B7FBD7C0093C56F /* BtcAddrOptionsSheet.swift */,
);
path = receive;
sourceTree = "<group>";
Expand Down Expand Up @@ -1688,6 +1691,7 @@
DC49FE9B2AC49CB500D8D2E2 /* KotlinExtensions+Lightning.swift in Sources */,
DCACF6FA2566D0BA0009B01E /* KeyStoreError.swift in Sources */,
DC0E31BB26EFDED4002071C6 /* VSlider.swift in Sources */,
DC370A892B7FBD7C0093C56F /* BtcAddrOptionsSheet.swift in Sources */,
DC27E4CB2791D17A00C777CC /* RecoveryPhraseView.swift in Sources */,
DCB410892902D5BF00CE4FF9 /* PaymentsSection.swift in Sources */,
DCA6DED0282AB7E20073C658 /* KeychainConstants.swift in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions phoenix-ios/phoenix-ios/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,9 @@
}
}
}
},
"A less efficient and less private format that does not rotate addresses. However, it is compatible with almost every service and wallet." : {

},
"A new attempt is scheduled in a few hours." : {
"localizations" : {
Expand Down Expand Up @@ -4879,6 +4882,9 @@
}
}
}
},
"Bitcoin address format" : {

},
"Bitcoin mempool is full and fees are high." : {
"localizations" : {
Expand Down Expand Up @@ -8125,6 +8131,9 @@
}
}
}
},
"Default format, with better privacy, cheaper fees and address rotation. Some older services or wallets may not understand this modern address format." : {

},
"Default payment description" : {
"localizations" : {
Expand Down Expand Up @@ -13937,6 +13946,9 @@
}
}
}
},
"Legacy" : {

},
"Legal" : {
"localizations" : {
Expand Down Expand Up @@ -21486,6 +21498,9 @@
}
}
}
},
"Share Text (bitcoin address)" : {

},
"Share Text (lightning invoice)" : {
"localizations" : {
Expand Down Expand Up @@ -22916,6 +22931,9 @@
}
}
}
},
"Taproot (recommended)" : {

},
"Terminate App" : {
"localizations" : {
Expand Down
173 changes: 173 additions & 0 deletions phoenix-ios/phoenix-ios/views/receive/BtcAddrOptionsSheet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import SwiftUI

fileprivate let filename = "BtcAddrOptionsSheet"
#if DEBUG && true
fileprivate var log = LoggerFactory.shared.logger(filename, .trace)
#else
fileprivate var log = LoggerFactory.shared.logger(filename, .warning)
#endif

struct BtcAddrOptionsSheet: View {

@Binding var swapInAddressType: SwapInAddressType

@EnvironmentObject var smartModalState: SmartModalState

@ViewBuilder
var body: some View {

VStack(alignment: HorizontalAlignment.leading, spacing: 0) {
header()
content()
}
.onChange(of: swapInAddressType) { _ in
swapInAddressTypeChanged()
}
}

@ViewBuilder
func header() -> some View {

HStack(alignment: VerticalAlignment.center, spacing: 0) {
Text("Bitcoin address format")
.font(.title3)
.accessibilityAddTraits(.isHeader)
.accessibilitySortPriority(100)
Spacer()
Button {
closeSheet()
} label: {
Image(systemName: "xmark").imageScale(.medium).font(.title2)
}
.accessibilityLabel("Close")
.accessibilityHidden(smartModalState.dismissable)
}
.padding(.horizontal)
.padding(.vertical, 8)
.background(
Color(UIColor.secondarySystemBackground)
.cornerRadius(15, corners: [.topLeft, .topRight])
)
.padding(.bottom, 4)
}

@ViewBuilder
func content() -> some View {

VStack(alignment: HorizontalAlignment.leading, spacing: 0) {

Toggle(isOn: taprootBinding()) {
Text("Taproot (recommended)")
.foregroundColor(.appAccent)
.bold()
}
.toggleStyle(CheckboxToggleStyle(
onImage: onImage(),
offImage: offImage()
))
.padding(.bottom, 5)

Label {
Text(
"""
Default format, with better privacy, cheaper fees and address rotation. \
Some older services or wallets may not understand this modern address format.
"""
)
.font(.subheadline)
.foregroundColor(.secondary)
} icon: {
invisibleImage()
}
.padding(.bottom, 15)

Toggle(isOn: legacyBinding()) {
Text("Legacy")
.foregroundColor(.appAccent)
.bold()
}
.toggleStyle(CheckboxToggleStyle(
onImage: onImage(),
offImage: offImage()
))

Label {
Text(
"""
A less efficient and less private format that does not rotate addresses. \
However, it is compatible with almost every service and wallet.
"""
)
.font(.subheadline)
.foregroundColor(.secondary)
} icon: {
invisibleImage()
}
}
.padding()
}

@ViewBuilder
func onImage() -> some View {
Image(systemName: "smallcircle.filled.circle")
.imageScale(.large)
.foregroundColor(.appAccent)
}

@ViewBuilder
func offImage() -> some View {
Image(systemName: "circle")
.imageScale(.large)
.foregroundColor(.appAccent)
}

@ViewBuilder
func invisibleImage() -> some View {

Image(systemName: "circle")
.imageScale(.large)
.foregroundColor(.clear)
.accessibilityHidden(true)
}

// --------------------------------------------------
// MARK: View Helpers
// --------------------------------------------------

private func taprootBinding() -> Binding<Bool> {

return Binding<Bool>(
get: { swapInAddressType == .taproot },
set: { if $0 { swapInAddressType = .taproot }}
)
}

private func legacyBinding() -> Binding<Bool> {

return Binding<Bool>(
get: { swapInAddressType == .legacy },
set: { if $0 { swapInAddressType = .legacy } }
)
}

// --------------------------------------------------
// MARK: Actions
// --------------------------------------------------

func swapInAddressTypeChanged() {
log.trace("swapInAddressTypeChanged()")

// It's nice to add a slight delay before we close the sheet.
// Because it's assuring to visually see the Toggle update, and then see the sheet close.

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.closeSheet()
}
}

func closeSheet() {
log.trace("closeSheet()")

smartModalState.close()
}
}
Loading

0 comments on commit a55bc15

Please sign in to comment.