mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Localize permission descriptions (#8661)
This commit is contained in:
parent
a0d64c7932
commit
4802ed1df5
@ -1,4 +1,8 @@
|
||||
{
|
||||
"eth_accounts": {
|
||||
"message": "View your public address (required)",
|
||||
"description": "The description for the `eth_accounts` permission"
|
||||
},
|
||||
"connectedSites": {
|
||||
"message": "Connected sites"
|
||||
},
|
||||
|
@ -1,8 +1,6 @@
|
||||
export default function getRestrictedMethods ({ getIdentities, getKeyringAccounts }) {
|
||||
return {
|
||||
|
||||
'eth_accounts': {
|
||||
description: `View your public address (required)`,
|
||||
method: (_, res, __, end) => {
|
||||
getKeyringAccounts()
|
||||
.then((accounts) => {
|
||||
|
@ -14,7 +14,6 @@ export default class ConnectedAccountsListPermissions extends PureComponent {
|
||||
static propTypes = {
|
||||
permissions: PropTypes.arrayOf(PropTypes.shape({
|
||||
key: PropTypes.string.isRequired,
|
||||
description: PropTypes.string.isRequired,
|
||||
})),
|
||||
}
|
||||
|
||||
@ -56,9 +55,9 @@ export default class ConnectedAccountsListPermissions extends PureComponent {
|
||||
>
|
||||
<p>{t('authorizedPermissions')}:</p>
|
||||
<ul className="connected-accounts-permissions__list">
|
||||
{permissions.map(({ key, description }) => (
|
||||
{permissions.map(({ key }) => (
|
||||
<li key={key} className="connected-accounts-permissions__list-item">
|
||||
<i className="fas fa-check-square" /> {description}
|
||||
<i className="fas fa-check-square" /> {t(key)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
@ -28,7 +28,6 @@ export default class ConnectedAccountsList extends PureComponent {
|
||||
})).isRequired,
|
||||
permissions: PropTypes.arrayOf(PropTypes.shape({
|
||||
key: PropTypes.string.isRequired,
|
||||
description: PropTypes.string.isRequired,
|
||||
})),
|
||||
selectedAddress: PropTypes.string.isRequired,
|
||||
addPermittedAccount: PropTypes.func.isRequired,
|
||||
|
@ -10,7 +10,6 @@ export default class PermissionPageContainerContent extends PureComponent {
|
||||
static propTypes = {
|
||||
domainMetadata: PropTypes.object.isRequired,
|
||||
selectedPermissions: PropTypes.object.isRequired,
|
||||
permissionsDescriptions: PropTypes.object.isRequired,
|
||||
onPermissionToggle: PropTypes.func.isRequired,
|
||||
selectedIdentities: PropTypes.array,
|
||||
allIdentitiesSelected: PropTypes.bool,
|
||||
@ -64,17 +63,13 @@ export default class PermissionPageContainerContent extends PureComponent {
|
||||
|
||||
renderRequestedPermissions () {
|
||||
const {
|
||||
selectedPermissions, permissionsDescriptions, onPermissionToggle,
|
||||
selectedPermissions, onPermissionToggle,
|
||||
} = this.props
|
||||
const { t } = this.context
|
||||
|
||||
const items = Object.keys(selectedPermissions).map((methodName) => {
|
||||
|
||||
// the request will almost certainly be reject by rpc-cap if this happens
|
||||
if (!permissionsDescriptions[methodName]) {
|
||||
console.warn(`Unknown permission requested: ${methodName}`)
|
||||
}
|
||||
const description = permissionsDescriptions[methodName] || methodName
|
||||
const description = t(methodName)
|
||||
// don't allow deselecting eth_accounts
|
||||
const isDisabled = methodName === 'eth_accounts'
|
||||
|
||||
|
@ -12,7 +12,6 @@ export default class PermissionPageContainer extends Component {
|
||||
rejectPermissionsRequest: PropTypes.func.isRequired,
|
||||
selectedIdentities: PropTypes.array,
|
||||
allIdentitiesSelected: PropTypes.bool,
|
||||
permissionsDescriptions: PropTypes.object.isRequired,
|
||||
request: PropTypes.object,
|
||||
redirect: PropTypes.bool,
|
||||
permissionRejected: PropTypes.bool,
|
||||
@ -116,7 +115,6 @@ export default class PermissionPageContainer extends Component {
|
||||
const {
|
||||
requestMetadata,
|
||||
targetDomainMetadata,
|
||||
permissionsDescriptions,
|
||||
selectedIdentities,
|
||||
redirect,
|
||||
permissionRejected,
|
||||
@ -129,7 +127,6 @@ export default class PermissionPageContainer extends Component {
|
||||
requestMetadata={requestMetadata}
|
||||
domainMetadata={targetDomainMetadata}
|
||||
selectedPermissions={this.state.selectedPermissions}
|
||||
permissionsDescriptions={permissionsDescriptions}
|
||||
onPermissionToggle={this.onPermissionToggle}
|
||||
selectedIdentities={selectedIdentities}
|
||||
redirect={redirect}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { connect } from 'react-redux'
|
||||
import PermissionPageContainer from './permission-page-container.component'
|
||||
import {
|
||||
getPermissionsDescriptions,
|
||||
getTargetDomainMetadata,
|
||||
getMetaMaskIdentities,
|
||||
} from '../../../selectors'
|
||||
@ -14,7 +13,6 @@ const mapStateToProps = (state, ownProps) => {
|
||||
const allIdentitiesSelected = Object.keys(selectedIdentities).length === Object.keys(allIdentities).length && selectedIdentities.length > 1
|
||||
|
||||
return {
|
||||
permissionsDescriptions: getPermissionsDescriptions(state),
|
||||
targetDomainMetadata,
|
||||
allIdentitiesSelected,
|
||||
}
|
||||
|
@ -241,14 +241,11 @@ export function getPermissionsForActiveTab (state) {
|
||||
const { activeTab, metamask } = state
|
||||
const {
|
||||
domains = {},
|
||||
permissionsDescriptions,
|
||||
} = metamask
|
||||
|
||||
return domains[activeTab.origin]?.permissions?.map(({ parentCapability }) => {
|
||||
const description = permissionsDescriptions[parentCapability]
|
||||
return {
|
||||
key: parentCapability,
|
||||
description,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -302,10 +302,6 @@ export function getCustomNonceValue (state) {
|
||||
return String(state.metamask.customNonceValue)
|
||||
}
|
||||
|
||||
export function getPermissionsDescriptions (state) {
|
||||
return state.metamask.permissionsDescriptions
|
||||
}
|
||||
|
||||
export function getPermissionsRequests (state) {
|
||||
return state.metamask.permissionsRequests || []
|
||||
}
|
||||
|
@ -428,16 +428,12 @@ describe('selectors', function () {
|
||||
},
|
||||
},
|
||||
},
|
||||
permissionsDescriptions: {
|
||||
'eth_accounts': "View the addresses of the user's chosen accounts.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
it('should return a list of permissions strings', function () {
|
||||
assert.deepEqual(getPermissionsForActiveTab(mockState), [{
|
||||
key: 'eth_accounts',
|
||||
description: "View the addresses of the user's chosen accounts.",
|
||||
}])
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user