Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close notification UI if no unapproved confirmations #8358

Merged
merged 8 commits into from
Apr 20, 2020
11 changes: 10 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,
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
}

UNSAFE_componentWillMount () {
Expand Down Expand Up @@ -81,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()
rekmarks marked this conversation as resolved.
Show resolved Hide resolved
}

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