1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/app/pages/home/home.container.js
Erik Marks 54e9c53b27
Add web3 shim usage notification (#10039)
* Add web3 shim usage alert background state and logic
* Cleanup alert background state, constants
* Implement web3 shim usage notification and settings
* nodeify alert controller background hooks
* Remove svg icon, again
* Tweak alert controller initialization
* Add support article URL
* Un-thunk alert UI "actions"
* Delete connect.svg file (unused)
2020-12-10 15:40:29 -08:00

136 lines
4.4 KiB
JavaScript

import { compose } from 'redux'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import {
activeTabHasPermissions,
getCurrentEthBalance,
getFirstPermissionRequest,
getIsMainnet,
getOriginOfCurrentTab,
getTotalUnapprovedCount,
getWeb3ShimUsageStateForOrigin,
unconfirmedTransactionsCountSelector,
} from '../../selectors'
import {
restoreFromThreeBox,
turnThreeBoxSyncingOn,
getThreeBoxLastUpdated,
setShowRestorePromptToFalse,
setConnectedStatusPopoverHasBeenShown,
setDefaultHomeActiveTabName,
setSwapsWelcomeMessageHasBeenShown,
setWeb3ShimUsageAlertDismissed,
setAlertEnabledness,
} from '../../store/actions'
import { setThreeBoxLastUpdated } from '../../ducks/app/app'
import { getWeb3ShimUsageAlertEnabledness } from '../../ducks/metamask/metamask'
import {
getSwapsWelcomeMessageSeenStatus,
getSwapsFeatureLiveness,
} from '../../ducks/swaps/swaps'
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
import {
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_POPUP,
} from '../../../../app/scripts/lib/enums'
import {
ALERT_TYPES,
WEB3_SHIM_USAGE_ALERT_STATES,
} from '../../../../shared/constants/alerts'
import Home from './home.component'
const mapStateToProps = (state) => {
const { metamask, appState } = state
const {
suggestedTokens,
seedPhraseBackedUp,
tokens,
threeBoxSynced,
showRestorePrompt,
selectedAddress,
connectedStatusPopoverHasBeenShown,
defaultHomeActiveTabName,
swapsState,
} = metamask
const accountBalance = getCurrentEthBalance(state)
const { forgottenPassword, threeBoxLastUpdated } = appState
const totalUnapprovedCount = getTotalUnapprovedCount(state)
const swapsEnabled = getSwapsFeatureLiveness(state)
const envType = getEnvironmentType()
const isPopup = envType === ENVIRONMENT_TYPE_POPUP
const isNotification = envType === ENVIRONMENT_TYPE_NOTIFICATION
const firstPermissionsRequest = getFirstPermissionRequest(state)
const firstPermissionsRequestId =
firstPermissionsRequest && firstPermissionsRequest.metadata
? firstPermissionsRequest.metadata.id
: null
const originOfCurrentTab = getOriginOfCurrentTab(state)
const shouldShowWeb3ShimUsageNotification =
isPopup &&
getWeb3ShimUsageAlertEnabledness(state) &&
activeTabHasPermissions(state) &&
getWeb3ShimUsageStateForOrigin(state, originOfCurrentTab) ===
WEB3_SHIM_USAGE_ALERT_STATES.RECORDED
return {
forgottenPassword,
suggestedTokens,
swapsEnabled,
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state),
shouldShowSeedPhraseReminder:
seedPhraseBackedUp === false &&
(parseInt(accountBalance, 16) > 0 || tokens.length > 0),
isPopup,
isNotification,
threeBoxSynced,
showRestorePrompt,
selectedAddress,
threeBoxLastUpdated,
firstPermissionsRequestId,
totalUnapprovedCount,
connectedStatusPopoverHasBeenShown,
defaultHomeActiveTabName,
swapsWelcomeMessageHasBeenShown: getSwapsWelcomeMessageSeenStatus(state),
haveSwapsQuotes: Boolean(Object.values(swapsState.quotes || {}).length),
swapsFetchParams: swapsState.fetchParams,
showAwaitingSwapScreen: swapsState.routeState === 'awaiting',
isMainnet: getIsMainnet(state),
originOfCurrentTab,
shouldShowWeb3ShimUsageNotification,
}
}
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()),
setConnectedStatusPopoverHasBeenShown: () =>
dispatch(setConnectedStatusPopoverHasBeenShown()),
onTabClick: (name) => dispatch(setDefaultHomeActiveTabName(name)),
setSwapsWelcomeMessageHasBeenShown: () =>
dispatch(setSwapsWelcomeMessageHasBeenShown()),
setWeb3ShimUsageAlertDismissed: (origin) =>
setWeb3ShimUsageAlertDismissed(origin),
disableWeb3ShimUsageAlert: () =>
setAlertEnabledness(ALERT_TYPES.web3ShimUsage, false),
})
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps),
)(Home)