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 () {
const args = process.argv.slice(2)
let pages = ['notification']
let pages = ['home']
let numSamples = DEFAULT_NUM_SAMPLES
let outputPath
let outputDirectory

@ -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,
@ -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 () {
@ -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)
@ -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()
}

@ -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,
@ -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
@ -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
@ -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,
}
}

@ -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) {
@ -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) {

Loading…
Cancel
Save