master
lza_menace 2 years ago
parent a6f92b7fe2
commit 817fcd49e2

@ -4,40 +4,10 @@
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<meta name="description" content="A Few Of Us Are Going To Make It. A Web3 lottery dApp." />
<title>AFOUAGMI</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
<div id="root"></div></body>
</html>

@ -3,16 +3,16 @@ import {
WagmiConfig, createClient, useAccount,
useConnect, useDisconnect, useContractReads,
configureChains, useContractWrite, usePrepareContractWrite,
useWaitForTransaction
useWaitForTransaction, useContractRead
} from 'wagmi';
import { localhost, goerli } from 'wagmi/chains';
import { publicProvider } from 'wagmi/providers/public';
import { InjectedConnector } from 'wagmi/connectors/injected';
import { readContract } from '@wagmi/core'
import { ethers, BigNumber } from 'ethers';
import Noty from 'noty';
import ABI from './abi.json';
import ERC721ABI from './721a.json';
import 'bulma/css/bulma.min.css';
import 'noty/lib/noty.css';
import 'noty/lib/themes/relax.css';
@ -32,6 +32,17 @@ const client = createClient({
provider
});
function GetClaimable(contract, tokenId) {
useContractRead({
...contract,
functionName: 'winningTokens',
args: [tokenId],
onSuccess(data) {
console.log(data);
}
});
}
function Contract() {
const { address, isConnected } = useAccount();
const { connect } = useConnect({connector});
@ -48,7 +59,9 @@ function Contract() {
balance: 0,
hash: '',
txPending: false,
tokensSet: ''
tokensSet: '',
winningTokens: '',
claimableTokens: ''
});
function handleStateChange(obj) {
setOptions(preState => ({...preState , ...obj}));
@ -81,10 +94,22 @@ function Contract() {
});
}
});
useContractRead({
..._contract,
enabled: options.totalSupply > 0 && options.totalSupply == options.max && options.tokensSet,
functionName: 'getWinningTokens',
watch: true,
cacheTime: 8000,
onSuccess(data) {
handleStateChange({
winningTokens: JSON.stringify(data)
});
}
});
const mintPrepare = usePrepareContractWrite({
address: contractAddress,
abi: ABI,
enabled: isConnected && options.mintAmount > 0,
enabled: isConnected && options.mintAmount > 0 && options.totalSupply < options.max,
functionName: 'mint',
args: [options.mintAmount],
overrides: {
@ -126,28 +151,56 @@ function Contract() {
}).show();
}
});
function checkClaimable(address) {
const raffle = new ethers.Contract(contractAddress, ERC721ABI);
console.log(raffle)
let claimableTokens = [];
for (let i; i < options.balance; i++) {
let token = raffle.tokenOfOwnerByIndex(address, i);
let _i = raffle.winningTokens(token);
console.log(token);
console.log(_i);
async function checkClaimable() {
const tokens = JSON.parse(options.winningTokens);
let claimable = [];
for (let i = 0; i < tokens.length; i++) {
const tokenId = BigNumber.from(tokens[i]).toString();
const data = await readContract({
address: contractAddress,
abi: ABI,
functionName: 'ownerOf',
args: [tokenId]
});
if (data === address) {
claimable.push(tokenId);
}
}
handleStateChange({claimableTokens: JSON.stringify(claimable)});
if (claimable.length > 0) {
new Noty({
type: 'success',
text: `Winner! Congratulations, you have ${claimable.length} tokens elligible to claim the Ether prize for.`,
theme: 'relax',
timeout: 8000
}).show();
} else {
new Noty({
type: 'error',
text: `Too bad! None of your tokens are elligible to claim`,
theme: 'relax',
timeout: 8000
}).show();
}
}
if (isConnected && options.phraseSet)
return (
<>
<button className="button" style={{marginBottom: '1em'}} onClick={() => disconnect()}>Disconnect Wallet</button>
{options.totalSupply === options.max && options.tokensSet === true && (
<button className="button is-info" style={{marginBottom: '1em', marginLeft: '1em'}} onClick={() => checkClaimable(address)}>Tokens entered</button>
<button className="button is-info" style={{marginBottom: '1em', marginLeft: '1em'}} onClick={async () => await checkClaimable()}>Check Claimable Tokens</button>
)}
{options.totalSupply === options.max && options.tokensSet === false && (
<button className="button is-warning" style={{marginBottom: '1em', marginLeft: '1em'}} disabled>Tokens not entered yet. Go degen.</button>
)}
<div className="buttons">
{JSON.parse(options.claimableTokens).map((tokenId, idx) => (
<button key={idx} className="button is-success" style={{marginBottom: '1em', marginRight: '1em'}}>{tokenId}</button>
))}
</div>
{options.totalSupply < options.max && (
<div className="block">
<h1 className="heading">Price: {ethers.utils.formatEther((options.price * options.mintAmount).toString())} ETH</h1>
@ -178,8 +231,13 @@ function Contract() {
)}</h1>
<progress className="progress is-primary" value={options.totalSupply} max={options.max}></progress>
</div>
{options.tokensSet && (
<div className="notification is-warning" style={{marginTop: '2em'}}>
Tokens have now been specified in the contract. Owners of those tokens can claim the Ether. Congrats to the winners!
</div>
)}
<div className="notification is-info" style={{marginTop: '2em'}}>
The secret phrase containing the pre-determined winners is: <strong>{options.hash}</strong>
The secret hash containing the pre-determined winners is: <strong>{options.hash}</strong>
</div>
<div className="notification">
ETH claims will be made available to winners approximately 48 hours after mint out.

@ -244,6 +244,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getWinningTokens",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
@ -650,6 +663,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "winningTokensIndex",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",

@ -0,0 +1,576 @@
[
{
"inputs": [],
"name": "ApprovalCallerNotOwnerNorApproved",
"type": "error"
},
{
"inputs": [],
"name": "ApprovalQueryForNonexistentToken",
"type": "error"
},
{
"inputs": [],
"name": "BalanceQueryForZeroAddress",
"type": "error"
},
{
"inputs": [],
"name": "InvalidQueryRange",
"type": "error"
},
{
"inputs": [],
"name": "MintERC2309QuantityExceedsLimit",
"type": "error"
},
{
"inputs": [],
"name": "MintToZeroAddress",
"type": "error"
},
{
"inputs": [],
"name": "MintZeroQuantity",
"type": "error"
},
{
"inputs": [],
"name": "OwnerQueryForNonexistentToken",
"type": "error"
},
{
"inputs": [],
"name": "OwnershipNotInitializedForExtraData",
"type": "error"
},
{
"inputs": [],
"name": "TransferCallerNotOwnerNorApproved",
"type": "error"
},
{
"inputs": [],
"name": "TransferFromIncorrectOwner",
"type": "error"
},
{
"inputs": [],
"name": "TransferToNonERC721ReceiverImplementer",
"type": "error"
},
{
"inputs": [],
"name": "TransferToZeroAddress",
"type": "error"
},
{
"inputs": [],
"name": "URIQueryForNonexistentToken",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "approved",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": false,
"internalType": "bool",
"name": "approved",
"type": "bool"
}
],
"name": "ApprovalForAll",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "fromTokenId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "toTokenId",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "ConsecutiveTransfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "approve",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "explicitOwnershipOf",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "addr",
"type": "address"
},
{
"internalType": "uint64",
"name": "startTimestamp",
"type": "uint64"
},
{
"internalType": "bool",
"name": "burned",
"type": "bool"
},
{
"internalType": "uint24",
"name": "extraData",
"type": "uint24"
}
],
"internalType": "struct IERC721A.TokenOwnership",
"name": "ownership",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[]",
"name": "tokenIds",
"type": "uint256[]"
}
],
"name": "explicitOwnershipsOf",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "addr",
"type": "address"
},
{
"internalType": "uint64",
"name": "startTimestamp",
"type": "uint64"
},
{
"internalType": "bool",
"name": "burned",
"type": "bool"
},
{
"internalType": "uint24",
"name": "extraData",
"type": "uint24"
}
],
"internalType": "struct IERC721A.TokenOwnership[]",
"name": "",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "getApproved",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "isApprovedForAll",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "ownerOf",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "safeTransferFrom",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"internalType": "bool",
"name": "approved",
"type": "bool"
}
],
"name": "setApprovalForAll",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "tokenURI",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "tokensOfOwner",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "uint256",
"name": "start",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "stop",
"type": "uint256"
}
],
"name": "tokensOfOwnerIn",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
]
Loading…
Cancel
Save