2024-04-28 20:27:25 -05:00
|
|
|
import { useCallback } from 'react';
|
2024-03-07 21:27:37 -06:00
|
|
|
import Button from 'react-bootstrap/Button';
|
2024-03-14 18:38:54 -05:00
|
|
|
import Container from 'react-bootstrap/Container';
|
|
|
|
import Row from 'react-bootstrap/Row';
|
|
|
|
import Col from 'react-bootstrap/Col';
|
|
|
|
import Stack from 'react-bootstrap/Stack';
|
2024-03-13 16:14:59 -05:00
|
|
|
|
2024-04-28 20:27:25 -05:00
|
|
|
import MainTabs from './components/tabs';
|
|
|
|
import useMainContext from './contexts/useMainContext';
|
2024-03-14 18:08:17 -05:00
|
|
|
|
2024-04-25 13:21:44 -05:00
|
|
|
function WebApp() {
|
2024-03-07 21:27:37 -06:00
|
|
|
const {
|
2024-04-28 20:27:25 -05:00
|
|
|
sdk, connected, chainId, account, reputation, totalReputation, balanceEther,
|
|
|
|
} = useMainContext();
|
2024-03-14 18:08:17 -05:00
|
|
|
|
|
|
|
const connect = useCallback(async () => {
|
2024-03-07 21:27:37 -06:00
|
|
|
try {
|
|
|
|
await sdk?.connect();
|
2024-04-28 20:27:25 -05:00
|
|
|
console.log('connected');
|
|
|
|
console.log('connected', connected);
|
2024-03-07 21:27:37 -06:00
|
|
|
} catch (err) {
|
|
|
|
console.warn('failed to connect..', err);
|
|
|
|
}
|
2024-04-28 20:27:25 -05:00
|
|
|
}, [sdk, connected]);
|
2024-03-07 21:27:37 -06:00
|
|
|
|
2024-03-14 18:08:17 -05:00
|
|
|
const disconnect = useCallback(async () => {
|
2024-03-07 21:27:37 -06:00
|
|
|
try {
|
|
|
|
sdk?.terminate();
|
|
|
|
} catch (err) {
|
|
|
|
console.warn('failed to disconnect..', err);
|
|
|
|
}
|
2024-03-14 18:08:17 -05:00
|
|
|
}, [sdk]);
|
2024-03-07 21:27:37 -06:00
|
|
|
|
2024-02-21 18:01:41 -06:00
|
|
|
return (
|
2024-04-28 20:27:25 -05:00
|
|
|
<>
|
2024-03-07 21:27:37 -06:00
|
|
|
{!connected && <Button onClick={() => connect()}>Connect</Button>}
|
|
|
|
|
|
|
|
{connected && (
|
|
|
|
<>
|
2024-03-14 18:38:54 -05:00
|
|
|
<Container>
|
|
|
|
<Row>
|
|
|
|
<Col>
|
2024-03-17 11:06:10 -05:00
|
|
|
{chainId !== '0xaa36a7' && (
|
2024-03-14 18:38:54 -05:00
|
|
|
<div>
|
|
|
|
Please switch MetaMask to Sepolia testnet!
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row>
|
|
|
|
<Col>
|
|
|
|
<Stack>
|
|
|
|
<div>
|
|
|
|
{chainId && `Chain ID: ${chainId}`}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{`Account: ${account}`}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{`Balance: ${balanceEther} ETH`}
|
|
|
|
</div>
|
|
|
|
</Stack>
|
|
|
|
</Col>
|
|
|
|
<Col>
|
|
|
|
<Stack>
|
|
|
|
<div>
|
2024-03-16 21:19:57 -05:00
|
|
|
{`Your REP: ${reputation?.toString()}`}
|
2024-03-14 18:38:54 -05:00
|
|
|
</div>
|
|
|
|
<div>
|
2024-03-16 21:19:57 -05:00
|
|
|
{`Total REP: ${totalReputation?.toString()}`}
|
2024-03-14 18:38:54 -05:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Button onClick={() => disconnect()}>Disconnect</Button>
|
|
|
|
</div>
|
|
|
|
</Stack>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Container>
|
2024-04-28 20:27:25 -05:00
|
|
|
|
|
|
|
<MainTabs />
|
2024-03-07 21:27:37 -06:00
|
|
|
</>
|
2024-03-07 10:58:55 -06:00
|
|
|
)}
|
2024-04-28 20:27:25 -05:00
|
|
|
</>
|
2024-03-16 20:34:36 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-25 13:21:44 -05:00
|
|
|
export default WebApp;
|