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

Add Copy Tx ID button to transaction-list-item-details #6146

Merged
merged 2 commits into from
Feb 17, 2019
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
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@
"copyAddress": {
"message": "Copy address to clipboard"
},
"copyTransactionId": {
"message": "Copy Transaction ID"
},
"copiedTransactionId": {
"message": "Copied Transaction ID"
},
"copyToClipboard": {
"message": "Copy to clipboard"
},
Expand Down
5 changes: 5 additions & 0 deletions ui/app/components/transaction-list-item-details/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
&:not(:last-child) {
margin-right: 8px;
}

&__copy-icon {
width: 10px;
height: 10px;
}
}

&__sender-to-recipient-container {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('TransactionListItemDetails Component', () => {
)

assert.ok(wrapper.hasClass('transaction-list-item-details'))
assert.equal(wrapper.find(Button).length, 1)
assert.equal(wrapper.find(Button).length, 2)
assert.equal(wrapper.find(SenderToRecipient).length, 1)
assert.equal(wrapper.find(TransactionBreakdown).length, 1)
assert.equal(wrapper.find(TransactionActivityLog).length, 1)
Expand Down Expand Up @@ -76,6 +76,6 @@ describe('TransactionListItemDetails Component', () => {
)

assert.ok(wrapper.hasClass('transaction-list-item-details'))
assert.equal(wrapper.find(Button).length, 2)
assert.equal(wrapper.find(Button).length, 3)
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import copyToClipboard from 'copy-to-clipboard'
import SenderToRecipient from '../sender-to-recipient'
import { FLAT_VARIANT } from '../sender-to-recipient/sender-to-recipient.constants'
import TransactionActivityLog from '../transaction-activity-log'
Expand All @@ -21,6 +22,10 @@ export default class TransactionListItemDetails extends PureComponent {
transactionGroup: PropTypes.object,
}

state = {
justCopied: false,
}

handleEtherscanClick = () => {
const { transactionGroup: { primaryTransaction } } = this.props
const { hash, metamaskNetworkId } = primaryTransaction
Expand All @@ -45,8 +50,20 @@ export default class TransactionListItemDetails extends PureComponent {
onRetry(id)
}

handleCopyTxId = () => {
const { transactionGroup} = this.props
const { primaryTransaction: transaction } = transactionGroup
const { hash } = transaction

this.setState({ justCopied: true }, () => {
copyToClipboard(hash)
setTimeout(() => this.setState({ justCopied: false }), 1000)
})
}

render () {
const { t } = this.context
const { justCopied } = this.state
const { transactionGroup, showCancel, showRetry, onCancel, onRetry } = this.props
const { primaryTransaction: transaction } = transactionGroup
const { txParams: { to, from } = {} } = transaction
Expand Down Expand Up @@ -78,6 +95,18 @@ export default class TransactionListItemDetails extends PureComponent {
</Button>
)
}
<Tooltip title={justCopied ? t('copiedTransactionId') : t('copyTransactionId')}>
<Button
type="raised"
onClick={this.handleCopyTxId}
className="transaction-list-item-details__header-button"
>
<img
className="transaction-list-item-details__header-button__copy-icon"
src="/images/copy-to-clipboard.svg"
/>
</Button>
</Tooltip>
<Tooltip title={t('viewOnEtherscan')}>
<Button
type="raised"
Expand Down