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

Cancel error rebased #6341

Merged
merged 6 commits into from
Mar 25, 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
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@
"noTransactions": {
"message": "You have no transactions"
},
"notEnoughGas": {
"message": "Not Enough Gas"
},
"notFound": {
"message": "Not Found"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export default class TransactionListItemDetails extends PureComponent {
onRetry: PropTypes.func,
showCancel: PropTypes.bool,
showRetry: PropTypes.bool,
cancelDisabled: PropTypes.bool,
transactionGroup: PropTypes.object,
}

state = {
justCopied: false,
cancelDisabled: false,
}

handleEtherscanClick = () => {
Expand Down Expand Up @@ -78,10 +80,52 @@ export default class TransactionListItemDetails extends PureComponent {
})
}

renderCancel () {
const { t } = this.context
const {
showCancel,
cancelDisabled,
} = this.props

if (!showCancel) {
return null
}

return cancelDisabled
? (
<Tooltip title={t('notEnoughGas')}>
<div>
<Button
type="raised"
onClick={this.handleCancel}
className="transaction-list-item-details__header-button"
disabled
>
{ t('cancel') }
</Button>
</div>
</Tooltip>
)
: (
<Button
type="raised"
onClick={this.handleCancel}
className="transaction-list-item-details__header-button"
>
{ t('cancel') }
</Button>
)
}

render () {
const { t } = this.context
const { justCopied } = this.state
const { transactionGroup, showCancel, showRetry, onCancel, onRetry } = this.props
const {
transactionGroup,
showRetry,
onCancel,
onRetry,
} = this.props
const { primaryTransaction: transaction } = transactionGroup
const { txParams: { to, from } = {} } = transaction

Expand All @@ -101,17 +145,7 @@ export default class TransactionListItemDetails extends PureComponent {
</Button>
)
}
{
showCancel && (
<Button
type="raised"
onClick={this.handleCancel}
className="transaction-list-item-details__header-button"
>
{ t('cancel') }
</Button>
)
}
{ this.renderCancel() }
<Tooltip title={justCopied ? t('copiedTransactionId') : t('copyTransactionId')}>
<Button
type="raised"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class TransactionListItem extends PureComponent {
setSelectedToken: PropTypes.func,
showCancelModal: PropTypes.func,
showCancel: PropTypes.bool,
hasEnoughCancelGas: PropTypes.bool,
showRetry: PropTypes.bool,
showFiat: PropTypes.bool,
token: PropTypes.object,
Expand Down Expand Up @@ -156,6 +157,7 @@ export default class TransactionListItem extends PureComponent {
nonceAndDate,
primaryTransaction,
showCancel,
hasEnoughCancelGas,
showRetry,
tokenData,
transactionGroup,
Expand Down Expand Up @@ -213,6 +215,7 @@ export default class TransactionListItem extends PureComponent {
showRetry={showRetry && methodData.done}
onCancel={this.handleCancel}
showCancel={showCancel}
cancelDisabled={!hasEnoughCancelGas}
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,40 @@ import TransactionListItem from './transaction-list-item.component'
import { setSelectedToken, showModal, showSidebar, addKnownMethodData } from '../../../store/actions'
import { hexToDecimal } from '../../../helpers/utils/conversions.util'
import { getTokenData } from '../../../helpers/utils/transactions.util'
import { increaseLastGasPrice } from '../../../helpers/utils/confirm-tx.util'
import { getHexGasTotal, increaseLastGasPrice } from '../../../helpers/utils/confirm-tx.util'
import { formatDate } from '../../../helpers/utils/util'
import {
fetchBasicGasAndTimeEstimates,
fetchGasEstimates,
setCustomGasPriceForRetry,
setCustomGasLimit,
} from '../../../ducks/gas/gas.duck'
import {getIsMainnet, preferencesSelector} from '../../../selectors/selectors'
import { getIsMainnet, preferencesSelector, getSelectedAddress, conversionRateSelector } from '../../../selectors/selectors'
import { isBalanceSufficient } from '../send/send.utils'

const mapStateToProps = state => {
const { metamask: { knownMethodData } } = state
const mapStateToProps = (state, ownProps) => {
const { metamask: { knownMethodData, accounts } } = state
const { showFiatInTestnets } = preferencesSelector(state)
const isMainnet = getIsMainnet(state)
const { transactionGroup: { primaryTransaction } = {} } = ownProps
const { txParams: { gas: gasLimit, gasPrice, value } = {} } = primaryTransaction
const selectedAccountBalance = accounts[getSelectedAddress(state)].balance

const hasEnoughCancelGas = primaryTransaction.txParams && isBalanceSufficient({
amount: value,
gasTotal: getHexGasTotal({
gasPrice: increaseLastGasPrice(gasPrice),
gasLimit,
}),
balance: selectedAccountBalance,
conversionRate: conversionRateSelector(state),
})

return {
knownMethodData,
showFiat: (isMainnet || !!showFiatInTestnets),
selectedAccountBalance,
hasEnoughCancelGas,
}
}

Expand Down