Skip to content

Commit

Permalink
feat: [GNS-9] Change the route of sourcing static token data from gno…
Browse files Browse the repository at this point in the history
…-token-resource
  • Loading branch information
jinoosss authored and Woongjae Lee committed May 23, 2023
1 parent 926c8b5 commit 207a7a7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/assets/svgs/icon-unknown-token.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions src/components/view/datatable/item/token-title.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Text from '@/components/ui/text';
import IconTokenDefault from '@/assets/svgs/icon-token-default.svg';
import UnknownToken from '@/assets/svgs/icon-unknown-token.svg';
import React from 'react';
import styled from 'styled-components';

Expand All @@ -11,11 +11,18 @@ interface Props {
pkgPath: string;
}

export const TokenTitle = ({name, symbol, pkgPath}: Props) => {
export const TokenTitle = ({name, symbol, pkgPath, imagePath}: Props) => {
return (
<a href={`/tokens/${pkgPath}`} target={'_blank'} rel={'noopener noreferrer'}>
<TokenTitleWrapper>
<IconTokenDefault />
{imagePath && imagePath !== '' ? (
<img className="token" src={imagePath} alt="token logo" />
) : (
<div className="unknown-token">
<UnknownToken width="20" height="20" />
</div>
)}

<Text type="p4">{`${name} (${symbol})`}</Text>
</TokenTitleWrapper>
</a>
Expand All @@ -32,9 +39,14 @@ const TokenTitleWrapper = styled.div`
color: ${({theme}) => theme.colors.blue};
cursor: pointer;
svg {
.token,
.unknown-token {
width: 20px;
height: 20px;
margin-right: 10px;
}
svg {
circle {
fill: ${({theme}) => theme.colors.primary};
}
Expand Down
31 changes: 25 additions & 6 deletions src/components/view/datatable/token/token.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use client';

import React from 'react';
import React, {useCallback} from 'react';
import Datatable, {DatatableOption} from '@/components/ui/datatable';
import usePageQuery from '@/common/hooks/use-page-query';
import {DatatableItem} from '..';
import {numberWithCommas} from '@/common/utils';
import useLoading from '@/common/hooks/use-loading';
import {API_URI, API_VERSION} from '@/common/values/constant-value';
import {useRecoilValue} from 'recoil';
import {themeState} from '@/states';
import {themeState, tokenState} from '@/states';
import theme from '@/styles/theme';
import styled from 'styled-components';
import {eachMedia} from '@/common/hooks/use-media';
import {Button} from '@/components/ui/button';
import {isGRC20TokenModel, TokenModel} from '@/repositories/api/models/meta-token-model';

interface ResponseData {
hits: number;
Expand All @@ -39,6 +40,7 @@ interface TokenData {
export const TokenDatatable = () => {
const media = eachMedia();
const themeMode = useRecoilValue(themeState);
const tokenInfos = useRecoilValue(tokenState);

const {data, fetchNextPage, finished, hasNextPage} = usePageQuery<ResponseData>({
key: ['token/token-list'],
Expand All @@ -51,12 +53,29 @@ export const TokenDatatable = () => {
if (!data) {
return [];
}
return data.pages.reduce<Array<TokenData>>(
(accum, current) => (current ? [...accum, ...current.tokens] : accum),
[],
);
return data.pages.reduce<Array<TokenData>>((accum, current) => {
const latest =
current?.tokens.map(token => ({
...token,
img_path: getTokenMetaInfo(token),
})) ?? [];
return [...accum, ...latest];
}, []);
};

const getTokenMetaInfo = useCallback(
(token: TokenData) => {
const tokenInfo = tokenInfos.find(tokenInfo => {
if (!isGRC20TokenModel(tokenInfo)) {
return false;
}
return `${tokenInfo.symbol}`.toUpperCase() === `${token.symbol}`.toUpperCase();
});
return tokenInfo?.image ?? '';
},
[tokenInfos],
);

const createHeaders = () => {
return [
createHeaderToken(),
Expand Down
2 changes: 0 additions & 2 deletions src/pages/accounts/[address].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const AccountDetails = () => {
},
);

if (detail) console.log('Detial : ', detail);

return (
<DetailsPageLayout
title="Account Details"
Expand Down

0 comments on commit 207a7a7

Please sign in to comment.