Merge pull request #1640 from AlphaWallet/clean-force-unwraps

clean up force unwraps
pull/1644/head
James Sangalli 5 years ago committed by GitHub
commit 160dcc2895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift
  2. 6
      AlphaWallet/Redeem/Helpers/CreateRedeem.swift
  3. 11
      AlphaWallet/Redeem/Helpers/SignatureHelper.swift
  4. 10
      AlphaWallet/Redeem/ViewControllers/TokenCardRedemptionViewController.swift

@ -609,9 +609,7 @@ class UniversalLinkCoordinator: Coordinator {
}
private func convert(ethCost: BigUInt) -> Decimal {
//TODO extract constant. Used elsewhere too
let divideAmount = Decimal(string: "1000000000000000000")!
let etherCostDecimal = Decimal(string: ethCost.description)! / divideAmount
let etherCostDecimal = Decimal(string: ethCost.description)! / Decimal(EthereumUnit.ether.rawValue)
return etherCostDecimal
}
}

@ -64,10 +64,10 @@ class CreateRedeem {
/* the method here is easier to express with matrix programming like this:
indexList = indexList - correctionFactor # reduce every element of the list by an int
selection = sum(2^indexList) # raise every element and add the result back */
var bitFieldLookup = BigUInt("0")!
var bitFieldLookup = BigUInt(0)
for _ in 0...indices.count - 1 {
let adder = BigUInt("2")?.power(Int(indices[0]) - correctionFactor)
bitFieldLookup = bitFieldLookup.advanced(by: BigInt(adder!))
let adder = BigUInt(2).power(Int(indices[0]) - correctionFactor)
bitFieldLookup = bitFieldLookup.advanced(by: BigInt(adder))
}
let bitIntLength: Int = bitFieldLookup.description.count

@ -10,8 +10,8 @@ import Foundation
import BigInt
class SignatureHelper {
class func signatureAsHex(for message: String, account: EthereumAccount) -> String? {
let keystore = try! EtherKeystore()
class func signatureAsHex(for message: String, account: EthereumAccount) throws -> String? {
let keystore = try EtherKeystore()
let signature = keystore.signMessageData(message.data(using: String.Encoding.utf8), for: account)
let signatureHex = try? signature.dematerialize().hex(options: .upperCase)
guard let data = signatureHex else {
@ -20,8 +20,9 @@ class SignatureHelper {
return data
}
class func signatureAsDecimal(for message: String, account: EthereumAccount) -> String? {
let signatureHex = signatureAsHex(for: message, account: account)!
return BigInt(signatureHex, radix: 16)!.description
class func signatureAsDecimal(for message: String, account: EthereumAccount) throws -> String? {
guard let signatureHex = try signatureAsHex(for: message, account: account) else { return nil }
guard let signatureDecimalString = BigInt(signatureHex, radix: 16)?.description else { return nil }
return signatureDecimalString
}
}

@ -114,9 +114,13 @@ class TokenCardRedemptionViewController: UIViewController, TokenVerifiableStatus
}
switch session.account.type {
case .real(let account):
let decimalSignature = SignatureHelper.signatureAsDecimal(for: redeemData.message, account: account)!
let qrCodeInfo = redeemData.qrCode + decimalSignature
imageView.image = qrCodeInfo.toQRCode()
do {
guard let decimalSignature = try SignatureHelper.signatureAsDecimal(for: redeemData.message, account: account) else { break }
let qrCodeInfo = redeemData.qrCode + decimalSignature
imageView.image = qrCodeInfo.toQRCode()
} catch {
break
}
case .watch: break
}
}

Loading…
Cancel
Save