Skip to content

Commit

Permalink
permission-page-container named vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Sep 18, 2024
1 parent 144dea4 commit 0dc84aa
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,22 @@ export default class PermissionPageContainer extends Component {
selectedAccounts,
} = this.props;

const approvedAccounts = selectedAccounts.map(
(selectedAccount) => selectedAccount.address,
)

const permittedChainsPermission = _request.permissions[
PermissionNames.permittedChains
]
const approvedChainIds = permittedChainsPermission?.caveats.find(
(caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching,
)?.value

const request = {
..._request,
permissions: { ..._request.permissions },
...(_request.permissions.eth_accounts && {
approvedAccounts: selectedAccounts.map(
(selectedAccount) => selectedAccount.address,
),
}),
...(_request.permissions[PermissionNames.permittedChains] && {
approvedChainIds: _request.permissions[
PermissionNames.permittedChains
]?.caveats.find(
(caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching,
)?.value,
}),
...(_request.permissions.eth_accounts && { approvedAccounts }),
...(_request.permissions[PermissionNames.permittedChains] && { approvedChainIds }),
};

if (Object.keys(request.permissions).length > 0) {
Expand Down

0 comments on commit 0dc84aa

Please sign in to comment.