mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Close transaction on close of notification window (#6340)
This commit is contained in:
parent
961ad267df
commit
69f7968c70
@ -2,6 +2,8 @@ const Component = require('react').Component
|
|||||||
const PropTypes = require('prop-types')
|
const PropTypes = require('prop-types')
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums'
|
||||||
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
||||||
import Identicon from '../ui/identicon'
|
import Identicon from '../ui/identicon'
|
||||||
const connect = require('react-redux').connect
|
const connect = require('react-redux').connect
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
@ -47,6 +49,42 @@ function mapDispatchToProps (dispatch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mergeProps (stateProps, dispatchProps, ownProps) {
|
||||||
|
const {
|
||||||
|
signPersonalMessage,
|
||||||
|
signTypedMessage,
|
||||||
|
cancelPersonalMessage,
|
||||||
|
cancelTypedMessage,
|
||||||
|
signMessage,
|
||||||
|
cancelMessage,
|
||||||
|
txData,
|
||||||
|
} = ownProps
|
||||||
|
|
||||||
|
const { type } = txData
|
||||||
|
|
||||||
|
let cancel
|
||||||
|
let sign
|
||||||
|
if (type === 'personal_sign') {
|
||||||
|
cancel = cancelPersonalMessage
|
||||||
|
sign = signPersonalMessage
|
||||||
|
} else if (type === 'eth_signTypedData') {
|
||||||
|
cancel = cancelTypedMessage
|
||||||
|
sign = signTypedMessage
|
||||||
|
} else if (type === 'eth_sign') {
|
||||||
|
cancel = cancelMessage
|
||||||
|
sign = signMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...stateProps,
|
||||||
|
...dispatchProps,
|
||||||
|
...ownProps,
|
||||||
|
txData,
|
||||||
|
cancel,
|
||||||
|
sign,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SignatureRequest.contextTypes = {
|
SignatureRequest.contextTypes = {
|
||||||
t: PropTypes.func,
|
t: PropTypes.func,
|
||||||
metricsEvent: PropTypes.func,
|
metricsEvent: PropTypes.func,
|
||||||
@ -54,7 +92,7 @@ SignatureRequest.contextTypes = {
|
|||||||
|
|
||||||
module.exports = compose(
|
module.exports = compose(
|
||||||
withRouter,
|
withRouter,
|
||||||
connect(mapStateToProps, mapDispatchToProps)
|
connect(mapStateToProps, mapDispatchToProps, mergeProps)
|
||||||
)(SignatureRequest)
|
)(SignatureRequest)
|
||||||
|
|
||||||
|
|
||||||
@ -67,6 +105,24 @@ function SignatureRequest (props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SignatureRequest.prototype.componentDidMount = function () {
|
||||||
|
const { clearConfirmTransaction, cancel } = this.props
|
||||||
|
const { metricsEvent } = this.context
|
||||||
|
if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) {
|
||||||
|
window.onbeforeunload = event => {
|
||||||
|
metricsEvent({
|
||||||
|
eventOpts: {
|
||||||
|
category: 'Transactions',
|
||||||
|
action: 'Sign Request',
|
||||||
|
name: 'Cancel Sig Request Via Notification Close',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
clearConfirmTransaction()
|
||||||
|
cancel(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SignatureRequest.prototype.renderHeader = function () {
|
SignatureRequest.prototype.renderHeader = function () {
|
||||||
return h('div.request-signature__header', [
|
return h('div.request-signature__header', [
|
||||||
|
|
||||||
@ -233,30 +289,7 @@ SignatureRequest.prototype.renderBody = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SignatureRequest.prototype.renderFooter = function () {
|
SignatureRequest.prototype.renderFooter = function () {
|
||||||
const {
|
const { cancel, sign } = this.props
|
||||||
signPersonalMessage,
|
|
||||||
signTypedMessage,
|
|
||||||
cancelPersonalMessage,
|
|
||||||
cancelTypedMessage,
|
|
||||||
signMessage,
|
|
||||||
cancelMessage,
|
|
||||||
} = this.props
|
|
||||||
|
|
||||||
const { txData } = this.props
|
|
||||||
const { type } = txData
|
|
||||||
|
|
||||||
let cancel
|
|
||||||
let sign
|
|
||||||
if (type === 'personal_sign') {
|
|
||||||
cancel = cancelPersonalMessage
|
|
||||||
sign = signPersonalMessage
|
|
||||||
} else if (type === 'eth_signTypedData') {
|
|
||||||
cancel = cancelTypedMessage
|
|
||||||
sign = signTypedMessage
|
|
||||||
} else if (type === 'eth_sign') {
|
|
||||||
cancel = cancelMessage
|
|
||||||
sign = signMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
return h('div.request-signature__footer', [
|
return h('div.request-signature__footer', [
|
||||||
h(Button, {
|
h(Button, {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import ethUtil from 'ethereumjs-util'
|
import ethUtil from 'ethereumjs-util'
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums'
|
||||||
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
||||||
import ConfirmPageContainer, { ConfirmDetailRow } from '../../components/app/confirm-page-container'
|
import ConfirmPageContainer, { ConfirmDetailRow } from '../../components/app/confirm-page-container'
|
||||||
import { isBalanceSufficient } from '../../components/app/send/send.utils'
|
import { isBalanceSufficient } from '../../components/app/send/send.utils'
|
||||||
import { DEFAULT_ROUTE, CONFIRM_TRANSACTION_ROUTE } from '../../helpers/constants/routes'
|
import { DEFAULT_ROUTE, CONFIRM_TRANSACTION_ROUTE } from '../../helpers/constants/routes'
|
||||||
@ -474,7 +476,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { txData: { origin } = {} } = this.props
|
const { txData: { origin, id } = {}, cancelTransaction } = this.props
|
||||||
const { metricsEvent } = this.context
|
const { metricsEvent } = this.context
|
||||||
metricsEvent({
|
metricsEvent({
|
||||||
eventOpts: {
|
eventOpts: {
|
||||||
@ -486,6 +488,22 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
origin,
|
origin,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) {
|
||||||
|
window.onbeforeunload = () => {
|
||||||
|
metricsEvent({
|
||||||
|
eventOpts: {
|
||||||
|
category: 'Transactions',
|
||||||
|
action: 'Confirm Screen',
|
||||||
|
name: 'Cancel Tx Via Notification Close',
|
||||||
|
},
|
||||||
|
customVariables: {
|
||||||
|
origin,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
cancelTransaction({ id })
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
@ -902,6 +902,7 @@ function signMsg (msgData) {
|
|||||||
log.debug('action - signMsg')
|
log.debug('action - signMsg')
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
log.debug(`actions calling background.signMessage`)
|
log.debug(`actions calling background.signMessage`)
|
||||||
@ -933,7 +934,7 @@ function signPersonalMsg (msgData) {
|
|||||||
log.debug('action - signPersonalMsg')
|
log.debug('action - signPersonalMsg')
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
log.debug(`actions calling background.signPersonalMessage`)
|
log.debug(`actions calling background.signPersonalMessage`)
|
||||||
background.signPersonalMessage(msgData, (err, newState) => {
|
background.signPersonalMessage(msgData, (err, newState) => {
|
||||||
@ -964,7 +965,7 @@ function signTypedMsg (msgData) {
|
|||||||
log.debug('action - signTypedMsg')
|
log.debug('action - signTypedMsg')
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
log.debug(`actions calling background.signTypedMessage`)
|
log.debug(`actions calling background.signTypedMessage`)
|
||||||
background.signTypedMessage(msgData, (err, newState) => {
|
background.signTypedMessage(msgData, (err, newState) => {
|
||||||
@ -1168,6 +1169,7 @@ function sendTx (txData) {
|
|||||||
log.info(`actions - sendTx: ${JSON.stringify(txData.txParams)}`)
|
log.info(`actions - sendTx: ${JSON.stringify(txData.txParams)}`)
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
log.debug(`actions calling background.approveTransaction`)
|
log.debug(`actions calling background.approveTransaction`)
|
||||||
|
window.onbeforeunload = null
|
||||||
background.approveTransaction(txData.id, (err) => {
|
background.approveTransaction(txData.id, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
dispatch(actions.txError(err))
|
dispatch(actions.txError(err))
|
||||||
@ -1230,7 +1232,7 @@ function updateAndApproveTx (txData) {
|
|||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
log.debug(`actions calling background.updateAndApproveTx`)
|
log.debug(`actions calling background.updateAndApproveTx`)
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
background.updateAndApproveTransaction(txData, err => {
|
background.updateAndApproveTransaction(txData, err => {
|
||||||
dispatch(actions.updateTransactionParams(txData.id, txData.txParams))
|
dispatch(actions.updateTransactionParams(txData.id, txData.txParams))
|
||||||
@ -1292,7 +1294,7 @@ function txError (err) {
|
|||||||
function cancelMsg (msgData) {
|
function cancelMsg (msgData) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
log.debug(`background.cancelMessage`)
|
log.debug(`background.cancelMessage`)
|
||||||
background.cancelMessage(msgData.id, (err, newState) => {
|
background.cancelMessage(msgData.id, (err, newState) => {
|
||||||
@ -1319,7 +1321,7 @@ function cancelMsg (msgData) {
|
|||||||
function cancelPersonalMsg (msgData) {
|
function cancelPersonalMsg (msgData) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const id = msgData.id
|
const id = msgData.id
|
||||||
background.cancelPersonalMessage(id, (err, newState) => {
|
background.cancelPersonalMessage(id, (err, newState) => {
|
||||||
@ -1346,7 +1348,7 @@ function cancelPersonalMsg (msgData) {
|
|||||||
function cancelTypedMsg (msgData) {
|
function cancelTypedMsg (msgData) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const id = msgData.id
|
const id = msgData.id
|
||||||
background.cancelTypedMessage(id, (err, newState) => {
|
background.cancelTypedMessage(id, (err, newState) => {
|
||||||
@ -1374,7 +1376,7 @@ function cancelTx (txData) {
|
|||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
log.debug(`background.cancelTransaction`)
|
log.debug(`background.cancelTransaction`)
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
background.cancelTransaction(txData.id, err => {
|
background.cancelTransaction(txData.id, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -1408,6 +1410,7 @@ function cancelTx (txData) {
|
|||||||
*/
|
*/
|
||||||
function cancelTxs (txDataList) {
|
function cancelTxs (txDataList) {
|
||||||
return async (dispatch, getState) => {
|
return async (dispatch, getState) => {
|
||||||
|
window.onbeforeunload = null
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
const txIds = txDataList.map(({id}) => id)
|
const txIds = txDataList.map(({id}) => id)
|
||||||
const cancellations = txIds.map((id) => new Promise((resolve, reject) => {
|
const cancellations = txIds.map((id) => new Promise((resolve, reject) => {
|
||||||
@ -1810,6 +1813,7 @@ function addTokens (tokens) {
|
|||||||
function removeSuggestedTokens () {
|
function removeSuggestedTokens () {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
|
window.onbeforeunload = null
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
background.removeSuggestedTokens((err, suggestedTokens) => {
|
background.removeSuggestedTokens((err, suggestedTokens) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
|
Loading…
Reference in New Issue
Block a user