Skip to content

Commit

Permalink
Merge pull request #1361 from WalletConnect/caip222-over-universal-li…
Browse files Browse the repository at this point in the history
…nking

Caip222 over universal linking
  • Loading branch information
llbartekll authored May 28, 2024
2 parents 5338c26 + 5afa672 commit c3f9c43
Show file tree
Hide file tree
Showing 86 changed files with 2,643 additions and 472 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectKMSTests"
BuildableName = "WalletConnectKMSTests"
BlueprintName = "WalletConnectKMSTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
11 changes: 11 additions & 0 deletions Example/DApp/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import WalletConnectSign

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -15,6 +16,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void) async -> Bool {
guard let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return true
}
try! Sign.instance.dispatchEnvelope(url.absoluteString)

return true
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
Expand Down
6 changes: 6 additions & 0 deletions Example/DApp/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import Foundation

enum Constants {
static let groupIdentifier = "group.com.walletconnect.dapp"
}
4 changes: 4 additions & 0 deletions Example/DApp/DApp.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!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.developer.associated-domains</key>
<array>
<string>applinks:lab.web3modal.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.walletconnect.dapp</string>
Expand Down
14 changes: 14 additions & 0 deletions Example/DApp/DAppRelease.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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.developer.associated-domains</key>
<array>
<string>applinks:lab.web3modal.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.walletconnect.dapp</string>
</array>
</dict>
</plist>
15 changes: 15 additions & 0 deletions Example/DApp/Modules/Configuration/ConfigModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SwiftUI

final class ConfigModule {
@discardableResult
static func create(app: Application) -> UIViewController {
let router = ConfigRouter(app: app)
let presenter = ConfigPresenter(router: router)
let view = ConfigView().environmentObject(presenter)

let viewController = SceneViewController(viewModel: presenter, content: view)
router.viewController = viewController

return viewController
}
}
36 changes: 36 additions & 0 deletions Example/DApp/Modules/Configuration/ConfigPresenter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import UIKit
import Combine

import WalletConnectSign

final class ConfigPresenter: ObservableObject, SceneViewModel {


private let router: ConfigRouter

init(
router: ConfigRouter
) {
defer { setupInitialState() }
self.router = router
}

func onAppear() {

}

private func setupInitialState() {

}

func cleanLinkModeSupportedWalletsCache() {
let userDefaults = UserDefaults(suiteName: Constants.groupIdentifier)!
let prefix = "com.walletconnect.sdk.linkModeLinks"
let keys = userDefaults.dictionaryRepresentation().keys

for key in keys where key.hasPrefix(prefix) {
userDefaults.removeObject(forKey: key)
}
}

}
14 changes: 14 additions & 0 deletions Example/DApp/Modules/Configuration/ConfigRouter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import Foundation
import UIKit
import WalletConnectSign

final class ConfigRouter {
weak var viewController: UIViewController!

private let app: Application

init(app: Application) {
self.app = app
}
}
53 changes: 53 additions & 0 deletions Example/DApp/Modules/Configuration/ConfigView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import SwiftUI

struct ConfigView: View {
@EnvironmentObject var presenter: ConfigPresenter

var body: some View {
NavigationStack {
ZStack {
Color(red: 25/255, green: 26/255, blue: 26/255)
.ignoresSafeArea()

ScrollView {
VStack {
Button {
presenter.cleanLinkModeSupportedWalletsCache()
} label: {
HStack {
Spacer()
Text("Clean Link Mode Supported Wallets Cache")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.padding(.vertical, 25)
Spacer()
}
.background(Color(red: 95/255, green: 159/255, blue: 248/255))
.cornerRadius(16)
}
.padding(.top, 10)
}
.padding(12)
}
.padding(.bottom, 76)
.onAppear {
presenter.onAppear()
}
}
.navigationTitle("Configuration")
.navigationBarTitleDisplayMode(.inline)
.toolbarColorScheme(.dark, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarBackground(
Color(red: 25/255, green: 26/255, blue: 26/255),
for: .navigationBar
)
}
}
}

struct ConfigView_Previews: PreviewProvider {
static var previews: some View {
ConfigView()
}
}
25 changes: 24 additions & 1 deletion Example/DApp/Modules/Sign/SignPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ final class SignPresenter: ObservableObject {
}
}

@MainActor
func connectWalletWithSessionAuthenticateLinkMode() {
Task {
do {
ActivityIndicatorManager.shared.start()
if let pairingUri = try await Sign.instance.authenticate(.stub(methods: ["personal_sign"]), walletUniversalLink: "https://lab.web3modal.com/wallet") {
walletConnectUri = pairingUri
ActivityIndicatorManager.shared.stop()
router.presentNewPairing(walletConnectUri: walletConnectUri!)
}
} catch {
AlertPresenter.present(message: error.localizedDescription, type: .error)
ActivityIndicatorManager.shared.stop()
}
}
}

@MainActor
func openConfiguration() {
router.openConfig()
}

@MainActor
func disconnect() {
if let session {
Task { @MainActor in
Expand Down Expand Up @@ -218,7 +241,7 @@ extension SignPresenter: SceneViewModel {}
// MARK: - Authenticate request stub
extension AuthRequestParams {
static func stub(
domain: String = "app.web3inbox",
domain: String = "lab.web3modal.com",
chains: [String] = ["eip155:1", "eip155:137"],
nonce: String = "32891756",
uri: String = "https://app.web3inbox.com/login",
Expand Down
4 changes: 4 additions & 0 deletions Example/DApp/Modules/Sign/SignRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ final class SignRouter {
func popToRoot() {
viewController.popToRoot()
}

func openConfig() {
ConfigModule.create(app: app).push(from: viewController)
}
}
Loading

0 comments on commit c3f9c43

Please sign in to comment.