Skip to content

Commit

Permalink
Client Side Fetching for Tangle dApp (#1849)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavan Soratur <[email protected]>
  • Loading branch information
AtelyPham and devpavan04 authored Nov 24, 2023
1 parent 704ab0b commit 56d2559
Show file tree
Hide file tree
Showing 89 changed files with 940 additions and 1,042 deletions.
99 changes: 0 additions & 99 deletions .github/workflows/deploy-tangle-website.yml

This file was deleted.

102 changes: 0 additions & 102 deletions .github/workflows/deploy-webbsite-dev.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
useConnectWallet,
useWebContext,
} from '@webb-tools/api-provider-environment';
import { useWebbUI, WalletModal } from '@webb-tools/webb-ui-components';
import getPlatformMetaData from '@webb-tools/browser-utils/platform/getPlatformMetaData';
import { WalletModal, useWebbUI } from '@webb-tools/webb-ui-components';

export const WalletModalContainer = () => {
const {
Expand All @@ -24,6 +25,7 @@ export const WalletModalContainer = () => {
return (
<WalletModal
connectingWalletId={connectingWalletId}
platformId={getPlatformMetaData()?.id ?? null}
failedWalletId={failedWalletId}
isModalOpen={isModalOpen}
resetState={resetState}
Expand Down
6 changes: 5 additions & 1 deletion apps/tangle-dapp/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const metadata: Metadata = {
template: 'Tangle Dapp | %s',
},
description: 'Welcome to Tangle Dapp!',
metadataBase: process.env.URL ? new URL(process.env.URL) : null,
metadataBase: process.env.URL
? new URL(process.env.URL)
: process.env.PORT != null
? new URL(`http://localhost:${process.env.PORT}`)
: null,
openGraph: {
title: 'Tangle Dapp',
description: 'Welcome to Tangle Dapp!',
Expand Down
4 changes: 2 additions & 2 deletions apps/tangle-dapp/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Typography } from '@webb-tools/webb-ui-components';

import {
HeaderChipsContainer,
KeyMetricsTableContainer,
KeyStatsContainer,
NominatorStatsContainer,
ValidatorTablesContainer,
} from '../containers';
Expand All @@ -19,7 +19,7 @@ export default async function Index() {
</div>

<div className="mt-12">
<KeyMetricsTableContainer />
<KeyStatsContainer />
</div>

<div className="mt-12">
Expand Down
28 changes: 28 additions & 0 deletions apps/tangle-dapp/components/HeaderChip/ChipText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client';

import SkeletonLoader from '@webb-tools/webb-ui-components/components/SkeletonLoader';

import getRoundedDownNumberWith2Decimals from '../../utils/getRoundedDownNumberWith2Decimals';
import dataHooks from './dataHooks';
import type { HeaderChipItemProps } from './types';

type Props = Pick<HeaderChipItemProps, 'label'>;

const ChipText = ({ label }: Props) => {
const { isLoading, error, data } = dataHooks[label]();

return (
<>
{label}:{' '}
{isLoading ? (
<SkeletonLoader className="w-[100px]" />
) : error ? (
'Error'
) : data === null ? null : (
getRoundedDownNumberWith2Decimals(data)
)}
</>
);
};

export default ChipText;
14 changes: 0 additions & 14 deletions apps/tangle-dapp/components/HeaderChip/ChipValueClient.tsx

This file was deleted.

22 changes: 4 additions & 18 deletions apps/tangle-dapp/components/HeaderChip/HeaderChip.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
import {
Chip,
SkeletonLoader,
Tooltip,
TooltipBody,
TooltipTrigger,
Typography,
} from '@webb-tools/webb-ui-components';
import { type FC, Suspense, useMemo } from 'react';
import { type FC, useMemo } from 'react';

import ChipValueClient from './ChipValueClient';
import ChipText from './ChipText';
import { HeaderChipItemProps } from './types';

export const HeaderChip: FC<HeaderChipItemProps> = ({
Icon,
label,
hasTooltip = false,
tooltipContent,
dataFetcher,
}: HeaderChipItemProps) => {
const mainContent = useMemo(
() => (
<Chip color="blue">
<Icon size="lg" className="stroke-blue-90 dark:stroke-blue-30" />
{label}:{' '}
<Suspense fallback={<SkeletonLoader className="w-[100px]" />}>
<HeaderChipValue label={label} dataFetcher={dataFetcher} />
</Suspense>
<ChipText label={label} />
</Chip>
),
[Icon, label, dataFetcher]
[Icon, label]
);

if (hasTooltip && tooltipContent) {
Expand All @@ -44,12 +39,3 @@ export const HeaderChip: FC<HeaderChipItemProps> = ({

return mainContent;
};

const HeaderChipValue = async ({
dataFetcher,
label,
}: Pick<HeaderChipItemProps, 'dataFetcher' | 'label'>) => {
const value = await dataFetcher();

return <ChipValueClient type={label} value={value} />;
};
1 change: 0 additions & 1 deletion apps/tangle-dapp/components/HeaderChip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ export interface HeaderChipItemProps {
label: ChipType;
hasTooltip?: boolean;
tooltipContent?: string;
dataFetcher: () => Promise<number | undefined>;
}
45 changes: 0 additions & 45 deletions apps/tangle-dapp/components/KeyMetricItem/KeyMetricItem.tsx

This file was deleted.

Loading

0 comments on commit 56d2559

Please sign in to comment.