mirror of
https://github.com/stronk-dev/RandomChad.git
synced 2025-07-05 10:35:08 +02:00
Listen better to metamask
This commit is contained in:
parent
82d2b6da08
commit
eca5b85e80
@ -62,13 +62,13 @@ function App() {
|
||||
// Check for action on load
|
||||
useEffect( f => {
|
||||
checkAction()
|
||||
window.addEventListener( 'popstate', checkAction )
|
||||
}, [] )
|
||||
return window.addEventListener( 'popstate', checkAction )
|
||||
}, [ address, loading ] )
|
||||
|
||||
// ///////////////////////////////
|
||||
// Rendering
|
||||
// ///////////////////////////////
|
||||
log( action, error, loading, address )
|
||||
log( 'Rendering with ', action, error, loading, address )
|
||||
// Initialisation interface
|
||||
if( error || loading || !address ) return <Container>
|
||||
{ error && <p>{ error }</p> }
|
||||
@ -80,9 +80,9 @@ function App() {
|
||||
</div> }
|
||||
{ !address && ( !error && !loading ) && <>
|
||||
|
||||
<h1>Rocketeer { action == 'mint' ? 'Minter' : 'Verifier' }</h1>
|
||||
{ action == 'mint' && <p>This interface is used to mint new Rocketeer NFTs. Minting is free, except for the gas fees. After minting you can view your new Rocketeer and its attributes on Opensea.</p> }
|
||||
{ action == 'verify' && <p>This interface is used to veriy that you are the owner of a Rocketeer</p> }
|
||||
<h1>Rocketeer { action === 'mint' ? 'Minter' : 'Verifier' }</h1>
|
||||
{ action === 'mint' && <p>This interface is used to mint new Rocketeer NFTs. Minting is free, except for the gas fees. After minting you can view your new Rocketeer and its attributes on Opensea.</p> }
|
||||
{ action === 'verify' && <p>This interface is used to veriy that you are the owner of a Rocketeer</p> }
|
||||
<a className="button" href="/#" onClick={ metamasklogin }>
|
||||
<img alt="metamask fox" src={ Fox } />
|
||||
Connect wallet
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Container } from './generic'
|
||||
import '../App.css'
|
||||
|
||||
import { useState, useEffect, useReducer } from 'react'
|
||||
import { log, setListenerAndReturnUnlistener } from '../modules/helpers'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { log } from '../modules/helpers'
|
||||
import { useAddress, useChainId, useBalanceOf } from '../modules/web3'
|
||||
|
||||
export default function Verifier() {
|
||||
@ -36,10 +36,14 @@ export default function Verifier() {
|
||||
|
||||
function verifyIfNeeded() {
|
||||
|
||||
log( 'Check the need to verify' )
|
||||
|
||||
if( !window.location.href.includes( 'message' ) ) return
|
||||
|
||||
try {
|
||||
|
||||
log( 'Verification started' )
|
||||
|
||||
const { search } = window.location
|
||||
const query = new URLSearchParams( search )
|
||||
const message = query.get( 'message' )
|
||||
@ -47,6 +51,8 @@ export default function Verifier() {
|
||||
log( 'Received message: ', verification )
|
||||
const json = JSON.parse( verification )
|
||||
|
||||
log( 'Showing status for ', json )
|
||||
|
||||
return setMessage( json )
|
||||
|
||||
} catch( e ) {
|
||||
@ -61,16 +67,17 @@ export default function Verifier() {
|
||||
// Lifecycle
|
||||
// ///////////////////////////////
|
||||
useEffect( f => {
|
||||
log( 'Triggering verification check and popstate listener' )
|
||||
verifyIfNeeded()
|
||||
window.addEventListener( 'popstate', verifyIfNeeded )
|
||||
return window.addEventListener( 'popstate', verifyIfNeeded )
|
||||
}, [] )
|
||||
|
||||
// ///////////////////////////////
|
||||
// Rendering
|
||||
// ///////////////////////////////
|
||||
|
||||
log('Rendering with ', message, verifyUrl )
|
||||
if( message ) return <Container>
|
||||
{ message.balance > 0 && <p>✅ { message.username } has { message.balance } Rocketeers</p> }
|
||||
{ message.balance > 0 && <p>✅ { message.username } has { message.balance } Rocketeers on chain ${ chainId }</p> }
|
||||
{ message.balance < 1 && <p>🛑 Computer says no</p> }
|
||||
</Container>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user