commit b3b335f91719d0c7e1936cab77b3ce08e00a5b83
parent dde48132c91283b02376020eaea2645026b76bb1
Author: Suhail Saqan <suhail.saqan@gmail.com>
Date: Fri, 2 Jun 2023 17:37:50 -0500
Add NWC paste button
Changelog-Added: Added Wallet Connect paste button
Closes: #1235
Diffstat:
1 file changed, 49 insertions(+), 10 deletions(-)
diff --git a/damus/Views/Wallet/NWCScannerView.swift b/damus/Views/Wallet/NWCScannerView.swift
@@ -45,26 +45,65 @@ enum WalletScanResult: Equatable {
case scanning
}
+struct NWCPaste: View {
+ @Binding var result: WalletScanResult
+
+ @Environment(\.colorScheme) var colorScheme
+
+ init(result: Binding<WalletScanResult>) {
+ self._result = result
+ }
+
+ var body: some View {
+ Button(action: {
+ if let pasted_nwc = UIPasteboard.general.string {
+ guard let url = WalletConnectURL(str: pasted_nwc) else {
+ self.result = .failed
+ return
+ }
+
+ self.result = .success(url)
+ }
+ }) {
+ HStack {
+ Image(systemName: "doc.on.clipboard")
+ Text("Paste")
+ }
+ .frame(minWidth: 300, maxWidth: .infinity, minHeight: 50, maxHeight: 50, alignment: .center)
+ .foregroundColor(colorScheme == .light ? DamusColors.black : DamusColors.white)
+ .overlay {
+ RoundedRectangle(cornerRadius: 24)
+ .stroke(colorScheme == .light ? DamusColors.black : DamusColors.white, lineWidth: 2)
+ }
+ .padding(EdgeInsets(top: 10, leading: 50, bottom: 25, trailing: 50))
+ }
+ }
+}
+
struct WalletScannerView: View {
@Binding var result: WalletScanResult
@Environment(\.dismiss) var dismiss
var body: some View {
- CodeScannerView(codeTypes: [.qr]) { res in
- switch res {
- case .success(let success):
- guard let url = WalletConnectURL(str: success.string) else {
+ VStack {
+ CodeScannerView(codeTypes: [.qr]) { res in
+ switch res {
+ case .success(let success):
+ guard let url = WalletConnectURL(str: success.string) else {
+ result = .failed
+ return
+ }
+
+ result = .success(url)
+ case .failure:
result = .failed
- return
}
- result = .success(url)
- case .failure:
- result = .failed
+ dismiss()
}
-
- dismiss()
+ NWCPaste(result: $result)
+ .padding(.vertical)
}
}
}