1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/ui/app/pages/home/home.container.js
Mark Stacey 63bd422840
Handle one specific permissions request per tab (#7620)
The connect route now takes a route parameter: the permissions request
id. This id is set whenever the permissions connect screen is opened,
ensuring that that tab is for that specific request alone.

This makes handling of multiple permissions requests a bit more
intuitive. Previously whenever opening multiple permissions requests,
the first one would be shown on each successive tab, whereas you
would expect each tab to show the request that prompted the tab to
open. Users may now address permissions request in whichever order
they'd like to, rather than being forced to deal with them
chronologically.
2019-12-05 17:05:50 -04:00

73 lines
2.4 KiB
JavaScript

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 { getCurrentEthBalance, getDaiV1Token, getFirstPermissionRequest } from '../../selectors/selectors'
import {
restoreFromThreeBox,
turnThreeBoxSyncingOn,
getThreeBoxLastUpdated,
setShowRestorePromptToFalse,
} 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'
const mapStateToProps = state => {
const { activeTab, metamask, appState } = state
const {
suggestedTokens,
seedPhraseBackedUp,
tokens,
threeBoxSynced,
showRestorePrompt,
selectedAddress,
} = metamask
const accountBalance = getCurrentEthBalance(state)
const { forgottenPassword, threeBoxLastUpdated } = appState
const isPopup = getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP
const firstPermissionsRequest = getFirstPermissionRequest(state)
const firstPermissionsRequestId = (firstPermissionsRequest && firstPermissionsRequest.metadata)
? firstPermissionsRequest.metadata.id
: null
return {
forgottenPassword,
suggestedTokens,
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state),
activeTab,
shouldShowSeedPhraseReminder: !seedPhraseBackedUp && (parseInt(accountBalance, 16) > 0 || tokens.length > 0),
isPopup,
threeBoxSynced,
showRestorePrompt,
selectedAddress,
threeBoxLastUpdated,
hasDaiV1Token: Boolean(getDaiV1Token(state)),
firstPermissionsRequestId,
}
}
const mapDispatchToProps = (dispatch) => ({
turnThreeBoxSyncingOn: () => dispatch(turnThreeBoxSyncingOn()),
setupThreeBox: () => {
dispatch(getThreeBoxLastUpdated())
.then(lastUpdated => {
if (lastUpdated) {
dispatch(setThreeBoxLastUpdated(lastUpdated))
} else {
dispatch(setShowRestorePromptToFalse())
dispatch(turnThreeBoxSyncingOn())
}
})
},
restoreFromThreeBox: (address) => dispatch(restoreFromThreeBox(address)),
setShowRestorePromptToFalse: () => dispatch(setShowRestorePromptToFalse()),
})
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps)
)(Home)