Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
ced55838
Commit
ced55838
authored
Mar 03, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
name, description and attributes
parent
1bd8a059
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
196 additions
and
47 deletions
+196
-47
attributesParser.ts
lib/token/metadata/attributesParser.ts
+46
-0
parseMetadata.ts
lib/token/parseMetadata.ts
+30
-0
token.ts
types/client/token.ts
+10
-0
TokenInstanceContent.tsx
ui/tokenInstance/TokenInstanceContent.tsx
+6
-1
TokenInstanceDetails.tsx
ui/tokenInstance/TokenInstanceDetails.tsx
+104
-46
No files found.
lib/token/metadata/attributesParser.ts
0 → 100644
View file @
ced55838
import
_capitalize
from
'
lodash/capitalize
'
;
import
type
{
Metadata
}
from
'
types/client/token
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
function
formatValue
(
value
:
string
|
number
,
display
:
string
|
undefined
):
string
{
// https://docs.opensea.io/docs/metadata-standards#attributes
switch
(
display
)
{
case
'
boost_number
'
:
{
return
`+
${
value
}
boost`
;
}
case
'
boost_percentage
'
:
{
return
`
${
value
}
% boost`
;
}
case
'
date
'
:
{
return
dayjs
(
value
).
format
(
'
YYYY-MM-DD
'
);
}
default
:
{
return
String
(
value
);
}
}
}
export
default
function
attributesParser
(
attributes
:
Array
<
unknown
>
):
Metadata
[
'
attributes
'
]
{
return
attributes
.
map
((
item
)
=>
{
if
(
typeof
item
!==
'
object
'
||
!
item
)
{
return
;
}
const
value
=
'
value
'
in
item
&&
(
typeof
item
.
value
===
'
string
'
||
typeof
item
.
value
===
'
number
'
)
?
item
.
value
:
undefined
;
const
trait
=
'
trait_type
'
in
item
&&
typeof
item
.
trait_type
===
'
string
'
?
item
.
trait_type
:
undefined
;
const
display
=
'
display_type
'
in
item
&&
typeof
item
.
display_type
===
'
string
'
?
item
.
display_type
:
undefined
;
if
(
!
value
)
{
return
;
}
return
{
value
:
formatValue
(
value
,
display
),
trait_type
:
_capitalize
(
trait
||
'
property
'
),
};
})
.
filter
(
Boolean
);
}
lib/token/parseMetadata.ts
0 → 100644
View file @
ced55838
import
type
{
TokenInstance
}
from
'
types/api/token
'
;
import
type
{
Metadata
}
from
'
types/client/token
'
;
import
attributesParser
from
'
./metadata/attributesParser
'
;
export
default
function
parseMetadata
(
raw
:
TokenInstance
[
'
metadata
'
]
|
undefined
):
Metadata
|
undefined
{
if
(
!
raw
)
{
return
;
}
const
parsed
:
Metadata
=
{};
if
(
'
name
'
in
raw
&&
typeof
raw
.
name
===
'
string
'
)
{
parsed
.
name
=
raw
.
name
;
}
if
(
'
description
'
in
raw
&&
typeof
raw
.
description
===
'
string
'
)
{
parsed
.
description
=
raw
.
description
;
}
if
(
'
attributes
'
in
raw
&&
Array
.
isArray
(
raw
.
attributes
))
{
parsed
.
attributes
=
attributesParser
(
raw
.
attributes
);
}
if
(
Object
.
keys
(
parsed
).
length
===
0
)
{
return
;
}
return
parsed
;
}
types/client/token.ts
0 → 100644
View file @
ced55838
export
interface
Metadata
{
name
?:
string
;
description
?:
string
;
attributes
?:
Array
<
MetadataAttributes
>
;
}
export
interface
MetadataAttributes
{
value
:
string
;
trait_type
:
string
;
}
ui/tokenInstance/TokenInstanceContent.tsx
View file @
ced55838
...
@@ -8,6 +8,7 @@ import useApiQuery from 'lib/api/useApiQuery';
...
@@ -8,6 +8,7 @@ import useApiQuery from 'lib/api/useApiQuery';
import
{
useAppContext
}
from
'
lib/appContext
'
;
import
{
useAppContext
}
from
'
lib/appContext
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useQueryWithPages
from
'
lib/hooks/useQueryWithPages
'
;
import
useQueryWithPages
from
'
lib/hooks/useQueryWithPages
'
;
import
parseMetadata
from
'
lib/token/parseMetadata
'
;
import
TextAd
from
'
ui/shared/ad/TextAd
'
;
import
TextAd
from
'
ui/shared/ad/TextAd
'
;
import
AddressHeadingInfo
from
'
ui/shared/AddressHeadingInfo
'
;
import
AddressHeadingInfo
from
'
ui/shared/AddressHeadingInfo
'
;
import
PageTitle
from
'
ui/shared/Page/PageTitle
'
;
import
PageTitle
from
'
ui/shared/Page/PageTitle
'
;
...
@@ -49,6 +50,10 @@ const TokenInstanceContent = () => {
...
@@ -49,6 +50,10 @@ const TokenInstanceContent = () => {
},
},
});
});
const
metadata
=
React
.
useMemo
(()
=>
{
return
parseMetadata
(
tokenInstanceQuery
.
data
?.
metadata
);
},
[
tokenInstanceQuery
.
data
?.
metadata
]);
const
tabs
:
Array
<
RoutedTab
>
=
[
const
tabs
:
Array
<
RoutedTab
>
=
[
{
id
:
'
token_transfers
'
,
title
:
'
Token transfers
'
,
component
:
<
TokenTransfer
transfersQuery=
{
transfersQuery
}
tokenId=
{
id
}
/>
},
{
id
:
'
token_transfers
'
,
title
:
'
Token transfers
'
,
component
:
<
TokenTransfer
transfersQuery=
{
transfersQuery
}
tokenId=
{
id
}
/>
},
// there is no api for this tab yet
// there is no api for this tab yet
...
@@ -86,7 +91,7 @@ const TokenInstanceContent = () => {
...
@@ -86,7 +91,7 @@ const TokenInstanceContent = () => {
<
AddressHeadingInfo
address=
{
address
}
token=
{
tokenInstanceQuery
.
data
.
token
}
/>
<
AddressHeadingInfo
address=
{
address
}
token=
{
tokenInstanceQuery
.
data
.
token
}
/>
<
TokenInstanceDetails
data=
{
tokenInstanceQuery
.
data
}
scrollRef=
{
scrollRef
}
/>
<
TokenInstanceDetails
data=
{
tokenInstanceQuery
.
data
}
metadata=
{
metadata
}
scrollRef=
{
scrollRef
}
/>
{
/* should stay before tabs to scroll up with pagination */
}
{
/* should stay before tabs to scroll up with pagination */
}
<
Box
ref=
{
scrollRef
}
></
Box
>
<
Box
ref=
{
scrollRef
}
></
Box
>
...
...
ui/tokenInstance/TokenInstanceDetails.tsx
View file @
ced55838
import
{
Box
,
Flex
,
Grid
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Flex
,
Grid
,
GridItem
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
TokenInstance
}
from
'
types/api/token
'
;
import
type
{
TokenInstance
}
from
'
types/api/token
'
;
import
type
{
Metadata
}
from
'
types/client/token
'
;
import
Address
from
'
ui/shared/address/Address
'
;
import
Address
from
'
ui/shared/address/Address
'
;
import
AddressIcon
from
'
ui/shared/address/AddressIcon
'
;
import
AddressIcon
from
'
ui/shared/address/AddressIcon
'
;
...
@@ -19,9 +20,10 @@ import TokenInstanceTransfersCount from './details/TokenInstanceTransfersCount';
...
@@ -19,9 +20,10 @@ import TokenInstanceTransfersCount from './details/TokenInstanceTransfersCount';
interface
Props
{
interface
Props
{
data
:
TokenInstance
;
data
:
TokenInstance
;
scrollRef
?:
React
.
RefObject
<
HTMLDivElement
>
;
scrollRef
?:
React
.
RefObject
<
HTMLDivElement
>
;
metadata
?:
Metadata
;
}
}
const
TokenInstanceDetails
=
({
data
,
scrollRef
}:
Props
)
=>
{
const
TokenInstanceDetails
=
({
data
,
scrollRef
,
metadata
}:
Props
)
=>
{
const
handleCounterItemClick
=
React
.
useCallback
(()
=>
{
const
handleCounterItemClick
=
React
.
useCallback
(()
=>
{
window
.
setTimeout
(()
=>
{
window
.
setTimeout
(()
=>
{
// cannot do scroll instantly, have to wait a little
// cannot do scroll instantly, have to wait a little
...
@@ -29,13 +31,18 @@ const TokenInstanceDetails = ({ data, scrollRef }: Props) => {
...
@@ -29,13 +31,18 @@ const TokenInstanceDetails = ({ data, scrollRef }: Props) => {
},
500
);
},
500
);
},
[
scrollRef
]);
},
[
scrollRef
]);
const
hasMetadata
=
metadata
&&
Boolean
((
metadata
.
name
||
metadata
.
description
||
metadata
.
attributes
));
const
attributeBgColor
=
useColorModeValue
(
'
blackAlpha.50
'
,
'
whiteAlpha.50
'
);
return
(
return
(
<>
<
Flex
alignItems=
"flex-start"
mt=
{
8
}
flexDir=
{
{
base
:
'
column-reverse
'
,
lg
:
'
row
'
}
}
columnGap=
{
6
}
rowGap=
{
6
}
>
<
Flex
alignItems=
"flex-start"
mt=
{
8
}
flexDir=
{
{
base
:
'
column-reverse
'
,
lg
:
'
row
'
}
}
columnGap=
{
6
}
rowGap=
{
6
}
>
<
Grid
<
Grid
flexGrow=
{
1
}
flexGrow=
{
1
}
columnGap=
{
8
}
columnGap=
{
8
}
rowGap=
{
{
base
:
1
,
lg
:
3
}
}
rowGap=
{
{
base
:
1
,
lg
:
3
}
}
templateColumns=
{
{
base
:
'
minmax(0, 1fr)
'
,
lg
:
'
200px minmax(0, 1fr)
'
}
}
overflow=
"hidden"
templateColumns=
{
{
base
:
'
minmax(0, 1fr)
'
,
lg
:
'
200px minmax(0, 1fr)
'
}
}
overflow=
"hidden"
>
>
<
DetailsInfoItem
<
DetailsInfoItem
title=
"Token"
title=
"Token"
...
@@ -76,6 +83,57 @@ const TokenInstanceDetails = ({ data, scrollRef }: Props) => {
...
@@ -76,6 +83,57 @@ const TokenInstanceDetails = ({ data, scrollRef }: Props) => {
alignSelf=
{
{
base
:
'
center
'
,
lg
:
'
flex-start
'
}
}
alignSelf=
{
{
base
:
'
center
'
,
lg
:
'
flex-start
'
}
}
/>
/>
</
Flex
>
</
Flex
>
{
hasMetadata
&&
(
<
Grid
mt=
{
8
}
columnGap=
{
8
}
rowGap=
{
{
base
:
1
,
lg
:
3
}
}
templateColumns=
{
{
base
:
'
minmax(0, 1fr)
'
,
lg
:
'
200px minmax(0, 1fr)
'
}
}
overflow=
"hidden"
>
{
metadata
?.
name
&&
(
<
DetailsInfoItem
title=
"Name"
hint=
"NFT name"
whiteSpace=
"normal"
>
{
metadata
.
name
}
</
DetailsInfoItem
>
)
}
{
metadata
?.
description
&&
(
<
DetailsInfoItem
title=
"Description"
hint=
"NFT description"
whiteSpace=
"normal"
>
{
metadata
.
description
}
</
DetailsInfoItem
>
)
}
{
metadata
?.
attributes
&&
(
<
DetailsInfoItem
title=
"Attributes"
hint=
"NFT attributes"
whiteSpace=
"normal"
>
<
Grid
gap=
{
2
}
templateColumns=
"repeat(auto-fit, minmax(160px, 1fr))"
w=
"100%"
>
{
metadata
.
attributes
.
map
((
attribute
,
index
)
=>
(
<
GridItem
key=
{
index
}
bgColor=
{
attributeBgColor
}
borderRadius=
"md"
px=
{
4
}
py=
{
2
}
>
<
Box
fontSize=
"xs"
color=
"text_secondary"
fontWeight=
{
500
}
>
{
attribute
.
trait_type
}
</
Box
>
<
Box
fontSize=
"sm"
>
{
attribute
.
value
}
</
Box
>
</
GridItem
>
))
}
</
Grid
>
</
DetailsInfoItem
>
)
}
</
Grid
>
)
}
</>
);
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment