-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1123 from WalletConnect/feature/notify-sample-part-2
[Notify] Sample Subscription and Preferences screens
- Loading branch information
Showing
26 changed files
with
631 additions
and
266 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import SwiftUI | ||
|
||
struct CacheAsyncImage<Content>: View where Content: View{ | ||
|
||
private let url: URL? | ||
private let scale: CGFloat | ||
private let transaction: Transaction | ||
private let content: (AsyncImagePhase) -> Content | ||
|
||
init( | ||
url: URL?, | ||
scale: CGFloat = 1.0, | ||
transaction: Transaction = Transaction(), | ||
@ViewBuilder content: @escaping (AsyncImagePhase) -> Content | ||
){ | ||
self.url = url | ||
self.scale = scale | ||
self.transaction = transaction | ||
self.content = content | ||
} | ||
|
||
var body: some View{ | ||
if let url, let cached = ImageCache[url] { | ||
content(.success(cached)) | ||
} else { | ||
AsyncImage( | ||
url: url, | ||
scale: scale, | ||
transaction: transaction | ||
){ phase in | ||
cacheAndRender(phase: phase) | ||
} | ||
} | ||
} | ||
func cacheAndRender(phase: AsyncImagePhase) -> some View{ | ||
if case .success (let image) = phase, let url { | ||
ImageCache[url] = image | ||
} | ||
return content(phase) | ||
} | ||
} | ||
fileprivate class ImageCache{ | ||
static private var cache: [URL: Image] = [:] | ||
static subscript(url: URL) -> Image?{ | ||
get{ | ||
ImageCache.cache[url] | ||
} | ||
set{ | ||
ImageCache.cache[url] = newValue | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
Example/WalletApp/PresentationLayer/Wallet/NotifySettings/NotifyPreferencesInteractor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import WalletConnectNotify | ||
|
||
final class NotifyPreferencesInteractor { | ||
|
||
func updatePreferences(subscription: NotifySubscription, scope: Set<String>) async throws { | ||
try await Notify.instance.update(topic: subscription.topic, scope: scope) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Example/WalletApp/PresentationLayer/Wallet/NotifySettings/NotifyPreferencesModule.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import SwiftUI | ||
import WalletConnectNotify | ||
|
||
final class NotifyPreferencesModule { | ||
|
||
@discardableResult | ||
static func create(app: Application, subscription: NotifySubscription) -> UIViewController { | ||
let router = NotifyPreferencesRouter(app: app) | ||
let interactor = NotifyPreferencesInteractor() | ||
let presenter = NotifyPreferencesPresenter(subscription: subscription, interactor: interactor, router: router) | ||
let view = NotifyPreferencesView().environmentObject(presenter) | ||
let viewController = SceneViewController(viewModel: presenter, content: view) | ||
|
||
router.viewController = viewController | ||
|
||
return viewController | ||
} | ||
|
||
} |
Oops, something went wrong.