Deployed to testnet
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 33s Details

This commit is contained in:
Ladd Hoffman 2024-03-10 19:39:15 -05:00
parent b3cdfcef73
commit c4fbce9f76
3 changed files with 212 additions and 338 deletions

View File

@ -1,63 +1,75 @@
import { useCallback, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
import { useSDK } from '@metamask/sdk-react';
import { Web3 } from 'web3';
import Button from 'react-bootstrap/Button';
// import './App.css';
import DAOArtifact from './assets/DAO.json';
import work1Artifact from './assets/Work1.json';
// import work1Artifact from './assets/Work1.json';
const DAOAddress = '0x91ffddC013E2Df43E8FB177922d762bC8D776e79';
const work1Address = '0x08673dE03e1e9b4c9A0aF99463fa4DEFD3891987';
const contracts = {
'0x539': { // Hardhat
DAO: '0x7209aa5b0B91700615bA982e4E4F1Eb967E31cf1',
Work1: '0x4a3f03f50b542BD27DbcaDAF9A3d608AE4f5AACc',
},
'0xaa36a7': { // Sepolia
DAO: '0x8d914D38dD301FC4606f5aa9fEcF8A76389020d3',
Work1: '0x050C420Cc4995B41217Eba1B54B82Fd5687e9139',
},
};
function App() {
const {
sdk, connected, provider, chainId, account, balance,
} = useSDK();
const [work1, setWork1] = useState();
const [DAO, setDAO] = useState();
const [work1Price, setWork1Price] = useState();
// const [work1, setWork1] = useState();
// const [work1Price, setWork1Price] = useState();
const [balanceEther, setBalanceEther] = useState();
const [reputation, setReputation] = useState();
const [totalReputation, setTotalReputation] = useState();
const [validationPoolCount, setValidationPoolCount] = useState();
const [latestPoolIndex, setLatestPoolIndex] = useState();
const [votePasses, setVotePasses] = useState();
const watchReputationNFT = useCallback(async (tokenId) => {
await provider.request({
method: 'wallet_watchAsset',
params: {
type: 'ERC721',
options: {
address: DAOAddress,
tokenId: BigInt(tokenId).toString(),
},
},
});
}, [provider]);
// const watchReputationToken = useCallback(async () => {
// await provider.request({
// method: 'wallet_watchAsset',
// params: {
// type: 'ERC20',
// options: {
// address: DAOAddress,
// },
// },
// });
// }, [provider]);
useEffect(() => {
if (!provider) return;
if (!provider || !chainId || !account) return;
if (!contracts[chainId]) return;
const web3 = new Web3(provider);
const work1Contract = new web3.eth.Contract(work1Artifact.abi, work1Address);
const DAOContract = new web3.eth.Contract(DAOArtifact.abi, DAOAddress);
const DAOContract = new web3.eth.Contract(DAOArtifact.abi, contracts[chainId].DAO);
// const work1Contract = new web3.eth.Contract(work1Artifact.abi, contracts[chainId].Work1);
// const fetchPrice = async () => {
// const priceWei = await work1Contract.methods.price().call();
// setWork1Price(web3.utils.fromWei(priceWei, 'ether'));
// };
const fetchPrice = async () => {
const priceWei = await work1Contract.methods.price().call();
setWork1Price(web3.utils.fromWei(priceWei, 'ether'));
};
const fetchReputation = async () => {
setReputation(await DAOContract.methods.valueOf(0).call());
console.log(`fetchReputation, account: ${account}`);
setReputation(await DAOContract.methods.balanceOf(account).call());
setTotalReputation(await DAOContract.methods.totalSupply().call());
};
const fetchValidationPoolCount = async () => {
setValidationPoolCount(await DAOContract.methods.validationPoolCount().call());
};
fetchPrice();
// fetchPrice();
fetchReputation();
fetchValidationPoolCount();
setWork1(work1Contract);
// setWork1(work1Contract);
setDAO(DAOContract);
DAOContract.events.ValidationPoolInitiated({ fromBlock: 'latest' }).on('data', (event) => {
@ -69,17 +81,14 @@ function App() {
DAOContract.events.ValidationPoolResolved({ fromBlock: 'latest' }).on('data', (event) => {
console.log('event: validation pool resolved', event);
setVotePasses(event.returnValues.votePasses);
if (event.returnValues.votePasses) {
watchReputationNFT(event.returnValues.newTokenId);
}
fetchReputation();
});
}, [provider, watchReputationNFT]);
}, [provider, account, chainId]);
useEffect(() => {
if (provider && balance) {
const web3 = new Web3(provider);
setBalanceEther(web3.utils.fromWei(balance, 'ether'));
}
if (!provider || balance === undefined) return;
const web3 = new Web3(provider);
setBalanceEther(web3.utils.fromWei(balance, 'ether'));
}, [provider, balance]);
const connect = async () => {
@ -133,6 +142,11 @@ function App() {
{connected && (
<>
<div>
{!contracts[chainId] && (
<div>
Please switch MetaMask to Sepolia testnet!
</div>
)}
<div>
{chainId && `Chain ID: ${chainId}`}
</div>
@ -143,7 +157,10 @@ function App() {
{`Balance: ${balanceEther} ETH`}
</div>
<div>
{`REP: ${reputation}`}
{`Your REP: ${reputation}`}
</div>
<div>
{`Total REP: ${totalReputation}`}
</div>
<Button onClick={() => disconnect()}>Disconnect</Button>
</div>
@ -160,7 +177,7 @@ function App() {
{`Outcome: ${votePasses}`}
</div>
<div>
{`Work1 Price: ${work1Price} ETH`}
{ /* `Work1 Price: ${work1Price} ETH` */ }
</div>
<div>
{ /* <Button onClick={() => requestWork()}>Request Work</Button> */ }

File diff suppressed because one or more lines are too long

View File

@ -11,5 +11,9 @@ module.exports = {
},
chainId: 1337,
},
sepolia: {
url: `https://sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [process.env.SEPOLIA_PRIVATE_KEY],
},
},
};