Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix for rendering nouns with traits missing from nouns/assets #881

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/nouns-webapp/src/components/StandaloneNoun/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ImageData as data, getNounData } from '@nouns/assets';
import { buildSVG } from '@nouns/sdk';
import { BigNumber as EthersBN } from 'ethers';
import { INounSeed, useNounSeed } from '../../wrappers/nounToken';
import { INounSeed, useGenerateSVGImage, useNounSeed } from '../../wrappers/nounToken';
import Noun from '../Noun';
import { Link } from 'react-router-dom';
import classes from './StandaloneNoun.module.css';
Expand Down Expand Up @@ -29,6 +29,21 @@ export const getNoun = (nounId: string | EthersBN, seed: INounSeed) => {
const name = `Noun ${id}`;
const description = `Noun ${id} is a member of the Nouns DAO`;
const { parts, background } = getNounData(seed);

// eslint-disable-next-line react-hooks/rules-of-hooks
const svg = useGenerateSVGImage(seed);

// if some parts are undefined, call nounsDescriptor.generateSVGImage and return the image
if (parts.some(part => part === undefined)) {

return {
name,
description,
image: `data:image/svg+xml;base64,${svg}`
};

}

const image = `data:image/svg+xml;base64,${btoa(buildSVG(parts, data.palette, background))}`;

return {
Expand Down
13 changes: 12 additions & 1 deletion packages/nouns-webapp/src/wrappers/nounToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContractCall, useContractFunction, useEthers } from '@usedapp/core';
import { BigNumber as EthersBN, ethers, utils } from 'ethers';
import { NounsTokenABI, NounsTokenFactory } from '@nouns/contracts';
import { NounsDescriptorABI, NounsTokenABI, NounsTokenFactory } from '@nouns/contracts';
import config, { cache, cacheKey, CHAIN_ID } from '../config';
import { useQuery } from '@apollo/client';
import {
Expand Down Expand Up @@ -42,6 +42,7 @@ export enum NounsTokenContractFunction {
}

const abi = new utils.Interface(NounsTokenABI);
const descriptorAbi = new utils.Interface(NounsDescriptorABI);
const seedCacheKey = cacheKey(cache.seed, CHAIN_ID, config.addresses.nounsToken);
const nounsTokenContract = NounsTokenFactory.connect(config.addresses.nounsToken, undefined!);
const isSeedValid = (seed: Record<string, any> | undefined) => {
Expand Down Expand Up @@ -130,6 +131,16 @@ export const useNounSeed = (nounId: EthersBN): INounSeed => {
return seed;
};

export const useGenerateSVGImage = (seed: INounSeed) => {
const image = useContractCall({
abi: descriptorAbi,
address: config.addresses.nounsDescriptor,
method: 'generateSVGImage',
args: [seed],
});
return image;
};

export const useUserVotes = (): number | undefined => {
const { account } = useEthers();
return useAccountVotes(account ?? ethers.constants.AddressZero);
Expand Down