Skip to content

Commit

Permalink
Merge pull request #677 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
llbartekll authored Jan 20, 2023
2 parents 53e3c5f + 8066e0b commit a342261
Show file tree
Hide file tree
Showing 63 changed files with 1,100 additions and 287 deletions.
290 changes: 244 additions & 46 deletions Example/ExampleApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

40 changes: 18 additions & 22 deletions Example/ExampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import UIKit
import UserNotifications
import WalletConnectNetworking
import WalletConnectEcho
import WalletConnectPairing
import WalletConnectPush
import Combine
Expand All @@ -23,13 +22,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
Networking.configure(projectId: InputConfig.projectId, socketFactory: DefaultSocketFactory())
Pair.configure(metadata: metadata)

let clientId = try! Networking.interactor.getClientId()
let sanitizedClientId = clientId.replacingOccurrences(of: "did:key:", with: "")

Echo.configure(projectId: InputConfig.projectId, clientId: sanitizedClientId)
Push.wallet.requestPublisher.sink { id, _ in
Push.configure()
Push.wallet.requestPublisher.sink { (id: RPCID, account: Account, metadata: AppMetadata) in
Task(priority: .high) { try! await Push.wallet.approve(id: id) }
}.store(in: &publishers)

Push.wallet.pushMessagePublisher.sink { pm in
print(pm)
}.store(in: &publishers)
Expand Down Expand Up @@ -61,20 +58,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
.requestAuthorization(
options: [.alert, .sound, .badge]) { [weak self] granted, _ in
print("Permission granted: \(granted)")
guard granted else { return }
self?.getNotificationSettings()
#if targetEnvironment(simulator)

// let clientId = try! Networking.interactor.socketConnectionStatusPublisher
// .first {$0 == .connected}
// .sink(receiveValue: { status in
// let deviceToken = InputConfig.simulatorIdentifier
// assert(deviceToken != "SIMULATOR_IDENTIFIER", "Please set your Simulator identifier")
// Task(priority: .high) {
// try await Echo.instance.register(deviceToken: deviceToken)
// }
// })
#endif
guard granted else { return }
self?.getNotificationSettings()
#if targetEnvironment(simulator)
Networking.interactor.socketConnectionStatusPublisher
.first {$0 == .connected}
.sink{ status in
let deviceToken = InputConfig.simulatorIdentifier
assert(deviceToken != "SIMULATOR_IDENTIFIER", "Please set your Simulator identifier")
Task(priority: .high) {
try await Push.wallet.register(deviceToken: deviceToken)
}
}.store(in: &self!.publishers)
#endif
}
}

Expand All @@ -90,7 +86,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Task(priority: .high) {
try await Echo.instance.register(deviceToken: deviceToken)
try await Push.wallet.register(deviceToken: deviceToken)
}
}

Expand All @@ -101,5 +97,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// TODO: when is this invoked?
print("Failed to register: \(error)")
}

}

1 change: 1 addition & 0 deletions Example/IntegrationTests/Pairing/PairingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ final class PairingTests: XCTestCase {
walletPushClient = WalletPushClientFactory.create(logger: pushLogger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
groupKeychainStorage: KeychainStorageMock(),
networkInteractor: networkingInteractor,
pairingRegisterer: pairingClient,
echoClient: echoClient)
Expand Down
13 changes: 7 additions & 6 deletions Example/IntegrationTests/Push/PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ final class PushTests: XCTestCase {
walletPushClient = WalletPushClientFactory.create(logger: pushLogger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
groupKeychainStorage: KeychainStorageMock(),
networkInteractor: networkingInteractor,
pairingRegisterer: pairingClient,
echoClient: echoClient)
Expand All @@ -90,7 +91,7 @@ final class PushTests: XCTestCase {
try! await walletPairingClient.pair(uri: uri)
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic)

walletPushClient.requestPublisher.sink { (_, _) in
walletPushClient.requestPublisher.sink { (_, _, _) in
expectation.fulfill()
}
.store(in: &publishers)
Expand All @@ -104,7 +105,7 @@ final class PushTests: XCTestCase {
try! await walletPairingClient.pair(uri: uri)
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic)

walletPushClient.requestPublisher.sink { [unowned self] (id, _) in
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in

Task(priority: .high) { try! await walletPushClient.approve(id: id) }
}.store(in: &publishers)
Expand All @@ -127,7 +128,7 @@ final class PushTests: XCTestCase {
try! await walletPairingClient.pair(uri: uri)
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic)

walletPushClient.requestPublisher.sink { [unowned self] (id, _) in
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in

Task(priority: .high) { try! await walletPushClient.reject(id: id) }
}.store(in: &publishers)
Expand All @@ -150,7 +151,7 @@ final class PushTests: XCTestCase {
try! await walletPairingClient.pair(uri: uri)
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic)

walletPushClient.requestPublisher.sink { [unowned self] (id, _) in
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in
Task(priority: .high) { try! await walletPushClient.approve(id: id) }
}.store(in: &publishers)

Expand Down Expand Up @@ -178,7 +179,7 @@ final class PushTests: XCTestCase {
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic)
var subscriptionTopic: String!

walletPushClient.requestPublisher.sink { [unowned self] (id, _) in
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in
Task(priority: .high) { try! await walletPushClient.approve(id: id) }
}.store(in: &publishers)

Expand All @@ -205,7 +206,7 @@ final class PushTests: XCTestCase {
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic)
var subscriptionTopic: String!

walletPushClient.requestPublisher.sink { [unowned self] (id, _) in
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in
Task(priority: .high) { try! await walletPushClient.approve(id: id) }
}.store(in: &publishers)

Expand Down
13 changes: 13 additions & 0 deletions Example/PushDecryptionService/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>
</dict>
</plist>
42 changes: 42 additions & 0 deletions Example/PushDecryptionService/NotificationService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//

import UserNotifications
import WalletConnectPush

class NotificationService: UNNotificationServiceExtension {

var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
let topic = bestAttemptContent.userInfo["topic"] as! String
let ciphertext = bestAttemptContent.userInfo["ciphertext"] as! String
do {
let service = PushDecryptionService()
let pushMessage = try service.decryptMessage(topic: topic, ciphertext: ciphertext)
bestAttemptContent.title = pushMessage.title
bestAttemptContent.body = pushMessage.body
contentHandler(bestAttemptContent)
return
}
catch {
print(error)
}
bestAttemptContent.title = ""
bestAttemptContent.body = "content not set"
contentHandler(bestAttemptContent)
}
}

override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}

}
10 changes: 10 additions & 0 deletions Example/PushDecryptionService/PushDecryptionService.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.walletconnect.sdk</string>
</array>
</dict>
</plist>
21 changes: 21 additions & 0 deletions Example/UITests/Regression/PushNotificationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import XCTest

class PushNotificationTests: XCTestCase {
let wallet = XCUIApplication(bundleIdentifier: "com.walletconnect.example")
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")

func testPushNotification() {
wallet.launch()

sleep(1)

// Launch springboard
springboard.activate()
let text = "Is this working"

let notification = springboard.otherElements["Notification"].descendants(matching: .any)["NotificationShortLookView"]
XCTAssertTrue(notification.waitForExistence(timeout: 5))
notification.tap()
}
}
1 change: 0 additions & 1 deletion Example/UITests/Regression/RegressionTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import XCTest

class PairingTests: XCTestCase {

private let engine: Engine = Engine()

override class func setUp() {
Expand Down
4 changes: 4 additions & 0 deletions Example/Wallet.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<array>
<string>applinks:walletconnect.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.walletconnect.sdk</string>
</array>
</dict>
</plist>
3 changes: 0 additions & 3 deletions Example/WalletApp/Common/Types/Types.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "welcome-dark.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "welcome-light.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ struct AuthRequestView: View {
.padding(.top, 9)

VStack(spacing: 0) {
HStack {
ScrollView {
Text(presenter.message)
.foregroundColor(.grey50)
.font(.system(size: 13, weight: .semibold, design: .rounded))

Spacer()
}
.padding(.horizontal, 18)
.padding(.vertical, 10)
.frame(height: 250)
}
.background(Color.whiteBackground)
.cornerRadius(20, corners: .allCorners)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Foundation

import Web3Wallet

final class SessionProposalInteractor {
lazy var accounts = [
"eip155": ETHSigner.address,
"solana": SOLSigner.address
]

func approve(proposal: Session.Proposal) async throws {
var sessionNamespaces = [String: SessionNamespace]()
proposal.requiredNamespaces.forEach {
let caip2Namespace = $0.key
let proposalNamespace = $0.value
let accounts = Set(proposalNamespace.chains.compactMap { Account($0.absoluteString + ":\(self.accounts[$0.namespace]!)") })

let extensions: [SessionNamespace.Extension]? = proposalNamespace.extensions?.map { element in
let accounts = Set(element.chains.compactMap { Account($0.absoluteString + ":\(self.accounts[$0.namespace]!)") })
return SessionNamespace.Extension(accounts: accounts, methods: element.methods, events: element.events)
}
let sessionNamespace = SessionNamespace(accounts: accounts, methods: proposalNamespace.methods, events: proposalNamespace.events, extensions: extensions)
sessionNamespaces[caip2Namespace] = sessionNamespace
}

try await Web3Wallet.instance.approve(proposalId: proposal.id, namespaces: sessionNamespaces)
}

func reject(proposal: Session.Proposal) async throws {
try await Web3Wallet.instance.reject(proposalId: proposal.id, reason: .userRejected)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SwiftUI

import Web3Wallet

final class SessionProposalModule {
@discardableResult
static func create(app: Application, proposal: Session.Proposal) -> UIViewController {
let router = SessionProposalRouter(app: app)
let interactor = SessionProposalInteractor()
let presenter = SessionProposalPresenter(
interactor: interactor,
router: router,
proposal: proposal
)
let view = SessionProposalView().environmentObject(presenter)
let viewController = SceneViewController(viewModel: presenter, content: view)

router.viewController = viewController

return viewController
}
}
Loading

0 comments on commit a342261

Please sign in to comment.