Fixed double conversion in tokens

pull/2/head
Michael Scoff 7 years ago
parent 89688bb360
commit 560f094bd7
  1. 4
      Trust.xcodeproj/project.pbxproj
  2. 4
      Trust/Models/Token.swift
  3. 8
      Trust/Tokens/ViewModels/TokenViewCellViewModel.swift

@ -34,6 +34,7 @@
291794FF1F95F5CE00539A30 /* Web3Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291794FE1F95F5CE00539A30 /* Web3Request.swift */; };
291795011F95F5E200539A30 /* GetBalance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291795001F95F5E200539A30 /* GetBalance.swift */; };
291795051F95F60100539A30 /* Web3RequestType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291795041F95F60100539A30 /* Web3RequestType.swift */; };
291795071F9602B500539A30 /* ConfirmSendViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291795061F9602B500539A30 /* ConfirmSendViewController.swift */; };
291D73C61F7F500D00A8AB56 /* TransactionItemState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291D73C51F7F500D00A8AB56 /* TransactionItemState.swift */; };
291E8FBF1F7DEA85003F0ECF /* EtherKeystoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291E8FBE1F7DEA85003F0ECF /* EtherKeystoreTests.swift */; };
291EC9DF1F7053C50004EDD0 /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291EC9DE1F7053C50004EDD0 /* NavigationController.swift */; };
@ -222,6 +223,7 @@
291794FE1F95F5CE00539A30 /* Web3Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Web3Request.swift; sourceTree = "<group>"; };
291795001F95F5E200539A30 /* GetBalance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetBalance.swift; sourceTree = "<group>"; };
291795041F95F60100539A30 /* Web3RequestType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Web3RequestType.swift; sourceTree = "<group>"; };
291795061F9602B500539A30 /* ConfirmSendViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmSendViewController.swift; sourceTree = "<group>"; };
291D73C51F7F500D00A8AB56 /* TransactionItemState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionItemState.swift; sourceTree = "<group>"; };
291E8FBE1F7DEA85003F0ECF /* EtherKeystoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EtherKeystoreTests.swift; sourceTree = "<group>"; };
291EC9DE1F7053C50004EDD0 /* NavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = "<group>"; };
@ -978,6 +980,7 @@
29285B411F6FB3E60044CF29 /* SendViewController.swift */,
29B6AECA1F7C5FA900EC6DE3 /* SendAndRequestViewContainer.swift */,
29B6AED31F7CA09600EC6DE3 /* TransactionConfigurationViewController.swift */,
291795061F9602B500539A30 /* ConfirmSendViewController.swift */,
);
path = Controllers;
sourceTree = "<group>";
@ -1558,6 +1561,7 @@
29E2E33A1F7A008C000CF94A /* UIView.swift in Sources */,
291795051F95F60100539A30 /* Web3RequestType.swift in Sources */,
290B2B5F1F9177860053C83E /* UIImage.swift in Sources */,
291795071F9602B500539A30 /* ConfirmSendViewController.swift in Sources */,
291F52B21F6B814300B369AB /* MG Benchmark Tools.swift in Sources */,
29FC0CB11F81CED10036089F /* TransactionByHashRequest.swift in Sources */,
291ED08F1F6F613200E7E93A /* GetTransactionRequest.swift in Sources */,

@ -7,7 +7,7 @@ struct Token {
let name: String
let symbol: String
let totalSupply: String
let balance: Int64
let balance: Double
let decimals: Int64
}
@ -19,7 +19,7 @@ extension Token {
name: tokenInfo["name"] as? String ?? "",
symbol: tokenInfo["symbol"] as? String ?? "",
totalSupply: tokenInfo["symbol"] as? String ?? "",
balance: json["balance"] as? Int64 ?? 0,
balance: json["balance"] as? Double ?? 0,
decimals: tokenInfo["decimals"] as? Int64 ?? Int64(tokenInfo["decimals"] as? String ?? "") ?? 0
)
}

@ -23,12 +23,8 @@ struct TokenViewCellViewModel {
}
var amount: String {
//Hack. Improve this part of the code
var value = String(token.balance)
if value.characters.count >= token.decimals {
value.insert(".", at: value.index(value.endIndex, offsetBy: -Int(token.decimals)))
}
let double = NSNumber(value: Double(value) ?? 0)
let res = pow(10.0, Double(token.decimals))
let double = NSNumber(value: token.balance / res)
return TokenViewCellViewModel.numberFormatter.string(from: double)!
}

Loading…
Cancel
Save