Skip to content

Commit c5ed091

Browse files
committed
update example
1 parent f1ac186 commit c5ed091

File tree

3 files changed

+95
-53
lines changed

3 files changed

+95
-53
lines changed

Example/web3swiftBrowser/web3swiftBrowser/Base.lproj/Main.storyboard

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="gLe-1b-Uz4">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.3" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="gLe-1b-Uz4">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17126"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7-
<capability name="System colors in document resources" minToolsVersion="11.0"/>
87
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
98
</dependencies>
109
<scenes>
@@ -15,10 +14,10 @@
1514
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1615
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1716
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18-
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
1917
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
18+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
2019
</view>
21-
<tabBarItem key="tabBarItem" title="web3Browser" image="infinity" catalog="system" id="9jl-vW-z4Z"/>
20+
<tabBarItem key="tabBarItem" title="web3Browser" id="9jl-vW-z4Z"/>
2221
</viewController>
2322
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
2423
</objects>
@@ -31,7 +30,7 @@
3130
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="frv-h2-1e3">
3231
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
3332
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
34-
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
33+
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
3534
<sections>
3635
<tableViewSection headerTitle="Account Management" id="AKB-Tc-2Lm">
3736
<cells>
@@ -42,7 +41,7 @@
4241
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
4342
<autoresizingMask key="autoresizingMask"/>
4443
<subviews>
45-
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Wpa-kh-BpQ">
44+
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Wpa-kh-BpQ">
4645
<rect key="frame" x="134" y="6" width="107" height="30"/>
4746
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
4847
<state key="normal" title="Create Account"/>
@@ -77,31 +76,50 @@
7776
</subviews>
7877
</tableViewCellContentView>
7978
</tableViewCell>
80-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="nwr-0W-mx7">
79+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="GVE-eA-dRm">
8180
<rect key="frame" x="0.0" y="115" width="375" height="43.5"/>
8281
<autoresizingMask key="autoresizingMask"/>
83-
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="nwr-0W-mx7" id="bYo-tP-e8R">
82+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="GVE-eA-dRm" id="xds-JW-hOG">
8483
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
8584
<autoresizingMask key="autoresizingMask"/>
85+
<subviews>
86+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="y1x-fD-oOZ">
87+
<rect key="frame" x="65" y="7" width="245" height="30"/>
88+
<state key="normal" title="Generate BIP32 Mnemonic"/>
89+
<connections>
90+
<action selector="generateBipMnemonic:" destination="ExQ-Th-f3A" eventType="touchUpInside" id="FLx-nD-IOX"/>
91+
</connections>
92+
</button>
93+
</subviews>
94+
<constraints>
95+
<constraint firstItem="y1x-fD-oOZ" firstAttribute="centerX" secondItem="xds-JW-hOG" secondAttribute="centerX" id="1Ki-9u-9rB"/>
96+
<constraint firstItem="y1x-fD-oOZ" firstAttribute="centerY" secondItem="xds-JW-hOG" secondAttribute="centerY" id="6aW-DI-tzz"/>
97+
<constraint firstItem="y1x-fD-oOZ" firstAttribute="height" secondItem="xds-JW-hOG" secondAttribute="height" multiplier="0.689655" id="FQO-gK-fJL"/>
98+
<constraint firstItem="y1x-fD-oOZ" firstAttribute="width" secondItem="xds-JW-hOG" secondAttribute="width" multiplier="0.653333" id="taA-fe-d61"/>
99+
</constraints>
86100
</tableViewCellContentView>
87101
</tableViewCell>
88-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="GVE-eA-dRm">
102+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="1cX-fV-3w1">
89103
<rect key="frame" x="0.0" y="158.5" width="375" height="43.5"/>
90104
<autoresizingMask key="autoresizingMask"/>
91-
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="GVE-eA-dRm" id="xds-JW-hOG">
105+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="1cX-fV-3w1" id="Bsv-1l-8Vd">
92106
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
93107
<autoresizingMask key="autoresizingMask"/>
94108
<subviews>
95-
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="y1x-fD-oOZ">
96-
<rect key="frame" x="130" y="6" width="116" height="30"/>
97-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
98-
<state key="normal" title="BIP32 Mnemonic"/>
109+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Lt9-fx-T7i">
110+
<rect key="frame" x="65" y="7" width="245" height="30"/>
111+
<state key="normal" title="Generate BIP32 Wallet"/>
99112
<connections>
100-
<action selector="createAccount:" destination="ExQ-Th-f3A" eventType="touchUpInside" id="dJH-QG-dtS"/>
101-
<action selector="generateBipMnemonic:" destination="ExQ-Th-f3A" eventType="touchUpInside" id="FLx-nD-IOX"/>
113+
<action selector="genBip32Account:" destination="ExQ-Th-f3A" eventType="touchUpInside" id="iGe-bI-zgm"/>
102114
</connections>
103115
</button>
104116
</subviews>
117+
<constraints>
118+
<constraint firstItem="Lt9-fx-T7i" firstAttribute="height" secondItem="Bsv-1l-8Vd" secondAttribute="height" multiplier="0.689655" id="2G8-f2-Ugy"/>
119+
<constraint firstItem="Lt9-fx-T7i" firstAttribute="centerY" secondItem="Bsv-1l-8Vd" secondAttribute="centerY" id="Cl6-wX-Jwc"/>
120+
<constraint firstItem="Lt9-fx-T7i" firstAttribute="width" secondItem="Bsv-1l-8Vd" secondAttribute="width" multiplier="0.653333" id="VfX-Bu-C5h"/>
121+
<constraint firstItem="Lt9-fx-T7i" firstAttribute="centerX" secondItem="Bsv-1l-8Vd" secondAttribute="centerX" id="nu9-tN-K4m"/>
122+
</constraints>
105123
</tableViewCellContentView>
106124
</tableViewCell>
107125
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" misplaced="YES" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="R4W-9G-vnO" detailTextLabel="i9j-7H-1gC" style="IBUITableViewCellStyleSubtitle" id="pRM-qd-tOr">
@@ -111,7 +129,7 @@
111129
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
112130
<autoresizingMask key="autoresizingMask"/>
113131
<subviews>
114-
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Mnemonic" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="R4W-9G-vnO">
132+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Mnemonic" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.25" adjustsLetterSpacingToFitWidth="YES" id="R4W-9G-vnO">
115133
<rect key="frame" x="16" y="5" width="80" height="20.5"/>
116134
<autoresizingMask key="autoresizingMask"/>
117135
<fontDescription key="fontDescription" type="system" pointSize="17"/>
@@ -139,12 +157,12 @@
139157
<outlet property="delegate" destination="ExQ-Th-f3A" id="E8y-63-xkE"/>
140158
</connections>
141159
</tableView>
142-
<tabBarItem key="tabBarItem" title="MainFunctions" image="tablecells" catalog="system" id="bzu-Ue-X9c"/>
160+
<tabBarItem key="tabBarItem" title="MainFunctions" id="bzu-Ue-X9c"/>
143161
<connections>
144162
<outlet property="accountName" destination="eag-jz-PDn" id="Xtc-PX-BPE"/>
145163
<outlet property="bipKey" destination="i9j-7H-1gC" id="g0X-mk-QSq"/>
146164
<outlet property="bipMnemonic" destination="R4W-9G-vnO" id="B4l-FU-9kr"/>
147-
<outlet property="mnemonic" destination="ghD-Lo-5Fe" id="qe2-lc-JQo"/>
165+
<outlet property="mnemonic" destination="ghD-Lo-5Fe" id="JXs-IW-Lyh"/>
148166
</connections>
149167
</tableViewController>
150168
<placeholder placeholderIdentifier="IBFirstResponder" id="0Vw-wG-i46" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
@@ -157,6 +175,7 @@
157175
<tabBarController automaticallyAdjustsScrollViewInsets="NO" id="gLe-1b-Uz4" sceneMemberID="viewController">
158176
<toolbarItems/>
159177
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="wcn-HH-Smk">
178+
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
160179
<autoresizingMask key="autoresizingMask"/>
161180
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
162181
</tabBar>
@@ -170,11 +189,4 @@
170189
<point key="canvasLocation" x="136.80000000000001" y="133.5832083958021"/>
171190
</scene>
172191
</scenes>
173-
<resources>
174-
<image name="infinity" catalog="system" width="128" height="62"/>
175-
<image name="tablecells" catalog="system" width="128" height="93"/>
176-
<systemColor name="systemBackgroundColor">
177-
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
178-
</systemColor>
179-
</resources>
180192
</document>

Example/web3swiftBrowser/web3swiftBrowser/MainTableViewController.swift

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,53 @@ import web3swift
1111

1212
class MainTableViewController: UITableViewController {
1313
var wallet: Wallet = Wallet(type: .EthereumKeystoreV3)
14+
var mnemonics: String? {
15+
16+
didSet {
17+
bipMnemonic.text = self.mnemonics
18+
}
19+
}
1420
let password = "web3swift"
15-
21+
1622
override func viewDidLoad() {
1723
super.viewDidLoad()
1824

1925
}
2026

2127
@IBOutlet weak var mnemonic: UILabel!
2228

23-
29+
2430
@IBOutlet weak var accountName: UILabel!
2531

26-
32+
2733
@IBAction func createAccount(_ sender: Any) {
28-
34+
2935
let wallet = Wallet(type: .EthereumKeystoreV3)
30-
36+
3137
accountName.text = wallet.name
3238
mnemonic.text = wallet.address
33-
39+
3440
}
41+
3542
@IBAction func generateBipMnemonic(_ sender: Any) {
36-
37-
let wallet = Wallet(type: .BIP39)
38-
43+
44+
self.mnemonics = try! BIP39.generateMnemonics(bitsOfEntropy: 128)!
45+
46+
}
47+
48+
@IBAction func genBip32Account(_ sender: Any) {
49+
if (self.mnemonics == nil) {self.generateBipMnemonic(self)
50+
51+
}
52+
53+
let wallet = Wallet(type: .BIP39(mnemonic: self.mnemonics!))
54+
55+
bipKey.text = wallet.address
56+
3957
}
40-
58+
4159
@IBOutlet weak var bipMnemonic: UILabel!
4260
@IBOutlet weak var bipKey: UILabel!
43-
61+
4462

4563
}

Example/web3swiftBrowser/web3swiftBrowser/PrefferedModels.swift

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import Foundation
1010
import web3swift
1111

1212
struct Wallet {
13-
enum walletType: Int {
13+
enum walletType {
1414
case EthereumKeystoreV3
15-
case BIP39
15+
case BIP39(mnemonic: String)
1616
}
1717

1818
var name: String = "Wallet"
@@ -22,6 +22,19 @@ struct Wallet {
2222
var address: String
2323

2424
var data: Data
25+
var mnemonics: String {
26+
get{self.mnemonics}
27+
set {
28+
let keystore = try! BIP32Keystore(
29+
mnemonics: newValue,
30+
password: password,
31+
mnemonicsPassword: "",
32+
language: .english)!
33+
self.data = try! JSONEncoder().encode(keystore.keystoreParams)
34+
self.isHD = true
35+
self.address = keystore.addresses!.first!.address
36+
}
37+
}
2538
var isHD: Bool
2639

2740
init(type: walletType) {
@@ -32,21 +45,20 @@ struct Wallet {
3245
self.data = try! JSONEncoder().encode(keystore.keystoreParams)
3346
self.isHD = false
3447
self.address = keystore.addresses!.first!.address
35-
36-
case .BIP39:
37-
let mnemonics = try! BIP39.generateMnemonics(bitsOfEntropy: bitsOfEntropy)!
38-
let keystore = try! BIP32Keystore(
39-
mnemonics: mnemonics,
40-
password: password,
41-
mnemonicsPassword: "",
42-
language: .english)!
43-
self.name = "HD Wallet"
44-
self.data = try! JSONEncoder().encode(keystore.keystoreParams)
45-
self.isHD = true
46-
self.address = keystore.addresses!.first!.address
48+
49+
case .BIP39(mnemonic: let mnemonic):
50+
let keystore = try! BIP32Keystore(
51+
mnemonics: mnemonic,
52+
password: password,
53+
mnemonicsPassword: "",
54+
language: .english)!
55+
self.name = "HD Wallet"
56+
self.data = try! JSONEncoder().encode(keystore.keystoreParams)
57+
self.isHD = true
58+
self.address = keystore.addresses!.first!.address
4759
}
4860

49-
61+
5062
}
5163
}
5264

0 commit comments

Comments
 (0)