Skip to content

Commit b267da1

Browse files
Merge pull request #495 from mloit/feature/pre-swiftlint-cleanup
2 parents cc9b109 + 9412b3b commit b267da1

File tree

114 files changed

+2274
-2631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2274
-2631
lines changed

Package.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version: 5.4
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

6-
76
#if os(macOS)
87
let excludeFiles = [
9-
"./Browser/BrowserViewController.swift", // Because of inheriting iOS only class failed to build on macOS.
8+
"./Browser/BrowserViewController.swift" // Because of inheriting iOS only class failed to build on macOS.
109
]
1110
#elseif os(iOS)
1211
let excludeFiles: String = []
@@ -20,7 +19,7 @@ let package = Package(
2019
products: [
2120
.library(name: "web3swift", targets: ["web3swift"])
2221
],
23-
22+
2423
dependencies: [
2524
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
2625
.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.16.2"),
@@ -60,6 +59,6 @@ let package = Package(
6059
.copy("../../../TestToken/Helpers/TokenBasics/IERC20.sol"),
6160
.copy("../../../TestToken/Token/Web3SwiftToken.sol")
6261
]
63-
),
62+
)
6463
]
6564
)

[email protected]

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// swift-tools-version:5.0
1+
// swift-tools-version: 5.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "Web3swift",
88
platforms: [
9-
.macOS(.v10_12), .iOS(.v11),
9+
.macOS(.v10_12), .iOS(.v11)
1010
],
1111
products: [
1212
// Products define the executables and libraries produced by a package, and make them visible to other packages.
1313
.library(name: "web3swift", targets: ["web3swift"]),
1414
],
15-
15+
1616
dependencies: [
1717
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
1818
.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.15.4"),
1919
.package(url: "https://github.com/daltoniam/Starscream.git", from: "4.0.4"),
20-
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.4.2"),
20+
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.4.2")
2121
],
2222
targets: [
2323
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -30,6 +30,6 @@ let package = Package(
3030
]),
3131
.testTarget(
3232
name: "web3swiftTests",
33-
dependencies: ["web3swift"]),
33+
dependencies: ["web3swift"])
3434
]
3535
)

Sources/web3swift/Browser/Bridge.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,76 @@ import WebKit
1010

1111
/// Bridge for WKWebView and JavaScript
1212
open class Bridge: NSObject {
13-
13+
1414
static let name: String = "pacific"
15-
15+
1616
fileprivate static let callbackEventName = "PacificDidReceiveNativeCallback"
1717
fileprivate static let postEventName = "PacificDidReceiveNativeBroadcast"
18-
18+
1919
fileprivate enum MessageKey {
2020
static let action = "action"
2121
static let parameters = "parameters"
2222
static let callback = "callback"
2323
static let printable = "print"
2424
}
25-
25+
2626
public struct JSError {
2727
public let code: Int
2828
public let description: String
29-
29+
3030
public init(code: Int, description: String) {
3131
self.code = code
3232
self.description = description
3333
}
3434
}
35-
35+
3636
/// Used to callback to webpage whether a message from webpage was handled successful or encountered an error.
3737
///
3838
/// - success: The result of message was successful
3939
///
4040
/// - failure: Unable to handle the message, notify js with error by **Object Error** { code: Int, description: String}
4141
///
4242
public enum Results {
43-
43+
4444
case success([String: Any]?)
45-
45+
4646
case failure(JSError)
4747
}
48-
48+
4949
/// Bridge Callback to webpage
5050
/// - Parameter results: Value pass to webpage
5151
public typealias Callback = (_ results: Results) -> Void
52-
52+
5353
/// Closure when js send message to native
5454
/// - Parameter parameters: js parameters
5555
/// - Parameter callback: callback func
5656
public typealias Handler = (_ parameters: [String: Any]?, _ callback: @escaping Callback) -> Void
57-
57+
5858
public typealias DefaultHandler = (_ name: String, _ parameters: [String: Any]?, _ callback: @escaping Callback) -> Void
59-
59+
6060
private(set) var handlers = [String: Handler]()
61-
61+
6262
public var defaultHandler: DefaultHandler?
63-
63+
6464
fileprivate let configuration: WKWebViewConfiguration
6565
fileprivate weak var webView: WKWebView?
66-
66+
6767
/// Print message body from webpage automatically.
6868
public var printScriptMessageAutomatically = false
69-
69+
7070
deinit {
7171
configuration.removeObserver(self, forKeyPath: #keyPath(WKWebViewConfiguration.userContentController))
7272
configuration.userContentController.removeScriptMessageHandler(forName: Bridge.name)
7373
}
74-
74+
7575
fileprivate init(webView: WKWebView) {
7676
self.webView = webView
7777
self.configuration = webView.configuration
7878
super.init()
7979
configuration.addObserver(self, forKeyPath: #keyPath(WKWebViewConfiguration.userContentController), options: [.new, .old], context: nil)
8080
configuration.userContentController.add(self, name: Bridge.name)
8181
}
82-
82+
8383
/// Register to handle action
8484
/// - Parameter handler: closure when handle message from webpage
8585
/// - parameter action: name of action
@@ -95,13 +95,13 @@ open class Bridge: NSObject {
9595
public func register(_ handler: @escaping Handler, for action: String) {
9696
handlers[action] = handler
9797
}
98-
98+
9999
/// Unregister an action
100100
/// - Parameters action: name of action
101101
public func unregister(for action: String) {
102102
handlers[action] = nil
103103
}
104-
104+
105105
/// send action to webpage
106106
/// - Parameter action: action listened by js `window.bridge.on(**action**, handler)`
107107
/// - Parameter parameters: parameters pass to js
@@ -114,16 +114,16 @@ open class Bridge: NSObject {
114114
guard let webView = webView else { return }
115115
webView.st_dispatchBridgeEvent(Bridge.postEventName, parameters: ["name": action], results: .success(parameters), completionHandler: nil)
116116
}
117-
117+
118118
/// Evaluates the given JavaScript string.
119119
/// - Parameter javaScriptString: The JavaScript string to evaluate.
120120
/// - Parameter completion: A block to invoke when script evaluation completes or fails.
121121
public func evaluate(_ javaScriptString: String, completion: ((Any?, Error?) -> Void)? = nil) {
122122
guard let webView = webView else { return }
123123
webView.evaluateJavaScript(javaScriptString, completionHandler: completion)
124124
}
125-
126-
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
125+
126+
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
127127
if let obj = object as? WKWebViewConfiguration, let kp = keyPath, obj == configuration && kp == #keyPath(WKWebViewConfiguration.userContentController) {
128128
if let change = change {
129129
if let oldContentController = change[.oldKey] as? WKUserContentController {
@@ -138,7 +138,7 @@ open class Bridge: NSObject {
138138
}
139139

140140
extension Bridge: WKScriptMessageHandler {
141-
141+
142142
/*! @abstract Invoked when a script message is received from a webpage.
143143
@param userContentController The user content controller invoking the
144144
delegate method.
@@ -171,7 +171,7 @@ extension Bridge: WKScriptMessageHandler {
171171
}
172172
return
173173
}
174-
174+
175175
if let callbackID = (body[MessageKey.callback] as? NSNumber) {
176176
handler(body[MessageKey.parameters] as? [String: Any]) { [weak self] (results) in
177177
guard let strongSelf = self else {
@@ -190,11 +190,11 @@ extension Bridge: WKScriptMessageHandler {
190190
}
191191

192192
public extension WKWebView {
193-
193+
194194
private struct STPrivateStatic {
195195
fileprivate static var bridgeKey = "STPrivateStatic.bridgeKey"
196196
}
197-
197+
198198
/// Bridge for WKWebView and JavaScript. Initialize `lazy`
199199
var bridge: Bridge {
200200
if let bridge = objc_getAssociatedObject(self, &STPrivateStatic.bridgeKey) as? Bridge {
@@ -204,7 +204,7 @@ public extension WKWebView {
204204
objc_setAssociatedObject(self, &STPrivateStatic.bridgeKey, bridge, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
205205
return bridge
206206
}
207-
207+
208208
/// Remove Bridge And Reset, All the handlers will be removed
209209
func removeBridge() {
210210
if let bridge = objc_getAssociatedObject(self, &STPrivateStatic.bridgeKey) as? Bridge {
@@ -216,12 +216,12 @@ public extension WKWebView {
216216
}
217217

218218
fileprivate extension WKWebView {
219-
219+
220220
func st_dispatchBridgeEvent(_ eventName: String,
221221
parameters: [String: Any],
222222
results: Bridge.Results,
223223
completionHandler: ((Any?, Error?) -> Void)? = nil) {
224-
224+
225225
var eventDetail: [String: Any] = parameters
226226
switch results {
227227
case .failure(let error):
@@ -234,7 +234,7 @@ fileprivate extension WKWebView {
234234
if
235235
let _data = try? JSONSerialization.data(withJSONObject: eventBody, options: JSONSerialization.WritingOptions()),
236236
let eventString = String(data: _data, encoding: .utf8) {
237-
237+
238238
jsString = "(function() { var event = new CustomEvent('\(eventName)', \(eventString)); document.dispatchEvent(event)}());"
239239
} else {
240240
// When JSON Not Serializable, Invoke with Default Parameters

Sources/web3swift/Browser/BrowserViewController.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import WebKit
1010

1111
// FIXME: Rewrite me, because i'm building only on iOS.
1212
open class BrowserViewController: UIViewController {
13-
13+
1414
public enum Method: String {
1515
case getAccounts
1616
case signTransaction
@@ -19,12 +19,12 @@ open class BrowserViewController: UIViewController {
1919
case publishTransaction
2020
case approveTransaction
2121
}
22-
22+
2323
public lazy var webView: WKWebView = {
2424
let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache])
2525
let date = NSDate(timeIntervalSince1970: 0)
26-
27-
WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes as! Set<String>, modifiedSince: date as Date, completionHandler:{ })
26+
27+
WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes as! Set<String>, modifiedSince: date as Date, completionHandler: { })
2828
let webView = WKWebView(
2929
frame: .zero,
3030
configuration: self.config
@@ -35,12 +35,12 @@ open class BrowserViewController: UIViewController {
3535
webView.configuration.preferences.setValue(true, forKey: "developerExtrasEnabled")
3636
return webView
3737
}()
38-
38+
3939
lazy var config: WKWebViewConfiguration = {
4040
let config = WKWebViewConfiguration()
41-
41+
4242
var js = ""
43-
43+
4444
if let filepath = Bundle.main.path(forResource: "browser.min", ofType: "js") {
4545
do {
4646
js += try String(contentsOfFile: filepath)
@@ -55,29 +55,29 @@ open class BrowserViewController: UIViewController {
5555
config.userContentController.addUserScript(userScript)
5656
return config
5757
}()
58-
58+
5959
public func registerBridges(for web3: web3) {
6060
self.webView.bridge.register({ (parameters, completion) in
6161
let url = web3.provider.url.absoluteString
6262
completion(.success(["rpcURL": url as Any]))
6363
}, for: "getRPCurl")
64-
64+
6565
self.webView.bridge.register({ (parameters, completion) in
6666
let allAccounts = web3.browserFunctions.getAccounts()
6767
completion(.success(["accounts": allAccounts as Any]))
6868
}, for: "eth_getAccounts")
69-
69+
7070
self.webView.bridge.register({ (parameters, completion) in
7171
let coinbase = web3.browserFunctions.getCoinbase()
7272
completion(.success(["coinbase": coinbase as Any]))
7373
}, for: "eth_coinbase")
74-
74+
7575
self.webView.bridge.register({ (parameters, completion) in
7676
if parameters == nil {
7777
completion(.failure(Bridge.JSError(code: 0, description: "No parameters provided")))
7878
return
7979
}
80-
let payload = parameters!["payload"] as? [String:Any]
80+
let payload = parameters!["payload"] as? [String: Any]
8181
if payload == nil {
8282
completion(.failure(Bridge.JSError(code: 0, description: "No parameters provided")))
8383
return
@@ -95,13 +95,13 @@ open class BrowserViewController: UIViewController {
9595
}
9696
completion(.success(["signedMessage": result as Any]))
9797
}, for: "eth_sign")
98-
98+
9999
self.webView.bridge.register({ (parameters, completion) in
100100
if parameters == nil {
101101
completion(.failure(Bridge.JSError(code: 0, description: "No parameters provided")))
102102
return
103103
}
104-
let transaction = parameters!["transaction"] as? [String:Any]
104+
let transaction = parameters!["transaction"] as? [String: Any]
105105
if transaction == nil {
106106
completion(.failure(Bridge.JSError(code: 0, description: "Not enough parameters provided")))
107107
return
@@ -118,7 +118,7 @@ open class BrowserViewController: UIViewController {
118118

119119
extension BrowserViewController: WKNavigationDelegate {
120120
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
121-
121+
122122
}
123123
}
124124

Sources/web3swift/Contract/ComparisonExtensions.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import Foundation
88
import BigInt
9-
//import EthereumAddress
109

1110
extension BigUInt: EventFilterComparable {
1211
public func isEqualTo(_ other: AnyObject) -> Bool {
@@ -92,4 +91,3 @@ extension EthereumAddress: EventFilterComparable {
9291
}
9392
}
9493
}
95-

0 commit comments

Comments
 (0)