Skip to content

Commit

Permalink
Merge pull request #550 from WalletConnect/develop
Browse files Browse the repository at this point in the history
[Sign] Release v2.0.0
  • Loading branch information
flypaper0 authored Oct 21, 2022
2 parents 099ed68 + 996dcbd commit 791679e
Show file tree
Hide file tree
Showing 213 changed files with 3,356 additions and 2,835 deletions.
5 changes: 5 additions & 0 deletions .github/actions/ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
description: 'The endpoint of the relay e.g. relay.walletconnect.com'
required: false
default: 'relay.walletconnect.com'
project-id:
description: 'WalletConnect project id'
required: true

runs:
using: "composite"
Expand All @@ -29,12 +32,14 @@ runs:
shell: bash
env:
RELAY_ENDPOINT: ${{ inputs.relay-endpoint }}
PROJECT_ID: ${{ inputs.project-id }}
run: "xcodebuild \
-project Example/ExampleApp.xcodeproj \
-scheme IntegrationTests \
-clonedSourcePackagesDirPath SourcePackagesCache \
-destination 'platform=iOS Simulator,name=iPhone 13' \
RELAY_HOST='$RELAY_ENDPOINT' \
PROJECT_ID='$PROJECT_ID' \
test"

# Wallet build
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ jobs:
- name: Setup Xcode Version
uses: maxim-lobanov/setup-xcode@v1

- name: Resolve Dependencies
shell: bash
run: "
xcodebuild -resolvePackageDependencies -project Example/ExampleApp.xcodeproj -scheme DApp -clonedSourcePackagesDirPath SourcePackagesCache; \
xcodebuild -resolvePackageDependencies -project Example/ExampleApp.xcodeproj -scheme WalletConnect -clonedSourcePackagesDirPath SourcePackagesCache"

- uses: actions/cache@v2
with:
path: |
Expand All @@ -43,9 +37,16 @@ jobs:
restore-keys: |
${{ runner.os }}-spm-
- name: Resolve Dependencies
shell: bash
run: "
xcodebuild -resolvePackageDependencies -project Example/ExampleApp.xcodeproj -scheme DApp -clonedSourcePackagesDirPath SourcePackagesCache; \
xcodebuild -resolvePackageDependencies -project Example/ExampleApp.xcodeproj -scheme WalletConnect -clonedSourcePackagesDirPath SourcePackagesCache"

- uses: ./.github/actions/ci
with:
type: ${{ matrix.test-type }}
project-id: ${{ secrets.PROJECT_ID }}

test-ui:
if: github.ref == 'refs/heads/main'
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ Package.resolved
*/fastlane/test_output
*/fastlane/README.md

# Configuration
Configuration.xcconfig

10 changes: 10 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/WalletConnect.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectPairingTests"
BuildableName = "WalletConnectPairingTests"
BlueprintName = "WalletConnectPairingTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
4 changes: 4 additions & 0 deletions Configuration.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELAY_HOST = relay.walletconnect.com

// Uncomment next line and paste your project id. Get this on: https://cloud.walletconnect.com/sign-in
// PROJECT_ID = YOUR_PROJECT_ID
4 changes: 2 additions & 2 deletions Example/DApp/Auth/AuthCoordinator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI
import Auth
import WalletConnectPairing

final class AuthCoordinator {

Expand Down Expand Up @@ -30,8 +31,7 @@ final class AuthCoordinator {
url: "wallet.connect",
icons: ["https://avatars.githubusercontent.com/u/37784886"])

Auth.configure(metadata: metadata, account: nil)

Pair.configure(metadata: metadata)
navigationController.viewControllers = [authViewController]
}
}
15 changes: 9 additions & 6 deletions Example/DApp/Auth/AuthViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UIKit
import Combine
import Auth
import WalletConnectPairing

final class AuthViewModel: ObservableObject {

Expand All @@ -13,10 +14,10 @@ final class AuthViewModel: ObservableObject {
private var disposeBag = Set<AnyCancellable>()

@Published var state: SigningState = .none
@Published var uri: String?
@Published var uriString: String?

var qrImage: UIImage? {
return uri.map { QRCodeGenerator.generateQRCode(from: $0) }
return uriString.map { QRCodeGenerator.generateQRCode(from: $0) }
}

init() {
Expand All @@ -26,20 +27,22 @@ final class AuthViewModel: ObservableObject {
@MainActor
func setupInitialState() async throws {
state = .none
uri = nil
uri = try await Auth.instance.request(.stub()).absoluteString
uriString = nil
let uri = try! await Pair.instance.create()
uriString = uri.absoluteString
try await Auth.instance.request(.stub(), topic: uri.topic)
}

func copyDidPressed() {
UIPasteboard.general.string = uri
UIPasteboard.general.string = uriString
}

func walletDidPressed() {

}

func deeplinkPressed() {
guard let uri = uri else { return }
guard let uri = uriString else { return }
UIApplication.shared.open(URL(string: "showcase://wc?uri=\(uri)")!)
}
}
Expand Down
12 changes: 12 additions & 0 deletions Example/DApp/Common/InputConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

struct InputConfig {

static var projectId: String {
return config(for: "PROJECT_ID")!
}

private static func config(for key: String) -> String? {
return Bundle.main.object(forInfoDictionaryKey: key) as? String
}
}
2 changes: 2 additions & 0 deletions Example/DApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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>PROJECT_ID</key>
<string>$(PROJECT_ID)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>UIApplicationSceneManifest</key>
Expand Down
3 changes: 2 additions & 1 deletion Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UIKit
import Starscream
import WalletConnectRelay
import WalletConnectNetworking

extension WebSocket: WebSocketConnecting { }

Expand All @@ -18,7 +19,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private let authCoordinator = AuthCoordinator()

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
Relay.configure(projectId: "3ca2919724fbfa5456a25194e369a8b4", socketFactory: SocketFactory())
Networking.configure(projectId: InputConfig.projectId, socketFactory: SocketFactory())

setupWindow(scene: scene)
}
Expand Down
3 changes: 2 additions & 1 deletion Example/DApp/Sign/Connect/ConnectViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Foundation
import UIKit
import WalletConnectSign
import WalletConnectPairing

class ConnectViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let uri: WalletConnectURI
let activePairings: [Pairing] = Sign.instance.getPairings()
let activePairings: [Pairing] = Pair.instance.getPairings()
let segmentedControl = UISegmentedControl(items: ["Pairings", "New Pairing"])

init(uri: WalletConnectURI) {
Expand Down
10 changes: 5 additions & 5 deletions Example/DApp/Sign/ResponseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class ResponseViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
let record = Sign.instance.getSessionRequestRecord(id: response.result.id)!
let record = Sign.instance.getSessionRequestRecord(id: response.id)!
switch response.result {
case .response(let response):
responseView.nameLabel.text = "Received Response\n\(record.request.method)"
responseView.descriptionLabel.text = try! response.result.get(String.self).description
responseView.nameLabel.text = "Received Response\n\(record.method)"
responseView.descriptionLabel.text = try! response.get(String.self).description
case .error(let error):
responseView.nameLabel.text = "Received Error\n\(record.request.method)"
responseView.descriptionLabel.text = error.error.message
responseView.nameLabel.text = "Received Error\n\(record.method)"
responseView.descriptionLabel.text = error.message
}
responseView.dismissButton.addTarget(self, action: #selector(dismissSelf), for: .touchUpInside)
}
Expand Down
10 changes: 4 additions & 6 deletions Example/DApp/Sign/SelectChain/SelectChainViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import WalletConnectSign
import WalletConnectPairing
import UIKit
import Combine

Expand All @@ -15,16 +16,12 @@ class SelectChainViewController: UIViewController, UITableViewDataSource {
private var publishers = [AnyCancellable]()

let chains = [Chain(name: "Ethereum", id: "eip155:1"), Chain(name: "Polygon", id: "eip155:137")]
var onSessionSettled: ((Session) -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Available Chains"
selectChainView.tableView.dataSource = self
selectChainView.connectButton.addTarget(self, action: #selector(connect), for: .touchUpInside)
selectChainView.openWallet.addTarget(self, action: #selector(openWallet), for: .touchUpInside)
Sign.instance.sessionSettlePublisher.sink {[unowned self] session in
onSessionSettled?(session)
}.store(in: &publishers)
}

override func loadView() {
Expand All @@ -38,8 +35,9 @@ class SelectChainViewController: UIViewController, UITableViewDataSource {
let blockchains: Set<Blockchain> = [Blockchain("eip155:1")!, Blockchain("eip155:137")!]
let namespaces: [String: ProposalNamespace] = ["eip155": ProposalNamespace(chains: blockchains, methods: methods, events: [], extensions: nil)]
Task {
let uri = try await Sign.instance.connect(requiredNamespaces: namespaces)
showConnectScreen(uri: uri!)
let uri = try await Pair.instance.create()
try await Sign.instance.connect(requiredNamespaces: namespaces, topic: uri.topic)
showConnectScreen(uri: uri)
}
}

Expand Down
13 changes: 9 additions & 4 deletions Example/DApp/Sign/SignCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import UIKit
import Combine
import WalletConnectSign
import WalletConnectRelay
import WalletConnectPairing

final class SignCoordinator {

Expand All @@ -25,7 +26,7 @@ final class SignCoordinator {
url: "wallet.connect",
icons: ["https://avatars.githubusercontent.com/u/37784886"])

Sign.configure(metadata: metadata)
Pair.configure(metadata: metadata)
#if DEBUG
if CommandLine.arguments.contains("-cleanInstall") {
try? Sign.instance.cleanup()
Expand All @@ -44,6 +45,12 @@ final class SignCoordinator {
presentResponse(for: response)
}.store(in: &publishers)

Sign.instance.sessionSettlePublisher
.receive(on: DispatchQueue.main)
.sink { [unowned self] session in
showAccountsScreen(session)
}.store(in: &publishers)

if let session = Sign.instance.getSessions().first {
showAccountsScreen(session)
} else {
Expand All @@ -53,9 +60,6 @@ final class SignCoordinator {

private func showSelectChainScreen() {
let controller = SelectChainViewController()
controller.onSessionSettled = { [unowned self] session in
showAccountsScreen(session)
}
navigationController.viewControllers = [controller]
}

Expand All @@ -64,6 +68,7 @@ final class SignCoordinator {
controller.onDisconnect = { [unowned self] in
showSelectChainScreen()
}
navigationController.presentedViewController?.dismiss(animated: false)
navigationController.viewControllers = [controller]
}

Expand Down
Loading

0 comments on commit 791679e

Please sign in to comment.