Skip to content

Commit

Permalink
Merge pull request #1122 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.8.2
  • Loading branch information
llbartekll authored Sep 20, 2023
2 parents 1e7d7ba + e41c2d0 commit 4f8789b
Show file tree
Hide file tree
Showing 41 changed files with 893 additions and 358 deletions.
80 changes: 56 additions & 24 deletions Example/ExampleApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ import UIKit
struct AppearanceConfigurator: Configurator {

func configure() {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .w_background
appearance.shadowColor = .clear
appearance.titleTextAttributes = [
.foregroundColor: UIColor.w_foreground
]

UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
}
}
2 changes: 2 additions & 0 deletions Example/WalletApp/ApplicationLayer/ProfilingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import Mixpanel
import WalletConnectNetworking
import Combine
import WalletConnectNotify

final class ProfilingService {
public static var instance = ProfilingService()
Expand Down Expand Up @@ -31,6 +32,7 @@ final class ProfilingService {
mixpanel.people.set(properties: ["$name": account, "account": account])

handleLogs(from: Networking.instance.logsPublisher)
handleLogs(from: Notify.instance.logsPublisher)
}

private func handleLogs(from publisher: AnyPublisher<Log, Never>) {
Expand Down
27 changes: 1 addition & 26 deletions Example/WalletApp/BusinessLayer/ListingsSertice/Listings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,10 @@ struct Listing: Codable {
@FailableDecodable
private(set) var lg: URL?
}
struct App: Codable {
@FailableDecodable
private(set) var ios: URL?

@FailableDecodable
private(set) var android: URL?

@FailableDecodable
private(set) var browser: URL?
}
struct Mobile: Codable {
let native: String?
let universal: String?
}
struct Metadata: Codable {
struct Colors: Codable {
let primary: String?
let secondary: String?
}
let shortName: String
let colors: Colors
}
let id: String
let name: String
let description: String
let homepage: String
let image_url: ImageURL
let app: App
let mobile: Mobile
let metadata: Metadata
let chains: [String]
let dapp_url: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import HTTPClient
enum ListingsAPI: HTTPService {

var path: String {
return "/v3/dapps"
return "/w3i/v1/projects"
}

var method: HTTPMethod {
Expand All @@ -16,7 +16,7 @@ enum ListingsAPI: HTTPService {
}

var queryParameters: [String : String]? {
return ["projectId": InputConfig.projectId, "is_notify_enabled": "true"]
return ["projectId": InputConfig.projectId, "entries": "100", "is_verified": "false"]
}

var additionalHeaderFields: [String : String]? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import HTTPClient
final class ListingsNetworkService {

struct ListingsResponse: Codable {
let listings: [String: Listing]
let projects: [String: Listing]
}

func getListings() async throws -> [Listing] {
let httpClient = HTTPNetworkClient(host: "explorer-api.walletconnect.com")
let response = try await httpClient.request(ListingsResponse.self, at: ListingsAPI.notifyDApps)
return response.listings.values.compactMap { $0 }
return response.projects.values.compactMap { $0 }
}
}
52 changes: 52 additions & 0 deletions Example/WalletApp/Common/Helpers/CacheAsyncImage.swift
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
}
}
}
9 changes: 9 additions & 0 deletions Example/WalletApp/Common/VIPER/SceneViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI

enum NavigationBarStyle {
case translucent(UIColor)
case clear
}

protocol SceneViewModel {
Expand Down Expand Up @@ -80,8 +81,16 @@ private extension SceneViewController {
func setupNavigationBarStyle() {
switch viewModel.navigationBarStyle {
case .translucent(let color):
navigationController?.navigationBar.backgroundColor = .w_background
navigationController?.navigationBar.barTintColor = color
navigationController?.navigationBar.isTranslucent = true
case .clear:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.backgroundColor = .clear
navigationController?.navigationBar.barTintColor = .clear
navigationController?.navigationBar.tintColor = .w_foreground
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class AuthRequestPresenter: ObservableObject {

let importAccount: ImportAccount
let request: AuthRequest
let verified: Bool?
let validationStatus: VerifyContext.ValidationStatus?

var message: String {
return interactor.formatted(request: request, account: importAccount.account)
Expand All @@ -29,7 +29,7 @@ final class AuthRequestPresenter: ObservableObject {
self.router = router
self.importAccount = importAccount
self.request = request
self.verified = (context?.validation == .valid) ? true : (context?.validation == .unknown ? nil : false)
self.validationStatus = context?.validation
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,10 @@ struct AuthRequestView: View {
.resizable()
.scaledToFit()

HStack {
Text(presenter.request.payload.domain)
.foregroundColor(.grey8)
.font(.system(size: 22, weight: .bold, design: .rounded))

if let verified = presenter.verified {
if verified {
Image(systemName: "checkmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
} else {
Image(systemName: "xmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .red)
}
} else {
Image(systemName: "exclamationmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .orange)
}
}
.padding(.top, 10)
Text(presenter.request.payload.domain)
.foregroundColor(.grey8)
.font(.system(size: 22, weight: .bold, design: .rounded))
.padding(.top, 10)

Text("would like to connect")
.foregroundColor(.grey8)
Expand All @@ -51,8 +33,41 @@ struct AuthRequestView: View {
.lineSpacing(4)
.padding(.top, 8)

switch presenter.validationStatus {
case .unknown:
verifyBadgeView(imageName: "exclamationmark.circle.fill", title: "Cannot verify", color: .orange)

case .valid:
verifyBadgeView(imageName: "checkmark.seal.fill", title: "Verified domain", color: .blue)

case .invalid:
verifyBadgeView(imageName: "exclamationmark.triangle.fill", title: "Invalid domain", color: .red)

case .scam:
verifyBadgeView(imageName: "exclamationmark.shield.fill", title: "Security risk", color: .red)

default:
EmptyView()
}

authRequestView()

Group {
switch presenter.validationStatus {
case .invalid:
verifyDescriptionView(imageName: "exclamationmark.triangle.fill", title: "Invalid domain", description: "This domain cannot be verified. Check the request carefully before approving.", color: .red)

case .unknown:
verifyDescriptionView(imageName: "exclamationmark.circle.fill", title: "Unknown domain", description: "This domain cannot be verified. Check the request carefully before approving.", color: .orange)

case .scam:
verifyDescriptionView(imageName: "exclamationmark.shield.fill", title: "Security risk", description: "This website is flagged as unsafe by multiple security providers. Leave immediately to protect your assets.", color: .red)

default:
EmptyView()
}
}

HStack(spacing: 20) {
Button {
Task(priority: .userInitiated) { try await
Expand Down Expand Up @@ -143,7 +158,46 @@ struct AuthRequestView: View {
.background(.thinMaterial)
.cornerRadius(25, corners: .allCorners)
}
.padding(.top, 30)
.padding(.vertical, 30)
}

private func verifyBadgeView(imageName: String, title: String, color: Color) -> some View {
HStack(spacing: 5) {
Image(systemName: imageName)
.font(.system(size: 14, weight: .semibold, design: .rounded))
.foregroundColor(color)

Text(title)
.foregroundColor(color)
.font(.system(size: 14, weight: .semibold, design: .rounded))

}
.padding(5)
.background(color.opacity(0.15))
.cornerRadius(10)
.padding(.top, 8)
}

private func verifyDescriptionView(imageName: String, title: String, description: String, color: Color) -> some View {
HStack(spacing: 15) {
Image(systemName: imageName)
.font(.system(size: 20, design: .rounded))
.foregroundColor(color)

VStack(alignment: .leading, spacing: 5) {
Text(title)
.foregroundColor(color)
.font(.system(size: 14, weight: .semibold, design: .rounded))

Text(description)
.foregroundColor(.grey8)
.font(.system(size: 14, weight: .medium, design: .rounded))
}
}
.frame(maxWidth: .infinity)
.padding()
.background(color.opacity(0.15))
.cornerRadius(20)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Foundation
import WalletConnectNotify

typealias SubscriptionScope = [String: ScopeValue]

struct SubscriptionsViewModel: Identifiable {
let subscription: NotifySubscription

Expand All @@ -12,15 +14,23 @@ struct SubscriptionsViewModel: Identifiable {
return try? subscription.metadata.icons.first?.asURL()
}

var title: String {
var subtitle: String {
return subscription.metadata.description
}

var name: String {
return subscription.metadata.name
}

var subtitle: String {
var description: String {
return subscription.metadata.description
}

var url: String {
var domain: String {
return subscription.metadata.url
}

var scope: SubscriptionScope {
return subscription.scope
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class NotificationsPresenter: ObservableObject {
}

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

func subscribe(listing: ListingViewModel) async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class NotificationsRouter {
}

func presentNotifications(subscription: NotifySubscription) {
PushMessagesModule.create(app: app, subscription: subscription)
SubscriptionModule.create(app: app, subscription: subscription)
.push(from: viewController)
}
}
Loading

0 comments on commit 4f8789b

Please sign in to comment.