Skip to content

Commit

Permalink
Merge pull request #1167 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.8.7
  • Loading branch information
flypaper0 authored Oct 7, 2023
2 parents b1b2486 + 9bab50d commit bb68f8f
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 129 deletions.
19 changes: 18 additions & 1 deletion Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -226,6 +226,7 @@
A5E22D242840C8DB00E36487 /* SafariEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E22D232840C8DB00E36487 /* SafariEngine.swift */; };
A5E22D2C2840EAC300E36487 /* XCUIElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E22D2B2840EAC300E36487 /* XCUIElement.swift */; };
A5E776BA29F4362D00172091 /* AlertError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E776B929F4362D00172091 /* AlertError.swift */; };
A5F1526F2ACDC46B00D745A6 /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = A5F1526E2ACDC46B00D745A6 /* Web3ModalUI */; };
A74D32BA2A1E25AD00CB8536 /* QueryParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74D32B92A1E25AD00CB8536 /* QueryParameters.swift */; };
C5133A78294125CC00A8314C /* Web3 in Frameworks */ = {isa = PBXBuildFile; productRef = C5133A77294125CC00A8314C /* Web3 */; };
C53AA4362941251C008EA57C /* DefaultSignerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59CF4F5292F83D50031A42F /* DefaultSignerFactory.swift */; };
Expand Down Expand Up @@ -729,6 +730,7 @@
C5B2F7052970573D000DBA0E /* SolanaSwift in Frameworks */,
8487A9462A836C3F0003D5AF /* Sentry in Frameworks */,
C55D349929630D440004314A /* Web3Wallet in Frameworks */,
A5F1526F2ACDC46B00D745A6 /* Web3ModalUI in Frameworks */,
C56EE255293F569A004840D1 /* Starscream in Frameworks */,
A5B6C0F52A6EAB2800927332 /* WalletConnectNotify in Frameworks */,
C56EE27B293F56F8004840D1 /* WalletConnectAuth in Frameworks */,
Expand Down Expand Up @@ -1999,6 +2001,7 @@
A5B6C0F42A6EAB2800927332 /* WalletConnectNotify */,
84943C7C2A9BA328007EBAC2 /* Mixpanel */,
A59D25ED2AB3672700D7EA3A /* AsyncButton */,
A5F1526E2ACDC46B00D745A6 /* Web3ModalUI */,
);
productName = ChatWallet;
productReference = C56EE21B293F55ED004840D1 /* WalletApp.app */;
Expand Down Expand Up @@ -2076,6 +2079,7 @@
A561C7FE29DF32CE00DF540D /* XCRemoteSwiftPackageReference "HDWallet" */,
8487A9422A836C2A0003D5AF /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
84943C792A9BA206007EBAC2 /* XCRemoteSwiftPackageReference "mixpanel-swift" */,
A5F1526D2ACDC46B00D745A6 /* XCRemoteSwiftPackageReference "web3modal-swift" */,
);
productRefGroup = 764E1D3D26F8D3FC00A1FB15 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3215,6 +3219,14 @@
version = 3.1.2;
};
};
A5F1526D2ACDC46B00D745A6 /* XCRemoteSwiftPackageReference "web3modal-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/WalletConnect/web3modal-swift";
requirement = {
branch = "feat/ui-package";
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -3363,6 +3375,11 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnectChat;
};
A5F1526E2ACDC46B00D745A6 /* Web3ModalUI */ = {
isa = XCSwiftPackageProductDependency;
package = A5F1526D2ACDC46B00D745A6 /* XCRemoteSwiftPackageReference "web3modal-swift" */;
productName = Web3ModalUI;
};
C5133A77294125CC00A8314C /* Web3 */ = {
isa = XCSwiftPackageProductDependency;
package = A5AE354528A1A2AC0059AE8A /* XCRemoteSwiftPackageReference "Web3" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@
"revision": "569255adcfff0b37e4cb8004aea29d0e2d6266df",
"version": "1.0.2"
}
},
{
"package": "swift-web3modal",
"repositoryURL": "https://github.com/WalletConnect/web3modal-swift",
"state": {
"branch": "feat/ui-package",
"revision": "c87ab80f45452e1980b018bfabd8ec1f672c5ed3",
"version": null
}
}
]
},
Expand Down
9 changes: 9 additions & 0 deletions Example/WalletApp/Common/Extensions/UIKit/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ extension UIColor {
blue: rgb & 0xFF
)
}

func image(size: CGSize = CGSize(width: 1, height: 1)) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
setFill()
UIRectFill(CGRect(origin: CGPoint.zero, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
15 changes: 10 additions & 5 deletions Example/WalletApp/Common/VIPER/SceneViewController.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

enum NavigationBarStyle {
case translucent(UIColor)
case solid(UIColor)
case clear
}

Expand Down Expand Up @@ -30,7 +30,7 @@ extension SceneViewModel {
return .none
}
var navigationBarStyle: NavigationBarStyle {
return .translucent(.w_background)
return .solid(.w_background)
}
var preferredStatusBarStyle: UIStatusBarStyle {
return .default
Expand All @@ -56,6 +56,10 @@ class SceneViewController<ViewModel: SceneViewModel, Content: View>: UIHostingCo
super.viewDidLoad()
setupView()
setupNavigation()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupNavigationBarStyle()
}

Expand All @@ -80,10 +84,11 @@ private extension SceneViewController {

func setupNavigationBarStyle() {
switch viewModel.navigationBarStyle {
case .translucent(let color):
navigationController?.navigationBar.backgroundColor = .w_background
case .solid(let color):
navigationController?.navigationBar.setBackgroundImage(color.image(), for: .default)
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.backgroundColor = color
navigationController?.navigationBar.barTintColor = color
navigationController?.navigationBar.isTranslucent = true
case .clear:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ final class NotificationsInteractor {
func unsubscribe(topic: String) async throws {
try await Notify.instance.deleteSubscription(topic: topic)
}

func messagesCount(subscription: NotifySubscription) -> Int {
return Notify.instance.getMessageHistory(topic: subscription.topic).count
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import UIKit
import Combine
import WalletConnectNotify

final class NotificationsPresenter: ObservableObject {

private let interactor: NotificationsInteractor
private let router: NotificationsRouter
private var disposeBag = Set<AnyCancellable>()

@Published var subscriptions: [SubscriptionsViewModel] = []
@Published var listings: [ListingViewModel] = []
@Published private var subscriptions: [NotifySubscription] = []
@Published private var listings: [Listing] = []

var subscriptionViewModels: [SubscriptionsViewModel] {
return subscriptions
.map { SubscriptionsViewModel(subscription: $0) }
.sorted { lhs, rhs in
return interactor.messagesCount(subscription: lhs.subscription) > interactor.messagesCount(subscription: rhs.subscription)
}
}

var listingViewModels: [ListingViewModel] {
return listings
.map { ListingViewModel(listing: $0) }
.sorted { lhs, rhs in
return subscription(forListing: lhs) != nil && subscription(forListing: rhs) == nil
}
}

init(interactor: NotificationsInteractor, router: NotificationsRouter) {
defer { setupInitialState() }
Expand All @@ -19,11 +36,11 @@ final class NotificationsPresenter: ObservableObject {

@MainActor
func fetch() async throws {
self.listings = try await interactor.getListings().map { ListingViewModel(listing: $0) }
listings = try await interactor.getListings()
}

func subscription(forListing listing: ListingViewModel) -> SubscriptionsViewModel? {
return subscriptions.first(where: { $0.domain == listing.appDomain })
return subscriptionViewModels.first(where: { $0.domain == listing.appDomain })
}

func subscribe(listing: ListingViewModel) async throws {
Expand All @@ -50,7 +67,7 @@ final class NotificationsPresenter: ObservableObject {

func removeSubscribtion(at indexSet: IndexSet) async {
if let index = indexSet.first {
await interactor.removeSubscription(subscriptions[index].subscription)
await interactor.removeSubscription(subscriptionViewModels[index].subscription)
}
}
}
Expand All @@ -72,13 +89,12 @@ extension NotificationsPresenter: SceneViewModel {
private extension NotificationsPresenter {

func setupSubscriptions() {
self.subscriptions = interactor.getSubscriptions().map { SubscriptionsViewModel(subscription: $0) }
self.subscriptions = interactor.getSubscriptions()

interactor.subscriptionsPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] notifySubscriptions in
self?.subscriptions = notifySubscriptions
.map { SubscriptionsViewModel(subscription: $0) }
}
.store(in: &disposeBag)
}
Expand Down
Loading

0 comments on commit bb68f8f

Please sign in to comment.