/* eslint-disable react/prop-types */ /* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable jsx-a11y/no-static-element-interactions */ import React, { Component } from 'react'; import Modal from 'react-modal'; import dateformat from 'dateformat'; import { shell } from 'electron'; import { withRouter } from 'react-router'; import { BalanceBlockHighlight } from './BalanceBlocks'; import styles from './Transactions.css'; import cstyles from './Common.css'; import { Transaction, Info } from './AppState'; import ScrollPane from './ScrollPane'; import Utils from '../utils/utils'; import AddressBook from './Addressbook'; import routes from '../constants/routes.json'; const TxModalInternal = ({ modalIsOpen, tx, closeModal, currencyName, zecPrice, setSendTo, history }) => { let txid = ''; let type = ''; let typeIcon = ''; let typeColor = ''; let confirmations = 0; let detailedTxns = []; let amount = 0; let datePart = ''; let timePart = ''; if (tx) { txid = tx.txid; type = tx.type; if (tx.type === 'receive') { typeIcon = 'fa-arrow-circle-down'; typeColor = 'green'; } else { typeIcon = 'fa-arrow-circle-up'; typeColor = 'red'; } datePart = dateformat(tx.time * 1000, 'mmm dd, yyyy'); timePart = dateformat(tx.time * 1000, 'hh:MM tt'); confirmations = tx.confirmations; detailedTxns = tx.detailedTxns; amount = Math.abs(tx.amount); } const openTxid = () => { if (currencyName === 'TAZ') { shell.openExternal(`https://chain.so/tx/ZECTEST/${txid}`); } else { shell.openExternal(`https://zcha.in/transactions/${txid}`); } }; const doReply = (address: string) => { setSendTo(address, 0.0001, null); closeModal(); history.push(routes.SEND); }; return (
Transaction Status
{type}
Time
{datePart} {timePart}
Confirmations
{confirmations}
TXID
{txid}
View TXID  

{detailedTxns.map(txdetail => { const { bigPart, smallPart } = Utils.splitZecAmountIntoBigSmall(Math.abs(txdetail.amount)); let { address } = txdetail; const { memo } = txdetail; if (!address) { address = '(Shielded)'; } let replyTo = null; if (tx.type === 'receive' && memo) { const split = memo.split(/[ :\n\r\t]+/); console.log(split); if (split && split.length > 0 && Utils.isSapling(split[split.length - 1])) { replyTo = split[split.length - 1]; } } console.log('replyto is', replyTo); return (
Address
{Utils.splitStringIntoChunks(address, 6).join(' ')}
Amount
{currencyName} {bigPart} {smallPart}
{memo && (
Memo
{memo}
{replyTo && (
doReply(replyTo)}> Reply
)}
)}
); })}
); }; const TxModal = withRouter(TxModalInternal); const TxItemBlock = ({ transaction, currencyName, zecPrice, txClicked, addressBookMap }) => { const txDate = new Date(transaction.time * 1000); const datePart = dateformat(txDate, 'mmm dd, yyyy'); const timePart = dateformat(txDate, 'hh:MM tt'); return (
{datePart}
{ txClicked(transaction); }} >
{transaction.type}
{timePart}
{transaction.detailedTxns.map(txdetail => { const { bigPart, smallPart } = Utils.splitZecAmountIntoBigSmall(Math.abs(txdetail.amount)); let { address } = txdetail; const { memo } = txdetail; if (!address) { address = '(Shielded)'; } const label = addressBookMap[address] || ''; return (
{label}
{Utils.splitStringIntoChunks(address, 6).join(' ')}
{memo}
{currencyName} {bigPart} {smallPart}
{Utils.getZecToUsdString(zecPrice, Math.abs(txdetail.amount))}
); })}
); }; type Props = { transactions: Transaction[], addressBook: AddressBook[], info: Info, setSendTo: (string, number | null, string | null) => void }; type State = { clickedTx: Transaction | null, modalIsOpen: boolean }; export default class Transactions extends Component { constructor(props: Props) { super(props); this.state = { clickedTx: null, modalIsOpen: false }; } txClicked = (tx: Transaction) => { // Show the modal if (!tx) return; this.setState({ clickedTx: tx, modalIsOpen: true }); }; closeModal = () => { this.setState({ clickedTx: null, modalIsOpen: false }); }; render() { const { transactions, info, addressBook, setSendTo } = this.props; const { clickedTx, modalIsOpen } = this.state; const addressBookMap = addressBook.reduce((map, obj) => { // eslint-disable-next-line no-param-reassign map[obj.address] = obj.label; return map; }, {}); return (
Transactions
{/* Change the hardcoded height */} {/* If no transactions, show the "loading..." text */ !transactions &&
Loading...
} {transactions && transactions.length === 0 && (
No Transactions Yet
)} {transactions && transactions.map(t => { const key = t.type + t.txid + t.address; return ( ); })}
); } }