Skip to content

Commit

Permalink
Merge pull request #64 from WalletConnect/develop
Browse files Browse the repository at this point in the history
Bata 3
  • Loading branch information
llbartekll committed Feb 3, 2022
2 parents 673318a + 9165278 commit 784eafb
Show file tree
Hide file tree
Showing 102 changed files with 2,685 additions and 710 deletions.
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


52 changes: 52 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/IntegrationTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "IntegrationTests"
BuildableName = "IntegrationTests"
BlueprintName = "IntegrationTests"
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>
14 changes: 14 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/WalletConnect.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TestingUtils"
BuildableName = "TestingUtils"
BlueprintName = "TestingUtils"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
29 changes: 29 additions & 0 deletions Example/DApp/ Accounts/AccountsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import UIKit

final class AccountsView: UIView {
let tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.backgroundColor = .tertiarySystemBackground
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "accountCell")
return tableView
}()

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

subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 16),
tableView.leadingAnchor.constraint(equalTo: leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
])
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
87 changes: 87 additions & 0 deletions Example/DApp/ Accounts/AccountsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import UIKit
import WalletConnect

struct AccountDetails {
let chain: String
let methods: [String]
let account: String
}

final class AccountsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let client = ClientDelegate.shared.client
let session: Session
var accountsDetails: [AccountDetails] = []
var onDisconnect: (()->())?

private let accountsView: AccountsView = {
AccountsView()
}()

init(session: Session) {
self.session = session
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func loadView() {
view = accountsView
}

override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Accounts"

navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "Disconnect",
style: .plain,
target: self,
action: #selector(disconnect)
)
accountsView.tableView.dataSource = self
accountsView.tableView.delegate = self
client.logger.setLogging(level: .debug)
session.accounts.forEach { account in
let splits = account.split(separator: ":", omittingEmptySubsequences: false)
guard splits.count == 3 else { return }
let chain = String(splits[0] + ":" + splits[1])
accountsDetails.append(AccountDetails(chain: chain, methods: Array(session.permissions.methods), account: account))
}
}

@objc
private func disconnect() {
client.disconnect(topic: session.topic, reason: Reason(code: 0, message: "disconnect"))
onDisconnect?()
}

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "accountCell", for: indexPath)
let details = accountsDetails[indexPath.row]
cell.textLabel?.text = details.account
cell.imageView?.image = UIImage(named: details.chain)
cell.textLabel?.numberOfLines = 0
return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
showAccountRequestScreen(accountsDetails[indexPath.row])
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 70
}

func showAccountRequestScreen(_ details: AccountDetails) {
let vc = AccountRequestViewController(session: session, accountDetails: details)
navigationController?.pushViewController(vc, animated: true)
}

}
69 changes: 69 additions & 0 deletions Example/DApp/AccountRequest/AccountRequestView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

import UIKit
import Foundation

class AccountRequestView: UIView {
let iconView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.backgroundColor = .systemFill
imageView.layer.cornerRadius = 32
return imageView
}()

let chainLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 17.0, weight: .heavy)
return label
}()
let accountLabel: UILabel = {
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .subheadline)
label.textColor = .secondaryLabel
label.numberOfLines = 0
label.textAlignment = .center
return label
}()

let headerStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = 16
stackView.alignment = .center
return stackView
}()

let tableView = UITableView()

override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .systemBackground
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "method_cell")
addSubview(iconView)
addSubview(headerStackView)
addSubview(tableView)

headerStackView.addArrangedSubview(chainLabel)
headerStackView.addArrangedSubview(accountLabel)

subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

NSLayoutConstraint.activate([
iconView.topAnchor.constraint(equalTo: topAnchor, constant: 64),
iconView.centerXAnchor.constraint(equalTo: centerXAnchor),

headerStackView.topAnchor.constraint(equalTo: iconView.bottomAnchor, constant: 32),
headerStackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 32),
headerStackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -32),

tableView.topAnchor.constraint(equalTo: headerStackView.bottomAnchor, constant: 0),
tableView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0),
tableView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),
])
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Loading

0 comments on commit 784eafb

Please sign in to comment.