Skip to content

Commit

Permalink
Merge pull request #796 from TrustlessComputer/feat/fractal
Browse files Browse the repository at this point in the history
feat: fractal heartbeats
  • Loading branch information
271212 authored Sep 9, 2024
2 parents 5659008 + 798cf90 commit 45e5cf7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 36 deletions.
69 changes: 40 additions & 29 deletions src/modules/l2-rollup-detail/TokenTransferTabBitcoin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { L2RollupDetailContext } from '../providers/l2-rollup-detail-context';
import s from './styles.module.scss';
import { useRouter } from 'next/navigation';
import { HEART_BEAT } from '@/constants/route-path';
import TransactionsTabFBitcoin from '../TransactionsTabFBitcoin';

interface IProps {}

Expand All @@ -25,7 +26,7 @@ const TokenTransferTabBitcoin = (props: IProps) => {
const router = useRouter();

const rollupApi = new CRollupL2DetailBitcoinAPI();
const [balanceType, setBalanceType] = useState<BalanceBitcoinType>('runes');
const [balanceType, setBalanceType] = useState<BalanceBitcoinType>('fractal');

const [list, setList] = useState<IBitcoinTokenTransaction[]>([]);

Expand Down Expand Up @@ -319,7 +320,13 @@ const TokenTransferTabBitcoin = (props: IProps) => {
borderRadius={'8px'}
mb={'20px'}
>
{BalanceTypes.map((balance) => (
{[
{
type: 'fractal',
title: 'Fractal',
},
...BalanceTypes,
].map((balance) => (
<Box
bg={balanceType === balance.type ? '#ffff' : 'transparent'}
fontWeight={balanceType === balance.type ? '400' : '500'}
Expand All @@ -332,33 +339,37 @@ const TokenTransferTabBitcoin = (props: IProps) => {
</Box>
))}
</Flex>
<Box className={`${s.container} ${s.shadow}`} h="60vh">
<ScrollWrapper
onFetch={() => {
refParams.current = {
...refParams.current,
page: refParams.current.page + 1,
};
hasIncrementedPageRef.current = true;
fetchData();
}}
isFetching={refreshing}
hasIncrementedPageRef={hasIncrementedPageRef}
onFetchNewData={onRefresh}
wrapClassName={s.wrapScroll}
dependData={list}
>
<ListTable
data={list}
columns={columns}
className={s.tableContainer}
showEmpty={!isFetching}
emptyLabel="No transactions found."
emptyIcon={<Image src={'/icons/icon-empty.svg'} />}
/>
{isFetching && <AppLoading className={s.loading} />}
</ScrollWrapper>
</Box>
{balanceType === 'fractal' ? (
<TransactionsTabFBitcoin />
) : (
<Box className={`${s.container} ${s.shadow}`} h="60vh">
<ScrollWrapper
onFetch={() => {
refParams.current = {
...refParams.current,
page: refParams.current.page + 1,
};
hasIncrementedPageRef.current = true;
fetchData();
}}
isFetching={refreshing}
hasIncrementedPageRef={hasIncrementedPageRef}
onFetchNewData={onRefresh}
wrapClassName={s.wrapScroll}
dependData={list}
>
<ListTable
data={list}
columns={columns}
className={s.tableContainer}
showEmpty={!isFetching}
emptyLabel="No transactions found."
emptyIcon={<Image src={'/icons/icon-empty.svg'} />}
/>
{isFetching && <AppLoading className={s.loading} />}
</ScrollWrapper>
</Box>
)}
</Flex>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CRollupL2DetailBitcoinAPI from '@/services/api/dapp/rollupl2-detail-bitco
import { IFBitcoinTransaction } from '@/services/api/dapp/rollupl2-detail-bitcoin/interface';
import { shortCryptoAddress } from '@/utils/address';
import { formatCurrency } from '@/utils/format';
import { formatTimeAgo } from '@/utils/time';
import { Box, Flex, Image, SimpleGrid, Text } from '@chakra-ui/react';
import BigNumber from 'bignumber.js';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -159,7 +160,7 @@ const TransactionsTabFBitcoin = (props: IProps) => {
.format('HH:mm:ss MM/DD/YYYY')}
<Text as={'span'}>
{' '}
({dayjs.unix(item.status.block_time).toNow()})
({formatTimeAgo(item.status.block_time)})
</Text>
</Text>
</Flex>
Expand Down
3 changes: 2 additions & 1 deletion src/modules/l2-rollup-detail/TxBTCExplorer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import s from './styles.module.scss';
import TokenTransfers from './tokenTransfer';
import { shortCryptoAddress } from '@/utils/address';
import { isMobile } from 'react-device-detect';
import { formatTimeAgo } from '@/utils/time';

const TxBTCExplorer = () => {
const { address, isBTCTxAddress } = useContext(L2RollupExplorerContext);
Expand Down Expand Up @@ -193,7 +194,7 @@ const TxBTCExplorer = () => {
) : (
<>
{dayjs.unix(timestamp).format('YYYY-MM-DD HH:mm:ss')}
<Text as={'span'}> ({dayjs.unix(timestamp).toNow()})</Text>
<Text as={'span'}> ({formatTimeAgo(timestamp)})</Text>
</>
)}
</Text>
Expand Down
5 changes: 0 additions & 5 deletions src/modules/l2-rollup-detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import TokenTransferTab from './TokenTransferTab';
import TokenTransferTabBitcoin from './TokenTransferTabBitcoin';
import TransactionsTab from './TransactionsTab';
import TransactionsTabBitcoin from './TransactionsTabBitcoin';
import TransactionsTabFBitcoin from './TransactionsTabFBitcoin';
import WatchListAddresses from './Watchlist';
import { formatAiSummary } from './utils';
import MarkdownComponent from './MarkdownComponent';
Expand Down Expand Up @@ -209,7 +208,6 @@ const L2RollupDetail = () => {
>
<Tab>Portfolio</Tab>
<Tab>Transactions</Tab>
<Tab>Fractal Transactions</Tab>
<Tab>Token Transfer</Tab>
</TabList>
<TabPanels className={s.tabPanel}>
Expand All @@ -219,9 +217,6 @@ const L2RollupDetail = () => {
<TabPanel minH={'40vh'}>
<TransactionsTabBitcoin />
</TabPanel>
<TabPanel minH={'40vh'}>
<TransactionsTabFBitcoin />
</TabPanel>
<TabPanel minH={'40vh'}>
<TokenTransferTabBitcoin />
</TabPanel>
Expand Down
1 change: 1 addition & 0 deletions src/services/api/dapp/rollupl2-detail-bitcoin/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type BalanceBitcoinType =
| 'fractal'
| 'runes'
| 'brc20'
| 'src20'
Expand Down
6 changes: 6 additions & 0 deletions src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import moment from 'moment';
import isNumber from 'lodash/isNumber';
import dayjs from 'dayjs';

const FORMAT_PATTERN = 'DD MMM hh:mm A';

Expand Down Expand Up @@ -48,11 +49,16 @@ function getCurrentUnixTimestamp() {
return Math.floor(Date.now() / 1000);
}

function formatTimeAgo(time: number) {
return dayjs.unix(time).toNow().replaceAll('in ', '') + ' ago';
}

export {
formatUnixDateTime,
formatDateTime,
isExpiredUnixTime,
isExpiredTime,
getCurrentUnixTimestamp,
formatTimeStamp,
formatTimeAgo,
};

0 comments on commit 45e5cf7

Please sign in to comment.