Skip to content

Commit

Permalink
fix: minor fixes, move paywall to qr displayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Fonta1n3 committed Dec 7, 2020
1 parent 08d474e commit 422468f
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 174 deletions.
8 changes: 4 additions & 4 deletions FullyNoded.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEVELOPMENT_TEAM = 8JHDU5M9KD;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
Expand All @@ -1431,7 +1431,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.358;
MARKETING_VERSION = 1.359;
PRODUCT_BUNDLE_IDENTIFIER = com.fontaine.FullyNoded;
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = com.fontaine.fullynodedmacos;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1456,7 +1456,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 8JHDU5M9KD;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
Expand All @@ -1469,7 +1469,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.358;
MARKETING_VERSION = 1.359;
PRODUCT_BUNDLE_IDENTIFIER = com.fontaine.FullyNoded;
"PRODUCT_BUNDLE_IDENTIFIER[sdk=macosx*]" = com.fontaine.fullynodedmacos;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
12 changes: 6 additions & 6 deletions FullyNoded/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@
<segue destination="B99-yZ-naR" kind="show" identifier="segueToAddANode" id="dhu-ZV-762"/>
<segue destination="fTf-eh-9Tk" kind="show" identifier="segueToTools" id="La3-qR-4jz"/>
<segue destination="bWB-tp-pgw" kind="show" identifier="segueToCreateUnlockPassword" id="4g3-DC-Q5z"/>
<segue destination="Xxg-Pp-vvN" kind="presentation" identifier="segueToPaywall" modalPresentationStyle="fullScreen" id="G4V-U1-MpW"/>
<segue destination="GlR-4A-eAx" kind="presentation" identifier="segueToPaywall" modalPresentationStyle="fullScreen" id="if0-NE-c9T"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dhK-90-srt" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -1974,11 +1974,11 @@
<objects>
<viewController storyboardIdentifier="QRDisplayer" useStoryboardIdentifierAsRestorationIdentifier="YES" id="GlR-4A-eAx" customClass="QRDisplayerViewController" customModule="FullyNoded" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="1Ax-bN-O8E">
<rect key="frame" x="0.0" y="0.0" width="375" height="574"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kj5-uB-hmc">
<rect key="frame" x="16" y="422" width="343" height="132"/>
<rect key="frame" x="16" y="422" width="343" height="225"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
Expand Down Expand Up @@ -7891,9 +7891,9 @@ COLD means no keys will be generated and no private keys can be imported.</strin
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="qed-hl-jG5"/>
<segue reference="UBf-qr-XYG"/>
<segue reference="dhu-ZV-762"/>
<segue reference="DLx-HT-rGm"/>
<segue reference="4g3-DC-Q5z"/>
<segue reference="w2g-bl-j8v"/>
<segue reference="RbT-dI-IvI"/>
<segue reference="IVc-aG-8QZ"/>
Expand All @@ -7904,7 +7904,7 @@ COLD means no keys will be generated and no private keys can be imported.</strin
<segue reference="IAz-j1-Gq6"/>
<segue reference="GTM-mT-JB4"/>
<segue reference="9TT-9o-7xG"/>
<segue reference="zi9-mK-A5a"/>
<segue reference="if0-NE-c9T"/>
<segue reference="8yc-oK-dlC"/>
<segue reference="7PS-EL-3d2"/>
<segue reference="j10-wi-hpr"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,12 @@ class MainMenuViewController: UIViewController {
}

case "segueToPaywall":
guard let vc = segue.destination as? InvoiceViewController else { fallthrough }
guard let vc = segue.destination as? QRDisplayerViewController else { fallthrough }

vc.isPaying = true
vc.headerIcon = UIImage(systemName: "bitcoinsign.circle")
vc.headerText = "Donation"
vc.descriptionText = "Your support is greatly appreciated! We are checking every 15 seconds in the background to see if a payment is made, as soon as we see one the app will automatically unlock and be fully functional."

default:
break
Expand Down Expand Up @@ -881,15 +884,15 @@ extension MainMenuViewController: OnionManagerDelegate {
self?.progressView.isHidden = true
self?.blurView.isHidden = true
}

// if KeyChain.getData("hasPaid") == nil {
// guard let data = KeyChain.getData("paymentAddress"), let paid = data.utf8 else {
// goToPaywall()
// return
// }
//
// checkIfPaymentReceived(paid)
// }
if KeyChain.getData("hasPaid") == nil {
guard let data = KeyChain.getData("paymentAddress"), let paid = data.utf8 else {
goToPaywall()
return
}

checkIfPaymentReceived(paid)
}
}

func torConnDifficulties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class InvoiceViewController: UIViewController, UITextFieldDelegate {
var descriptor = ""
var wallet = [String:Any]()
let ud = UserDefaults.standard
var isPaying = false
var isBtc = false
var isSats = false

Expand All @@ -50,18 +49,10 @@ class InvoiceViewController: UIViewController, UITextFieldDelegate {
getAddressSettings()
addDoneButtonOnKeyboard()
setUnits()
addressOutlet.text = "tap \"🔗 onchain invoice\" to get an address"

if isPaying {
spinner.label.text = "fetching donation address..."
segmentedControlOutlet.alpha = 0
addressOutlet.alpha = 0
amountField.alpha = 0
labelField.alpha = 0
}

invoiceText.text = "invoice text will show here"
addressOutlet.text = ""
invoiceText.text = ""
qrView.image = generateQrCode(key: "bitcoin:")
generateOnchainInvoice()
}

private func setUnits() {
Expand Down Expand Up @@ -153,6 +144,7 @@ class InvoiceViewController: UIViewController, UITextFieldDelegate {

var millisats = "\"any\""
var label = "Fully-Noded-\(randomString(length: 5))"
var description = "\(Date())"

if amountField.text != "" {
if isBtc {
Expand All @@ -171,7 +163,11 @@ class InvoiceViewController: UIViewController, UITextFieldDelegate {
label = labelField.text!
}

let param = "\(millisats), \"\(label)\", \"\(Date())\", \(86400)"
if messageField.text != "" {
description = messageField.text!
}

let param = "\(millisats), \"\(label)\", \"\(description)\", \(86400)"
let commandId = UUID()

LightningRPC.command(id: commandId, method: .invoice, param: param) { [weak self] (uuid, response, errorDesc) in
Expand Down Expand Up @@ -216,155 +212,27 @@ class InvoiceViewController: UIViewController, UITextFieldDelegate {
}

func generateOnchainInvoice() {
if isPaying {
guard let data = KeyChain.getData("paymentAddress") else {

guard let paymentAddress = Keys.donationAddress() else { return }

guard KeyChain.set(paymentAddress.dataUsingUTF8StringEncoding, forKey: "paymentAddress") else {
return
}

getPaid(paymentAddress)

return
}

let paymentAddress = data.utf8 ?? ""
getPaid(paymentAddress)

} else {
spinner.addConnectingView(vc: self, description: "fetching address...")

addressOutlet.text = ""

activeWallet { [weak self] wallet in
guard let self = self else { return }

guard let wallet = wallet else {
self.fetchAddress()
return
}

let descriptorParser = DescriptorParser()
let descriptorStruct = descriptorParser.descriptor(wallet.receiveDescriptor)

if descriptorStruct.isMulti {
self.getReceieveAddressForFullyNodedMultiSig(wallet)
} else {
self.fetchAddress()
}
}
}
}

private func getPaid(_ address: String) {
FiatConverter.sharedInstance.getFxRate { [weak self] fxRate in
guard let self = self, let fxRate = fxRate else { return }

let btcAmount = 1.0 / (fxRate / 20.0)

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

let qr = self.generateQrCode(key:"bitcoin:\(address)?amount=\(btcAmount.avoidNotation)&label=FullyNoded-Payment")

self.qrView.image = qr
self.addPaymentLabels()

self.spinner.removeConnectingView()

showAlert(vc: self, title: "Thank you for supporting Fully Noded", message: "In order to use Fully Noded via direct download a donation of $20 in btc is suggested. You can scan this QR with any wallet to automatically pay the suggested amount, this address is unique to you and will not change that way you can pay whenever you want.\n\nThe app has taken years of hard work, and your support will help make Fully Noded even better and ensure its long term survival.\n\nOnce the payment is made you will have full lifetime access to the app.")
}

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { [weak self] in
guard let self = self else { return }

self.checkIfPaymentReceived(address)
}
}
}

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

let topLabel = UILabel()
topLabel.font = .systemFont(ofSize: 28)
topLabel.textColor = .white
topLabel.frame = CGRect(x: 16, y: 100, width: self.view.frame.width - 32, height: 20)
topLabel.text = "Donation"
topLabel.textAlignment = .left
self.view.addSubview(topLabel)

let bottomLabel = UILabel()
bottomLabel.font = .systemFont(ofSize: 14)
bottomLabel.textColor = .lightGray
bottomLabel.textAlignment = .left
bottomLabel.frame = CGRect(x: 16, y: self.view.frame.maxY - 110, width: self.view.frame.width - 32, height: 100)
bottomLabel.numberOfLines = 0
bottomLabel.text = "Your support is greatly appreciated! We are checking every 15 seconds in the background to see if a payment is made, as soon as we see one the app will automatically unlock and be fully functional."
self.view.addSubview(bottomLabel)
}
}

private func checkIfPaymentReceived(_ address: String) {
let blockstreamUrl = "http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/api/address/" + address
spinner.addConnectingView(vc: self, description: "fetching address...")

guard let url = URL(string: blockstreamUrl) else { return }
addressOutlet.text = ""

var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("text/plain", forHTTPHeaderField: "Content-Type")

let task = TorClient.sharedInstance.session.dataTask(with: request as URLRequest) { (data, response, error) in

guard let urlContent = data else {
showAlert(vc: self, title: "Ooops", message: "There was an issue checking on payment status")
return
}
activeWallet { [weak self] wallet in
guard let self = self else { return }

guard let json = try? JSONSerialization.jsonObject(with: urlContent, options: JSONSerialization.ReadingOptions.mutableLeaves) as? NSDictionary else {
showAlert(vc: self, title: "Ooops", message: "There was an issue decoding the response when fetching payment status")
guard let wallet = wallet else {
self.fetchAddress()
return
}

var txCount = 0
let descriptorParser = DescriptorParser()
let descriptorStruct = descriptorParser.descriptor(wallet.receiveDescriptor)

if let chain_stats = json["chain_stats"] as? NSDictionary {
guard let count = chain_stats["tx_count"] as? Int else { return }

txCount += count
}

if let mempool_stats = json["mempool_stats"] as? NSDictionary {
guard let count = mempool_stats["tx_count"] as? Int else { return }

txCount += count
}

if txCount == 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + 15.0) { [weak self] in
guard let self = self else { return }

self.checkIfPaymentReceived(address)
}

if descriptorStruct.isMulti {
self.getReceieveAddressForFullyNodedMultiSig(wallet)
} else {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

let _ = KeyChain.set("hasPaid".dataUsingUTF8StringEncoding, forKey: "hasPaid")

self.dismiss(animated: true) {

showAlert(vc: self, title: "Thank you!", message: "Your support is greatly appreciated and will directly help making Fully Noded even better 💪")
}
}
self.fetchAddress()
}
}

task.resume()
}

private func getReceieveAddressForFullyNodedMultiSig(_ wallet: Wallet) {
Expand Down Expand Up @@ -435,7 +303,7 @@ class InvoiceViewController: UIViewController, UITextFieldDelegate {

self.addressOutlet.text = "see lightning invoice below"
self.addressString = invoice
self.updateQRImage()
self.qrView.image = self.generateQrCode(key: invoice)
self.invoiceText.text = invoice
self.spinner.removeConnectingView()
}
Expand Down
Loading

0 comments on commit 422468f

Please sign in to comment.