Skip to content

Commit

Permalink
feat: move NFT properties to tab (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruitran authored Nov 30, 2022
1 parent 0b8996c commit df41a6a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 25 deletions.
19 changes: 0 additions & 19 deletions pages/token/[token]/instance/[index].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ const TokenInstanceDetailPage: React.FC<Props> = props => {
const { token, tokenData, tokenId, errorMessage } = props
const title = tokenData ? `${tokenData.name} (${tokenId}) - ${process.env.NEXT_PUBLIC_TITLE}` : `Token ${token}`

const _convertRawDataToCardData = useCallback((data: TokenNFTAttributes[]): CardRowItem[] => {
if (!data) return []
let items: CardRowItem[] = []
for (let item of data) {
if (item !== undefined && item !== null)
items.push({
label: item.trait_type,
type: 'text',
contents: [{ value: item.value }]
})
}

return items
}, [])
return (
<Layout>
<Head>
Expand All @@ -57,11 +43,6 @@ const TokenInstanceDetailPage: React.FC<Props> = props => {
{tokenData ? (
<>
<NftOverview token={token} tokenId={tokenId} tokenData={tokenData} />
<CardInfo
topElement={<span className="text text-xl padding-2xl">Properties</span>}
items={_convertRawDataToCardData(tokenData.attributes)}
classes={['margin-top-sm padding-top-md']}
/>
<NftDetailTab token={token} tokenId={tokenId} tokenData={tokenData} />
</>
) : (
Expand Down
2 changes: 1 addition & 1 deletion views/accounts/AddressDetailTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const AddressDetailTab = ({ address, addressData }: Props) => {
classes="none"
tabs={[
{ title: 'Transactions', id: 'transactions' },
{ title: 'Token Transfer', id: 'token-transfer' },
{ title: 'Token Transfers', id: 'token-transfer' },
{ title: 'Tokens', id: 'tokens' },
{ title: 'Internal Transactions', id: 'internal-transactions' },
{ title: 'Coin Balance History', id: 'balance-history' },
Expand Down
9 changes: 7 additions & 2 deletions views/tokens/[instance]/NftDetailTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import BackgroundCard from 'components/Card/Background/BackgroundCard'
import Tabs from 'components/Tabs/Tabs'
import useRouterTag from 'hooks/useRouterTag'
import NftTransferTab from './tabs/NftTransfers'
import NftProperties from './tabs/NftProperties'

interface Props {
token: string
Expand All @@ -18,9 +19,13 @@ const NftDetailTab = ({ token, tokenId, tokenData }: Props) => {
tabChange={setTag}
defaultTab={defaultTag}
classes="none"
tabs={[{ title: 'Token Transfers', id: 'token-transfers' }]}
tabs={[
{ title: 'Token Transfers', id: 'token-transfers' },
{ title: 'Properties', id: 'properties' }
]}
contents={{
'token-transfers': <NftTransferTab token={token} tokenId={tokenId} tokenData={tokenData} />
'token-transfers': <NftTransferTab token={token} tokenId={tokenId} tokenData={tokenData} />,
'properties': <NftProperties tokenData={tokenData} />
}}
></Tabs>
</BackgroundCard>
Expand Down
39 changes: 39 additions & 0 deletions views/tokens/[instance]/tabs/NftProperties/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { PaginationLite } from '@astraprotocol/astra-ui'
import Row from 'components/Grid/Row'
import CardInfo, { CardRowItem } from 'components/Card/CardInfo'
import Empty from 'components/Typography/Empty'
import usePaginationLite from 'hooks/usePaginationLite'
import { useState, useCallback } from 'react'

interface Props {
tokenData: TokenNFTMetadata
}

const NftPropertiesTab = ({ tokenData }: Props) => {
const _convertRawDataToCardData = useCallback((data: TokenNFTAttributes[]): CardRowItem[] => {
if (!data) return []
let items: CardRowItem[] = []
for (let item of data) {
if (item !== undefined && item !== null)
items.push({
label: item.trait_type,
type: 'text',
contents: [{ value: item.value }]
})
}

return items
}, [])

return (
<CardInfo
topElement={<span className="text text-xl padding-2xl">Properties</span>}
items={_convertRawDataToCardData(tokenData.attributes)}
classes={['margin-top-sm padding-top-md']}
background={false}
backgroundCardBlur={false}
/>
)
}

export default NftPropertiesTab
4 changes: 2 additions & 2 deletions views/transactions/TransactionTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export default function TransactionTabs({
}

if (type === 'cosmos') {
tabs.unshift({ title: 'Token Transfer', id: 'transfers' })
tabs.unshift({ title: 'Token Transfers', id: 'transfers' })
contents['transfers'] = (
<Transactions rows={transactions} emptyMsg="There are no transfer for this transaction." />
)
} else {
tabs.unshift({ title: 'Internal Transactions', id: 'internal-transactions' })
tabs.unshift({ title: 'Token Transfer', id: 'transfers' })
tabs.unshift({ title: 'Token Transfers', id: 'transfers' })

contents['transfers'] = (
<Transactions rows={transactions} emptyMsg="There are no transfer for this transaction." />
Expand Down
2 changes: 1 addition & 1 deletion views/transactions/hook/useConvertData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export default function useConvertData({ data }: { data: TransactionDetail }) {
CardInfoLabels.gasPrice,
CardInfoLabels.typeOfTransfer
])
//remove label of token transfer
//remove label of Token Transfers
let hashTransfer = false
mainItems.map(item => {
if (item.label === CardInfoLabels.tokenTransfers) {
Expand Down

0 comments on commit df41a6a

Please sign in to comment.