mirror of
https://github.com/stronk-dev/RandomChad.git
synced 2025-07-06 10:55:10 +02:00
✨ Enable beta pluripotent changing room
This commit is contained in:
parent
d10743413b
commit
ebb63e6960
@ -25,9 +25,8 @@ exports.generateNewOutfit = async function( req, res ) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Disable changing room for now
|
// Internal beta
|
||||||
const potentialLaunchDate = new Date( `2021-12-10` )
|
if( id != 1 ) return res.json( { error: `Sorry the changing room is in private beta for now <3` } )
|
||||||
if( new Date() < potentialLaunchDate ) throw new Error( `Changing room is not yet live, sorry. Stay tuned on Discord.` )
|
|
||||||
|
|
||||||
// Get request data
|
// Get request data
|
||||||
const { message, signature, signatory } = req.body
|
const { message, signature, signatory } = req.body
|
||||||
@ -79,29 +78,37 @@ exports.generateMultipleNewOutfits = async function( req, res ) {
|
|||||||
// Protect against malformed input
|
// Protect against malformed input
|
||||||
if( !address.match( /0x.{40}/ ) ) return res.json( { error: `Malformed request` } )
|
if( !address.match( /0x.{40}/ ) ) return res.json( { error: `Malformed request` } )
|
||||||
|
|
||||||
// ⚠️ WIP
|
// Lowercase the address
|
||||||
const network = 'rinkeby'
|
address = address.toLowerCase()
|
||||||
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 :)` } )
|
|
||||||
|
// Internal beta
|
||||||
|
if( !address.includes( '0xe3ae14' ) && !address.includes( '0x7dbf68' ) ) return res.json( { error: `Sorry this endpoint is in private beta for now <3` } )
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// // Get request data
|
// Get request data
|
||||||
// const { message, signature, signatory } = req.body
|
const { message, signature, signatory } = req.body
|
||||||
// if( !message || !signatory || !signature ) throw new Error( `Malformed request` )
|
if( !message || !signatory || !signature ) 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 )
|
||||||
// if( signatory.toLowerCase() !== confirmedSignatory.toLowerCase() ) throw new Error( `Bad signature` )
|
if( signatory.toLowerCase() !== confirmedSignatory.toLowerCase() ) throw new Error( `Bad signature` )
|
||||||
|
|
||||||
// // Validate message
|
// Validate message
|
||||||
// const messageObject = JSON.parse( message )
|
const messageObject = JSON.parse( message )
|
||||||
// let { signer, action, chainId } = messageObject
|
let { signer, action, chainId } = messageObject
|
||||||
// const network = chainId == '0x1' ? 'mainnet' : 'rinkeby'
|
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}` )
|
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
|
// Check that the signer is the owner of the token
|
||||||
const outfits = await generateNewOutfitsByAddress( address, network )
|
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 )
|
return res.json( outfits )
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,10 +114,7 @@ async function generateNewOutfitsByAddress( address, network='mainnet' ) {
|
|||||||
|
|
||||||
const ids = await getTokenIdsOfAddress( address, network )
|
const ids = await getTokenIdsOfAddress( address, network )
|
||||||
const queue = ids.map( id => function() {
|
const queue = ids.map( id => function() {
|
||||||
return generateNewOutfitFromId( id, network ).then( outfit => ( { id: id, src: outfit } ) ).catch( e => {
|
return generateNewOutfitFromId( id, network ).then( outfit => ( { id: id, src: outfit } ) ).catch( e => ( { id: id, error: e.message } ) )
|
||||||
console.log( e )
|
|
||||||
return ( { id: id, error: e.message } )
|
|
||||||
} )
|
|
||||||
} )
|
} )
|
||||||
const outfits = await Throttle.all( queue, {
|
const outfits = await Throttle.all( queue, {
|
||||||
maxInProgress: 2,
|
maxInProgress: 2,
|
||||||
|
@ -25,7 +25,7 @@ const Wrapper = styled.div`
|
|||||||
justify-content: ${ ( { justify='center' } ) => justify };
|
justify-content: ${ ( { justify='center' } ) => justify };
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
width: 100%;
|
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;
|
// margin-bottom: 10rem;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
& * {
|
& * {
|
||||||
|
@ -6,7 +6,7 @@ import { useParams, useNavigate } from 'react-router'
|
|||||||
|
|
||||||
import Container from '../atoms/Container'
|
import Container from '../atoms/Container'
|
||||||
import Section from '../atoms/Section'
|
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 Button from '../atoms/Button'
|
||||||
import Avatar from '../molecules/Avatar'
|
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
|
// Lifecycle
|
||||||
// ///////////////////////////////
|
// ///////////////////////////////
|
||||||
@ -178,6 +224,7 @@ export default function Verifier() {
|
|||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<Text className="row">Rocketeers owned by: { address }.</Text>
|
<Text className="row">Rocketeers owned by: { address }.</Text>
|
||||||
|
<Sidenote onClick={ generateByAddress } className="row">_</Sidenote>
|
||||||
|
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user