GraphemeNFT / rarible-scaffold

MIT License
0 stars 0 forks source link

graphemes are updating - cos of PRNG inside grapheme.js ? #48

Closed dcsan closed 2 years ago

dcsan commented 2 years ago

I'm not changing anything but the image data is updating on UI refresh.

I think cos there's still some random number entropy stuff inside the grapheme renderer. not sure if its good for me to dig into that code...

btw I'm just taking a slice off the numbers - first 12 hex digits to use to render with.

            graphemeContract.getInfo(tokenId)
                .then((infoRes) => {
                    // returns an array of dna, isClaimed
                    const [dnaObj, isClaimed] = infoRes
                    // console.log('info', infoRes)
                    const hex = dnaObj.toHexString()
                    setHex(hex)
                    const firstHex = hex.slice(0, 12)
                    const num = parseInt(firstHex, 16)
                    const digits = num.toString().split('')
                    const dna = digits.map(digit => parseInt(digit))

                    // const num = dnaObj.toNumber() / 1e12
                    setItemDna(dna) // last 6 digits e12-e18
                    setClaimed(isClaimed)
                    console.log({ isClaimed, hex, num, dna })
                })

image

image

tomosaigon commented 2 years ago

There's no PRNG, the generator cycles through the token's DNA passed in.

You are probably changing the value and calling the render code with a different value.

dcsan commented 2 years ago

There's no PRNG, the generator cycles through the token's DNA passed in.

is it expecting a set number of characters? I'm passing 12 nums now eg 176661098459

it's triggered by the transfer events coming in

put the token in now lets see:

image

image

dcsan commented 2 years ago

so the top left one, token is consistent at 176661098459 but the images are changing.

image

image

dcsan commented 2 years ago

if it's rotating through what's the goal of that? or you mean it just iterates over the data passed in?

dcsan commented 2 years ago

ok i think perhaps tokenId and metadata are getting shifted somehow

dcsan commented 2 years ago

ok finally figured this out. the code inside grapheme was mutating the passed in react state variables. so each render was indeed rotating the dna, causing the letter to change on each redraw.

fix

        const cloneDna = [...itemSig.dna]
        renderLetter(grid, makeRng(cloneDna));