neu-fi / regen-bingo

Monorepo for both backend and contract developments of Regen Bingo!
https://regen.bingo
2 stars 1 forks source link

Updating tokenURI's of CardList #127

Open oytuncoban opened 1 year ago

oytuncoban commented 1 year ago

When a number is drawn, we should update tokenURI's of only the tokens that have that specific number.

hantuzun commented 1 year ago

I've this for a long time and now it's possible:


Some ideas:

For this to work, we should keep map from card ids to card objects like:

cardIdstoCards = {
515: Card,
293: Card,
48: Card
}

When cards are set, there should be a map created from numbers to cards containing them like below:

numbersToCardIds =  {
1: [],
2: [515],
3: [],
4: [293],
...
89: [293, 515]
90: [48]
}

And an order array for IDs: sortedCardIds = [293,48,515]


Network/account change Mint and Transfer events update cardIdsToCards.

Changes in cardIdsToCards updates numbersToCardIds and sortedCardIds.

NumberDrawn events are watched, update relevant cardIdstoCards.

The frontend renders the list of sortedCardIds with data in cardIdstoCards.

However, it's not a good practice to chain useEffects. This can have a worse performance.