Skip to content

Commit fdc880f

Browse files
Merge branch 'develop' into feat/solidity-sha3
2 parents d1c6f12 + fa44455 commit fdc880f

File tree

118 files changed

+2406
-2616
lines changed

Some content is hidden

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

118 files changed

+2406
-2616
lines changed

.swiftlint.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
excluded:
2+
- Carthage
3+
- Pods
4+
- .build
5+
- Build
6+
- DerivedData
7+
8+
disabled_rules:
9+
- type_name
10+
- identifier_name
11+
- line_length
12+
- multiple_closures_with_trailing_closure
13+
- todo
14+
15+
opt_in_rules:
16+
- weak_delegate
17+
- unused_import
18+
- unneeded_parentheses_in_closure_argument
19+
- trailing_closure
20+
- static_operator
21+
- redundant_nil_coalescing
22+
- override_in_extension
23+
- legacy_objc_type
24+
- implicitly_unwrapped_optional
25+
- force_unwrapping
26+
- empty_string
27+
- closure_body_length
28+
- fallthrough
29+
30+
# force warnings
31+
force_cast: error
32+
force_try: error
33+
34+
custom_rules:
35+
commented_out_code:
36+
included: ".*\\.swift" # regex that defines paths to include during linting. optional.
37+
excluded: ".*Test(s)?\\.swift" # regex that defines paths to exclude during linting. optional
38+
name: "Commented out code" # rule name. optional.
39+
regex: "^\\/\\/\\s*(@|\\.?([a-z]|(\\})))" # matching pattern
40+
capture_group: 0 # number of regex capture group to highlight the rule violation at. optional.
41+
match_kinds: # SyntaxKinds to match. optional.
42+
- comment
43+
message: "No commented code in devel branch allowed." # violation message. optional.
44+
severity: warning # violation severity. optional.

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

0 commit comments

Comments
 (0)