-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from lukso-network/feat/controller-permissions
feat: display list of permissions next to each controller
- Loading branch information
Showing
5 changed files
with
828 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import ERC725, { encodeKeyName } from '@erc725/erc725.js'; | ||
|
||
import { getDataBatch } from '../../utils/web3'; | ||
import useWeb3 from '../../hooks/useWeb3'; | ||
import AddressInfos from '../AddressInfos'; | ||
|
||
interface Props { | ||
address: string; | ||
controllers: string[]; | ||
} | ||
|
||
const ControllersList: React.FC<Props> = ({ address, controllers }) => { | ||
const [controllersPermissions, setControllersPermissions] = useState<{ | ||
[key: string]: any; | ||
}>([]); | ||
|
||
const web3 = useWeb3(); | ||
|
||
useEffect(() => { | ||
const getPermissions = async () => { | ||
try { | ||
if (address && web3 !== undefined) { | ||
const permissionsDataKeys = controllers.map((controller) => { | ||
return encodeKeyName( | ||
'AddressPermissions:Permissions:<address>', | ||
controller, | ||
); | ||
}); | ||
|
||
const result = await getDataBatch(address, permissionsDataKeys, web3); | ||
|
||
const decodedPermissions = result.map((value) => | ||
ERC725.decodePermissions(value), | ||
); | ||
setControllersPermissions(decodedPermissions); | ||
} | ||
} catch (error: any) { | ||
console.error(error); | ||
} | ||
}; | ||
getPermissions(); | ||
}, [address, web3]); | ||
|
||
return ( | ||
<ul> | ||
<li style={{ listStyleType: 'none' }}> | ||
{controllers.length} controllers found | ||
</li> | ||
{controllers && | ||
controllers.map( | ||
(item, index) => | ||
item && ( | ||
<li key={index} className="my-2"> | ||
<div className="columns"> | ||
<div className="column"> | ||
<p>Controller Infos:</p> | ||
<AddressInfos address={item.toString()} /> | ||
</div> | ||
<div className="column"> | ||
<p>Permissions:</p> | ||
{controllersPermissions[index] && | ||
Object.entries(controllersPermissions[index]).map( | ||
([permission, isSet]) => | ||
isSet && ( | ||
<span key={index} className="tag is-primary m-1"> | ||
{permission} | ||
</span> | ||
), | ||
)} | ||
</div> | ||
</div> | ||
</li> | ||
), | ||
)} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default ControllersList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ControllersList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.