mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
b97cd1dc04
The notification window is now kept open after the connect flow if there are still pending confirmations. Previously, the notification window would be closed after the connect flow no matter what, and any pending confirmations would never be shown to the user. This was accomplished by redirecting to the home screen after the connect flow. The logic for deciding whether or not to close the window is already handled by the home page. This does have the unfortunate side-effect of briefly rendering the home page before the window closes, but this is a minor problem that exists already in a number of other scenarios, and it will be fixed in a subsequent PR. Fixes #8973
123 lines
3.5 KiB
JavaScript
123 lines
3.5 KiB
JavaScript
import { connect } from 'react-redux'
|
|
import PropTypes from 'prop-types'
|
|
import PermissionApproval from './permissions-connect.component'
|
|
import {
|
|
getPermissionsRequests,
|
|
getNativeCurrency,
|
|
getAccountsWithLabels,
|
|
getLastConnectedInfo,
|
|
getDomainMetadata,
|
|
getSelectedAddress,
|
|
} from '../../selectors'
|
|
|
|
import { formatDate } from '../../helpers/utils/util'
|
|
import {
|
|
approvePermissionsRequest,
|
|
rejectPermissionsRequest,
|
|
showModal,
|
|
getCurrentWindowTab,
|
|
getRequestAccountTabIds,
|
|
} from '../../store/actions'
|
|
import {
|
|
CONNECT_ROUTE,
|
|
CONNECT_CONFIRM_PERMISSIONS_ROUTE,
|
|
} from '../../helpers/constants/routes'
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
const {
|
|
match: { params: { id: permissionsRequestId } },
|
|
location: { pathname },
|
|
} = ownProps
|
|
const permissionsRequests = getPermissionsRequests(state)
|
|
const currentAddress = getSelectedAddress(state)
|
|
|
|
const permissionsRequest = permissionsRequests
|
|
.find((permissionsRequest) => permissionsRequest.metadata.id === permissionsRequestId)
|
|
|
|
const { metadata = {} } = permissionsRequest || {}
|
|
const { origin } = metadata
|
|
const nativeCurrency = getNativeCurrency(state)
|
|
|
|
const domainMetadata = getDomainMetadata(state)
|
|
|
|
let targetDomainMetadata = null
|
|
if (origin) {
|
|
if (domainMetadata[origin]) {
|
|
targetDomainMetadata = { ...domainMetadata[origin], origin }
|
|
} else {
|
|
const targetUrl = new URL(origin)
|
|
targetDomainMetadata = {
|
|
host: targetUrl.host,
|
|
name: targetUrl.hostname,
|
|
origin,
|
|
}
|
|
}
|
|
}
|
|
|
|
const accountsWithLabels = getAccountsWithLabels(state)
|
|
|
|
const lastConnectedInfo = getLastConnectedInfo(state) || {}
|
|
const addressLastConnectedMap = lastConnectedInfo[origin]?.accounts || {}
|
|
|
|
Object.keys(addressLastConnectedMap).forEach((key) => {
|
|
addressLastConnectedMap[key] = formatDate(addressLastConnectedMap[key], 'yyyy-MM-dd')
|
|
})
|
|
|
|
const connectPath = `${CONNECT_ROUTE}/${permissionsRequestId}`
|
|
const confirmPermissionPath = `${CONNECT_ROUTE}/${permissionsRequestId}${CONNECT_CONFIRM_PERMISSIONS_ROUTE}`
|
|
|
|
let page = ''
|
|
if (pathname === connectPath) {
|
|
page = '1'
|
|
} else if (pathname === confirmPermissionPath) {
|
|
page = '2'
|
|
} else {
|
|
throw new Error('Incorrect path for permissions-connect component')
|
|
}
|
|
|
|
return {
|
|
permissionsRequest,
|
|
permissionsRequestId,
|
|
accounts: accountsWithLabels,
|
|
currentAddress,
|
|
origin,
|
|
newAccountNumber: accountsWithLabels.length + 1,
|
|
nativeCurrency,
|
|
addressLastConnectedMap,
|
|
lastConnectedInfo,
|
|
connectPath,
|
|
confirmPermissionPath,
|
|
page,
|
|
targetDomainMetadata,
|
|
}
|
|
}
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
approvePermissionsRequest: (request, accounts) => dispatch(approvePermissionsRequest(request, accounts)),
|
|
rejectPermissionsRequest: (requestId) => dispatch(rejectPermissionsRequest(requestId)),
|
|
showNewAccountModal: ({ onCreateNewAccount, newAccountNumber }) => {
|
|
return dispatch(showModal({
|
|
name: 'NEW_ACCOUNT',
|
|
onCreateNewAccount,
|
|
newAccountNumber,
|
|
}))
|
|
},
|
|
getRequestAccountTabIds: () => dispatch(getRequestAccountTabIds()),
|
|
getCurrentWindowTab: () => dispatch(getCurrentWindowTab()),
|
|
}
|
|
}
|
|
|
|
const PermissionApprovalContainer = connect(mapStateToProps, mapDispatchToProps)(PermissionApproval)
|
|
|
|
PermissionApprovalContainer.propTypes = {
|
|
history: PropTypes.object.isRequired,
|
|
match: PropTypes.shape({
|
|
params: PropTypes.shape({
|
|
id: PropTypes.string,
|
|
}).isRequired,
|
|
}).isRequired,
|
|
}
|
|
|
|
export default PermissionApprovalContainer
|