Skip to content

Commit

Permalink
fix: allow boolean metadata properties (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Aug 30, 2024
1 parent ee6f282 commit d52861a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ export class PgStore extends BasePgStore {
}
if (locale.properties && locale.properties.length > 0) {
const values = locale.properties.map(property => ({
...property,
name: property.name,
value:
typeof property.value == 'boolean'
? sql`TO_JSONB(${property.value})`
: property.value,
metadata_id: metadataId,
}));
await sql`INSERT INTO metadata_properties ${sql(values)}`;
Expand Down
18 changes: 8 additions & 10 deletions src/token-processor/util/metadata-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,14 @@ async function parseMetadataForInsertion(
const properties: DbMetadataPropertyInsert[] = defaultInsert?.properties ?? [];
if (RawMetadataPropertiesCType.Check(metadata.properties)) {
for (const [key, value] of Object.entries(metadata.properties)) {
if (key && value) {
const defaultProp = properties.find(p => p.name === key);
if (defaultProp) {
defaultProp.value = value;
} else {
properties.push({
name: key,
value: value,
});
}
const defaultProp = properties.find(p => p.name === key);
if (defaultProp) {
defaultProp.value = value;
} else {
properties.push({
name: key,
value: value,
});
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/api/nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ describe('NFT routes', () => {
name: 'prop2',
value: 1,
},
{
name: 'prop3',
value: true,
},
],
},
],
Expand Down Expand Up @@ -251,6 +255,7 @@ describe('NFT routes', () => {
properties: {
prop1: 'ABC',
prop2: 1,
prop3: true,
},
},
});
Expand Down
5 changes: 4 additions & 1 deletion tests/token-queue/metadata-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Metadata Helpers', () => {
await expect(fetchMetadata(url, 'ABCD.test', 1n)).rejects.toThrow(MetadataHttpError);
});

test('does not throw on raw metadata with null or stringable values', async () => {
test('does not throw on raw metadata with null, stringable, or boolean values', async () => {
const crashPunks1 = {
version: '1',
name: 'Crash Punk 294',
Expand All @@ -74,6 +74,9 @@ describe('Metadata Helpers', () => {
external_url:
'https://thisisnumberone.com/nfts/SP3QSAJQ4EA8WXEDSRRKMZZ29NH91VZ6C5X88FGZQ.crashpunks-v2/294',
animation_url: null,
allow_multiple_claims: true,
whitelisted: false,
minted: 160,
},
localization: {
uri: null,
Expand Down
6 changes: 6 additions & 0 deletions tests/token-queue/process-token-job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ describe('ProcessTokenJob', () => {
collection_size: 5000,
artist: 'Bitcoin Monkeys',
prop: { a: 1, b: 2 },
allow_multiple_claims: true,
whitelisted: false,
},
};
const agent = new MockAgent();
Expand Down Expand Up @@ -441,6 +443,10 @@ describe('ProcessTokenJob', () => {
expect(properties[4].value).toBe(5000);
expect(properties[6].name).toBe('prop');
expect(properties[6].value).toStrictEqual({ a: 1, b: 2 });
expect(properties[7].name).toBe('allow_multiple_claims');
expect(properties[7].value).toStrictEqual(true);
expect(properties[8].name).toBe('whitelisted');
expect(properties[8].value).toStrictEqual(false);
});

test('parses metadata with localizations', async () => {
Expand Down

0 comments on commit d52861a

Please sign in to comment.