Have minter check periodically for address

This commit is contained in:
Mentor Palokaj 2021-10-21 19:17:17 +02:00
parent 262000f313
commit 5229525ccc
4 changed files with 23 additions and 1 deletions

View File

@ -16170,6 +16170,11 @@
"resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",
"integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ=="
},
"use-interval": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/use-interval/-/use-interval-1.4.0.tgz",
"integrity": "sha512-1betIJun2rXKLxa30AFOBZCeZhsBJoJ/3+gkCeYbJ63lAR//EnAb1NjNeFqzgqeM7zQfR76rrCUaA8DvfgoOpA=="
},
"utf-8-validate": {
"version": "5.0.7",
"resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.7.tgz",

View File

@ -10,6 +10,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"use-interval": "^1.4.0",
"web-vitals": "^1.1.2",
"web3": "^1.6.0"
},

View File

@ -79,6 +79,7 @@ export default function Verifier() {
if( message ) return <Container>
{ message.balance > 0 && <p> { message.username } has { message.balance } Rocketeers on chain { chainId }</p> }
{ message.balance < 1 && <p>🛑 Computer says no</p> }
<p>Something went wrong, contact #support in Discord</p>
</Container>
if( verifyUrl ) return <Container>

View File

@ -1,4 +1,5 @@
import { useState, useEffect } from "react"
import useInterval from 'use-interval'
import { log, setListenerAndReturnUnlistener } from './helpers'
// Ethers and web3 sdk
@ -30,17 +31,31 @@ export async function getAddress() {
export function useAddress() {
const [ address, setAddress ] = useState( undefined )
const [ interval, setInterval ] = useState( 5000 )
useInterval( () => {
log( 'Checking for address' )
if( window.ethereum && window.ethereum.selectedAddress ) setAddress( window.ethereum.selectedAddress )
}, interval )
// Set initial value if known
useEffect( f => {
log( 'useAddress setting: ', window.ethereum && window.ethereum.selectedAddress, ` based on `, window.ethereum )
if( window.ethereum && window.ethereum.selectedAddress ) setAddress( window.ethereum.selectedAddress )
if( window.ethereum && window.ethereum.selectedAddress ) {
setAddress( window.ethereum.selectedAddress )
setInterval( null )
} else {
setInterval( 5000 )
}
}, [] )
// Create listener to accounts change
useEffect( f => setListenerAndReturnUnlistener( window.ethereum, 'accountsChanged', addresses => {
log( 'Addresses changed to ', addresses )
setAddress( addresses[0] )
setInterval( 5000 )
} ), [ ] )