Files
js/utils/parseAttributes.ts
T
752b2c2634 Refactor for react/sdk v3 (#457)
* Refactor claim conditions

* Add util function

* Full NFT pages refactor

* Improve onDashboard

* Token refactor fun

* Fix some logic

* Make token drop use custom contract pages

* Remove all the things

* Fix checks

* Fix delayed reveal

* Fix marketplace embed

* Fix lgtm

* Change detection strategy

* Improve some checks

* Reduce use of actualContract

* Fix lgtm

* Fix build

* Some renamings and some more cleanup

* Default sources to release source if found

* Fix lgtm

* Rename multiwrap

* Use useTokenDecimals hook

* Fix token forms not accepting decimals

* Check decimals for inputs

* Fix logic

* Update packages

* update SDK + add Optimism/Arbitrum goerli testnets

* Add goerli l2s to disabled chains of gnosis

* Add comment

* Fix todo

* Rename detection

* Fix code tab on multiwrap and pack

* Add deprecated text

* Add faucet links

* Prettier comments

* Check isDirty for all forms

* add latest nightly

* upgrade nightly and use stable for storage

Co-authored-by: Joaquim Verges <[email protected]>
Co-authored-by: Jonas Daniels <[email protected]>
2022-09-09 18:16:09 -07:00

31 lines
838 B
TypeScript

import type { Json, NFTMetadataInput } from "@thirdweb-dev/sdk";
export function parseAttributes<T extends NFTMetadataInput>(input: T): T {
return {
...input,
attributes: removeEmptyValues(input.attributes),
properties: removeEmptyValues(input.properties),
};
}
export function removeEmptyValues(data: NFTMetadataInput["attributes"]) {
if (!data) {
return data;
}
if (Array.isArray(data)) {
const parsedArray = data
.filter(({ value }) => value !== "")
.map(({ value, trait_type }) => ({
...(!!trait_type && { trait_type }),
value,
}));
return parsedArray.length === 0 ? undefined : parsedArray;
}
return Object.entries(data).reduce((acc, [key, value]) => {
if (value !== "") {
acc[key] = value;
}
return acc;
}, {} as Record<string, Json>);
}