Skip to content

Commit

Permalink
Merge pull request #645 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
llbartekll authored Jan 2, 2023
2 parents 2bbbb2b + 2d79586 commit c9b6e10
Show file tree
Hide file tree
Showing 114 changed files with 2,188 additions and 321 deletions.
4 changes: 2 additions & 2 deletions Example/DApp/Sign/Connect/ConnectViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ class ConnectViewController: UIViewController, UITableViewDataSource, UITableVie
),
"solana": ProposalNamespace(
chains: [
Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!,
Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!
],
methods: [
"solana_signMessage",
"solana_signTransaction",
"solana_signTransaction"
], events: [], extensions: nil
)
]
Expand Down
4 changes: 2 additions & 2 deletions Example/DApp/Sign/SelectChain/SelectChainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class SelectChainViewController: UIViewController, UITableViewDataSource {
),
"solana": ProposalNamespace(
chains: [
Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!,
Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!
],
methods: [
"solana_signMessage",
"solana_signTransaction",
"solana_signTransaction"
], events: [], extensions: nil
)
]
Expand Down
48 changes: 48 additions & 0 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@
7694A5262874296A0001257E /* RegistryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7694A5252874296A0001257E /* RegistryTests.swift */; };
76B149F02821C03B00F05F91 /* Proposal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76B149EF2821C03B00F05F91 /* Proposal.swift */; };
76B6E39F2807A3B6004DF775 /* WalletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76B6E39E2807A3B6004DF775 /* WalletViewController.swift */; };
840BCF142949B9F900CB0655 /* WalletConnectPush in Frameworks */ = {isa = PBXBuildFile; productRef = 840BCF132949B9F900CB0655 /* WalletConnectPush */; };
840BCF162949C6C100CB0655 /* WalletConnectEcho in Frameworks */ = {isa = PBXBuildFile; productRef = 840BCF152949C6C100CB0655 /* WalletConnectEcho */; };
8439CB89293F658E00F2F2E2 /* PushMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8439CB88293F658E00F2F2E2 /* PushMessage.swift */; };
8448F1D427E4726F0000B866 /* WalletConnect in Frameworks */ = {isa = PBXBuildFile; productRef = 8448F1D327E4726F0000B866 /* WalletConnect */; };
84494388278D9C1B00CC26BB /* UIAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84494387278D9C1B00CC26BB /* UIAlertController.swift */; };
845B8D8C2934B36C0084A966 /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845B8D8B2934B36C0084A966 /* Account.swift */; };
8460DCFC274F98A10081F94C /* RequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8460DCFB274F98A10081F94C /* RequestViewController.swift */; };
847CF3AF28E3141700F1D760 /* WalletConnectPush in Frameworks */ = {isa = PBXBuildFile; productRef = 847CF3AE28E3141700F1D760 /* WalletConnectPush */; settings = {ATTRIBUTES = (Required, ); }; };
8485617D295079730064877B /* WalletConnectPairing in Frameworks */ = {isa = PBXBuildFile; productRef = 8485617C295079730064877B /* WalletConnectPairing */; };
849D7A90292665D3006A2BD4 /* WalletConnectVerify in Frameworks */ = {isa = PBXBuildFile; productRef = 849D7A8F292665D3006A2BD4 /* WalletConnectVerify */; };
849D7A93292E2169006A2BD4 /* PushTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D7A92292E2169006A2BD4 /* PushTests.swift */; };
84AA01DB28CF0CD7005D48D8 /* XCTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA01DA28CF0CD7005D48D8 /* XCTest.swift */; };
84CE641F27981DED00142511 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE641E27981DED00142511 /* AppDelegate.swift */; };
84CE642127981DED00142511 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CE642027981DED00142511 /* SceneDelegate.swift */; };
Expand Down Expand Up @@ -191,6 +197,7 @@
A5E22D222840C8D300E36487 /* WalletEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E22D212840C8D300E36487 /* WalletEngine.swift */; };
A5E22D242840C8DB00E36487 /* SafariEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E22D232840C8DB00E36487 /* SafariEngine.swift */; };
A5E22D2C2840EAC300E36487 /* XCUIElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5E22D2B2840EAC300E36487 /* XCUIElement.swift */; };
C5DD5BE1294E09E3008FD3A4 /* Web3Wallet in Frameworks */ = {isa = PBXBuildFile; productRef = C5DD5BE0294E09E3008FD3A4 /* Web3Wallet */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -237,8 +244,11 @@
7694A5252874296A0001257E /* RegistryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistryTests.swift; sourceTree = "<group>"; };
76B149EF2821C03B00F05F91 /* Proposal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Proposal.swift; sourceTree = "<group>"; };
76B6E39E2807A3B6004DF775 /* WalletViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletViewController.swift; sourceTree = "<group>"; };
8439CB88293F658E00F2F2E2 /* PushMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushMessage.swift; sourceTree = "<group>"; };
84494387278D9C1B00CC26BB /* UIAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIAlertController.swift; sourceTree = "<group>"; };
845B8D8B2934B36C0084A966 /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
8460DCFB274F98A10081F94C /* RequestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestViewController.swift; sourceTree = "<group>"; };
849D7A92292E2169006A2BD4 /* PushTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushTests.swift; sourceTree = "<group>"; };
84AA01DA28CF0CD7005D48D8 /* XCTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTest.swift; sourceTree = "<group>"; };
84CE641C27981DED00142511 /* DApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
84CE641E27981DED00142511 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -393,7 +403,10 @@
A5AE354728A1A2AC0059AE8A /* Web3 in Frameworks */,
A5434023291E6A270068F706 /* SolanaSwift in Frameworks */,
849D7A90292665D3006A2BD4 /* WalletConnectVerify in Frameworks */,
840BCF162949C6C100CB0655 /* WalletConnectEcho in Frameworks */,
8485617D295079730064877B /* WalletConnectPairing in Frameworks */,
764E1D5826F8DBAB00A1FB15 /* WalletConnect in Frameworks */,
840BCF142949B9F900CB0655 /* WalletConnectPush in Frameworks */,
A5D85226286333D500DAF5C3 /* Starscream in Frameworks */,
A5C4DD8728A2DE88006A626D /* WalletConnectRouter in Frameworks */,
);
Expand Down Expand Up @@ -437,6 +450,7 @@
847CF3AF28E3141700F1D760 /* WalletConnectPush in Frameworks */,
A5C8BE85292FE20B006CC85C /* Web3 in Frameworks */,
84DDB4ED28ABB663003D66ED /* WalletConnectAuth in Frameworks */,
C5DD5BE1294E09E3008FD3A4 /* Web3Wallet in Frameworks */,
A5E03E01286466EA00888481 /* WalletConnectChat in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -567,6 +581,14 @@
path = SessionDetails;
sourceTree = "<group>";
};
849D7A91292E2115006A2BD4 /* Push */ = {
isa = PBXGroup;
children = (
849D7A92292E2169006A2BD4 /* PushTests.swift */,
);
path = Push;
sourceTree = "<group>";
};
84CE641D27981DED00142511 /* DApp */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1095,6 +1117,7 @@
A5E03DEE286464DB00888481 /* IntegrationTests */ = {
isa = PBXGroup;
children = (
849D7A91292E2115006A2BD4 /* Push */,
84CEC64728D8A98900D081A8 /* Pairing */,
A5E03E0B28646AA500888481 /* Relay */,
A5E03E0A28646A8A00888481 /* Stubs */,
Expand Down Expand Up @@ -1130,6 +1153,8 @@
A5E03E1028646F8000888481 /* KeychainStorageMock.swift */,
A5E03DFC286465D100888481 /* Stubs.swift */,
84FE684528ACDB4700C893FF /* RequestParams.swift */,
845B8D8B2934B36C0084A966 /* Account.swift */,
8439CB88293F658E00F2F2E2 /* PushMessage.swift */,
);
path = Stubs;
sourceTree = "<group>";
Expand Down Expand Up @@ -1181,6 +1206,9 @@
A5C4DD8628A2DE88006A626D /* WalletConnectRouter */,
A5434022291E6A270068F706 /* SolanaSwift */,
849D7A8F292665D3006A2BD4 /* WalletConnectVerify */,
840BCF132949B9F900CB0655 /* WalletConnectPush */,
840BCF152949C6C100CB0655 /* WalletConnectEcho */,
8485617C295079730064877B /* WalletConnectPairing */,
);
productName = ExampleApp;
productReference = 764E1D3C26F8D3FC00A1FB15 /* WalletConnect Wallet.app */;
Expand Down Expand Up @@ -1271,6 +1299,7 @@
84DDB4EC28ABB663003D66ED /* WalletConnectAuth */,
847CF3AE28E3141700F1D760 /* WalletConnectPush */,
A5C8BE84292FE20B006CC85C /* Web3 */,
C5DD5BE0294E09E3008FD3A4 /* Web3Wallet */,
);
productName = IntegrationTests;
productReference = A5E03DED286464DB00888481 /* IntegrationTests.xctest */;
Expand Down Expand Up @@ -1547,10 +1576,13 @@
files = (
84CEC64628D89D6B00D081A8 /* PairingTests.swift in Sources */,
767DC83528997F8E00080FA9 /* EthSendTransaction.swift in Sources */,
8439CB89293F658E00F2F2E2 /* PushMessage.swift in Sources */,
A518B31428E33A6500A2CE93 /* InputConfig.swift in Sources */,
A541959E2934BFEF0035AD19 /* CacaoSignerTests.swift in Sources */,
A59CF4F6292F83D50031A42F /* DefaultSignerFactory.swift in Sources */,
A5E03E03286466F400888481 /* ChatTests.swift in Sources */,
849D7A93292E2169006A2BD4 /* PushTests.swift in Sources */,
845B8D8C2934B36C0084A966 /* Account.swift in Sources */,
84D2A66628A4F51E0088AE09 /* AuthTests.swift in Sources */,
84FE684628ACDB4700C893FF /* RequestParams.swift in Sources */,
7694A5262874296A0001257E /* RegistryTests.swift in Sources */,
Expand Down Expand Up @@ -2077,6 +2109,14 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnect;
};
840BCF132949B9F900CB0655 /* WalletConnectPush */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectPush;
};
840BCF152949C6C100CB0655 /* WalletConnectEcho */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectEcho;
};
8448F1D327E4726F0000B866 /* WalletConnect */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnect;
Expand All @@ -2085,6 +2125,10 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnectPush;
};
8485617C295079730064877B /* WalletConnectPairing */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectPairing;
};
849D7A8F292665D3006A2BD4 /* WalletConnectVerify */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectVerify;
Expand Down Expand Up @@ -2162,6 +2206,10 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnectChat;
};
C5DD5BE0294E09E3008FD3A4 /* Web3Wallet */ = {
isa = XCSwiftPackageProductDependency;
productName = Web3Wallet;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 764E1D3426F8D3FC00A1FB15 /* Project object */;
Expand Down
87 changes: 87 additions & 0 deletions Example/ExampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
import UIKit
import UserNotifications
import WalletConnectNetworking
import WalletConnectEcho
import WalletConnectPairing
import WalletConnectPush
import Combine

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
private var publishers = [AnyCancellable]()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
registerForPushNotifications()


let metadata = AppMetadata(
name: "Example Wallet",
description: "wallet description",
url: "example.wallet",
icons: ["https://avatars.githubusercontent.com/u/37784886"])

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
Task(priority: .high) { try! await Push.wallet.approve(id: id) }
}.store(in: &publishers)
Push.wallet.pushMessagePublisher.sink { pm in
print(pm)
}.store(in: &publishers)

return true
}

Expand All @@ -15,4 +45,61 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}

func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
print("Notification settings: \(settings)")
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}

func registerForPushNotifications() {
UNUserNotificationCenter.current()
.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
}
}

func modelIdentifier() -> String {
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier }
var sysinfo = utsname()
uname(&sysinfo) // ignore return value
return String(bytes: Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters)
}

func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Task(priority: .high) {
try await Echo.instance.register(deviceToken: deviceToken)
}
}

func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
) {
// TODO: when is this invoked?
print("Failed to register: \(error)")
}

}
5 changes: 5 additions & 0 deletions Example/ExampleApp/Common/InputConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ struct InputConfig {
static var projectId: String {
return config(for: "PROJECT_ID")!
}
#if targetEnvironment(simulator)
static var simulatorIdentifier: String {
return config(for: "SIMULATOR_IDENTIFIER")!
}
#endif

private static func config(for key: String) -> String? {
return Bundle.main.object(forInfoDictionaryKey: key) as? String
Expand Down
2 changes: 2 additions & 0 deletions Example/ExampleApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>PROJECT_ID</key>
<string>$(PROJECT_ID)</string>
<key>SIMULATOR_IDENTIFIER</key>
<string>$(SIMULATOR_IDENTIFIER)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand Down
10 changes: 2 additions & 8 deletions Example/ExampleApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@ import WalletConnectSign
import WalletConnectNetworking
import WalletConnectRelay
import WalletConnectPairing
import Combine

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
private var publishers = [AnyCancellable]()

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

let metadata = AppMetadata(
name: "Example Wallet",
description: "wallet description",
url: "example.wallet",
icons: ["https://avatars.githubusercontent.com/u/37784886"])

Networking.configure(projectId: InputConfig.projectId, socketFactory: DefaultSocketFactory())
Pair.configure(metadata: metadata)
#if DEBUG
if CommandLine.arguments.contains("-cleanInstall") {
try? Sign.instance.cleanup()
Expand Down
2 changes: 1 addition & 1 deletion Example/ExampleApp/Shared/Signer/SOLSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct SOLSigner {
}
}

fileprivate struct SolSignTransaction: Codable {
private struct SolSignTransaction: Codable {
let instructions: [TransactionInstruction]
let recentBlockhash: String
let feePayer: PublicKey
Expand Down
Loading

0 comments on commit c9b6e10

Please sign in to comment.