Skip to content

Commit

Permalink
feat: sqt balance
Browse files Browse the repository at this point in the history
  • Loading branch information
HuberTRoy committed Jan 2, 2024
1 parent 84b1c78 commit 1052603
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 37 deletions.
26 changes: 14 additions & 12 deletions src/components/AccountActions/AccountActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Address, Typography } from '@subql/components';
import { Button, Dropdown, Tooltip } from 'antd';
import { useDisconnect, useWalletClient } from 'wagmi';

import { BRIDGE_URL } from 'src/const/bridge';

import { useSQToken } from '../../containers';
import { formatEther, ROUTES, STABLE_TOKEN, STABLE_TOKEN_ADDRESS, TOKEN, tokenDecimals } from '../../utils';
import styles from './AccountActions.module.less';
Expand Down Expand Up @@ -105,16 +107,18 @@ export const AccountActions: React.FC<{ account: string }> = ({ account }) => {
key: 'bridge tokens',
label: (
<div style={{ padding: '0 16px 8px 16px' }}>
<Button
shape="round"
size="large"
type="primary"
ghost
style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10 }}
>
Bridge Tokens
<BsBoxArrowInUpRight />
</Button>
<a href={BRIDGE_URL} target="_blank" rel="noreferrer" style={{ textDecoration: 'none' }}>
<Button
shape="round"
size="large"
type="primary"
ghost
style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10 }}
>
Bridge Tokens
<BsBoxArrowInUpRight />
</Button>
</a>
</div>
),
},
Expand All @@ -137,8 +141,6 @@ export const AccountActions: React.FC<{ account: string }> = ({ account }) => {
{formatEther(consumerHostBalance.data?.balance, 4)} {TOKEN}
</Typography>
</div>

<Typography.Link active>View Details</Typography.Link>
</div>
),
},
Expand Down
13 changes: 9 additions & 4 deletions src/components/IndexerDetails/PlansTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { LazyQueryResult } from '@apollo/client';
import TokenTooltip from '@components/TokenTooltip/TokenTooltip';
import { NETWORK_NAME } from '@containers/Web3';
import { BigNumber } from '@ethersproject/bignumber';
import { ContractTransaction } from '@ethersproject/contracts';
Expand All @@ -28,7 +29,7 @@ import { IndexerName } from './IndexerName';

export type PlansTableProps = {
loadPlans: () => void;
asyncPlans: LazyQueryResult<Plan[], any>;
asyncPlans: LazyQueryResult<Plan[], object>;
} & Omit<DoPurchaseProps, 'plan'>;

type DoPurchaseProps = {
Expand Down Expand Up @@ -88,18 +89,22 @@ const DoPurchase: React.FC<DoPurchaseProps> = ({
},
{
label: t('plans.headers.dailyReqCap'),
value: plan.planTemplate?.dailyReqCap,
value: (plan.planTemplate?.dailyReqCap || 0).toString(),
},
{
label: t('plans.headers.rateLimit'),
value: plan.planTemplate?.rateLimit,
value: (plan.planTemplate?.rateLimit || 0).toString(),
},
{
label: t('plans.headers.deploymentId'),
value: deploymentId,
},
{
label: t('plans.purchase.yourBalance'),
label: (
<div>
{t('plans.purchase.yourBalance')} <TokenTooltip></TokenTooltip>
</div>
),
value: renderAsync(balance, {
loading: () => <Spinner />,
error: () => <Typography>{t('plans.purchase.failToLoadBalance')}</Typography>,
Expand Down
22 changes: 15 additions & 7 deletions src/components/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import * as React from 'react';
import { useMemo } from 'react';
import TokenTooltip from '@components/TokenTooltip/TokenTooltip';
import { Typography } from '@subql/components';
import { TOKEN } from '@utils';
import { Button, InputNumber, InputNumberProps } from 'antd';
Expand Down Expand Up @@ -64,13 +65,20 @@ export const NumberInput: React.FC<NumberInputProps> = ({
);
}, [maxAmount, inputParams, unit]);

const maxText = useMemo(
() =>
BigNumber(maxAmount.toString()).gt(0)
? `Current ${unit === '%' ? 'rate' : 'balance'}: ${maxAmount ?? ''} ${unit ?? ''}`
: undefined,
[maxAmount, unit],
);
const maxText = useMemo(() => {
if (BigNumber(maxAmount.toString()).gt(0)) {
const text = `Current ${unit === '%' ? 'rate' : 'balance'}: ${maxAmount ?? ''} ${unit ?? ''}`;
if (unit !== '%') {
return (
<>
{text} <TokenTooltip></TokenTooltip>
</>
);
}
return text;
}
return '';
}, [maxAmount, unit]);

const inputBottomText = useMemo(() => description ?? maxAmountText ?? maxText, [description, maxAmountText]);
const DescriptionText = ({ text }: { text: string }) => (
Expand Down
3 changes: 0 additions & 3 deletions src/components/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import * as React from 'react';
import { Address, Typography } from '@subql/components';
import { ProjectFieldsFragment } from '@subql/network-query';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';

import { ProjectMetadata } from 'src/models';

import IPFSImage from '../IPFSImage';
import styles from './ProjectCard.module.css';

dayjs.extend(relativeTime);

type Props = {
project: { metadata: ProjectMetadata | undefined } & Omit<ProjectFieldsFragment, 'metadata'>;
onClick?: () => void;
Expand Down
3 changes: 0 additions & 3 deletions src/components/ProjectDeployments/ProjectDeployments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import { parseError } from '@utils';
import { Form, Radio } from 'antd';
import { useForm } from 'antd/es/form/Form';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';

import { NewDeployment } from '../../models';
import { Table, TableBody, TableCell, TableHead, TableRow } from '../Table';
import { Copy } from '..';
import styles from './ProjectDeployments.module.less';

dayjs.extend(utc);

type Deployment = NewDeployment & { createdAt?: Date };

type Props = {
Expand Down
8 changes: 4 additions & 4 deletions src/components/SummaryList/SummaryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { clsx } from 'clsx';
import styles from './SummaryList.module.css';

interface List {
label: string;
value: string | React.ReactNode | any;
label: React.ReactNode;
value: React.ReactNode;
strong?: boolean;
tooltip?: string;
}
Expand All @@ -26,8 +26,8 @@ export const SummaryList: React.FC<SummaryListProps> = ({ title, list }) => {
<div className={styles.container}>
{title && <Typography>{title}</Typography>}
<div className={styles.list}>
{list.map((listItem) => (
<div className={styles.listItem} key={listItem.label}>
{list.map((listItem, index) => (
<div className={styles.listItem} key={index}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<Typography
variant={listItem.strong ? 'text' : 'medium'}
Expand Down
21 changes: 17 additions & 4 deletions src/components/TokenTooltip/TokenTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// SPDX-License-Identifier: Apache-2.0

import React, { FC } from 'react';
import { BsBoxArrowInUpRight } from 'react-icons/bs';
import { ExclamationCircleFilled, InfoCircleOutlined } from '@ant-design/icons';
import { useSQToken } from '@containers';
import { Typography } from '@subql/components';
import { formatEther, TOKEN } from '@utils';
import { Button, Tooltip } from 'antd';

import { BRIDGE_URL } from 'src/const/bridge';

import styles from './index.module.less';

interface IProps {
Expand All @@ -34,11 +37,21 @@ const TokenTooltip: FC<IProps> = (props) => {
to Polygon, you’ll need to bridge them across.
</Typography>

<div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: 4 }}>
<Button type="primary" shape="round">
Bridge Token
<a
href={BRIDGE_URL}
target="_blank"
rel="noreferrer"
style={{ display: 'flex', justifyContent: 'flex-end', marginTop: 4, textDecoration: 'none' }}
>
<Button
type="primary"
shape="round"
style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6 }}
>
Bridge Tokens
<BsBoxArrowInUpRight />
</Button>
</div>
</a>
</div>
}
>
Expand Down
4 changes: 4 additions & 0 deletions src/config/dayjsConf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import localeData from 'dayjs/plugin/localeData';
import relativeTime from 'dayjs/plugin/relativeTime';
import utc from 'dayjs/plugin/utc';
import weekday from 'dayjs/plugin/weekday';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import weekYear from 'dayjs/plugin/weekYear';

dayjs.extend(utc);
dayjs.extend(customParseFormat);
dayjs.extend(advancedFormat);
dayjs.extend(weekday);
dayjs.extend(localeData);
dayjs.extend(weekOfYear);
dayjs.extend(weekYear);
dayjs.extend(relativeTime);
4 changes: 4 additions & 0 deletions src/const/bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0

export const BRIDGE_URL = 'https://portal.polygon.technology/';

0 comments on commit 1052603

Please sign in to comment.