Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: grouping transactions by date #655

Merged
merged 10 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 44 additions & 78 deletions DashWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "Group 1805.png",
"filename" : "cn-tx.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group 1805@2x.png",
"filename" : "cn-tx@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group 1805@3x.png",
"filename" : "cn-tx@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "transaction.prev.receive.png",
"filename" : "Transaction types - Primary.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "transaction.prev.receive@2x.png",
"filename" : "Transaction types - Primary@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "transaction.prev.receive@3x.png",
"filename" : "Transaction types - Primary@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Transaction types - Primary.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Transaction types - Primary@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Transaction types - Primary@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Transaction types - Primary.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Transaction types - Primary@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Transaction types - Primary@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

28 changes: 17 additions & 11 deletions DashWallet/Sources/Categories/DSTransaction+DashWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension DSTransaction {

switch direction {
case .moved:
amount = account!.amountReceivedFromTransaction(onExternalAddresses: self)
amount = 0
case .sent:
let amountSent = chain.amountSent(by: self)
let amountReceived = chain.amountReceived(from: self)
Expand Down Expand Up @@ -129,7 +129,7 @@ extension DSTransaction {
@objc
extension DSTransaction {
var formattedShortTxDate: String {
DWDateFormatter.sharedInstance.shortString(from: date)
DWDateFormatter.sharedInstance.dateOnly(from: date)
}

var formattedLongTxDate: String {
Expand All @@ -139,6 +139,10 @@ extension DSTransaction {
var formattedISO8601TxDate: String {
DWDateFormatter.sharedInstance.iso8601String(from: date)
}

var formattedShortTxTime: String {
DWDateFormatter.sharedInstance.timeOnly(from: date)
}

var formattedDashAmountWithDirectionalSymbol: String {
let formatted = dashAmount.formattedDashAmount
Expand All @@ -151,7 +155,7 @@ extension DSTransaction {
}

func attributedDashAmount(with font: UIFont, color: UIColor = .dw_label()) -> NSAttributedString {
var formatted = formattedDashAmountWithDirectionalSymbol
let formatted = formattedDashAmountWithDirectionalSymbol
return formatted.attributedAmountStringWithDashSymbol(tintColor: color, dashSymbolColor: color, font: font)
}
}
Expand Down Expand Up @@ -186,31 +190,33 @@ extension DSTransactionDirection {
return .dw_label()
}
}

var icon: UIImage {
var iconName: String {
switch self {
case .moved:
return UIImage(named: "tx.item.internal.icon")!
return "tx.item.internal.icon"
case .sent:
return systemImage("arrow.up.circle.fill")
return "tx.item.sent.icon"
case .received:
return systemImage("arrow.down.circle.fill")
return "tx.item.received.icon"
case .notAccountFunds:
return systemImage("arrow.down.circle.fill")
return "tx.item.received.icon"
@unknown default:
fatalError()
}
}

var icon: UIImage {
return UIImage(named: iconName)!
}

private func systemImage(_ name: String) -> UIImage {
let iconConfig = UIImage.SymbolConfiguration(pointSize: 50, weight: .regular, scale: .large)
return UIImage(systemName: name, withConfiguration: iconConfig)!
}

var directionSymbol: String {
switch self {
case .moved:
return "⟲"
case .received:
return "+";
case .sent:
Expand Down
43 changes: 32 additions & 11 deletions DashWallet/Sources/Models/DWDateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,46 @@ class DWDateFormatter: NSObject {
private let shortDateFormatter: DateFormatter
private let longDateFormatter: DateFormatter
private let iso8601DateFormatter: DateFormatter
private let dateOnlyFormatter: DateFormatter
private let timeOnlyFormatter: DateFormatter
private let dayOfWeekFormatter: DateFormatter

private override init() {
let locale = Locale.current

shortDateFormatter = DateFormatter()
shortDateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "MMMdjmma", options: 0, locale: locale)
shortDateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "dd MMMM", options: 0, locale: locale)

longDateFormatter = DateFormatter()
longDateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "yyyyMMMdjmma", options: 0, locale: locale)
longDateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "dd MMMM, yyyy", options: 0, locale: locale)

iso8601DateFormatter = DateFormatter()
let enUSPOSIXLocale = Locale(identifier: "en_US_POSIX")
iso8601DateFormatter.locale = enUSPOSIXLocale
iso8601DateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
iso8601DateFormatter.calendar = Calendar(identifier: .gregorian)

dateOnlyFormatter = DateFormatter()
shortDateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "MMMd", options: 0, locale: locale)
timeOnlyFormatter = DateFormatter()
timeOnlyFormatter.timeStyle = .short
timeOnlyFormatter.dateStyle = .none
timeOnlyFormatter.locale = Locale.current

dayOfWeekFormatter = DateFormatter()
dayOfWeekFormatter.dateFormat = "EEEE"
}

func shortString(from date: Date) -> String {
func dateOnly(from date: Date, useRelative: Bool = true) -> String {
let calendar = Calendar.current

if useRelative {
if calendar.isDateInToday(date) {
return NSLocalizedString("Today", comment: "")
}

if calendar.isDateInYesterday(date) {
return NSLocalizedString("Yesterday", comment: "")
}
}

let nowYear = calendar.component(.year, from: Date())
let dateYear = calendar.component(.year, from: date)

Expand All @@ -56,18 +73,22 @@ class DWDateFormatter: NSObject {
func longString(from date: Date) -> String {
return longDateFormatter.string(from: date)
}

func dateOnly(from date: Date) -> String {
return shortDateFormatter.string(from: date)
}

func iso8601String(from date: Date) -> String {
return iso8601DateFormatter.string(from: date)
}

func timeOnly(from dateTime: Date) -> String {
return timeOnlyFormatter.string(from: dateTime)
}

func dayOfWeek(from date: Date) -> String {
return dayOfWeekFormatter.string(from: date).capitalized
}
}

@objc extension DWDateFormatter {
@objc func shortStringFromDate(_ date: Date) -> String {
return shortString(from: date)
return dateOnly(from: date)
}
}
43 changes: 37 additions & 6 deletions DashWallet/Sources/Models/Transactions/Model/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation

// MARK: - Transaction

class Transaction: TransactionDataItem {
class Transaction: TransactionDataItem, Identifiable {
enum State {
case ok
case invalid
Expand All @@ -36,6 +36,10 @@ class Transaction: TransactionDataItem {
case masternodeRevoke
case blockchainIdentityRegistration
}

var id: String {
tx.txHashHexString
}

let tx: DSTransaction
var direction: DSTransactionDirection { _direction }
Expand All @@ -56,8 +60,16 @@ class Transaction: TransactionDataItem {

var specialInfoAddresses: [String: Int]?

var dashAmount: UInt64 { _dashAmount }
private lazy var _dashAmount: UInt64 = tx.dashAmount

var dashAmount: UInt64 { _dashAmount }
var signedDashAmount: Int64 {
if dashAmount == UInt64.max {
return Int64.max
}

return direction == .sent ? -Int64(dashAmount) : Int64(dashAmount)
}

var fiatAmount: String {
storedFiatAmount
Expand Down Expand Up @@ -116,13 +128,17 @@ class Transaction: TransactionDataItem {
return .ok
}()

private lazy var _shortDateString: String = tx.formattedShortTxDate
var date: Date
var shortDateString: String {
_shortDateString
}

private lazy var _shortDateString: String = tx.formattedShortTxDate


private lazy var _shortTimeString: String = tx.formattedShortTxTime
var shortTimeString: String {
_shortTimeString
}

var stateTitle: String {
switch transactionType {
case .classic:
Expand Down Expand Up @@ -153,7 +169,7 @@ class Transaction: TransactionDataItem {
return NSLocalizedString("DashPay Upgrade Fee", comment: "")
}
}

init(transaction: DSTransaction) {
tx = transaction
date = transaction.date
Expand Down Expand Up @@ -187,3 +203,18 @@ extension Transaction {
tx is DSCoinbaseTransaction
}
}

extension Transaction: Hashable {
// MARK: - Equatable
static func == (lhs: Transaction, rhs: Transaction) -> Bool {
return lhs.tx.txHashData == rhs.tx.txHashData
}

// MARK: - Hashable
func hash(into hasher: inout Hasher) {
hasher.combine(dashAmount)
hasher.combine(direction)
hasher.combine(transactionType)
hasher.combine(date)
}
}
Loading