Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#56 query record by id #59

Merged
merged 19 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ jobs:
run: swift build -v
- name: Run tests
run: swift test -v
- name: Test Example App
- name: Test Wallet
working-directory: ./Example
run: fastlane test_app
run: fastlane test_wallet
- name: Test Dapp
working-directory: ./Example
run: fastlane test_dapp


Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AccountRequestViewController: UIViewController, UITableViewDelegate, UITab


let request = Request(topic: session.topic, method: method, params: requestParams, chainId: chainId)
client.request(params: request) { _ in }
client.request(params: request)
presentConfirmationAlert()
}

Expand Down
18 changes: 18 additions & 0 deletions Example/DApp/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,91 +1,109 @@
{
"images" : [
{
"filename" : "Icon-App-20x20@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "Icon-App-20x20@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"filename" : "Icon-App-29x29@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "Icon-App-29x29@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"filename" : "Icon-App-40x40@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "Icon-App-40x40@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"filename" : "Icon-App-60x60@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"filename" : "Icon-App-60x60@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"filename" : "Icon-App-20x20@1x.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"filename" : "Icon-App-20x20@2x-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "Icon-App-29x29@1x.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"filename" : "Icon-App-29x29@2x-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "Icon-App-40x40@1x.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"filename" : "Icon-App-40x40@2x-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "Icon-App-76x76@1x.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"filename" : "Icon-App-76x76@2x.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"filename" : "Icon-App-83.5x83.5@2x.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"filename" : "ItunesArtwork@2x.png",
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Example/DApp/ClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ClientDelegate: WalletConnectClientDelegate {
var onPairingSettled: ((Pairing)->())?
var onSessionProposal: ((Session.Proposal)->())?
var onSessionRequest: ((Request)->())?
var onSessionResponse: ((Response)->())?
var onSessionRejected: ((String, Reason)->())?
var onSessionDelete: (()->())?
var onSessionUpgrade: ((String, Session.Permissions)->())?
Expand Down Expand Up @@ -62,4 +63,7 @@ class ClientDelegate: WalletConnectClientDelegate {
func didUpdate(pairingTopic: String, appMetadata: AppMetadata) {
onPairingUpdate?(pairingTopic, appMetadata)
}
func didReceive(sessionResponse: Response) {
onSessionResponse?(sessionResponse)
}
}
29 changes: 27 additions & 2 deletions Example/DApp/Connect/ConnectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Foundation
import UIKit

final class ConnectView: UIView {
let tableView = UITableView()

let qrCodeView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
Expand All @@ -20,16 +22,34 @@ final class ConnectView: UIView {
return button
}()

let connectWalletButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Connect Wallet", for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 17.0, weight: .semibold)
button.backgroundColor = .systemBlue
button.tintColor = .white
button.layer.cornerRadius = 8
return button
}()

override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .systemBackground
addSubview(qrCodeView)
addSubview(copyButton)

addSubview(connectWalletButton)
addSubview(tableView)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "pairing_cell")
subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

NSLayoutConstraint.activate([
qrCodeView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 64),
tableView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),


qrCodeView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 50),
qrCodeView.centerXAnchor.constraint(equalTo: centerXAnchor),
qrCodeView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.6),
qrCodeView.widthAnchor.constraint(equalTo: qrCodeView.heightAnchor),
Expand All @@ -38,6 +58,11 @@ final class ConnectView: UIView {
copyButton.centerXAnchor.constraint(equalTo: centerXAnchor),
copyButton.widthAnchor.constraint(equalTo: qrCodeView.widthAnchor),
copyButton.heightAnchor.constraint(equalToConstant: 44),

connectWalletButton.topAnchor.constraint(equalTo: copyButton.bottomAnchor, constant: 16),
connectWalletButton.centerXAnchor.constraint(equalTo: centerXAnchor),
connectWalletButton.widthAnchor.constraint(equalTo: copyButton.widthAnchor),
connectWalletButton.heightAnchor.constraint(equalToConstant: 44),
])
}

Expand Down
62 changes: 61 additions & 1 deletion Example/DApp/Connect/ConnectViewController.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@

import Foundation
import UIKit
import WalletConnect

class ConnectViewController: UIViewController {
class ConnectViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let uriString: String
let activePairings: [Pairing] = ClientDelegate.shared.client.getSettledPairings()
let segmentedControl = UISegmentedControl(items: ["Pairings", "New Pairing"])

init(uri: String) {
self.uriString = uri
super.init(nibName: nil, bundle: nil)
Expand Down Expand Up @@ -32,9 +36,26 @@ class ConnectViewController: UIViewController {
}
}
connectView.copyButton.addTarget(self, action: #selector(copyURI), for: .touchUpInside)
connectView.connectWalletButton.addTarget(self, action: #selector(connectWithExampleWallet), for: .touchUpInside)
connectView.tableView.dataSource = self
connectView.tableView.delegate = self
connectView.copyButton.isHidden = true
setUpSegmentedControl()
}

func setUpSegmentedControl() {
segmentedControl.selectedSegmentIndex = 0
self.navigationItem.titleView = segmentedControl
segmentedControl.addTarget(self, action: #selector(segmentAction), for: .valueChanged)
}

@objc func segmentAction() {
if segmentedControl.selectedSegmentIndex == 0 {
connectView.tableView.isHidden = false
} else {
connectView.tableView.isHidden = true
}
}

@objc func copyURI() {
UIPasteboard.general.string = uriString
Expand All @@ -51,4 +72,43 @@ class ConnectViewController: UIViewController {
}
return nil
}

@objc func connectWithExampleWallet() {
let url = URL(string: "walletconnectwallet:\(uriString)")!
UIApplication.shared.open(url, options: [:]) { [weak self] _ in
self?.dismiss(animated: true, completion: nil)
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
activePairings.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "pairing_cell", for: indexPath)
cell.textLabel?.text = activePairings[indexPath.row].peer!.name
return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let pairingTopic = activePairings[indexPath.row].topic
let permissions = Session.Permissions(
blockchains: ["eip155:1", "eip155:137"],
methods: ["eth_sendTransaction", "personal_sign", "eth_signTypedData"],
notifications: []
)
_ = try! ClientDelegate.shared.client.connect(sessionPermissions: permissions, topic: pairingTopic)
presentConfirmationAlert()
}

private func presentConfirmationAlert() {
let url = URL(string: "walletconnectwallet:")!
UIApplication.shared.open(url, options: [:]) { [weak self] _ in
self?.dismiss(animated: true, completion: nil)
}
let alert = UIAlertController(title: "Session Proposal Sent", message: "You can open a wallet now", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .cancel)
alert.addAction(action)
present(alert, animated: true)
}
}
39 changes: 0 additions & 39 deletions Example/DApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>dApp</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand All @@ -41,24 +21,5 @@
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Loading