Skip to content

Commit

Permalink
Show origin in connect flow rather than site name
Browse files Browse the repository at this point in the history
The designs for the connect flow show the site `origin` below the site
icon rather than the site name. This was done for security reasons,
and because the site name is often set to an unwieldy long string.

This was accidentally undone in #8815 in the process of fixing a
separate bug. The origin has now been restored. More specific PropTypes
have been set on each use of the `domainMetadata` prop as well.
  • Loading branch information
Gudahtt committed Jul 2, 2020
1 parent 603093a commit 57f4ea5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import CheckBox from '../../../ui/check-box'
export default class PermissionPageContainerContent extends PureComponent {

static propTypes = {
domainMetadata: PropTypes.object.isRequired,
domainMetadata: PropTypes.shape({
extensionId: PropTypes.string,
icon: PropTypes.string,
host: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
origin: PropTypes.string.isRequired,
}),
selectedPermissions: PropTypes.object.isRequired,
onPermissionToggle: PropTypes.func.isRequired,
selectedIdentities: PropTypes.array,
Expand Down Expand Up @@ -145,6 +151,7 @@ export default class PermissionPageContainerContent extends PureComponent {
? t('allowExternalExtensionTo', [domainMetadata.extensionId])
: t('allowThisSiteTo')
}
siteOrigin={domainMetadata.origin}
/>
<section className="permission-approval-container__permissions-container">
{ this.renderRequestedPermissions() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export default class PermissionPageContainer extends Component {
allIdentitiesSelected: PropTypes.bool,
request: PropTypes.object,
requestMetadata: PropTypes.object,
targetDomainMetadata: PropTypes.object.isRequired,
targetDomainMetadata: PropTypes.shape({
extensionId: PropTypes.string,
icon: PropTypes.string,
host: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
origin: PropTypes.string.isRequired,
}),
}

static defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import SiteIcon from '../../ui/site-icon'
export default class PermissionsConnectHeader extends Component {
static propTypes = {
icon: PropTypes.string,
iconName: PropTypes.string,
iconName: PropTypes.string.isRequired,
siteOrigin: PropTypes.string.isRequired,
headerTitle: PropTypes.node,
headerText: PropTypes.string,
}

static defaultProps = {
icon: null,
iconName: '',
headerTitle: '',
headerText: '',
}

renderHeaderIcon () {
const { icon, iconName } = this.props
const { icon, iconName, siteOrigin } = this.props

return (
<div className="permissions-connect-header__icon">
<SiteIcon icon={ icon } name={ iconName } size={64} />
<div className="permissions-connect-header__text">{iconName}</div>
<div className="permissions-connect-header__text">{siteOrigin}</div>
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ export default class ChooseAccount extends Component {
cancelPermissionsRequest: PropTypes.func.isRequired,
permissionsRequestId: PropTypes.string.isRequired,
selectedAccountAddresses: PropTypes.object.isRequired,
targetDomainMetadata: PropTypes.object,
targetDomainMetadata: PropTypes.shape({
extensionId: PropTypes.string,
icon: PropTypes.string,
host: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
origin: PropTypes.string.isRequired,
}),
}

state = {
Expand Down Expand Up @@ -197,6 +203,7 @@ export default class ChooseAccount extends Component {
? t('selectAccounts')
: t('connectAccountOrCreate')
}
siteOrigin={targetDomainMetadata.origin}
/>
{this.renderAccountsListHeader()}
{this.renderAccountsList()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export default class PermissionConnect extends Component {
connectPath: PropTypes.string.isRequired,
confirmPermissionPath: PropTypes.string.isRequired,
page: PropTypes.string.isRequired,
targetDomainMetadata: PropTypes.object,
targetDomainMetadata: PropTypes.shape({
extensionId: PropTypes.string,
icon: PropTypes.string,
host: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
origin: PropTypes.string.isRequired,
}),
}

static defaultProps = {
Expand Down Expand Up @@ -95,7 +101,7 @@ export default class PermissionConnect extends Component {

if (
permissionsRequest &&
savedMetadata.name !== targetDomainMetadata?.name
savedMetadata.origin !== targetDomainMetadata?.origin
) {
return { targetDomainMetadata }
}
Expand Down
19 changes: 13 additions & 6 deletions ui/app/pages/permissions-connect/permissions-connect.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ const mapStateToProps = (state, ownProps) => {
const nativeCurrency = getNativeCurrency(state)

const domainMetadata = getDomainMetadata(state)
const targetDomainMetadata = origin
? domainMetadata[origin] || {
origin,
name: (new URL(origin)).hostname,
icon: null,

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,
}
}
: null
}

const accountsWithLabels = getAccountsWithLabels(state)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ export default function PermissionsRedirect ({ domainMetadata }) {
}

PermissionsRedirect.propTypes = {
domainMetadata: PropTypes.object.isRequired,
domainMetadata: PropTypes.shape({
extensionId: PropTypes.string,
icon: PropTypes.string,
host: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
origin: PropTypes.string.isRequired,
}),
}

0 comments on commit 57f4ea5

Please sign in to comment.