import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' import { getEthConversionFromWeiHex, getValueFromWeiHex } from '../../helpers/conversions.util' import { formatDate } from '../../util' import TransactionActivityLogIcon from './transaction-activity-log-icon' import { CONFIRMED_STATUS } from './transaction-activity-log.constants' import prefixForNetwork from '../../../lib/etherscan-prefix-for-network' export default class TransactionActivityLog extends PureComponent { static contextTypes = { t: PropTypes.func, } static propTypes = { activities: PropTypes.array, className: PropTypes.string, conversionRate: PropTypes.number, inlineRetryIndex: PropTypes.number, inlineCancelIndex: PropTypes.number, nativeCurrency: PropTypes.string, onCancel: PropTypes.func, onRetry: PropTypes.func, primaryTransaction: PropTypes.object, } handleActivityClick = hash => { const { primaryTransaction } = this.props const { dekusanNetworkId } = primaryTransaction const prefix = prefixForNetwork(dekusanNetworkId) const etherscanUrl = `https://${prefix}dexonscan.app/transaction/${hash}` global.platform.openWindow({ url: etherscanUrl }) } renderInlineRetry (index, activity) { const { t } = this.context const { inlineRetryIndex, primaryTransaction = {}, onRetry } = this.props const { status } = primaryTransaction const { id } = activity return status !== CONFIRMED_STATUS && index === inlineRetryIndex ? (
onRetry(id)} > { t('speedUpTransaction') }
) : null } renderInlineCancel (index, activity) { const { t } = this.context const { inlineCancelIndex, primaryTransaction = {}, onCancel } = this.props const { status } = primaryTransaction const { id } = activity return status !== CONFIRMED_STATUS && index === inlineCancelIndex ? (
onCancel(id)} > { t('speedUpCancellation') }
) : null } renderActivity (activity, index) { const { conversionRate, nativeCurrency } = this.props const { eventKey, value, timestamp, hash } = activity const ethValue = index === 0 ? `${getValueFromWeiHex({ value, fromCurrency: nativeCurrency, toCurrency: nativeCurrency, conversionRate, numberOfDecimals: 6, })} ${nativeCurrency}` : getEthConversionFromWeiHex({ value, fromCurrency: nativeCurrency, conversionRate, numberOfDecimals: 3, }) const formattedTimestamp = formatDate(timestamp, 'T \'on\' M/d/y') const activityText = this.context.t(eventKey, [ethValue, formattedTimestamp]) return (
this.handleActivityClick(hash)} > { activityText }
{ this.renderInlineRetry(index, activity) } { this.renderInlineCancel(index, activity) }
) } render () { const { t } = this.context const { className, activities } = this.props return (
{ t('activityLog') }
{ activities.map((activity, index) => this.renderActivity(activity, index)) }
) } } #n5'>5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
<!--