master
lza_menace 2 years ago
parent a6f92b7fe2
commit 817fcd49e2

@ -4,40 +4,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="description" content="A Few Of Us Are Going To Make It. A Web3 lottery dApp." />
<meta <title>AFOUAGMI</title>
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>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div> <div id="root"></div></body>
<!--
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>
</html> </html>

@ -3,16 +3,16 @@ import {
WagmiConfig, createClient, useAccount, WagmiConfig, createClient, useAccount,
useConnect, useDisconnect, useContractReads, useConnect, useDisconnect, useContractReads,
configureChains, useContractWrite, usePrepareContractWrite, configureChains, useContractWrite, usePrepareContractWrite,
useWaitForTransaction useWaitForTransaction, useContractRead
} from 'wagmi'; } from 'wagmi';
import { localhost, goerli } from 'wagmi/chains'; import { localhost, goerli } from 'wagmi/chains';
import { publicProvider } from 'wagmi/providers/public'; import { publicProvider } from 'wagmi/providers/public';
import { InjectedConnector } from 'wagmi/connectors/injected'; import { InjectedConnector } from 'wagmi/connectors/injected';
import { readContract } from '@wagmi/core'
import { ethers, BigNumber } from 'ethers'; import { ethers, BigNumber } from 'ethers';
import Noty from 'noty'; import Noty from 'noty';
import ABI from './abi.json'; import ABI from './abi.json';
import ERC721ABI from './721a.json';
import 'bulma/css/bulma.min.css'; import 'bulma/css/bulma.min.css';
import 'noty/lib/noty.css'; import 'noty/lib/noty.css';
import 'noty/lib/themes/relax.css'; import 'noty/lib/themes/relax.css';
@ -32,6 +32,17 @@ const client = createClient({
provider provider
}); });
function GetClaimable(contract, tokenId) {
useContractRead({
...contract,
functionName: 'winningTokens',
args: [tokenId],
onSuccess(data) {
console.log(data);
}
});
}
function Contract() { function Contract() {
const { address, isConnected } = useAccount(); const { address, isConnected } = useAccount();
const { connect } = useConnect({connector}); const { connect } = useConnect({connector});
@ -48,7 +59,9 @@ function Contract() {
balance: 0, balance: 0,
hash: '', hash: '',
txPending: false, txPending: false,
tokensSet: '' tokensSet: '',
winningTokens: '',
claimableTokens: ''
}); });
function handleStateChange(obj) { function handleStateChange(obj) {
setOptions(preState => ({...preState , ...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({ const mintPrepare = usePrepareContractWrite({
address: contractAddress, address: contractAddress,
abi: ABI, abi: ABI,
enabled: isConnected && options.mintAmount > 0, enabled: isConnected && options.mintAmount > 0 && options.totalSupply < options.max,
functionName: 'mint', functionName: 'mint',
args: [options.mintAmount], args: [options.mintAmount],
overrides: { overrides: {
@ -126,28 +151,56 @@ function Contract() {
}).show(); }).show();
} }
}); });
function checkClaimable(address) { async function checkClaimable() {
const raffle = new ethers.Contract(contractAddress, ERC721ABI); const tokens = JSON.parse(options.winningTokens);
console.log(raffle) let claimable = [];
let claimableTokens = []; for (let i = 0; i < tokens.length; i++) {
for (let i; i < options.balance; i++) { const tokenId = BigNumber.from(tokens[i]).toString();
let token = raffle.tokenOfOwnerByIndex(address, i); const data = await readContract({
let _i = raffle.winningTokens(token); address: contractAddress,
console.log(token); abi: ABI,
console.log(_i); 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) if (isConnected && options.phraseSet)
return ( return (
<> <>
<button className="button" style={{marginBottom: '1em'}} onClick={() => disconnect()}>Disconnect Wallet</button> <button className="button" style={{marginBottom: '1em'}} onClick={() => disconnect()}>Disconnect Wallet</button>
{options.totalSupply === options.max && options.tokensSet === true && ( {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 && ( {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> <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 && ( {options.totalSupply < options.max && (
<div className="block"> <div className="block">
<h1 className="heading">Price: {ethers.utils.formatEther((options.price * options.mintAmount).toString())} ETH</h1> <h1 className="heading">Price: {ethers.utils.formatEther((options.price * options.mintAmount).toString())} ETH</h1>
@ -178,8 +231,13 @@ function Contract() {
)}</h1> )}</h1>
<progress className="progress is-primary" value={options.totalSupply} max={options.max}></progress> <progress className="progress is-primary" value={options.totalSupply} max={options.max}></progress>
</div> </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'}}> <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>
<div className="notification"> <div className="notification">
ETH claims will be made available to winners approximately 48 hours after mint out. ETH claims will be made available to winners approximately 48 hours after mint out.

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