Add testnet ad option

This commit is contained in:
Mentor Palokaj 2021-11-05 12:25:18 +01:00
parent 5d709f4aca
commit c3edb22229
3 changed files with 32 additions and 7 deletions

View File

@ -11,8 +11,8 @@ module.exports = async function( req, res ) {
try { try {
// Get request data // Get request data
const { message, signature, signatory } = req.body const { message, signature, signatory, network } = req.body
if( !message || !signatory || !signature ) throw new Error( `Malformed request` ) if( !message || !signatory || !signature || !network ) throw new Error( `Malformed request` )
// Decode message // Decode message
const confirmedSignatory = web3.eth.accounts.recover( message, signature ) const confirmedSignatory = web3.eth.accounts.recover( message, signature )
@ -24,21 +24,21 @@ module.exports = async function( req, res ) {
if( signer.toLowerCase() !== confirmedSignatory.toLowerCase() || !tokenId || !validator || chainId !== chain ) throw new Error( `Invalid message` ) if( signer.toLowerCase() !== confirmedSignatory.toLowerCase() || !tokenId || !validator || chainId !== chain ) throw new Error( `Invalid message` )
// Check if validator was already assigned // Check if validator was already assigned
const validatorProfile = await db.collection( `${ chain === '0x1' ? 'mainnet' : 'rinkeby' }Validators` ).doc( validator ).get().then( dataFromSnap ) const validatorProfile = await db.collection( `${ network }Validators` ).doc( validator ).get().then( dataFromSnap )
if( validatorProfile && validatorProfile.owner !== signatory ) throw new Error( `Validator already claimed by another wallet. If this is in error, contact mentor.eth on Discord.\n\nThe reason someone else can claim your validator is that we don't want to you to have to expose your validator private key to the world for security reasons <3` ) if( validatorProfile && validatorProfile.owner !== signatory ) throw new Error( `Validator already claimed by another wallet. If this is in error, contact mentor.eth on Discord.\n\nThe reason someone else can claim your validator is that we don't want to you to have to expose your validator private key to the world for security reasons <3` )
// Write new data to db // Write new data to db
await db.collection( `${ chain === '0x1' ? 'mainnet' : 'rinkeby' }Validators` ).doc( validator ).set( { await db.collection( `${ chain === '0x1' ? 'mainnet' : 'rinkeby' }Validators` ).doc( validator ).set( {
tokenId, tokenId,
owner: signatory, owner: signatory,
src: `https://storage.googleapis.com/rocketeer-nft.appspot.com/${ chain === '0x1' ? 'mainnet' : 'rinkeby' }Rocketeers/${ tokenId }.jpg`, src: `https://storage.googleapis.com/rocketeer-nft.appspot.com/${ network }Rocketeers/${ tokenId }.jpg`,
updated: Date.now() updated: Date.now()
} ) } )
// Update the static overview JSON // Update the static overview JSON
const storage = getStorage() const storage = getStorage()
const bucket = storage.bucket() const bucket = storage.bucket()
const cacheFile = bucket.file( `integrations/${ chain === '0x1' ? 'mainnet' : 'rinkeby' }Avatars.json` ) const cacheFile = bucket.file( `integrations/${ network }Avatars.json` )
// Load existing json // Load existing json
let jsonstring = '{}' let jsonstring = '{}'
@ -52,7 +52,7 @@ module.exports = async function( req, res ) {
// Get items that have not been updated // Get items that have not been updated
const tenSecondsAgo = Date.now() - ( 10 * 1000 ) const tenSecondsAgo = Date.now() - ( 10 * 1000 )
const shouldBeUpdated = await db.collection( `${ chain === '0x1' ? 'mainnet' : 'rinkeby' }Validators` ).where( 'updated', '>', cachedJson.updated || tenSecondsAgo ).get().then( dataFromSnap ) const shouldBeUpdated = await db.collection( `${ network }Validators` ).where( 'updated', '>', cachedJson.updated || tenSecondsAgo ).get().then( dataFromSnap )
// Update items that should be updated ( including current update ) // Update items that should be updated ( including current update )
shouldBeUpdated.map( doc => { shouldBeUpdated.map( doc => {

View File

@ -137,7 +137,7 @@ h1, p, label {
height: 200px; height: 200px;
} }
#avatar input { #avatar input:not([type=radio]) {
padding: 1rem; padding: 1rem;
width: 350px; width: 350px;
} }
@ -146,4 +146,14 @@ h1, p, label {
margin: 3rem 0; margin: 3rem 0;
max-width: 300px; max-width: 300px;
text-align: center; text-align: center;
}
.radios {
display: flex;
align-items: center;
justify-content: center;
}
.radios .row {
width: 200px;
} }

View File

@ -15,6 +15,7 @@ export default function Verifier() {
const balance = useBalanceOf() const balance = useBalanceOf()
const chainId = useChainId() const chainId = useChainId()
const address = useAddress() const address = useAddress()
const [ network, setNetwork ] = useState( 'mainnet' )
const [ loading, setLoading ] = useState( ) const [ loading, setLoading ] = useState( )
const metamaskAddress = useAddress() const metamaskAddress = useAddress()
const [ validatorAddress, setValidatorAddress ] = useState( ) const [ validatorAddress, setValidatorAddress ] = useState( )
@ -36,6 +37,7 @@ export default function Verifier() {
signer: address.toLowerCase(), signer: address.toLowerCase(),
tokenId: id, tokenId: id,
validator: validatorAddress.toLowerCase(), validator: validatorAddress.toLowerCase(),
network,
chainId chainId
} ), address ) } ), address )
@ -79,6 +81,19 @@ export default function Verifier() {
<p>Input the address you want to assign the avatar to.</p> <p>Input the address you want to assign the avatar to.</p>
<input type='text' value={ validatorAddress } /> <input type='text' value={ validatorAddress } />
<p>Select the network you want to assign for:</p>
<div className="radios">
<div className="row">
<input onClick={ f => setNetwork( 'mainnet' ) } id="mainnet" type="radio" name="network" checked={ network == 'mainnet' }/>
<label onClick={ f => setNetwork( 'mainnet' ) } for="mainnet">Mainnet</label>
</div>
<div className="row">
<input onClick={ f => setNetwork( 'testnet' ) } id="testnet" type="radio" name="network" checked={ network == 'testnet' }/>
<label onClick={ f => setNetwork( 'testnet' ) } for="testnet">Testnet</label>
</div>
</div>
<p>Click the Rocketeer you want to assign to this address.</p> <p>Click the Rocketeer you want to assign to this address.</p>
<div className="row"> <div className="row">