From c07e8cac9050d2830e9e73174ef47d9c534b7bad Mon Sep 17 00:00:00 2001 From: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:51:08 +0100 Subject: [PATCH] Improve Connections screen --- Gem.xcodeproj/project.pbxproj | 4 + Gem/Connections/Scenes/ConnectionsScene.swift | 74 ++++++++++++------- 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/Gem.xcodeproj/project.pbxproj b/Gem.xcodeproj/project.pbxproj index f2b3d2e9..4ccffc45 100644 --- a/Gem.xcodeproj/project.pbxproj +++ b/Gem.xcodeproj/project.pbxproj @@ -201,6 +201,7 @@ D8A1F87F2B17F23500B15F54 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A1F87E2B17F23500B15F54 /* SnapshotHelper.swift */; }; D8A1F8822B17F88100B15F54 /* PaymentURLDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A1F8812B17F88100B15F54 /* PaymentURLDecoder.swift */; }; D8A1F8862B17F8FB00B15F54 /* PaymentURLDecoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A1F8852B17F8FB00B15F54 /* PaymentURLDecoderTests.swift */; }; + D8AF81252C0E615B002E5FCF /* ButtonListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8AF81242C0E615B002E5FCF /* ButtonListItem.swift */; }; D8AF91F22B51BBCE002193E3 /* StakeDetailScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8AF91F12B51BBCE002193E3 /* StakeDetailScene.swift */; }; D8AF91F42B51BBEE002193E3 /* StakeDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8AF91F32B51BBEE002193E3 /* StakeDetailViewModel.swift */; }; D8B27CDD2B64402200E04154 /* GemstoneSwift in Frameworks */ = {isa = PBXBuildFile; productRef = D8B27CDC2B64402200E04154 /* GemstoneSwift */; }; @@ -455,6 +456,7 @@ D8A1F87E2B17F23500B15F54 /* SnapshotHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapshotHelper.swift; sourceTree = ""; }; D8A1F8812B17F88100B15F54 /* PaymentURLDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentURLDecoder.swift; sourceTree = ""; }; D8A1F8852B17F8FB00B15F54 /* PaymentURLDecoderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentURLDecoderTests.swift; sourceTree = ""; }; + D8AF81242C0E615B002E5FCF /* ButtonListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonListItem.swift; sourceTree = ""; }; D8AF91F12B51BBCE002193E3 /* StakeDetailScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakeDetailScene.swift; sourceTree = ""; }; D8AF91F32B51BBEE002193E3 /* StakeDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakeDetailViewModel.swift; sourceTree = ""; }; D8B977FD2AA95435009933B5 /* DeviceService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceService.swift; sourceTree = ""; }; @@ -1205,6 +1207,7 @@ children = ( D8148C2A2BF54BA30066586A /* AddressListItem.swift */, D8148C2C2BF54FB80066586A /* MemoListItem.swift */, + D8AF81242C0E615B002E5FCF /* ButtonListItem.swift */, ); path = Views; sourceTree = ""; @@ -1844,6 +1847,7 @@ C366790A2A0B7E5800F1D74D /* Environment.swift in Sources */, D848B5932AE3024200814FB4 /* ConnectionsService.swift in Sources */, C3B6F09429E7C32900C3B746 /* ConfirmTransferViewModel.swift in Sources */, + D8AF81252C0E615B002E5FCF /* ButtonListItem.swift in Sources */, D8BAC95D2BD1A3E2001608BC /* AddAssetViewModel.swift in Sources */, D801814A2B46209200F4D22B /* StakeValidatorsScene.swift in Sources */, D80700522BBB6AEC00ED770B /* ImportWalletNavigationStack.swift in Sources */, diff --git a/Gem/Connections/Scenes/ConnectionsScene.swift b/Gem/Connections/Scenes/ConnectionsScene.swift index 037e1dfe..77750e5e 100644 --- a/Gem/Connections/Scenes/ConnectionsScene.swift +++ b/Gem/Connections/Scenes/ConnectionsScene.swift @@ -37,26 +37,28 @@ struct ConnectionsScene: View { var body: some View { List { Section { - Button(Localized.Common.paste) { - guard let content = UIPasteboard.general.string else { - return - } - Task { - await connectURI(uri: content) - } - } - - Button(Localized.Wallet.scan) { - isPresentingScanner = true - } + ButtonListItem( + title: Localized.Wallet.scanQrCode, + image: Image(systemName: SystemImage.qrCode), + action: onScan + ) + ButtonListItem( + title: Localized.Common.paste, + image: Image(systemName: SystemImage.paste), + action: onPaste + ) } - ForEach(headers, id: \.self) { header in - Section( - header: Text(header.name) - ) { - ForEach(groupedByWallet[header]!) { connection in - NavigationLink(value: connection) { - ConnectionView(model: WalletConnectionViewModel(connection: connection)) + if headers.isEmpty { + StateEmptyView(message: Localized.WalletConnect.noActiveConnections) + } else { + ForEach(headers, id: \.self) { header in + Section( + header: Text(header.name) + ) { + ForEach(groupedByWallet[header]!) { connection in + NavigationLink(value: connection) { + ConnectionView(model: WalletConnectionViewModel(connection: connection)) + } } } } @@ -81,7 +83,7 @@ struct ConnectionsScene: View { } .sheet(isPresented: $isPresentingScanner) { ScanQRCodeNavigationStack(isPresenting: $isPresentingScanner) { - handleScan(value: $0) + onHandleScan(value: $0) } } .toolbar { @@ -99,14 +101,6 @@ struct ConnectionsScene: View { .navigationTitle(Localized.WalletConnect.title) } - private func handleScan(value: String) { - NSLog("handle scan value: \(value)") - - Task { - await connectURI(uri: value) - } - } - func connectURI(uri: String) async { do { try await model.addConnectionURI(uri: uri, wallet: keystore.currentWallet!) @@ -116,3 +110,27 @@ struct ConnectionsScene: View { } } } + +// MARK: Actions + +private extension ConnectionsScene { + private func onHandleScan(value: String) { + Task { + await connectURI(uri: value) + } + } + + private func onScan() { + isPresentingScanner = true + } + + private func onPaste() { + guard let content = UIPasteboard.general.string else { + return + } + + Task { + await connectURI(uri: content) + } + } +}