Skip to content

Commit

Permalink
Improve Connections screen
Browse files Browse the repository at this point in the history
  • Loading branch information
gemcoder21 committed Jun 3, 2024
1 parent 737484b commit c07e8ca
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Gem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -455,6 +456,7 @@
D8A1F87E2B17F23500B15F54 /* SnapshotHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapshotHelper.swift; sourceTree = "<group>"; };
D8A1F8812B17F88100B15F54 /* PaymentURLDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentURLDecoder.swift; sourceTree = "<group>"; };
D8A1F8852B17F8FB00B15F54 /* PaymentURLDecoderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentURLDecoderTests.swift; sourceTree = "<group>"; };
D8AF81242C0E615B002E5FCF /* ButtonListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonListItem.swift; sourceTree = "<group>"; };
D8AF91F12B51BBCE002193E3 /* StakeDetailScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakeDetailScene.swift; sourceTree = "<group>"; };
D8AF91F32B51BBEE002193E3 /* StakeDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StakeDetailViewModel.swift; sourceTree = "<group>"; };
D8B977FD2AA95435009933B5 /* DeviceService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1205,6 +1207,7 @@
children = (
D8148C2A2BF54BA30066586A /* AddressListItem.swift */,
D8148C2C2BF54FB80066586A /* MemoListItem.swift */,
D8AF81242C0E615B002E5FCF /* ButtonListItem.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
74 changes: 46 additions & 28 deletions Gem/Connections/Scenes/ConnectionsScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand All @@ -81,7 +83,7 @@ struct ConnectionsScene: View {
}
.sheet(isPresented: $isPresentingScanner) {
ScanQRCodeNavigationStack(isPresenting: $isPresentingScanner) {
handleScan(value: $0)
onHandleScan(value: $0)
}
}
.toolbar {
Expand All @@ -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!)
Expand All @@ -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)
}
}
}

0 comments on commit c07e8ca

Please sign in to comment.