Skip to content

Commit

Permalink
Close notification UI if no unapproved confirmations (MetaMask#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 and yqrashawn committed Apr 27, 2020
1 parent 39f3808 commit 9060bd3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/e2e/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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
22 changes: 20 additions & 2 deletions ui/app/pages/home/home.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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 @@ -43,6 +44,7 @@ export default class Home extends PureComponent {
threeBoxLastUpdated: PropTypes.number,
hasDaiV1Token: PropTypes.bool,
firstPermissionsRequestId: PropTypes.string,
totalUnapprovedCount: PropTypes.number.isRequired,
}

UNSAFE_componentWillMount () {
Expand All @@ -62,7 +64,16 @@ export default class Home extends PureComponent {
}

componentDidMount () {
const { history, suggestedTokens = {} } = this.props
const {
history,
isNotification,
suggestedTokens = {},
totalUnapprovedCount,
} = this.props

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

// suggested new tokens
if (Object.keys(suggestedTokens).length > 0) {
Expand All @@ -72,11 +83,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
18 changes: 15 additions & 3 deletions ui/app/pages/home/home.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import Home from './home.component'
import { compose } from 'recompose'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { unconfirmedTransactionsCountSelector } from '../../selectors/confirm-transaction'
import {
unconfirmedTransactionsCountSelector,
} from '../../selectors/confirm-transaction'
import {
getCurrentEthBalance,
getDaiV1Token,
getFirstPermissionRequest,
getTotalUnapprovedCount,
} from '../../selectors/selectors'
import {
restoreFromThreeBox,
Expand All @@ -16,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 @@ -30,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
Expand All @@ -46,12 +56,14 @@ const mapStateToProps = (state) => {
!seedPhraseBackedUp &&
(parseInt(accountBalance, 16) > 0 || tokens.length > 0),
isPopup,
isNotification,
threeBoxSynced,
showRestorePrompt,
selectedAddress,
threeBoxLastUpdated,
hasDaiV1Token: Boolean(getDaiV1Token(state)),
firstPermissionsRequestId,
totalUnapprovedCount,
}
}

Expand Down
40 changes: 28 additions & 12 deletions ui/app/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,37 @@ 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 (
Object.keys(unapprovedTxs).length +
unapprovedMsgCount +
unapprovedPersonalMsgCount +
unapprovedTypedMessagesCount +
unapprovedDecryptMsgCount +
unapprovedEncryptionPublicKeyMsgCount
unapprovedEncryptionPublicKeyMsgCount +
unapprovedTypedMessagesCount +
getUnapprovedTxCount(state) +
getPermissionsRequestCount(state) +
getSuggestedTokenCount(state)
)
}

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) {
const networkType = getNetworkIdentifier(state)
return networkType === NETWORK_TYPES.MAINNET
Expand Down Expand Up @@ -395,7 +406,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 9060bd3

Please sign in to comment.