Skip to content

Commit

Permalink
[explorer] Support dynamic field names (MystenLabs#5627)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Mysten authored Oct 27, 2022
1 parent 0eebffb commit cf16bc1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions apps/explorer/src/utils/objectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ export const checkIsPropertyType = (value: any) =>
['number', 'string'].includes(typeof value);

export const extractName = (
contents: object | undefined
contents: Record<string, any> | undefined
): string | undefined => {
if (!contents) return undefined;
return Object.entries(contents)
.filter(([key, _]) => key === 'name')
.map(([_, value]) => value)?.[0];
if (!contents || !('name' in contents)) return undefined;
const name = contents.name;

if (typeof name === 'string') {
return name;
}

// Dynamic fields
if (typeof name === 'object' && typeof name?.fields?.name === 'string') {
return name?.fields?.name;
}
};

0 comments on commit cf16bc1

Please sign in to comment.