Craig Raw
5 years ago
10 changed files with 232 additions and 20 deletions
@ -0,0 +1,31 @@ |
|||
package com.sparrowwallet.sparrow.control; |
|||
|
|||
import java.text.DateFormat; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
|
|||
public class DateLabel extends CopyableLabel { |
|||
private static final DateFormat LAST_24_HR = new SimpleDateFormat("HH:mm"); |
|||
private static final DateFormat LAST_YEAR = new SimpleDateFormat("d MMM"); |
|||
private static final DateFormat ALL_TIME = new SimpleDateFormat("yyyy/MM/dd"); |
|||
|
|||
private Date date; |
|||
|
|||
public DateLabel(Date date) { |
|||
super(getShortDateFormat(date)); |
|||
this.date = date; |
|||
} |
|||
|
|||
public static String getShortDateFormat(Date date) { |
|||
Date now = new Date(); |
|||
long elapsed = (now.getTime() - date.getTime()) / 1000; |
|||
|
|||
if(elapsed < 24 * 60 * 60) { |
|||
return LAST_24_HR.format(date); |
|||
} else if(elapsed < 365 * 24 * 60 * 60) { |
|||
return LAST_YEAR.format(date); |
|||
} else { |
|||
return ALL_TIME.format(date); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
package com.sparrowwallet.sparrow.event; |
|||
|
|||
import com.sparrowwallet.drongo.wallet.BlockTransaction; |
|||
import com.sparrowwallet.sparrow.wallet.HashIndexEntry; |
|||
|
|||
public class TransactionViewEvent { |
|||
public final BlockTransaction blockTransaction; |
|||
public final HashIndexEntry hashIndexEntry; |
|||
|
|||
public TransactionViewEvent(BlockTransaction blockTransaction) { |
|||
this(blockTransaction, null); |
|||
} |
|||
|
|||
public TransactionViewEvent(BlockTransaction blockTransaction, HashIndexEntry hashIndexEntry) { |
|||
this.blockTransaction = blockTransaction; |
|||
this.hashIndexEntry = hashIndexEntry; |
|||
} |
|||
|
|||
public BlockTransaction getBlockTransaction() { |
|||
return blockTransaction; |
|||
} |
|||
|
|||
public HashIndexEntry getHashIndexEntry() { |
|||
return hashIndexEntry; |
|||
} |
|||
} |
@ -0,0 +1,64 @@ |
|||
package com.sparrowwallet.sparrow.wallet; |
|||
|
|||
import com.sparrowwallet.drongo.wallet.BlockTransaction; |
|||
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex; |
|||
import com.sparrowwallet.drongo.wallet.Wallet; |
|||
import com.sparrowwallet.sparrow.EventManager; |
|||
import com.sparrowwallet.sparrow.control.DateLabel; |
|||
import com.sparrowwallet.sparrow.event.WalletChangedEvent; |
|||
|
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
|
|||
public class HashIndexEntry extends Entry { |
|||
private final Wallet wallet; |
|||
private final BlockTransactionHashIndex hashIndex; |
|||
private final Type type; |
|||
|
|||
public HashIndexEntry(Wallet wallet, BlockTransactionHashIndex hashIndex, Type type) { |
|||
super(hashIndex.getLabel(), hashIndex.getSpentBy() != null ? List.of(new HashIndexEntry(wallet, hashIndex.getSpentBy(), Type.INPUT)) : Collections.emptyList()); |
|||
this.wallet = wallet; |
|||
this.hashIndex = hashIndex; |
|||
this.type = type; |
|||
|
|||
labelProperty().addListener((observable, oldValue, newValue) -> { |
|||
hashIndex.setLabel(newValue); |
|||
EventManager.get().post(new WalletChangedEvent(wallet)); |
|||
}); |
|||
} |
|||
|
|||
public Wallet getWallet() { |
|||
return wallet; |
|||
} |
|||
|
|||
public BlockTransactionHashIndex getHashIndex() { |
|||
return hashIndex; |
|||
} |
|||
|
|||
public Type getType() { |
|||
return type; |
|||
} |
|||
|
|||
public BlockTransaction getBlockTransaction() { |
|||
return wallet.getTransactions().get(hashIndex.getHash()); |
|||
} |
|||
|
|||
public String getDescription() { |
|||
return (type.equals(Type.INPUT) ? "Spent by " : "Received from ") + |
|||
getHashIndex().getHash().toString().substring(0, 8) + "...:" + getHashIndex().getIndex() + |
|||
" on " + DateLabel.getShortDateFormat(getHashIndex().getDate()); |
|||
} |
|||
|
|||
public boolean isSpent() { |
|||
return getType().equals(HashIndexEntry.Type.INPUT) || getHashIndex().getSpentBy() != null; |
|||
} |
|||
|
|||
@Override |
|||
public Long getValue() { |
|||
return hashIndex.getValue(); |
|||
} |
|||
|
|||
public enum Type { |
|||
INPUT, OUTPUT |
|||
} |
|||
} |
Loading…
Reference in new issue