Skip to content

Commit

Permalink
Add NavigationOpenLink and simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
gemcoder21 committed Sep 10, 2024
1 parent 3ecc552 commit dda3a23
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
4 changes: 0 additions & 4 deletions Gem/Asset/AssetScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ extension AssetScene {

@MainActor
private func onOpenLink(_ url: URL) {
// TODO: - find issue why we can't use @Environment(\.openURL) private var openURL here
// once we add native env url openning, we go to recursion on NavigationLink(value: model.assetModel.asset) { }
// AssetSceneViewModel recreates infinitly
guard UIApplication.shared.canOpenURL(url) else { return }
UIApplication.shared.open(url)
}

Expand Down
4 changes: 1 addition & 3 deletions Gem/Assets/Scenes/AddTokenScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ extension AddTokenScene {
}
if let url = asset.explorerUrl {
Section {
NavigationCustomLink(with: ListItemView(title: asset.explorerText)) {
UIApplication.shared.open(url)
}
NavigationOpenLink(url: url, with: ListItemView(title: asset.explorerText))
}
}
case .error(let error):
Expand Down
7 changes: 4 additions & 3 deletions Gem/Charts/Scenes/ChartScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ struct ChartScene: View {
}
Section(Localized.Social.links) {
ForEach(details.socialUrls) { link in
NavigationCustomLink(with: ListItemView(title: link.type.name, image: link.type.image)) {
UIApplication.shared.open(link.url)
}
NavigationOpenLink(
url: link.url,
with: ListItemView(title: link.type.name, image: link.type.image)
)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Gem/Fiat/Scenes/BuyAssetScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ extension BuyAssetScene {
guard let quote = model.input.quote,
let url = URL(string: quote.redirectUrl) else { return }

// TODO: - use new @Environment(\.openURL) var openURL, insead use UIKit UIApplication
// currently impossible to use due navigation issues in nav stack
UIApplication.shared.open(url, options: [:])
}

Expand Down
9 changes: 4 additions & 5 deletions Gem/Settings/Scenes/SettingsScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,15 @@ extension SettingsScene {

private var aboutSection: some View {
Section {

ListItemView(
NavigationOpenLink(url: model.helpCenterURL, with: ListItemView(
title: model.helpCenterTitle,
image: model.helpCenterImage
)
))

ListItemView(
NavigationOpenLink(url: model.supportURL, with: ListItemView(
title: model.supportTitle,
image: model.supportImage
)
))

NavigationLink(value: Scenes.AboutUs()) {
ListItemView(
Expand Down
2 changes: 2 additions & 0 deletions Gem/Settings/ViewModels/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ class SettingsViewModel: ObservableObject {

var helpCenterTitle: String { Localized.Settings.helpCenter }
var helpCenterImage: Image { Image(.settingsHelpCenter) }
var helpCenterURL: URL { Docs.url(.start) }

var supportTitle: String { Localized.Settings.support }
var supportImage: Image { Image(.settingsSupport) }
var supportURL: URL { PublicConstants.url(.support) }

var developerModeTitle: String { Localized.Settings.developer }
var developerModeImage: Image { Image(.settingsDeveloper) }
Expand Down
13 changes: 5 additions & 8 deletions Gem/Transactions/Scenes/TransactionScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,11 @@ struct TransactionScene: View {
}

Section {
Button(role: .none) {
UIApplication.shared.open(model.transactionExplorerUrl)
} label: {
HStack {
Text(model.transactionExplorerText)
.tint(Colors.black)
}
}
NavigationOpenLink(
url: model.transactionExplorerUrl,
with: Text(model.transactionExplorerText)
.tint(Colors.black)
)
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions Packages/Components/Sources/NavigationOpenLink.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Foundation
import SwiftUI

public struct NavigationOpenLink<Content: View>: View {
private let url: URL
private let content: Content

public init(
url: URL,
with content: Content
) {
self.url = url
self.content = content
}

public var body: some View {
NavigationCustomLink(with: content) {
UIApplication.shared.open(url)
}
}
}

0 comments on commit dda3a23

Please sign in to comment.