Skip to content

Commit

Permalink
fix: add close button to help view
Browse files Browse the repository at this point in the history
feat: add master wallet backup
fix: iOS 14 file exporting
  • Loading branch information
Fonta1n3 committed Mar 5, 2021
1 parent 7e26282 commit 6ce96e8
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 23 deletions.
26 changes: 17 additions & 9 deletions FullyNoded/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,20 @@
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="99C-tr-rdf">
<rect key="frame" x="322" y="20" width="37" height="30"/>
<state key="normal" title="close">
<color key="titleColor" systemColor="systemTealColor"/>
</state>
<connections>
<action selector="closeAction:" destination="heC-cF-uyp" eventType="touchUpInside" id="1Ba-FS-IhQ"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="Wi0-7U-B1t"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Wi0-7U-B1t" firstAttribute="trailing" secondItem="99C-tr-rdf" secondAttribute="trailing" constant="16" id="3Fq-LE-vES"/>
<constraint firstItem="Wi0-7U-B1t" firstAttribute="bottom" secondItem="dDU-sK-Uyb" secondAttribute="bottom" constant="20" id="4RI-uO-1B6"/>
<constraint firstItem="kx4-l2-X19" firstAttribute="top" secondItem="UPz-XB-3K6" secondAttribute="bottom" constant="3.5" id="IgF-T8-ihd"/>
<constraint firstItem="dDU-sK-Uyb" firstAttribute="leading" secondItem="Wi0-7U-B1t" secondAttribute="leading" constant="16" id="J3J-Fe-gGo"/>
Expand All @@ -737,6 +747,7 @@
<constraint firstItem="kx4-l2-X19" firstAttribute="leading" secondItem="Wi0-7U-B1t" secondAttribute="leading" constant="16" id="gCQ-yn-Fpj"/>
<constraint firstItem="UPz-XB-3K6" firstAttribute="leading" secondItem="Wi0-7U-B1t" secondAttribute="leading" constant="16" id="qIp-f0-BLs"/>
<constraint firstItem="Wi0-7U-B1t" firstAttribute="trailing" secondItem="kx4-l2-X19" secondAttribute="trailing" constant="223" id="tGT-OB-lSN"/>
<constraint firstItem="99C-tr-rdf" firstAttribute="top" secondItem="Wi0-7U-B1t" secondAttribute="top" constant="20" id="ty9-Rh-a8h"/>
</constraints>
</view>
<connections>
Expand Down Expand Up @@ -5026,25 +5037,22 @@ xxxxx</string>
<rect key="frame" x="0.0" y="0.0" width="343" height="54"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" tag="2" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aJj-v6-1yx">
<rect key="frame" x="281" y="11.5" width="51" height="31"/>
<color key="onTintColor" systemColor="systemTealColor"/>
<color key="thumbTintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</switch>
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="N0t-XW-74V">
<rect key="frame" x="16" y="16.5" width="257" height="21"/>
<constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="260" id="6Re-79-D8V"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" tag="2" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aJj-v6-1yx">
<rect key="frame" x="281" y="11.5" width="51" height="31"/>
<color key="onTintColor" systemColor="systemTealColor"/>
<color key="thumbTintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</switch>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="aJj-v6-1yx" secondAttribute="trailing" constant="13" id="5d1-0E-BW8"/>
<constraint firstItem="aJj-v6-1yx" firstAttribute="leading" secondItem="N0t-XW-74V" secondAttribute="trailing" constant="8" symbolic="YES" id="9aI-hY-mCP"/>
<constraint firstItem="aJj-v6-1yx" firstAttribute="centerY" secondItem="8vt-jV-ete" secondAttribute="centerY" id="Mcc-Z3-vwx"/>
<constraint firstItem="aJj-v6-1yx" firstAttribute="leading" secondItem="N0t-XW-74V" secondAttribute="trailing" constant="8" id="YV2-HH-IQS"/>
<constraint firstItem="N0t-XW-74V" firstAttribute="leading" secondItem="8vt-jV-ete" secondAttribute="leadingMargin" id="nV1-0b-E9I"/>
<constraint firstItem="N0t-XW-74V" firstAttribute="centerY" secondItem="8vt-jV-ete" secondAttribute="centerY" id="p9p-RG-bDe"/>
</constraints>
Expand Down
9 changes: 9 additions & 0 deletions FullyNoded/View Controllers/HelpViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class HelpViewController: UIViewController {
textView.layer.borderWidth = 0.5
}


@IBAction func closeAction(_ sender: Any) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

self.dismiss(animated: true, completion: nil)
}
}


/*
// MARK: - Navigation
Expand Down
64 changes: 58 additions & 6 deletions FullyNoded/View Controllers/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
icon.image = UIImage(systemName: "lock.shield")
background.backgroundColor = .systemOrange

// case 3:
// label.text = "Kill Switch ☠️"
// icon.image = UIImage(systemName: "exclamationmark.triangle")
// background.backgroundColor = .systemRed
case 4:
label.text = "Wallet Backup"
icon.image = UIImage(systemName: "triangle.righthalf.fill")
background.backgroundColor = .systemGreen

default:
break
Expand Down Expand Up @@ -178,7 +178,7 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0, 1:
case 0, 1, 4:
return settingsCell(indexPath)

case 2:
Expand Down Expand Up @@ -218,6 +218,9 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
case 3:
textLabel.text = "Exchange Rate API"

case 4:
textLabel.text = "Wallet Backup"

default:
break
}
Expand All @@ -226,7 +229,7 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
}

func numberOfSections(in tableView: UITableView) -> Int {
return 4
return 5
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Expand Down Expand Up @@ -269,13 +272,62 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView

// case 3:
// kill()

case 4:
alertToBackup()

default:
break

}
}

private func alertToBackup() {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

let tit = "Master Wallet Backup"
let mess = "Exports all wallet backup QR codes! These QR codes can be used to recreate each wallet."
let alert = UIAlertController(title: tit, message: mess, preferredStyle: .alert)

alert.addAction(UIAlertAction(title: "Backup ", style: .default, handler: { action in
self.backup()
}))

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { action in }))
self.present(alert, animated: true, completion: nil)
}
}

private func backup() {
var backups:[UIImage] = []

CoreDataService.retrieveEntity(entityName: .wallets) { wallets in
guard let wallets = wallets, wallets.count > 0 else { return }

for wallet in wallets {
let walletStr = Wallet(dictionary: wallet)
let json = AccountMap.create(wallet: walletStr) ?? ""
let generator = QRGenerator()
generator.textInput = json
backups.append(generator.getQRCode())
}

DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

let activityViewController = UIActivityViewController(activityItems: backups, applicationActivities: nil)

if UIDevice.current.userInterfaceIdiom == .pad {
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: 100, height: 100)
}

self.present(activityViewController, animated: true) {}
}
}
}

// func kill() {
// let tit = "Danger!"
// let mess = "This will DELETE all the apps data, are you sure you want to proceed?"
Expand Down
19 changes: 13 additions & 6 deletions FullyNoded/View Controllers/VerifyTransactionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,37 @@ class VerifyTransactionViewController: UIViewController, UINavigationControllerD
private func finalizePsbt(_ psbt: String) {
Reducer.makeCommand(command: .finalizepsbt, param: "\"\(psbt)\"") { [weak self] (object, errorDescription) in
guard let self = self else { return }

guard let result = object as? NSDictionary, let complete = result["complete"] as? Bool else {
showAlert(vc: self, title: "", message: "There was an issue finalizing your psbt: \(errorDescription ?? "unknown error")")
return
}

self.enableExportButton()

guard complete, let hex = result["hex"] as? String else {
guard let psbt = result["psbt"] as? String else {
showAlert(vc: self, title: "", message: "There was an issue finalizing your psbt: \(errorDescription ?? "unknown error")")
return
}

self.unsignedPsbt = psbt
self.enableSignButton()
self.load()

return
}

self.signedRawTx = hex
self.load()
}

// Finalizes locally - here for testing purposes
// guard let hex = Keys.finalize(psbt) else {
// return
// }
//
// print("hex: \(hex)")
}

private func enableExportButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class WalletDetailViewController: UIViewController, UITextFieldDelegate, UITable
try? self.json.dataUsingUTF8StringEncoding.write(to: fileURL)

if #available(iOS 14, *) {
//let controller = UIDocumentPickerViewController(forExporting: [fileURL]) // 5
//present(controller, animated: true)
let controller = UIDocumentPickerViewController(forExporting: [fileURL]) // 5
self.present(controller, animated: true)
} else {
let controller = UIDocumentPickerViewController(url: fileURL, in: .exportToService)
self.present(controller, animated: true)
Expand Down
12 changes: 12 additions & 0 deletions FullyNoded/Wallet Logic/CreateFullyNodedWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,16 @@ enum Keys {
}
}
}

static func finalize(_ psbt: String) -> String? {
guard let psbt = try? PSBT(psbt: psbt, network: .testnet) else {
return nil
}

guard let finalizedPsbt = try? psbt.finalized(), let final = finalizedPsbt.transactionFinal else {
return nil
}

return final.description
}
}

0 comments on commit 6ce96e8

Please sign in to comment.