diff --git a/AlphaWallet/Activities/ViewModels/DefaultActivityViewModel.swift b/AlphaWallet/Activities/ViewModels/DefaultActivityViewModel.swift index f48ac07cd..4e9bdc24b 100644 --- a/AlphaWallet/Activities/ViewModels/DefaultActivityViewModel.swift +++ b/AlphaWallet/Activities/ViewModels/DefaultActivityViewModel.swift @@ -37,11 +37,19 @@ struct DefaultActivityViewModel { let string: String switch activity.nativeViewType { - case .erc20Sent, .erc20Received, .erc20OwnerApproved, .erc20ApprovalObtained, .nativeCryptoSent, .nativeCryptoReceived: + case .erc20Sent, .erc20Received, .nativeCryptoSent, .nativeCryptoReceived: if let value = cardAttributes["amount"]?.uintValue { - let formatter = EtherNumberFormatter.short - let value = formatter.string(from: BigInt(value)) - string = "\(sign)\(value) \(activity.tokenObject.symbol)" + string = stringFromFungibleAmount(sign: sign, amount: value) + } else { + string = "" + } + case .erc20OwnerApproved, .erc20ApprovalObtained: + if let value = cardAttributes["amount"]?.uintValue { + if doesApprovedAmountLookReallyBig(value, decimals: activity.tokenObject.decimals) { + string = R.string.localizable.activityApproveAmountAll(activity.tokenObject.symbol) + } else { + string = stringFromFungibleAmount(sign: sign, amount: value) + } } else { string = "" } @@ -64,4 +72,15 @@ struct DefaultActivityViewModel { return NSAttributedString(string: string, attributes: [.font: Fonts.regular(size: 28), .foregroundColor: R.color.silver()!, .strikethroughStyle: NSUnderlineStyle.single.rawValue]) } } + + private func stringFromFungibleAmount(sign: String, amount: BigUInt) -> String { + let formatter = EtherNumberFormatter.short + let value = formatter.string(from: BigInt(amount), decimals: activity.tokenObject.decimals) + return "\(sign)\(value) \(activity.tokenObject.symbol)" + } + + private func doesApprovedAmountLookReallyBig(_ amount: BigUInt, decimals: Int) -> Bool { + let empiricallyBigLimit: Double = 90_000_000 + return Double(amount) / pow(10, activity.tokenObject.decimals).doubleValue > empiricallyBigLimit + } }