Commit b9c169bd authored by Jü's avatar

Merge remote-tracking branch 'origin/development'

parents d57be09e 741e9621
......@@ -12,6 +12,14 @@ extension Double {
private static let exactNumberOfFractionDigits = 2
public func toXMR() -> UInt64? {
if self >= Double(UInt64.min) && self * Double(Constants.atomicUnitsPerMonero) < Double(UInt64.max) {
return UInt64(self * Double(Constants.atomicUnitsPerMonero))
} else {
return nil
}
}
public func toCurrency() -> String {
guard let currency = Double.currencyFormatter.string(from: NSNumber(value: self)) else {
return ""
......@@ -19,10 +27,6 @@ extension Double {
return currency
}
public func toXMR() -> UInt64 {
return UInt64(self * Double(Constants.atomicUnitsPerMonero))
}
private static let currencyFormatter: NumberFormatter = {
let numberFormatter = NumberFormatter()
numberFormatter.allowsFloats = true
......
......@@ -483,18 +483,19 @@ extension WalletCoordinator: AmountVCDelegate {
return
}
let requestedXmrInAtomicUnits = UInt64(requestedXmrDouble * Double(Constants.atomicUnitsPerMonero))
let requestedXmrInAtomicUnits = (requestedXmrDouble).toXMR()
let fiatValue = self.otherAmount(forXMRValue: requestedXmrInAtomicUnits)
viewController.showFiatValue(fiatValue, forCurrency: self.propertyStore.currency)
let available = self.moneroBag.wallet?.balance ?? 0
if requestedXmrInAtomicUnits > 0 && requestedXmrInAtomicUnits <= available {
if requestedXmrInAtomicUnits != nil && requestedXmrInAtomicUnits! > 0 && requestedXmrInAtomicUnits! <= available {
viewController.nextAllowed()
} else {
viewController.nextNotAllowed()
}
}
private func showPaymentIdViewController() {
let vc = self.storyboard.instantiateViewController(withIdentifier: PaymentIdSceneName) as! PaymentIdVC
vc.delegate = self
......
......@@ -202,8 +202,7 @@ extension AmountVC: UITextFieldDelegate {
}
if let amountValue = textField.text {
self.delegate?.amountVCAmountValueChanged(amount: amountValue.toDouble(),
viewController: self)
self.delegate?.amountVCAmountValueChanged(amount: amountValue.toDouble(), viewController: self)
}
return false
......
......@@ -19,13 +19,21 @@ class Double_ExtensionTests: XCTestCase {
super.tearDown()
}
public func test_toXMR_Success() {
let givenDouble: Double = 11.01
let expectedUInt64: UInt64 = 11010000000000
public func test_toXMR() {
let expectedXmr: UInt64 = 22080000000000
let result = givenDouble.toXMR()
let result = 22.08.toXMR()
XCTAssertEqual(expectedUInt64, result)
}
public func test_toXMR_Error() {
let givenDouble: Double = 99999999
let result = givenDouble.toXMR()
XCTAssertEqual(expectedXmr, result)
XCTAssertEqual(nil, result)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment