Skip to content

Commit 473b2b2

Browse files
Fix pending erc20 amount
1 parent e189bae commit 473b2b2

13 files changed

+36
-25
lines changed

Adamant/CoreData/BaseTransaction+TransactionDetails.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension BaseTransaction: TransactionDetails {
2020
var confirmationsValue: String? { return isConfirmed ? String(confirmations) : nil }
2121
var blockValue: String? { return isConfirmed ? blockId : nil }
2222

23-
var amountValue: Decimal {
23+
var amountValue: Decimal? {
2424
if let amount = self.amount {
2525
return amount.decimalValue
2626
} else {

Adamant/Models/BaseBtcTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BaseBtcTransaction: TransactionDetails {
1818
let senderAddress: String
1919
let recipientAddress: String
2020

21-
let amountValue: Decimal
21+
let amountValue: Decimal?
2222
let feeValue: Decimal?
2323
let confirmationsValue: String?
2424

Adamant/Models/EthTransaction.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension EthResponse: Decodable {
4444
struct EthTransaction {
4545
let date: Date?
4646
let hash: String
47-
let value: Decimal
47+
let value: Decimal?
4848
let from: String
4949
let to: String
5050
let gasUsed: Decimal?
@@ -140,7 +140,7 @@ extension EthTransaction: TransactionDetails {
140140
var senderAddress: String { return from }
141141
var recipientAddress: String { return to }
142142
var dateValue: Date? { return date }
143-
var amountValue: Decimal { return value }
143+
var amountValue: Decimal? { return value }
144144
var confirmationsValue: String? { return confirmations }
145145
var blockValue: String? { return blockNumber}
146146

@@ -161,8 +161,8 @@ extension EthTransaction: TransactionDetails {
161161
extension EthereumTransaction {
162162
func asEthTransaction(date: Date?, gasUsed: BigUInt?, blockNumber: String?, confirmations: String?, receiptStatus: TransactionReceipt.TXStatus, isOutgoing: Bool, hash: String? = nil, for token: ERC20Token? = nil) -> EthTransaction {
163163

164-
var recipient = self.to
165-
var txValue = value
164+
var recipient = to
165+
var txValue: BigUInt? = value
166166

167167
var exponent = EthWalletService.currencyExponent
168168
if let naturalUnits = token?.naturalUnits {
@@ -178,10 +178,14 @@ extension EthereumTransaction {
178178
txValue = v
179179
}
180180
}
181+
182+
if receiptStatus == .notYetProcessed {
183+
txValue = nil
184+
}
181185

182186
return EthTransaction(date: date,
183187
hash: hash ?? txhash ?? "",
184-
value: txValue.asDecimal(exponent: exponent),
188+
value: txValue?.asDecimal(exponent: exponent),
185189
from: sender?.address ?? "",
186190
to: recipient.address,
187191
gasUsed: gasUsed?.asDecimal(exponent: 0),

Adamant/Models/SimpleTransactionDetails.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct SimpleTransactionDetails: TransactionDetails {
1919

2020
var dateValue: Date?
2121

22-
var amountValue: Decimal
22+
var amountValue: Decimal?
2323

2424
var feeValue: Decimal?
2525

Adamant/Wallets/Dash/DashTransactionsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class DashTransactionsViewController: TransactionsListViewControllerBase {
179179
isOutgoing: outgoing,
180180
partnerId: partnerId,
181181
partnerName: partnerName,
182-
amount: transaction.amountValue,
182+
amount: transaction.amountValue ?? 0,
183183
date: transaction.dateValue)
184184
}
185185

Adamant/Wallets/Doge/DogeTransactionsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class DogeTransactionsViewController: TransactionsListViewControllerBase {
180180
isOutgoing: outgoing,
181181
partnerId: partnerId,
182182
partnerName: partnerName,
183-
amount: transaction.amountValue,
183+
amount: transaction.amountValue ?? 0,
184184
date: transaction.dateValue)
185185
}
186186

Adamant/Wallets/Doge/DogeWalletService+Send.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ extension BitcoinKit.Transaction: TransactionDetails {
124124
}
125125
}
126126

127-
var amountValue: Decimal {
127+
var amountValue: Decimal? {
128128
return Decimal(outputs[0].value) / Decimal(100000000)
129129
}
130130

Adamant/Wallets/ERC20/ERC20WalletService+RichMessageProviderWithStatusCheck.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extension ERC20WalletService: RichMessageProviderWithStatusCheck {
6565
let min = reportedValue - reportedValue*0.005
6666
let max = reportedValue + reportedValue*0.005
6767

68-
guard (min...max).contains(tx.value) else {
68+
guard (min...max).contains(tx.value ?? 0) else {
6969
completion(.success(result: .warning))
7070
return
7171
}

Adamant/Wallets/ERC20/ERC20WalletService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ extension ERC20WalletService {
411411
let result: WalletServiceResult<EthTransaction>
412412

413413
switch error {
414-
// Transaction not delivired yet
414+
// Transaction not delivered yet
415415
case .inputError, .nodeError:
416416
let transaction = details.transaction.asEthTransaction(date: nil, gasUsed: nil, blockNumber: nil, confirmations: nil, receiptStatus: TransactionReceipt.TXStatus.notYetProcessed, isOutgoing: false)
417417
result = .success(result: transaction)

Adamant/Wallets/Lisk/LskTransactionsViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class LskTransactionsViewController: TransactionsListViewControllerBase {
109109
isOutgoing: outgoing,
110110
partnerId: partnerId ?? "",
111111
partnerName: nil,
112-
amount: transaction.amountValue,
112+
amount: transaction.amountValue ?? 0,
113113
date: transaction.dateValue)
114114
}
115115

@@ -129,7 +129,7 @@ extension Transactions.TransactionModel: TransactionDetails {
129129
return Date(timeIntervalSince1970: TimeInterval(self.timestamp) + Constants.Time.epochSeconds)
130130
}
131131

132-
var amountValue: Decimal {
132+
var amountValue: Decimal? {
133133
let value = BigUInt(self.amount) ?? BigUInt(0)
134134

135135
return value.asDecimal(exponent: LskWalletService.currencyExponent)
@@ -192,7 +192,7 @@ extension LocalTransaction: TransactionDetails {
192192
return Date(timeIntervalSince1970: TimeInterval(self.timestamp) + Constants.Time.epochSeconds)
193193
}
194194

195-
var amountValue: Decimal {
195+
var amountValue: Decimal? {
196196
let value = BigUInt(self.amount)
197197

198198
return value.asDecimal(exponent: LskWalletService.currencyExponent)

Adamant/Wallets/Lisk/LskWalletService+RichMessageProviderWithStatusCheck.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extension LskWalletService: RichMessageProviderWithStatusCheck {
5757
let min = reported - reported*0.005
5858
let max = reported + reported*0.005
5959

60-
guard (min...max).contains(lskTransaction.amountValue) else {
60+
guard (min...max).contains(lskTransaction.amountValue ?? 0) else {
6161
completion(.success(result: .warning))
6262
return
6363
}

Adamant/Wallets/TransactionDetails.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protocol TransactionDetails {
2323
var dateValue: Date? { get }
2424

2525
/// The amount of currency that was sent.
26-
var amountValue: Decimal { get }
26+
var amountValue: Decimal? { get }
2727

2828
/// The amount of fee that taken for transaction process.
2929
var feeValue: Decimal? { get }
@@ -52,7 +52,7 @@ extension TransactionDetails {
5252
Summary
5353
Sender: \(senderAddress)
5454
Recipient: \(recipientAddress)
55-
Amount: \(AdamantBalanceFormat.full.format(amountValue, withCurrencySymbol: symbol))
55+
Amount: \(AdamantBalanceFormat.full.format(amountValue ?? 0, withCurrencySymbol: symbol))
5656
"""
5757

5858
if let fee = feeValue {

Adamant/Wallets/TransactionDetailsViewControllerBase.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,22 +318,29 @@ class TransactionDetailsViewControllerBase: FormViewController {
318318
detailsSection.append(dateRow)
319319

320320
// MARK: Amount
321-
let amountRow = DecimalRow() {
321+
let amountRow = LabelRow() {
322322
$0.disabled = true
323323
$0.tag = Rows.amount.tag
324324
$0.title = Rows.amount.localized
325-
$0.formatter = AdamantBalanceFormat.currencyFormatter(for: .full, currencySymbol: currencySymbol)
326-
$0.value = transaction?.amountValue.doubleValue
325+
if let value = transaction?.amountValue {
326+
$0.value = currencyFormatter.string(from: value)
327+
} else {
328+
$0.value = TransactionDetailsViewControllerBase.awaitingValueString
329+
}
327330
}.cellSetup { (cell, _) in
328331
cell.selectionStyle = .gray
329332
}.onCellSelection { [weak self] (cell, row) in
330333
if let value = row.value {
331-
let text = AdamantBalanceFormat.full.format(value, withCurrencySymbol: self?.currencySymbol ?? nil)
332-
self?.shareValue(text, from: cell)
334+
self?.shareValue(value, from: cell)
333335
}
334336
}.cellUpdate { [weak self] (cell, row) in
335337
cell.textLabel?.textColor = .black
336-
row.value = self?.transaction?.amountValue.doubleValue
338+
339+
if let value = self?.transaction?.amountValue, let formatter = self?.currencyFormatter {
340+
row.value = formatter.string(from: value)
341+
} else {
342+
row.value = TransactionDetailsViewControllerBase.awaitingValueString
343+
}
337344
}
338345

339346
detailsSection.append(amountRow)

0 commit comments

Comments
 (0)