Skip to content

Commit c9803ff

Browse files
committed
Close transaction on close of notification window
1 parent 4ff9126 commit c9803ff

File tree

3 files changed

+88
-33
lines changed

3 files changed

+88
-33
lines changed

ui/app/components/app/signature-request.js

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const Component = require('react').Component
22
const PropTypes = require('prop-types')
33
const h = require('react-hyperscript')
44
const inherits = require('util').inherits
5+
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums'
6+
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
57
import Identicon from '../ui/identicon'
68
const connect = require('react-redux').connect
79
const ethUtil = require('ethereumjs-util')
@@ -47,14 +49,50 @@ function mapDispatchToProps (dispatch) {
4749
}
4850
}
4951

52+
function mergeProps (stateProps, dispatchProps, ownProps) {
53+
const {
54+
signPersonalMessage,
55+
signTypedMessage,
56+
cancelPersonalMessage,
57+
cancelTypedMessage,
58+
signMessage,
59+
cancelMessage,
60+
txData,
61+
} = ownProps
62+
63+
const { type } = txData
64+
65+
let cancel
66+
let sign
67+
if (type === 'personal_sign') {
68+
cancel = cancelPersonalMessage
69+
sign = signPersonalMessage
70+
} else if (type === 'eth_signTypedData') {
71+
cancel = cancelTypedMessage
72+
sign = signTypedMessage
73+
} else if (type === 'eth_sign') {
74+
cancel = cancelMessage
75+
sign = signMessage
76+
}
77+
78+
return {
79+
...stateProps,
80+
...dispatchProps,
81+
...ownProps,
82+
txData,
83+
cancel,
84+
sign,
85+
}
86+
}
87+
5088
SignatureRequest.contextTypes = {
5189
t: PropTypes.func,
5290
metricsEvent: PropTypes.func,
5391
}
5492

5593
module.exports = compose(
5694
withRouter,
57-
connect(mapStateToProps, mapDispatchToProps)
95+
connect(mapStateToProps, mapDispatchToProps, mergeProps)
5896
)(SignatureRequest)
5997

6098

@@ -67,6 +105,24 @@ function SignatureRequest (props) {
67105
}
68106
}
69107

108+
SignatureRequest.prototype.componentDidMount = function () {
109+
const { clearConfirmTransaction, cancel } = this.props
110+
const { metricsEvent } = this.context
111+
if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) {
112+
window.onbeforeunload = event => {
113+
metricsEvent({
114+
eventOpts: {
115+
category: 'Transactions',
116+
action: 'Sign Request',
117+
name: 'Cancel Sig Request Via Notification Close',
118+
},
119+
})
120+
clearConfirmTransaction()
121+
cancel(event)
122+
}
123+
}
124+
}
125+
70126
SignatureRequest.prototype.renderHeader = function () {
71127
return h('div.request-signature__header', [
72128

@@ -233,30 +289,7 @@ SignatureRequest.prototype.renderBody = function () {
233289
}
234290

235291
SignatureRequest.prototype.renderFooter = function () {
236-
const {
237-
signPersonalMessage,
238-
signTypedMessage,
239-
cancelPersonalMessage,
240-
cancelTypedMessage,
241-
signMessage,
242-
cancelMessage,
243-
} = this.props
244-
245-
const { txData } = this.props
246-
const { type } = txData
247-
248-
let cancel
249-
let sign
250-
if (type === 'personal_sign') {
251-
cancel = cancelPersonalMessage
252-
sign = signPersonalMessage
253-
} else if (type === 'eth_signTypedData') {
254-
cancel = cancelTypedMessage
255-
sign = signTypedMessage
256-
} else if (type === 'eth_sign') {
257-
cancel = cancelMessage
258-
sign = signMessage
259-
}
292+
const { cancel, sign } = this.props
260293

261294
return h('div.request-signature__footer', [
262295
h(Button, {

ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import ethUtil from 'ethereumjs-util'
22
import React, { Component } from 'react'
33
import PropTypes from 'prop-types'
4+
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums'
5+
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
46
import ConfirmPageContainer, { ConfirmDetailRow } from '../../components/app/confirm-page-container'
57
import { isBalanceSufficient } from '../../components/app/send/send.utils'
68
import { DEFAULT_ROUTE, CONFIRM_TRANSACTION_ROUTE } from '../../helpers/constants/routes'
@@ -474,7 +476,7 @@ export default class ConfirmTransactionBase extends Component {
474476
}
475477

476478
componentDidMount () {
477-
const { txData: { origin } = {} } = this.props
479+
const { txData: { origin, id } = {}, cancelTransaction } = this.props
478480
const { metricsEvent } = this.context
479481
metricsEvent({
480482
eventOpts: {
@@ -486,6 +488,22 @@ export default class ConfirmTransactionBase extends Component {
486488
origin,
487489
},
488490
})
491+
492+
if (getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION) {
493+
window.onbeforeunload = () => {
494+
metricsEvent({
495+
eventOpts: {
496+
category: 'Transactions',
497+
action: 'Confirm Screen',
498+
name: 'Cancel Tx Via Notification Close',
499+
},
500+
customVariables: {
501+
origin,
502+
},
503+
})
504+
cancelTransaction({ id })
505+
}
506+
}
489507
}
490508

491509
render () {

ui/app/store/actions.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ function signMsg (msgData) {
902902
log.debug('action - signMsg')
903903
return (dispatch, getState) => {
904904
dispatch(actions.showLoadingIndication())
905+
window.onbeforeunload = null
905906

906907
return new Promise((resolve, reject) => {
907908
log.debug(`actions calling background.signMessage`)
@@ -933,7 +934,7 @@ function signPersonalMsg (msgData) {
933934
log.debug('action - signPersonalMsg')
934935
return (dispatch, getState) => {
935936
dispatch(actions.showLoadingIndication())
936-
937+
window.onbeforeunload = null
937938
return new Promise((resolve, reject) => {
938939
log.debug(`actions calling background.signPersonalMessage`)
939940
background.signPersonalMessage(msgData, (err, newState) => {
@@ -964,7 +965,7 @@ function signTypedMsg (msgData) {
964965
log.debug('action - signTypedMsg')
965966
return (dispatch, getState) => {
966967
dispatch(actions.showLoadingIndication())
967-
968+
window.onbeforeunload = null
968969
return new Promise((resolve, reject) => {
969970
log.debug(`actions calling background.signTypedMessage`)
970971
background.signTypedMessage(msgData, (err, newState) => {
@@ -1168,6 +1169,7 @@ function sendTx (txData) {
11681169
log.info(`actions - sendTx: ${JSON.stringify(txData.txParams)}`)
11691170
return (dispatch, getState) => {
11701171
log.debug(`actions calling background.approveTransaction`)
1172+
window.onbeforeunload = null
11711173
background.approveTransaction(txData.id, (err) => {
11721174
if (err) {
11731175
dispatch(actions.txError(err))
@@ -1230,7 +1232,7 @@ function updateAndApproveTx (txData) {
12301232
return (dispatch, getState) => {
12311233
log.debug(`actions calling background.updateAndApproveTx`)
12321234
dispatch(actions.showLoadingIndication())
1233-
1235+
window.onbeforeunload = null
12341236
return new Promise((resolve, reject) => {
12351237
background.updateAndApproveTransaction(txData, err => {
12361238
dispatch(actions.updateTransactionParams(txData.id, txData.txParams))
@@ -1292,7 +1294,7 @@ function txError (err) {
12921294
function cancelMsg (msgData) {
12931295
return (dispatch, getState) => {
12941296
dispatch(actions.showLoadingIndication())
1295-
1297+
window.onbeforeunload = null
12961298
return new Promise((resolve, reject) => {
12971299
log.debug(`background.cancelMessage`)
12981300
background.cancelMessage(msgData.id, (err, newState) => {
@@ -1319,7 +1321,7 @@ function cancelMsg (msgData) {
13191321
function cancelPersonalMsg (msgData) {
13201322
return (dispatch, getState) => {
13211323
dispatch(actions.showLoadingIndication())
1322-
1324+
window.onbeforeunload = null
13231325
return new Promise((resolve, reject) => {
13241326
const id = msgData.id
13251327
background.cancelPersonalMessage(id, (err, newState) => {
@@ -1346,7 +1348,7 @@ function cancelPersonalMsg (msgData) {
13461348
function cancelTypedMsg (msgData) {
13471349
return (dispatch, getState) => {
13481350
dispatch(actions.showLoadingIndication())
1349-
1351+
window.onbeforeunload = null
13501352
return new Promise((resolve, reject) => {
13511353
const id = msgData.id
13521354
background.cancelTypedMessage(id, (err, newState) => {
@@ -1374,7 +1376,7 @@ function cancelTx (txData) {
13741376
return (dispatch, getState) => {
13751377
log.debug(`background.cancelTransaction`)
13761378
dispatch(actions.showLoadingIndication())
1377-
1379+
window.onbeforeunload = null
13781380
return new Promise((resolve, reject) => {
13791381
background.cancelTransaction(txData.id, err => {
13801382
if (err) {
@@ -1408,6 +1410,7 @@ function cancelTx (txData) {
14081410
*/
14091411
function cancelTxs (txDataList) {
14101412
return async (dispatch, getState) => {
1413+
window.onbeforeunload = null
14111414
dispatch(actions.showLoadingIndication())
14121415
const txIds = txDataList.map(({id}) => id)
14131416
const cancellations = txIds.map((id) => new Promise((resolve, reject) => {
@@ -1810,6 +1813,7 @@ function addTokens (tokens) {
18101813
function removeSuggestedTokens () {
18111814
return (dispatch) => {
18121815
dispatch(actions.showLoadingIndication())
1816+
window.onbeforeunload = null
18131817
return new Promise((resolve, reject) => {
18141818
background.removeSuggestedTokens((err, suggestedTokens) => {
18151819
dispatch(actions.hideLoadingIndication())

0 commit comments

Comments
 (0)