Skip to content

Commit

Permalink
Merge pull request #656 from Syn-McJ/fix/historical-rates
Browse files Browse the repository at this point in the history
fix: historical rates regression & other fixes
  • Loading branch information
Syn-McJ authored Jun 7, 2024
2 parents b2d1b24 + d26fc26 commit b719906
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DashSyncCurrentCommit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
49b6db28808308255a8a6a30d1fe5670d9c9c50e
8e211b3d6c33781c1cad47ec58f66ad5914e8ae6
5 changes: 1 addition & 4 deletions DashWallet/Sources/Categories/DSTransaction+DashWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ extension DSTransaction {
}

var direction: DSTransactionDirection {
let currentAccount = DWEnvironment.sharedInstance().currentAccount
let account = accounts.contains(where: { ($0 as! DSAccount) == currentAccount }) ? currentAccount : nil

return account != nil ? chain.direction(of: self) : .notAccountFunds
return chain.direction(of: self)
}

var outputReceiveAddresses: [String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ enum TaxReportGenerator {
return taxCategoryString
case .sentQuantity:
let fee = transactionDirection == .sent ? transaction.feeUsed : 0
guard transaction.dashAmount != UInt64.max else { return "" }
let dashAmount = transaction.dashAmount + fee
let formattedNumber = NumberFormatter.csvDashFormatter.string(from: dashAmount.dashAmount as NSDecimalNumber) ?? ""
return isOutcoming ? formattedNumber : ""
Expand All @@ -143,6 +144,7 @@ enum TaxReportGenerator {
return isOutcoming ? kSource : ""
case .receivedQuantity:
let fee = transactionDirection == .sent ? transaction.feeUsed : 0
guard transaction.dashAmount != UInt64.max else { return "" }
let dashAmount = transaction.dashAmount + fee
let formattedNumber = NumberFormatter.csvDashFormatter.string(from: dashAmount.dashAmount as NSDecimalNumber) ?? ""
return isOutcoming ? "" : formattedNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Transaction: TransactionDataItem, Identifiable {
storedFiatAmount
}

lazy var storedFiatAmount = userInfo?.fiatAmountString(from: _dashAmount) ?? NSLocalizedString("Not available", comment: "");
private lazy var storedFiatAmount = userInfo?.fiatAmountString(from: _dashAmount) ?? NSLocalizedString("Not available", comment: "");

lazy var userInfo: TxUserInfo? = TxUserInfoDAOImpl.shared.get(by: tx.txHashData)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ struct CrowdNodeGroupedTransactionsScreen: View {
title: txItem.stateTitle,
subtitle: txItem.shortDateString,
icon: .custom(txItem.direction.iconName),
dashAmount: txItem.direction == .sent ? -Int64(txItem.dashAmount) : Int64(txItem.dashAmount)
dashAmount: txItem.signedDashAmount,
overrideFiatAmount: txItem.fiatAmount
) {
self.currentTag = txItem.txHashHexString
onShowBackButton(true)
Expand Down
3 changes: 2 additions & 1 deletion DashWallet/Sources/UI/Home/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ struct TransactionList<Content: View>: View {
title: txItem.stateTitle,
subtitle: txItem.shortTimeString,
icon: .custom(txItem.direction.iconName),
dashAmount: txItem.signedDashAmount
dashAmount: txItem.signedDashAmount,
overrideFiatAmount: txItem.fiatAmount
) {
self.selectedTxDataItem = txDataItem
}
Expand Down
14 changes: 10 additions & 4 deletions DashWallet/Sources/UI/SwiftUI Components/MenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct MenuItem: View {
var showInfo: Bool = false
var showChevron: Bool = false
var dashAmount: Int64? = nil
var overrideFiatAmount: String? = nil
var isToggled: Binding<Bool>? = nil
var action: (() -> Void)? = nil

Expand Down Expand Up @@ -119,8 +120,14 @@ struct MenuItem: View {
if let dashAmount = dashAmount {
DashAmount(amount: dashAmount)

if dashAmount != 0 {
FormattedFiatText(from: dashAmount)
if dashAmount != 0 && dashAmount != Int64.max && dashAmount != Int64.min {
if let overriden = overrideFiatAmount {
Text(overriden)
.font(.caption)
.foregroundColor(.secondaryText)
} else {
FormattedFiatText(from: dashAmount)
}
}
}
}
Expand All @@ -137,14 +144,13 @@ struct MenuItem: View {
@ViewBuilder
private func FormattedFiatText(from dashAmount: Int64) -> some View {
let text = (try? CurrencyExchanger.shared.convertDash(amount: abs(dashAmount.dashAmount), to: App.fiatCurrency).formattedFiatAmount) ?? NSLocalizedString("Not available", comment: "")

Text(text)
.font(.caption)
.foregroundColor(.secondaryText)
}
}


#Preview {
MenuItem(
title: "Title",
Expand Down
4 changes: 2 additions & 2 deletions DashWallet/Sources/UI/SwiftUI Components/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ struct ToastView: View {
Spacer()

if let text = actionText, let action = action {
DashButton(text: text, style: .plain, size: .extraSmall, action: action)
DashButton(text: text, style: .plain, size: .extraSmall, stretch: false, action: action)
.overrideForegroundColor(Color.primaryBackground)
}

if let icon = closeButtonIcon, let action = closeAction {
DashButton(leadingIcon: icon, style: .plain, size: .small, action: action)
DashButton(leadingIcon: icon, style: .plain, size: .small, stretch: false, action: action)
.overrideForegroundColor(Color.primaryBackground)
}
}
Expand Down

0 comments on commit b719906

Please sign in to comment.