Close notification UI if no unapproved confirmations (#8358)

* close notification UI if no pending confirmations

* change benchmark page to 'home'
feature/default_network_editable
Erik Marks 5 years ago committed by GitHub
parent 18eaae2721
commit 62777a81b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      test/e2e/benchmark.js
  2. 17
      ui/app/pages/home/home.component.js
  3. 24
      ui/app/pages/home/home.container.js
  4. 37
      ui/app/selectors/selectors.js

@ -110,7 +110,7 @@ async function getFirstParentDirectoryThatExists (directory) {
async function main () { async function main () {
const args = process.argv.slice(2) const args = process.argv.slice(2)
let pages = ['notification'] let pages = ['home']
let numSamples = DEFAULT_NUM_SAMPLES let numSamples = DEFAULT_NUM_SAMPLES
let outputPath let outputPath
let outputDirectory let outputDirectory

@ -39,6 +39,7 @@ export default class Home extends PureComponent {
unconfirmedTransactionsCount: PropTypes.number, unconfirmedTransactionsCount: PropTypes.number,
shouldShowSeedPhraseReminder: PropTypes.bool, shouldShowSeedPhraseReminder: PropTypes.bool,
isPopup: PropTypes.bool, isPopup: PropTypes.bool,
isNotification: PropTypes.bool.isRequired,
threeBoxSynced: PropTypes.bool, threeBoxSynced: PropTypes.bool,
setupThreeBox: PropTypes.func, setupThreeBox: PropTypes.func,
turnThreeBoxSyncingOn: PropTypes.func, turnThreeBoxSyncingOn: PropTypes.func,
@ -49,6 +50,7 @@ export default class Home extends PureComponent {
threeBoxLastUpdated: PropTypes.number, threeBoxLastUpdated: PropTypes.number,
hasDaiV1Token: PropTypes.bool, hasDaiV1Token: PropTypes.bool,
firstPermissionsRequestId: PropTypes.string, firstPermissionsRequestId: PropTypes.string,
totalUnapprovedCount: PropTypes.number.isRequired,
} }
UNSAFE_componentWillMount () { UNSAFE_componentWillMount () {
@ -70,9 +72,15 @@ export default class Home extends PureComponent {
componentDidMount () { componentDidMount () {
const { const {
history, history,
isNotification,
suggestedTokens = {}, suggestedTokens = {},
totalUnapprovedCount,
} = this.props } = this.props
if (isNotification && totalUnapprovedCount === 0) {
global.platform.closeCurrentWindow()
}
// suggested new tokens // suggested new tokens
if (Object.keys(suggestedTokens).length > 0) { if (Object.keys(suggestedTokens).length > 0) {
history.push(CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE) history.push(CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE)
@ -81,11 +89,18 @@ export default class Home extends PureComponent {
componentDidUpdate () { componentDidUpdate () {
const { const {
threeBoxSynced, isNotification,
setupThreeBox, setupThreeBox,
showRestorePrompt, showRestorePrompt,
threeBoxLastUpdated, threeBoxLastUpdated,
threeBoxSynced,
totalUnapprovedCount,
} = this.props } = this.props
if (isNotification && totalUnapprovedCount === 0) {
global.platform.closeCurrentWindow()
}
if (threeBoxSynced && showRestorePrompt && threeBoxLastUpdated === null) { if (threeBoxSynced && showRestorePrompt && threeBoxLastUpdated === null) {
setupThreeBox() setupThreeBox()
} }

@ -2,8 +2,15 @@ import Home from './home.component'
import { compose } from 'redux' import { compose } from 'redux'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom' import { withRouter } from 'react-router-dom'
import { unconfirmedTransactionsCountSelector } from '../../selectors/confirm-transaction' import {
import { getCurrentEthBalance, getDaiV1Token, getFirstPermissionRequest } from '../../selectors/selectors' unconfirmedTransactionsCountSelector,
} from '../../selectors/confirm-transaction'
import {
getCurrentEthBalance,
getDaiV1Token,
getFirstPermissionRequest,
getTotalUnapprovedCount,
} from '../../selectors/selectors'
import { import {
restoreFromThreeBox, restoreFromThreeBox,
turnThreeBoxSyncingOn, turnThreeBoxSyncingOn,
@ -12,7 +19,10 @@ import {
} from '../../store/actions' } from '../../store/actions'
import { setThreeBoxLastUpdated } from '../../ducks/app/app' import { setThreeBoxLastUpdated } from '../../ducks/app/app'
import { getEnvironmentType } from '../../../../app/scripts/lib/util' 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 mapStateToProps = (state) => {
const { metamask, appState } = state const { metamask, appState } = state
@ -26,8 +36,12 @@ const mapStateToProps = (state) => {
} = metamask } = metamask
const accountBalance = getCurrentEthBalance(state) const accountBalance = getCurrentEthBalance(state)
const { forgottenPassword, threeBoxLastUpdated } = appState 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 firstPermissionsRequest = getFirstPermissionRequest(state)
const firstPermissionsRequestId = (firstPermissionsRequest && firstPermissionsRequest.metadata) const firstPermissionsRequestId = (firstPermissionsRequest && firstPermissionsRequest.metadata)
? firstPermissionsRequest.metadata.id ? firstPermissionsRequest.metadata.id
@ -39,12 +53,14 @@ const mapStateToProps = (state) => {
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state), unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state),
shouldShowSeedPhraseReminder: !seedPhraseBackedUp && (parseInt(accountBalance, 16) > 0 || tokens.length > 0), shouldShowSeedPhraseReminder: !seedPhraseBackedUp && (parseInt(accountBalance, 16) > 0 || tokens.length > 0),
isPopup, isPopup,
isNotification,
threeBoxSynced, threeBoxSynced,
showRestorePrompt, showRestorePrompt,
selectedAddress, selectedAddress,
threeBoxLastUpdated, threeBoxLastUpdated,
hasDaiV1Token: Boolean(getDaiV1Token(state)), hasDaiV1Token: Boolean(getDaiV1Token(state)),
firstPermissionsRequestId, firstPermissionsRequestId,
totalUnapprovedCount,
} }
} }

@ -306,18 +306,28 @@ export function getSelectedTokenContract (state) {
: null : null
} }
export function getTotalUnapprovedCount ({ metamask }) { export function getTotalUnapprovedCount (state) {
const { const {
unapprovedTxs = {}, unapprovedMsgCount = 0,
unapprovedMsgCount, unapprovedPersonalMsgCount = 0,
unapprovedPersonalMsgCount, unapprovedDecryptMsgCount = 0,
unapprovedDecryptMsgCount, unapprovedEncryptionPublicKeyMsgCount = 0,
unapprovedEncryptionPublicKeyMsgCount, unapprovedTypedMessagesCount = 0,
unapprovedTypedMessagesCount, } = state.metamask
} = metamask
return unapprovedMsgCount + unapprovedPersonalMsgCount + unapprovedDecryptMsgCount +
unapprovedEncryptionPublicKeyMsgCount + unapprovedTypedMessagesCount +
getUnapprovedTxCount(state) + getPermissionsRequestCount(state) + getSuggestedTokenCount(state)
}
return Object.keys(unapprovedTxs).length + unapprovedMsgCount + unapprovedPersonalMsgCount + function getUnapprovedTxCount (state) {
unapprovedTypedMessagesCount + unapprovedDecryptMsgCount + unapprovedEncryptionPublicKeyMsgCount 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) { export function getIsMainnet (state) {
@ -363,7 +373,12 @@ export function getPermissionsDescriptions (state) {
} }
export function getPermissionsRequests (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) { export function getDomainMetadata (state) {

Loading…
Cancel
Save