diff --git a/app/js/App.js b/app/js/App.js index d1b4da8..da362dd 100644 --- a/app/js/App.js +++ b/app/js/App.js @@ -5,6 +5,7 @@ import ThemeProvider from 'react-bootstrap/ThemeProvider'; import EmbarkJS from 'Embark/EmbarkJS'; +import {isAdmin} from './services/Meritocracy'; import Header from './components/Header'; import Home from './components/Home'; import Admin from './components/Admin'; @@ -16,7 +17,8 @@ class App extends React.Component { state = { error: null, - loading: true + loading: true, + isUserAdmin: false }; componentDidMount() { @@ -32,12 +34,15 @@ class App extends React.Component { if (EmbarkJS.environment === 'livenet' && netId !== MAINNET) { return this.setState({error: 'Please connect to Mainnet'}); } - this.setState({loading: false}) + + const isUserAdmin = await isAdmin(web3.eth.defaultAccount); + + this.setState({loading: false, isUserAdmin}) }); } render() { - const {error, loading} = this.state; + const {error, loading, isUserAdmin} = this.state; if (error) { return (
@@ -54,10 +59,10 @@ class App extends React.Component { return ( -
+
- + {isUserAdmin && } diff --git a/app/js/components/Header.js b/app/js/components/Header.js index 60beb65..4a351f8 100644 --- a/app/js/components/Header.js +++ b/app/js/components/Header.js @@ -4,15 +4,15 @@ import {Navbar, Nav} from 'react-bootstrap'; import './header.scss' import logo from '../../images/logo.png'; -const Header = () => ( +const Header = ({isUserAdmin}) => ( LogoStatus Meritocracy - + {isUserAdmin && - + } ); diff --git a/app/js/services/Meritocracy.js b/app/js/services/Meritocracy.js index f72a91d..10431da 100644 --- a/app/js/services/Meritocracy.js +++ b/app/js/services/Meritocracy.js @@ -152,3 +152,17 @@ export function saveContributorList(list) { }); } +export function isAdmin(address) { + return new Promise(async (resolve, reject) => { + try { + const result = await Meritocracy.methods.admins(address).call(); + resolve(result); + } catch (e) { + const message = 'Could not get status of user'; + console.error(message); + console.error(e); + reject(message); + } + }); +} +