Skip to content

Commit

Permalink
Fix Asset Id Parsing (#11334)
Browse files Browse the repository at this point in the history
* fix: correct asset supply check in PayWithAssetProvider

* refactor: improve asset display and validation in Balances and Asset components
  • Loading branch information
ap211unitech authored Feb 25, 2025
1 parent 62348cf commit 046ea0c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/page-assets/src/Balances/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Balances ({ className, infos = [] }: Props): React.ReactElement<Props>
const completeAssets = useMemo(
() => infos
.filter((i): i is AssetInfoComplete => !!(i.details && i.metadata) && !i.details.supply.isZero())
.sort((a, b) => a.id.cmp(b.id)),
,
[infos]
);

Expand Down
10 changes: 7 additions & 3 deletions packages/page-assets/src/Overview/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { AssetInfo } from '@polkadot/react-hooks/types';

import React, { useMemo } from 'react';

import { AddressSmall, Table } from '@polkadot/react-components';
import { AddressSmall } from '@polkadot/react-components';
import { FormatBalance } from '@polkadot/react-query';

import Mint from './Mint/index.js';
Expand All @@ -25,8 +25,12 @@ function Asset ({ className, value: { details, id, isIssuerMe, metadata } }: Pro

return (
<tr className={className}>
<Table.Column.Id value={id} />
<td className='together'>{metadata?.name.toUtf8()}</td>
<td></td>
<td className='together'>
<span style={{ fontSize: 18, marginRight: 10 }}>
{id.toString()}
</span>
{metadata?.name.toUtf8()}</td>
<td className='address media--1000'>{details && <AddressSmall value={details.owner} />}</td>
<td className='address media--1300'>{details && <AddressSmall value={details.admin} />}</td>
<td className='address media--1600'>{details && <AddressSmall value={details.issuer} />}</td>
Expand Down
5 changes: 4 additions & 1 deletion packages/page-assets/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ function AssetApp ({ basePath, className }: Props): React.ReactElement<Props> {
);

const openId = useMemo(
() => findOpenId(api.genesisHash.toHex(), ids),
() => findOpenId(
api.genesisHash.toHex(),
// Check if id is valid digit
ids?.filter((id) => /^\d{1,3}(,\d{3})*$/.test(id.toString()))),
[api.genesisHash, ids]
);

Expand Down
4 changes: 2 additions & 2 deletions packages/react-hooks/src/ctx/PayWithAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function PayWithAssetProvider ({ children }: Props): React.ReactElement<Props> {
const completeAssetInfos = useMemo(
() => (assetInfos
?.filter((i): i is AssetInfoComplete =>
!!(i.details && i.metadata) && !i.details.supply.isZero() && !!i.details?.toJSON().isSufficient)
.sort((a, b) => a.id.cmp(b.id))) || [],
!!(i.details && i.metadata) && !i.details.supply.toHuman() && !!i.details?.toJSON().isSufficient)
) || [],
[assetInfos]
);

Expand Down

0 comments on commit 046ea0c

Please sign in to comment.