-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from WalletConnect/develop
Bata 3
- Loading branch information
Showing
102 changed files
with
2,685 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.swiftpm/xcode/xcshareddata/xcschemes/IntegrationTests.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
Oops, something went wrong.