Skip to content

Commit

Permalink
Close notification UI if no unapproved confirmations (#8358)
Browse files Browse the repository at this point in the history
* close notification UI if no pending confirmations

* change benchmark page to 'home'
  • Loading branch information
rekmarks authored Apr 20, 2020
1 parent 18eaae2 commit 62777a8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
2 changes: 1 addition & 1 deletion test/e2e/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function getFirstParentDirectoryThatExists (directory) {
async function main () {
const args = process.argv.slice(2)

let pages = ['notification']
let pages = ['home']
let numSamples = DEFAULT_NUM_SAMPLES
let outputPath
let outputDirectory
Expand Down
17 changes: 16 additions & 1 deletion ui/app/pages/home/home.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class Home extends PureComponent {
unconfirmedTransactionsCount: PropTypes.number,
shouldShowSeedPhraseReminder: PropTypes.bool,
isPopup: PropTypes.bool,
isNotification: PropTypes.bool.isRequired,
threeBoxSynced: PropTypes.bool,
setupThreeBox: PropTypes.func,
turnThreeBoxSyncingOn: PropTypes.func,
Expand All @@ -49,6 +50,7 @@ export default class Home extends PureComponent {
threeBoxLastUpdated: PropTypes.number,
hasDaiV1Token: PropTypes.bool,
firstPermissionsRequestId: PropTypes.string,
totalUnapprovedCount: PropTypes.number.isRequired,
}

UNSAFE_componentWillMount () {
Expand All @@ -70,9 +72,15 @@ export default class Home extends PureComponent {
componentDidMount () {
const {
history,
isNotification,
suggestedTokens = {},
totalUnapprovedCount,
} = this.props

if (isNotification && totalUnapprovedCount === 0) {
global.platform.closeCurrentWindow()
}

// suggested new tokens
if (Object.keys(suggestedTokens).length > 0) {
history.push(CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE)
Expand All @@ -81,11 +89,18 @@ export default class Home extends PureComponent {

componentDidUpdate () {
const {
threeBoxSynced,
isNotification,
setupThreeBox,
showRestorePrompt,
threeBoxLastUpdated,
threeBoxSynced,
totalUnapprovedCount,
} = this.props

if (isNotification && totalUnapprovedCount === 0) {
global.platform.closeCurrentWindow()
}

if (threeBoxSynced && showRestorePrompt && threeBoxLastUpdated === null) {
setupThreeBox()
}
Expand Down
24 changes: 20 additions & 4 deletions ui/app/pages/home/home.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import Home from './home.component'
import { compose } from 'redux'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { unconfirmedTransactionsCountSelector } from '../../selectors/confirm-transaction'
import { getCurrentEthBalance, getDaiV1Token, getFirstPermissionRequest } from '../../selectors/selectors'
import {
unconfirmedTransactionsCountSelector,
} from '../../selectors/confirm-transaction'
import {
getCurrentEthBalance,
getDaiV1Token,
getFirstPermissionRequest,
getTotalUnapprovedCount,
} from '../../selectors/selectors'
import {
restoreFromThreeBox,
turnThreeBoxSyncingOn,
Expand All @@ -12,7 +19,10 @@ import {
} from '../../store/actions'
import { setThreeBoxLastUpdated } from '../../ducks/app/app'
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
import { ENVIRONMENT_TYPE_POPUP } from '../../../../app/scripts/lib/enums'
import {
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_POPUP,
} from '../../../../app/scripts/lib/enums'

const mapStateToProps = (state) => {
const { metamask, appState } = state
Expand All @@ -26,8 +36,12 @@ const mapStateToProps = (state) => {
} = metamask
const accountBalance = getCurrentEthBalance(state)
const { forgottenPassword, threeBoxLastUpdated } = appState
const totalUnapprovedCount = getTotalUnapprovedCount(state)

const envType = getEnvironmentType()
const isPopup = envType === ENVIRONMENT_TYPE_POPUP
const isNotification = envType === ENVIRONMENT_TYPE_NOTIFICATION

const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP
const firstPermissionsRequest = getFirstPermissionRequest(state)
const firstPermissionsRequestId = (firstPermissionsRequest && firstPermissionsRequest.metadata)
? firstPermissionsRequest.metadata.id
Expand All @@ -39,12 +53,14 @@ const mapStateToProps = (state) => {
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state),
shouldShowSeedPhraseReminder: !seedPhraseBackedUp && (parseInt(accountBalance, 16) > 0 || tokens.length > 0),
isPopup,
isNotification,
threeBoxSynced,
showRestorePrompt,
selectedAddress,
threeBoxLastUpdated,
hasDaiV1Token: Boolean(getDaiV1Token(state)),
firstPermissionsRequestId,
totalUnapprovedCount,
}
}

Expand Down
37 changes: 26 additions & 11 deletions ui/app/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,28 @@ export function getSelectedTokenContract (state) {
: null
}

export function getTotalUnapprovedCount ({ metamask }) {
export function getTotalUnapprovedCount (state) {
const {
unapprovedTxs = {},
unapprovedMsgCount,
unapprovedPersonalMsgCount,
unapprovedDecryptMsgCount,
unapprovedEncryptionPublicKeyMsgCount,
unapprovedTypedMessagesCount,
} = metamask
unapprovedMsgCount = 0,
unapprovedPersonalMsgCount = 0,
unapprovedDecryptMsgCount = 0,
unapprovedEncryptionPublicKeyMsgCount = 0,
unapprovedTypedMessagesCount = 0,
} = state.metamask

return unapprovedMsgCount + unapprovedPersonalMsgCount + unapprovedDecryptMsgCount +
unapprovedEncryptionPublicKeyMsgCount + unapprovedTypedMessagesCount +
getUnapprovedTxCount(state) + getPermissionsRequestCount(state) + getSuggestedTokenCount(state)
}

return Object.keys(unapprovedTxs).length + unapprovedMsgCount + unapprovedPersonalMsgCount +
unapprovedTypedMessagesCount + unapprovedDecryptMsgCount + unapprovedEncryptionPublicKeyMsgCount
function getUnapprovedTxCount (state) {
const { unapprovedTxs = {} } = state.metamask
return Object.keys(unapprovedTxs).length
}

function getSuggestedTokenCount (state) {
const { suggestedTokens = {} } = state.metamask
return Object.keys(suggestedTokens).length
}

export function getIsMainnet (state) {
Expand Down Expand Up @@ -363,7 +373,12 @@ export function getPermissionsDescriptions (state) {
}

export function getPermissionsRequests (state) {
return state.metamask.permissionsRequests
return state.metamask.permissionsRequests || []
}

export function getPermissionsRequestCount (state) {
const permissionsRequests = getPermissionsRequests(state)
return permissionsRequests.length
}

export function getDomainMetadata (state) {
Expand Down

0 comments on commit 62777a8

Please sign in to comment.