Skip to content

Commit 2c3a236

Browse files
Merge branch 'develop' into fix/web3-wallet-example
2 parents 61b9f1b + 3081a92 commit 2c3a236

Some content is hidden

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

46 files changed

+650
-658
lines changed

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-json
11+
- id: mixed-line-ending
12+
- id: no-commit-to-branch
13+
args: [--branch, staging, --branch, main, --branch, master, --branch, develop-4.0, --branch, develop-upstream]
14+
- repo: https://github.com/codespell-project/codespell
15+
rev: v2.2.2
16+
hooks:
17+
- id: codespell
18+
args: ["--count --ignore-words-list=ans,deriver,inout,packag --skip=\"*.js,*WordLists.swift,.git,Carthage,.build,build\""]
19+
# SwiftLint is commented out until we fix all SwiftLint warnings and errors.
20+
# https://github.com/web3swift-team/web3swift/pull/756
21+
#- repo: https://github.com/realm/SwiftLint
22+
# rev: 0.50.3
23+
# hooks:
24+
# - id: swiftlint
25+
# args: [--fix, Sources, Tests]

.swiftlint.yml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
excluded:
2-
- Carthage
3-
- Pods
42
- .build
53
- Build
4+
- Carthage
65
- DerivedData
6+
- Pods
77

88
disabled_rules:
9-
- type_name
9+
- function_parameter_count
1010
- identifier_name
1111
- line_length
1212
- multiple_closures_with_trailing_closure
13+
- nesting
1314
- todo
15+
- type_name
1416

1517
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-
- indentation_width
18+
- closure_body_length
19+
- empty_string
20+
- fallthrough
21+
- force_unwrapping
22+
- implicitly_unwrapped_optional
23+
- indentation_width
24+
- legacy_objc_type
25+
- override_in_extension
26+
- redundant_nil_coalescing
27+
- static_operator
28+
- trailing_closure
29+
- unneeded_parentheses_in_closure_argument
30+
- unused_import
31+
- weak_delegate
3032

3133
# force warnings
3234
force_cast: error
3335
force_try: error
3436

3537
custom_rules:
3638
commented_out_code:
37-
included: ".*\\.swift" # regex that defines paths to include during linting. optional.
38-
excluded: ".*Test(s)?\\.swift" # regex that defines paths to exclude during linting. optional
39-
name: "Commented out code" # rule name. optional.
40-
regex: "^\\/\\/\\s*(@|\\.?([a-z]|(\\})))" # matching pattern
39+
included: .*\.swift # regex that defines paths to include during linting. optional.
40+
excluded: .*Test(s)?\.swift # regex that defines paths to exclude during linting. optional
41+
name: Commented out code # rule name. optional.
42+
regex: ^\s*(\/\/(?!\s*swiftlint:).*|\/\*[\s\S]*?\*\/) # matching pattern
4143
capture_group: 0 # number of regex capture group to highlight the rule violation at. optional.
4244
match_kinds: # SyntaxKinds to match. optional.
4345
- comment
44-
message: "No commented code in devel branch allowed." # violation message. optional.
46+
message: No commented code in devel branch allowed. # violation message. optional.
4547
severity: warning # violation severity. optional.

Example/myWeb3Wallet/myWeb3Wallet/Appdelegate/AppDelegate.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import UIKit
1010
@main
1111
class AppDelegate: UIResponder, UIApplicationDelegate {
1212

13-
14-
1513
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1614
// Override point for customization after application launch.
1715
return true
@@ -31,6 +29,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3129
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
3230
}
3331

34-
3532
}
36-

Example/myWeb3Wallet/myWeb3Wallet/Appdelegate/SceneDelegate.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1111

1212
var window: UIWindow?
1313

14-
1514
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
1615
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
1716
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
@@ -47,6 +46,4 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
4746
// to restore the scene back to its current state.
4847
}
4948

50-
5149
}
52-

Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/DashboardViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class DashboardViewController: UIViewController {
1919

2020
}
2121
}
22-
2322

2423
/*
2524
// MARK: - Navigation

Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/SplashViewController.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ import UIKit
1010
class SplashViewController: UIViewController {
1111

1212
@IBOutlet weak var logoView: UIImageView!
13-
13+
1414
override func viewDidLoad() {
1515
super.viewDidLoad()
1616
UIView.animate(withDuration: 0.9) {
1717
self.logoView.center.y = self.view.center.y
1818
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.moveToWalletView), userInfo: nil, repeats: false)
1919

2020
}
21-
2221

2322
// Do any additional setup after loading the view.
2423
}
25-
@objc func moveToWalletView(){
26-
24+
@objc func moveToWalletView() {
25+
2726
guard let walletScreen = self.storyboard?.instantiateViewController(withIdentifier: "WalletViewController") as? WalletViewController else {
2827
#if DEBUG
2928
printContent("Unable to get Wallet controller")

Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/WalletViewController.swift

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import web3swift
1010
import Web3Core
1111

1212
class WalletViewController: UIViewController {
13-
13+
1414
@IBOutlet weak var continueButton: UIButton!
1515
@IBOutlet weak var walletAddressLabel: UILabel!
1616
@IBOutlet weak var importWalletButton: UIButton!
1717
@IBOutlet weak var createWalletButton: UIButton!
1818
var _walletAddress: String {
19-
set{
19+
set {
2020
self.continueButton.isHidden = false
2121
self.walletAddressLabel.text = newValue
2222
}
@@ -29,23 +29,22 @@ class WalletViewController: UIViewController {
2929
super.viewDidLoad()
3030
self.createWalletButton.layer.cornerRadius = 5.0
3131
self.importWalletButton.layer.cornerRadius = 5.0
32-
32+
3333
// Do any additional setup after loading the view.
3434
}
35-
36-
35+
3736
@IBAction func onClickCreateWallet(_ sender: UIButton) {
3837
#if DEBUG
3938
print("Clicked on Create Wallet Option")
4039
#endif
4140
self.createMnemonics()
42-
41+
4342
}
4443
@IBAction func onClickImportWalletButton(_ sender: UIButton) {
4544
print("Clicked on import Wallet Option")
4645
self.showImportALert()
4746
}
48-
47+
4948
@IBAction func onClickContinueButton(_ sender: UIButton) {
5049
print("Clicked on COntinue button")
5150
guard let dashboardScreen = self.storyboard?.instantiateViewController(withIdentifier: "DashboardViewController") as? DashboardViewController else {
@@ -56,7 +55,7 @@ class WalletViewController: UIViewController {
5655
}
5756
self.navigationController?.pushViewController(dashboardScreen, animated: true)
5857
}
59-
fileprivate func showImportALert(){
58+
fileprivate func showImportALert() {
6059
let alert = UIAlertController(title: "MyWeb3Wallet", message: "", preferredStyle: .alert)
6160
alert.addTextField { textfied in
6261
textfied.placeholder = "Enter mnemonics/private Key"
@@ -71,15 +70,15 @@ class WalletViewController: UIViewController {
7170
guard let privateKey = alert.textFields?[0].text else { return }
7271
print(privateKey)
7372
self.importWalletWith(privateKey: privateKey)
74-
73+
7574
}
7675
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
7776
alert.addAction(mnemonicsAction)
7877
alert.addAction(privateKeyAction)
7978
alert.addAction(cancelAction)
8079
self.present(alert, animated: true, completion: nil)
8180
}
82-
func importWalletWith(privateKey: String){
81+
func importWalletWith(privateKey: String) {
8382
let formattedKey = privateKey.trimmingCharacters(in: .whitespacesAndNewlines)
8483
guard let dataKey = Data.fromHex(formattedKey) else {
8584
self.showAlertMessage(title: "Error", message: "Please enter a valid Private key ", actionName: "Ok")
@@ -96,7 +95,7 @@ class WalletViewController: UIViewController {
9695
#endif
9796
let walletAddress = manager.addresses?.first?.address
9897
self.walletAddressLabel.text = walletAddress ?? "0x"
99-
98+
10099
print(walletAddress)
101100
} else {
102101
print("error")
@@ -111,9 +110,7 @@ class WalletViewController: UIViewController {
111110
alert.addAction(okAction)
112111
self.present(alert, animated: true)
113112
}
114-
115-
116-
113+
117114
}
118115

119116
func importWalletWith(mnemonics: String) {
@@ -123,19 +120,20 @@ class WalletViewController: UIViewController {
123120
}
124121

125122
extension WalletViewController {
126-
127-
fileprivate func createMnemonics(){
123+
124+
fileprivate func createMnemonics() {
128125
let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
129126
let web3KeystoreManager = KeystoreManager.managerForPath(userDir + "/keystore")
130127
do {
131-
if (web3KeystoreManager?.addresses?.count ?? 0 >= 0) {
128+
if web3KeystoreManager?.addresses?.count ?? 0 >= 0 {
132129
let tempMnemonics = try? BIP39.generateMnemonics(bitsOfEntropy: 256, language: .english)
133130
guard let tMnemonics = tempMnemonics else {
134131
self.showAlertMessage(title: "", message: "We are unable to create wallet", actionName: "Ok")
135132
return
136133
}
137134
self._mnemonics = tMnemonics
138135
print(_mnemonics)
136+
139137
let tempWalletAddress = try? BIP32Keystore(mnemonics: self._mnemonics, password: "", prefixPath: "m/44'/77777'/0'/0")
140138
guard let walletAddress = tempWalletAddress?.addresses?.first else {
141139
self.showAlertMessage(title: "", message: "Unable to create wallet", actionName: "Ok")
@@ -150,9 +148,9 @@ extension WalletViewController {
150148
FileManager.default.createFile(atPath: userDir + "/keystore" + "/key.json", contents: keyData, attributes: nil)
151149
}
152150
} catch {
153-
151+
154152
}
155-
153+
156154
}
157155
}
158156
extension UIViewController {
@@ -162,5 +160,5 @@ extension UIViewController {
162160
alertController.addAction(action)
163161
self.present(alertController, animated: true)
164162
}
165-
163+
166164
}

README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
- [Core features](#core-features)
2121
- [Installation](#installation)
22-
- [CocoaPods](#cocoapods)
2322
- [Swift Package](#swift-package)
23+
- [CocoaPods](#cocoapods)
2424
- [Example usage](#example-usage)
2525
- [Send Ether](#send-ether)
2626
- [Contract read method](#contract-read-method)
@@ -66,6 +66,27 @@
6666

6767
## Installation
6868

69+
### Swift Package (Recommended)
70+
The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code that is well integrated with Swift build system.
71+
72+
Once you have your Swift package set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
73+
```swift
74+
dependencies: [
75+
.package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0"))
76+
]
77+
```
78+
79+
Or if your project is not a package follow these guidelines on [how to add a Swift Package to your Xcode project](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app).
80+
81+
82+
## Example usage
83+
In the imports section:
84+
85+
```swift
86+
import web3swift
87+
import Web3Core
88+
```
89+
6990
### CocoaPods
7091

7192
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
@@ -91,23 +112,7 @@ Then, run the following command:
91112
$ pod install
92113
```
93114

94-
### Swift Package
95-
The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
96-
97-
Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
98-
```swift
99-
dependencies: [
100-
.package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0"))
101-
]
102-
```
103-
104-
## Example usage
105-
In the imports section:
106-
107-
```swift
108-
import web3swift
109-
import Web3Core
110-
```
115+
> **WARNING**: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that preventing us of providing first class support there. We highly recommend using SPM first as using CocoaPods will delay new updates and bug fixes being delivered to you.
111116
112117
### Send Ether
113118
```swift
@@ -188,6 +193,10 @@ $ ganache
188193
This will create a local blockchain and also some test accounts that are used throughout our tests.
189194
Make sure that `ganache` is running on its default port `8546`. To change the port in test cases locate `LocalTestCase.swift` and modify the static `url` variable.
190195

196+
### Before you commit
197+
198+
We are using [pre-commit](https://pre-commit.com) to run validations locally before a commit is created. Please, install pre-commit and run `pre-commit install` from project's root directory. After that before every commit git hook will run and execute `codespell`, `swiftlint` and other checks.
199+
191200
## Contribute
192201
Want to improve? It's awesome:
193202
Then good news for you: **We are ready to pay for your contribution via [@gitcoin bot](https://gitcoin.co/grants/358/web3swift)!**

0 commit comments

Comments
 (0)