Enable beta pluripotent changing room

This commit is contained in:
Mentor Palokaj 2021-12-09 15:55:21 +01:00
parent d10743413b
commit ebb63e6960
4 changed files with 74 additions and 23 deletions

View File

@ -25,9 +25,8 @@ exports.generateNewOutfit = async function( req, res ) {
try {
// Disable changing room for now
const potentialLaunchDate = new Date( `2021-12-10` )
if( new Date() < potentialLaunchDate ) throw new Error( `Changing room is not yet live, sorry. Stay tuned on Discord.` )
// Internal beta
if( id != 1 ) return res.json( { error: `Sorry the changing room is in private beta for now <3` } )
// Get request data
const { message, signature, signatory } = req.body
@ -79,29 +78,37 @@ exports.generateMultipleNewOutfits = async function( req, res ) {
// Protect against malformed input
if( !address.match( /0x.{40}/ ) ) return res.json( { error: `Malformed request` } )
// ⚠️ WIP
const network = 'rinkeby'
if( !process.env.NODE_ENV == 'development' ) return res.json( { error: `This endpoint is not live yet. While I appreciate your enthusiasm please don't touch this one yet :)` } )
// Lowercase the address
address = address.toLowerCase()
// Internal beta
if( !address.includes( '0xe3ae14' ) && !address.includes( '0x7dbf68' ) ) return res.json( { error: `Sorry this endpoint is in private beta for now <3` } )
try {
// // Get request data
// const { message, signature, signatory } = req.body
// if( !message || !signatory || !signature ) throw new Error( `Malformed request` )
// Get request data
const { message, signature, signatory } = req.body
if( !message || !signatory || !signature ) throw new Error( `Malformed request` )
// // Decode message
// const confirmedSignatory = web3.eth.accounts.recover( message, signature )
// if( signatory.toLowerCase() !== confirmedSignatory.toLowerCase() ) throw new Error( `Bad signature` )
// Decode message
const confirmedSignatory = web3.eth.accounts.recover( message, signature )
if( signatory.toLowerCase() !== confirmedSignatory.toLowerCase() ) throw new Error( `Bad signature` )
// // Validate message
// const messageObject = JSON.parse( message )
// let { signer, action, chainId } = messageObject
// const network = chainId == '0x1' ? 'mainnet' : 'rinkeby'
// if( signer.toLowerCase() !== confirmedSignatory.toLowerCase() || action != 'generateMultipleNewOutfits' || !network ) throw new Error( `Invalid setPrimaryOutfit message with ${ signer }, ${confirmedSignatory}, ${action}, ${chainId}, ${network}` )
// Validate message
const messageObject = JSON.parse( message )
let { signer, action, chainId } = messageObject
const network = chainId == '0x1' ? 'mainnet' : 'rinkeby'
if( signer.toLowerCase() !== confirmedSignatory.toLowerCase() || action != 'generateMultipleNewOutfits' || !network ) throw new Error( `Invalid setPrimaryOutfit message with ${ signer }, ${confirmedSignatory}, ${action}, ${chainId}, ${network}` )
// Check that the signer is the owner of the token
const outfits = await generateNewOutfitsByAddress( address, network )
await db.collection( 'meta' ).doc( address ).set( {
last_changing_room: Date.now(),
last_changing_room_errors: outfits.error.map( ( { id } ) => id ),
last_changing_room_successes: outfits.success.map( ( { id } ) => id )
}, { merge: true } )
return res.json( outfits )

View File

@ -114,10 +114,7 @@ async function generateNewOutfitsByAddress( address, network='mainnet' ) {
const ids = await getTokenIdsOfAddress( address, network )
const queue = ids.map( id => function() {
return generateNewOutfitFromId( id, network ).then( outfit => ( { id: id, src: outfit } ) ).catch( e => {
console.log( e )
return ( { id: id, error: e.message } )
} )
return generateNewOutfitFromId( id, network ).then( outfit => ( { id: id, src: outfit } ) ).catch( e => ( { id: id, error: e.message } ) )
} )
const outfits = await Throttle.all( queue, {
maxInProgress: 2,

View File

@ -25,7 +25,7 @@ const Wrapper = styled.div`
justify-content: ${ ( { justify='center' } ) => justify };
min-height: 100vh;
width: 100%;
padding: ${ ( { gutter=true } ) => gutter ? '0 max( 1rem, calc( 25vw - 4rem ) )' : 'none' };
padding: ${ ( { gutter=true } ) => gutter ? '3rem max( 1rem, calc( 25vw - 4rem ) )' : 'none' };
// margin-bottom: 10rem;
box-sizing: border-box;
& * {

View File

@ -6,7 +6,7 @@ import { useParams, useNavigate } from 'react-router'
import Container from '../atoms/Container'
import Section from '../atoms/Section'
import { H1, H2, Text } from '../atoms/Text'
import { H1, H2, Text, Sidenote } from '../atoms/Text'
import Button from '../atoms/Button'
import Avatar from '../molecules/Avatar'
@ -119,6 +119,52 @@ export default function Verifier() {
}
async function generateByAddress( ) {
try {
log( `Generating new outfit for address ${ address }` )
setLoading( `Generating new outfits for ${ address }` )
alert( 'You will be prompted to sign a message, this is NOT a transaction' )
const signature = await sign( JSON.stringify( {
signer: address.toLowerCase(),
action: 'generateMultipleNewOutfits',
chainId,
} ), address )
log( 'Making request with ', signature )
setLoading( 'Generating new outfits, this can take a few minutes' )
const { error, success } = await callApi( `/rocketeers/${ address }`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify( signature )
} )
log( `Errored: `, error )
log( `Succeeded: `, success )
if( typeof error == 'string' ) throw new Error( error )
alert( `Success! ${ success.length } outfits generated, ${ error.length } failed.` )
window?.location.reload()
} catch( e ) {
log( e )
alert( e.message )
} finally {
setLoading( false )
}
}
// ///////////////////////////////
// Lifecycle
// ///////////////////////////////
@ -178,6 +224,7 @@ export default function Verifier() {
</Section>
<Text className="row">Rocketeers owned by: { address }.</Text>
<Sidenote onClick={ generateByAddress } className="row">_</Sidenote>
</Container>