-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 21 additions & 1 deletion
22
app/src/main/java/com/github/jvsena42/floresta/presentation/ui/screens/home/TransactionVM.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
package com.github.jvsena42.floresta.presentation.ui.screens.home | ||
|
||
import com.github.jvsena42.floresta.domain.model.ChainPosition | ||
import com.github.jvsena42.floresta.domain.model.TransactionDetails | ||
import com.github.jvsena42.floresta.domain.model.TxType | ||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.util.Locale | ||
|
||
data class TransactionVM( | ||
val title: String, | ||
val date: String, | ||
val amount: String, | ||
val isReceived: Boolean | ||
) | ||
) | ||
|
||
fun TransactionDetails.toTransactionVM() = TransactionVM( | ||
title = this.txid, | ||
date = if (this.chainPosition is ChainPosition.Confirmed) convertMillisecondsToDateString(this.chainPosition.timestamp.toLong()) else "", | ||
amount = (if (txType == TxType.RECEIVE) this.received.toSat() else this.sent.toSat()).toString(), | ||
isReceived = txType == TxType.RECEIVE | ||
) | ||
|
||
private fun convertMillisecondsToDateString(milliseconds: Long): String { | ||
val date = Date(milliseconds) | ||
val format = SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.getDefault()) | ||
return format.format(date) | ||
} |