Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add some Asset hubs reserved amount #1394

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c9bd62d
Show reserved amount for assetHubs
AMIRKHANEF Jun 22, 2024
5a4ff9c
Fetch asset reserved amount reason on AssetHubs
AMIRKHANEF Jun 22, 2024
cab37c0
Add new NFT reason
AMIRKHANEF Jun 26, 2024
d206c68
Merge branch 'main' into AssetHubsReservedAmount
AMIRKHANEF Jun 26, 2024
230133e
Add Asset hubs reserved amount to extension mode
AMIRKHANEF Jul 1, 2024
0c23779
Merge branch 'main' into pr/1394
Nick-1979 Jul 1, 2024
997e2dc
fix asset id changing issue
Nick-1979 Jul 1, 2024
5ce3a47
Update ReservedDisplayBalance.tsx
Nick-1979 Jul 1, 2024
baba7b2
Fix displaying reserved amount for non native tokens
AMIRKHANEF Jul 1, 2024
18e75ab
Merge branch 'main' into pr/1394
Nick-1979 Jul 2, 2024
7e37bed
refactor
Nick-1979 Jul 2, 2024
563ace5
Update index.tsx
Nick-1979 Jul 2, 2024
25c00eb
distinguish not native tokens
AMIRKHANEF Jul 3, 2024
6368c65
Merge branch 'PolkaGate:main' into AssetHubsReservedAmount
AMIRKHANEF Jul 23, 2024
579ba40
Update ReservedDisplayBalance.tsx
AMIRKHANEF Jul 23, 2024
b7cc69d
Merge branch 'AssetHubsReservedAmount' of https://github.com/AMIRKHAN…
AMIRKHANEF Sep 8, 2024
0e8b670
Merge branch 'AssetHubsReservedAmount' of https://github.com/AMIRKHAN…
AMIRKHANEF Nov 12, 2024
82d46a3
Merge branch 'PolkaGate:main' into AssetHubsReservedAmount
AMIRKHANEF Nov 20, 2024
c239115
fix: minor issues
AMIRKHANEF Nov 20, 2024
38ebfd4
feat: calculate the reserved amount on Asset Hubs
AMIRKHANEF Nov 20, 2024
1b98694
Merge branch 'PolkaGate:main' into AssetHubsReservedAmount
AMIRKHANEF Nov 30, 2024
6fc6c8f
refactor: update some deposit calculation
AMIRKHANEF Nov 30, 2024
2f854f7
Merge branch 'PolkaGate:main' into AssetHubsReservedAmount
AMIRKHANEF Nov 30, 2024
2eddc22
fix: resolve some minor issues
AMIRKHANEF Nov 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/extension-polkagate/src/components/Assets.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

/* eslint-disable react/jsx-max-props-per-line */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import type { Balance } from '@polkadot/types/interfaces';

import { Collapse, Divider, Grid, Skeleton, type SxProps, type Theme, Typography } from '@mui/material';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

import { useTranslation } from '@polkadot/extension-polkagate/src/components/translate';
import useReservedDetails, { type Reserved } from '@polkadot/extension-polkagate/src/hooks/useReservedDetails';
import { isOnAssetHub, isOnRelayChain } from '@polkadot/extension-polkagate/src/util/utils';
import { isOnRelayChain } from '@polkadot/extension-polkagate/src/util/utils';
import { BN } from '@polkadot/util';
import { useParams } from 'react-router';
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

import { ShowValue } from '../../../components';
import { useInfo } from '../../../hooks';
Expand All @@ -37,7 +38,7 @@ interface WaitForReservedProps {
style?: SxProps<Theme> | undefined;
}

function WaitForReserved ({ rows = 2, skeletonHeight = 20, skeletonWidth = 60, style }: WaitForReservedProps): React.ReactElement {
function WaitForReserved({ rows = 2, skeletonHeight = 20, skeletonWidth = 60, style }: WaitForReservedProps): React.ReactElement {
return (
<Grid container justifyContent='center' sx={{ ...style }}>
{Array.from({ length: rows }).map((_, index) => (
Expand Down Expand Up @@ -65,16 +66,38 @@ function WaitForReserved ({ rows = 2, skeletonHeight = 20, skeletonWidth = 60, s
const ReservedDetails = ({ reservedDetails, showReservedDetails }: ReservedDetailsType) => {
const { t } = useTranslation();

const reasonsToShow = useMemo(() => {
const details = Object.values(reservedDetails);

if (details.length === 0) {
return undefined
}

const noReason = details.every((deposit) => deposit === null);

if (noReason) {
return null;
}

const filteredReservedDetails = Object.fromEntries(
Object.entries(reservedDetails).filter(([_key, value]) => value && !value.isZero())
);

return Object.values(filteredReservedDetails).length > 0
? filteredReservedDetails
: undefined
}, [reservedDetails]);
AMIRKHANEF marked this conversation as resolved.
Show resolved Hide resolved
AMIRKHANEF marked this conversation as resolved.
Show resolved Hide resolved

return (
<Collapse in={showReservedDetails} sx={{ width: '100%' }}>
<Divider sx={{ bgcolor: 'divider', height: '1px', m: '3px auto', width: '90%' }} />
<Grid container sx={{ float: 'right', fontSize: '16px', my: '10px', width: '85%' }}>
<Typography fontSize='16px' fontWeight={500}>
{t('Reasons')}
</Typography>
{Object.entries(reservedDetails)?.length
{reasonsToShow
? <Grid container direction='column' item>
{Object.entries(reservedDetails)?.map(([key, value], index) => (
{Object.entries(reasonsToShow)?.map(([key, value], index) => (
<Grid container item key={index} sx={{ fontSize: '16px' }}>
<Grid item sx={{ fontWeight: 300 }} xs={4}>
{toTitleCase(key)}
Expand All @@ -86,37 +109,48 @@ const ReservedDetails = ({ reservedDetails, showReservedDetails }: ReservedDetai
))
}
</Grid>
: <WaitForReserved rows={2} />
: reasonsToShow === null
? <Typography fontSize='16px' fontWeight={500} width='100%'>
{t('No reasons found!')}
</Typography>
: <WaitForReserved rows={2} />
}
</Grid>
</Collapse>
);
};

export default function ReservedDisplayBalance ({ address, amount, disabled, price }: Props): React.ReactElement {
export default function ReservedDisplayBalance({ address, amount, disabled, price }: Props): React.ReactElement {
const { t } = useTranslation();
const reservedDetails = useReservedDetails(address);
const { decimal, genesisHash, token } = useInfo(address);
const { paramAssetId } = useParams<{ address: string, paramAssetId: string }>();

const notOnNativeAsset = useMemo(() => {
const assetIdNumber = Number(paramAssetId);

return Number.isNaN(assetIdNumber) || assetIdNumber > 0;
}, [paramAssetId]);

const [showReservedDetails, setShowReservedDetails] = useState<boolean>(false);

useEffect(() => {
setShowReservedDetails(false); // to reset collapsed area on chain change
}, [genesisHash]);
}, [address, genesisHash]);

const toggleShowReservedDetails = useCallback(() => {
reservedDetails && !amount?.isZero() && setShowReservedDetails(!showReservedDetails);
}, [amount, reservedDetails, showReservedDetails]);

return !genesisHash || isOnAssetHub(genesisHash)
return !genesisHash || notOnNativeAsset
? <></>
: (
<Grid container item sx={{ '> div': { bgcolor: 'unset', boxShadow: 'none' }, bgcolor: 'background.paper', borderRadius: '5px', boxShadow: '2px 3px 4px 0px rgba(0, 0, 0, 0.1)' }}>
<DisplayBalance
amount={amount}
decimal={decimal}
disabled={disabled}
onClick={isOnRelayChain(genesisHash) ? toggleShowReservedDetails : undefined}
onClick={isOnRelayChain(genesisHash) || !notOnNativeAsset ? toggleShowReservedDetails : undefined}
openCollapse={showReservedDetails}
price={price}
title={t('Reserved')}
Expand Down
Loading
Loading