Use metadata v14 types in assets (statemine upgraded) (#6446)
This commit is contained in:
parent
0d629766ca
commit
3715cfe6d3
@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AssetBalance, AssetId, TAssetBalance } from '@polkadot/types/interfaces';
|
||||
import type BN from 'bn.js';
|
||||
import type { PalletAssetsAssetBalance } from '@polkadot/types/lookup';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
@ -13,14 +14,14 @@ import Transfer from './Transfer';
|
||||
|
||||
interface Props {
|
||||
accountId: string;
|
||||
assetId: AssetId;
|
||||
balance: AssetBalance;
|
||||
assetId: BN;
|
||||
balance: PalletAssetsAssetBalance;
|
||||
className?: string;
|
||||
minBalance: TAssetBalance;
|
||||
minBalance: BN;
|
||||
siFormat: [number, string];
|
||||
}
|
||||
|
||||
function Account ({ accountId, assetId, balance: { balance, isFrozen, isSufficient }, className, minBalance, siFormat }: Props): React.ReactElement<Props> {
|
||||
function Account ({ accountId, assetId, balance: { balance, isFrozen, sufficient }, className, minBalance, siFormat }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
@ -32,7 +33,7 @@ function Account ({ accountId, assetId, balance: { balance, isFrozen, isSufficie
|
||||
{isFrozen.isTrue ? t<string>('Yes') : t<string>('No')}
|
||||
</td>
|
||||
<td className='start'>
|
||||
{isSufficient.isTrue ? t<string>('Yes') : t<string>('No')}
|
||||
{sufficient.isTrue ? t<string>('Yes') : t<string>('No')}
|
||||
</td>
|
||||
<td className='number all'>
|
||||
<FormatBalance
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetId, TAssetBalance } from '@polkadot/types/interfaces';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
|
||||
@ -13,9 +12,9 @@ import { useTranslation } from '../translate';
|
||||
|
||||
interface Props {
|
||||
accountId: string;
|
||||
assetId: AssetId;
|
||||
assetId: BN;
|
||||
className?: string;
|
||||
minBalance: TAssetBalance;
|
||||
minBalance: BN;
|
||||
siFormat: [number, string];
|
||||
}
|
||||
|
||||
|
||||
@ -1,22 +1,23 @@
|
||||
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AssetBalance, AssetId } from '@polkadot/types/interfaces';
|
||||
import type BN from 'bn.js';
|
||||
import type { PalletAssetsAssetBalance } from '@polkadot/types/lookup';
|
||||
|
||||
import { useAccounts, useApi, useCall } from '@polkadot/react-hooks';
|
||||
|
||||
interface BalanceResult {
|
||||
accountId: string;
|
||||
balance: AssetBalance;
|
||||
balance: PalletAssetsAssetBalance;
|
||||
}
|
||||
|
||||
interface Result {
|
||||
assetId: AssetId;
|
||||
assetId: BN;
|
||||
balances: BalanceResult[];
|
||||
}
|
||||
|
||||
const queryOptions = {
|
||||
transform: ([[params], balances]: [[[AssetId, string][]], AssetBalance[]]): Result => ({
|
||||
transform: ([[params], balances]: [[[BN, string][]], PalletAssetsAssetBalance[]]): Result => ({
|
||||
assetId: params[0][0],
|
||||
balances: params
|
||||
.map(([, accountId], index) => ({
|
||||
@ -28,7 +29,7 @@ const queryOptions = {
|
||||
withParamsTransform: true
|
||||
};
|
||||
|
||||
export default function useBalances (id?: AssetId | null): BalanceResult[] | null {
|
||||
export default function useBalances (id?: BN | null): BalanceResult[] | null {
|
||||
const { api } = useApi();
|
||||
const { allAccounts } = useAccounts();
|
||||
const query = useCall(id && api.query.assets.account.multi, id && [allAccounts.map((a) => [id, a])], queryOptions);
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetId } from '@polkadot/types/interfaces';
|
||||
import type { InfoState, TeamState } from './types';
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
@ -15,7 +14,7 @@ import Info from './Info';
|
||||
import Team from './Team';
|
||||
|
||||
interface Props {
|
||||
assetIds: AssetId[];
|
||||
assetIds: BN[];
|
||||
className?: string;
|
||||
onClose: () => void;
|
||||
openId: BN;
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetId } from '@polkadot/types/interfaces';
|
||||
import type { InfoState } from './types';
|
||||
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
@ -14,7 +13,7 @@ import { BN_ZERO } from '@polkadot/util';
|
||||
import { useTranslation } from '../../translate';
|
||||
|
||||
interface Props {
|
||||
assetIds: AssetId[];
|
||||
assetIds: BN[];
|
||||
className?: string;
|
||||
defaultValue: InfoState | null;
|
||||
onChange: (info: InfoState | null) => void;
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetId } from '@polkadot/types/interfaces';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
@ -13,7 +12,7 @@ import { useTranslation } from '../../translate';
|
||||
import Create from './Create';
|
||||
|
||||
interface Props {
|
||||
assetIds?: AssetId[];
|
||||
assetIds?: BN[];
|
||||
className?: string;
|
||||
openId: BN;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetDetails, AssetId, AssetMetadata } from '@polkadot/types/interfaces';
|
||||
import type { PalletAssetsAssetDetails, PalletAssetsAssetMetadata } from '@polkadot/types/lookup';
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
@ -13,9 +13,9 @@ import { useTranslation } from '../../translate';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
details: AssetDetails;
|
||||
id: AssetId;
|
||||
metadata: AssetMetadata;
|
||||
details: PalletAssetsAssetDetails;
|
||||
id: BN;
|
||||
metadata: PalletAssetsAssetMetadata;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AssetDetails, AssetId, AssetMetadata } from '@polkadot/types/interfaces';
|
||||
import type BN from 'bn.js';
|
||||
import type { PalletAssetsAssetDetails, PalletAssetsAssetMetadata } from '@polkadot/types/lookup';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
@ -13,9 +14,9 @@ import Modal from './Mint';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
details: AssetDetails;
|
||||
id: AssetId;
|
||||
metadata: AssetMetadata;
|
||||
details: PalletAssetsAssetDetails;
|
||||
id: BN;
|
||||
metadata: PalletAssetsAssetMetadata;
|
||||
}
|
||||
|
||||
function Mint ({ className, details, id, metadata }: Props): React.ReactElement<Props> {
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetId } from '@polkadot/types/interfaces';
|
||||
import type { AssetInfo } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
@ -15,7 +14,7 @@ import Summary from './Summary';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
ids?: AssetId[];
|
||||
ids?: BN[];
|
||||
infos?: AssetInfo[];
|
||||
openId: BN;
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AssetId } from '@polkadot/types/interfaces';
|
||||
|
||||
import React, { useMemo, useRef } from 'react';
|
||||
import { Route, Switch } from 'react-router';
|
||||
@ -22,7 +21,7 @@ interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function findOpenId (ids?: AssetId[]): BN {
|
||||
function findOpenId (ids?: BN[]): BN {
|
||||
if (!ids || !ids.length) {
|
||||
return BN_ONE;
|
||||
}
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AssetDetails, AssetId, AssetMetadata } from '@polkadot/types/interfaces';
|
||||
import type BN from 'bn.js';
|
||||
import type { PalletAssetsAssetDetails, PalletAssetsAssetMetadata } from '@polkadot/types/lookup';
|
||||
|
||||
export interface AssetInfo {
|
||||
details: AssetDetails | null;
|
||||
id: AssetId;
|
||||
details: PalletAssetsAssetDetails | null;
|
||||
id: BN;
|
||||
isAdminMe: boolean;
|
||||
isIssuerMe: boolean;
|
||||
isFreezerMe: boolean;
|
||||
isOwnerMe: boolean;
|
||||
key: string;
|
||||
metadata: AssetMetadata | null;
|
||||
metadata: PalletAssetsAssetMetadata | null;
|
||||
}
|
||||
|
||||
export interface AssetInfoComplete extends AssetInfo {
|
||||
details: AssetDetails;
|
||||
metadata: AssetMetadata;
|
||||
details: PalletAssetsAssetDetails;
|
||||
metadata: PalletAssetsAssetMetadata;
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId, AssetDetails, AssetId, AssetMetadata } from '@polkadot/types/interfaces';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { PalletAssetsAssetDetails, PalletAssetsAssetMetadata } from '@polkadot/types/lookup';
|
||||
import type { AssetInfo } from './types';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
@ -24,7 +26,7 @@ function isAccount (allAccounts: string[], accountId: AccountId): boolean {
|
||||
return allAccounts.some((a) => a === address);
|
||||
}
|
||||
|
||||
function extractInfo (allAccounts: string[], id: AssetId, optDetails: Option<AssetDetails>, metadata: AssetMetadata): AssetInfo {
|
||||
function extractInfo (allAccounts: string[], id: BN, optDetails: Option<PalletAssetsAssetDetails>, metadata: PalletAssetsAssetMetadata): AssetInfo {
|
||||
const details = optDetails.unwrapOr(null);
|
||||
|
||||
return {
|
||||
@ -46,11 +48,11 @@ function extractInfo (allAccounts: string[], id: AssetId, optDetails: Option<Ass
|
||||
};
|
||||
}
|
||||
|
||||
export default function useAssetInfos (ids?: AssetId[]): AssetInfo[] | undefined {
|
||||
export default function useAssetInfos (ids?: BN[]): AssetInfo[] | undefined {
|
||||
const { api } = useApi();
|
||||
const { allAccounts } = useAccounts();
|
||||
const metadata = useCall<[[AssetId[]], AssetMetadata[]]>(api.query.assets.metadata.multi, [ids], QUERY_OPTS);
|
||||
const details = useCall<[[AssetId[]], Option<AssetDetails>[]]>(api.query.assets.asset.multi, [ids], QUERY_OPTS);
|
||||
const metadata = useCall<[[BN[]], PalletAssetsAssetMetadata[]]>(api.query.assets.metadata.multi, [ids], QUERY_OPTS);
|
||||
const details = useCall<[[BN[]], Option<PalletAssetsAssetDetails>[]]>(api.query.assets.asset.multi, [ids], QUERY_OPTS);
|
||||
const [state, setState] = useState<AssetInfo[] | undefined>();
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user