diff --git a/packages/page-assets/src/Overview/Asset.tsx b/packages/page-assets/src/Overview/Asset.tsx
index 15dc2448e1..c7e979df48 100644
--- a/packages/page-assets/src/Overview/Asset.tsx
+++ b/packages/page-assets/src/Overview/Asset.tsx
@@ -18,6 +18,7 @@ function Asset ({ className, value: { details, id, metadata } }: Props): React.R
{formatNumber(id)} |
{metadata?.name.toUtf8()} |
+ {details && } |
{details && } |
{details && } |
{details && } |
diff --git a/packages/page-assets/src/Overview/Assets.tsx b/packages/page-assets/src/Overview/Assets.tsx
index eba3748c87..0bc66f036c 100644
--- a/packages/page-assets/src/Overview/Assets.tsx
+++ b/packages/page-assets/src/Overview/Assets.tsx
@@ -22,9 +22,10 @@ function Assets ({ assetIds, className }: Props): React.ReactElement {
const headerRef = useRef([
[t('assets'), 'start', 2],
- [t('admin'), 'start'],
- [t('issuer'), 'start'],
- [t('freezer'), 'start'],
+ [t('owner'), 'address'],
+ [t('admin'), 'address'],
+ [t('issuer'), 'address'],
+ [t('freezer'), 'address'],
[t('decimals')],
[t('symbol'), 'start'],
[]
diff --git a/packages/page-assets/src/Overview/Create/Create.tsx b/packages/page-assets/src/Overview/Create/Create.tsx
new file mode 100644
index 0000000000..a4111a0f71
--- /dev/null
+++ b/packages/page-assets/src/Overview/Create/Create.tsx
@@ -0,0 +1,116 @@
+// Copyright 2017-2021 @polkadot/app-assets authors & contributors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { SubmittableExtrinsic } from '@polkadot/api/types';
+import type { AssetId } from '@polkadot/types/interfaces';
+import type { InfoState, MetadataState, TeamState } from './types';
+
+import React, { useEffect, useState } from 'react';
+
+import { Button, Modal, TxButton } from '@polkadot/react-components';
+import { useApi, useStepper } from '@polkadot/react-hooks';
+
+import { useTranslation } from '../../translate';
+import Info from './Info';
+import Metadata from './Metadata';
+import Team from './Team';
+
+interface Props {
+ assetIds: AssetId[];
+ className?: string;
+ onClose: () => void;
+}
+
+function Create ({ assetIds, className, onClose }: Props): React.ReactElement {
+ const { t } = useTranslation();
+ const { api } = useApi();
+ const [step, nextStep, prevStep] = useStepper();
+ const [asset, setAsset] = useState(null);
+ const [metadata, setMetadata] = useState(null);
+ const [team, setTeam] = useState(null);
+ const [extrinsic, setExtrinsic] = useState | null>(null);
+
+ useEffect((): void => {
+ setExtrinsic(
+ () => asset && metadata && team
+ ? team.teamTx
+ ? api.tx.utility.batchAll([asset.createTx, metadata.metadataTx, team.teamTx])
+ : api.tx.utility.batchAll([asset.createTx, metadata.metadataTx])
+ : null
+ );
+ }, [api, asset, metadata, team]);
+
+ return (
+ ('create asset {{step}}/{{steps}}', { replace: { step, steps: 3 } })}
+ size='large'
+ >
+ {step === 1 && (
+
+ )}
+ {step === 2 && (
+
+ )}
+ {step === 3 && (
+
+ )}
+
+ {step === 1 &&
+
+
+ );
+}
+
+export default React.memo(Create);
diff --git a/packages/page-assets/src/Overview/Create/Info.tsx b/packages/page-assets/src/Overview/Create/Info.tsx
index f0a10c146e..21a751c860 100644
--- a/packages/page-assets/src/Overview/Create/Info.tsx
+++ b/packages/page-assets/src/Overview/Create/Info.tsx
@@ -9,19 +9,28 @@ import React, { useEffect, useMemo, useState } from 'react';
import { InputAddress, InputNumber, Modal } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
-import { BN_ZERO } from '@polkadot/util';
+import { BN_ONE, BN_ZERO } from '@polkadot/util';
import { useTranslation } from '../../translate';
interface Props {
assetIds: AssetId[];
className?: string;
+ defaultValue: InfoState | null;
onChange: (info: InfoState | null) => void;
}
-function Info ({ assetIds, className = '', onChange }: Props): React.ReactElement {
+function findAvailbleId (assetIds: AssetId[]): BN {
+ return assetIds.length
+ ? assetIds[assetIds.length - 1].add(BN_ONE)
+ : BN_ONE;
+}
+
+function Info ({ assetIds, className = '', defaultValue, onChange }: Props): React.ReactElement {
const { t } = useTranslation();
const { api } = useApi();
+ const [initial] = useState(() => defaultValue);
+ const [initialId] = useState(() => findAvailbleId(assetIds));
const [accountId, setAccountId] = useState(null);
const [assetId, setAssetId] = useState(null);
const [minBalance, setMinBalance] = useState(null);
@@ -34,11 +43,7 @@ function Info ({ assetIds, className = '', onChange }: Props): React.ReactElemen
useEffect((): void => {
onChange(
assetId && accountId && minBalance && isIdValid && !minBalance.isZero()
- ? {
- accountId,
- assetId,
- createTx: api.tx.assets.create(assetId, accountId, minBalance)
- }
+ ? { accountId, assetId, createTx: api.tx.assets.create(assetId, accountId, minBalance), minBalance }
: null
);
}, [api, accountId, assetId, assetIds, isIdValid, minBalance, onChange]);
@@ -47,14 +52,16 @@ function Info ({ assetIds, className = '', onChange }: Props): React.ReactElemen
('The account that is to be used to create this asset and setup the initial metadata.')}>
('creator account')}
onChange={setAccountId}
type='account'
/>
- ('The selected id for the asset. Should not match an already-existing id.')}>
+ ('The selected id for the asset. This should not match an already-existing asset id.')}>
('asset id')}
@@ -63,6 +70,7 @@ function Info ({ assetIds, className = '', onChange }: Props): React.ReactElemen
('The minimum balance for the asset.')}>
('minimum balance')}
onChange={setMinBalance}
diff --git a/packages/page-assets/src/Overview/Create/Metadata.tsx b/packages/page-assets/src/Overview/Create/Metadata.tsx
index fcaf1fda8c..d585ffd3e3 100644
--- a/packages/page-assets/src/Overview/Create/Metadata.tsx
+++ b/packages/page-assets/src/Overview/Create/Metadata.tsx
@@ -14,15 +14,17 @@ import { useTranslation } from '../../translate';
interface Props {
assetId?: BN | null;
className?: string;
+ defaultValue: MetadataState | null;
onChange: (info: MetadataState | null) => void;
}
-function Metadata ({ assetId, className = '', onChange }: Props): React.ReactElement {
+function Metadata ({ assetId, className = '', defaultValue, onChange }: Props): React.ReactElement {
const { t } = useTranslation();
const { api } = useApi();
+ const [initial] = useState(() => defaultValue);
const [assetDecimals, setAssetDecimals] = useState(null);
- const [assetName, setAssetName] = useState(null);
- const [assetSymbol, setAssetSymbol] = useState(null);
+ const [assetName, setAssetName] = useState(() => defaultValue?.assetName);
+ const [assetSymbol, setAssetSymbol] = useState(() => defaultValue?.assetSymbol);
const isValidDecimals = useMemo(
() => !!assetDecimals && assetDecimals.lten(20),
@@ -42,7 +44,7 @@ function Metadata ({ assetId, className = '', onChange }: Props): React.ReactEle
useEffect((): void => {
onChange(
assetId && assetName && assetSymbol && assetDecimals && isValidName && isValidSymbol && isValidDecimals
- ? { metadataTx: api.tx.assets.setMetadata(assetId, assetName, assetSymbol, assetDecimals) }
+ ? { assetDecimals, assetName, assetSymbol, metadataTx: api.tx.assets.setMetadata(assetId, assetName, assetSymbol, assetDecimals) }
: null
);
}, [api, assetDecimals, assetId, assetName, assetSymbol, isValidName, isValidSymbol, isValidDecimals, onChange]);
@@ -52,6 +54,7 @@ function Metadata ({ assetId, className = '', onChange }: Props): React.ReactEle
('The descriptive name for this asset.')}>
('asset name')}
onChange={setAssetName}
@@ -59,6 +62,7 @@ function Metadata ({ assetId, className = '', onChange }: Props): React.ReactEle
('The symbol that will represent this asset.')}>
('asset symbol')}
onChange={setAssetSymbol}
@@ -66,6 +70,7 @@ function Metadata ({ assetId, className = '', onChange }: Props): React.ReactEle
('The number of decimals for this token. Max allowed via the UI is set to 20.')}>
('asset decimals')}
onChange={setAssetDecimals}
diff --git a/packages/page-assets/src/Overview/Create/Team.tsx b/packages/page-assets/src/Overview/Create/Team.tsx
index 6c5be2ee02..7e37f6b4d3 100644
--- a/packages/page-assets/src/Overview/Create/Team.tsx
+++ b/packages/page-assets/src/Overview/Create/Team.tsx
@@ -15,12 +15,14 @@ interface Props {
accountId?: string;
assetId?: BN;
className?: string;
+ defaultValue: TeamState | null;
onChange: (info: TeamState | null) => void;
}
-function Team ({ accountId, assetId, className = '', onChange }: Props): React.ReactElement {
+function Team ({ accountId, assetId, className = '', defaultValue, onChange }: Props): React.ReactElement {
const { t } = useTranslation();
const { api } = useApi();
+ const [initial] = useState(() => defaultValue);
const [adminId, setAdminId] = useState(null);
const [freezerId, setFreezerId] = useState(null);
const [issuerId, setIssuerId] = useState(null);
@@ -29,8 +31,8 @@ function Team ({ accountId, assetId, className = '', onChange }: Props): React.R
onChange(
assetId && accountId && adminId && freezerId && issuerId
? adminId !== accountId || freezerId !== accountId || issuerId !== accountId
- ? { teamTx: api.tx.assets.setTeam(assetId, issuerId, adminId, freezerId) }
- : { teamTx: null }
+ ? { adminId, freezerId, issuerId, teamTx: api.tx.assets.setTeam(assetId, issuerId, adminId, freezerId) }
+ : { adminId, freezerId, issuerId, teamTx: null }
: null
);
}, [api, assetId, accountId, adminId, freezerId, issuerId, onChange]);
@@ -39,7 +41,7 @@ function Team ({ accountId, assetId, className = '', onChange }: Props): React.R
('The account that is to be used for ongoing admin on the token.')}>
('admin account')}
onChange={setAdminId}
type='account'
@@ -47,7 +49,7 @@ function Team ({ accountId, assetId, className = '', onChange }: Props): React.R
('The account that is to be used for issuing for this token.')}>
('issuer account')}
onChange={setIssuerId}
type='account'
@@ -55,7 +57,7 @@ function Team ({ accountId, assetId, className = '', onChange }: Props): React.R
('The account that is to be used for performing freezing.')}>
('freezer account')}
onChange={setFreezerId}
type='account'
diff --git a/packages/page-assets/src/Overview/Create/index.tsx b/packages/page-assets/src/Overview/Create/index.tsx
index 32853e2706..19dcbcd064 100644
--- a/packages/page-assets/src/Overview/Create/index.tsx
+++ b/packages/page-assets/src/Overview/Create/index.tsx
@@ -1,47 +1,27 @@
// Copyright 2017-2021 @polkadot/app-assets authors & contributors
// SPDX-License-Identifier: Apache-2.0
-import type { SubmittableExtrinsic } from '@polkadot/api/types';
import type { AssetId } from '@polkadot/types/interfaces';
-import type { InfoState, MetadataState, TeamState } from './types';
-import React, { useEffect, useState } from 'react';
-import styled from 'styled-components';
+import React from 'react';
-import { Button, Modal, TxButton } from '@polkadot/react-components';
-import { useAccounts, useApi, useStepper, useToggle } from '@polkadot/react-hooks';
+import { Button } from '@polkadot/react-components';
+import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks';
import { isFunction } from '@polkadot/util';
import { useTranslation } from '../../translate';
-import Info from './Info';
-import Metadata from './Metadata';
-import Team from './Team';
+import Create from './Create';
interface Props {
assetIds?: AssetId[];
className?: string;
}
-function Create ({ assetIds, className }: Props): React.ReactElement {
+function CreateButton ({ assetIds, className }: Props): React.ReactElement {
const { t } = useTranslation();
const { api } = useApi();
const { hasAccounts } = useAccounts();
- const [step, nextStep, prevStep] = useStepper();
const [isOpen, toggleOpen] = useToggle();
- const [asset, setAsset] = useState(null);
- const [metadata, setMetadata] = useState(null);
- const [team, setTeam] = useState(null);
- const [extrinsic, setExtrinsic] = useState | null>(null);
-
- useEffect((): void => {
- setExtrinsic(
- () => asset && metadata && team
- ? team.teamTx
- ? api.tx.utility.batchAll([asset.createTx, metadata.metadataTx, team.teamTx])
- : api.tx.utility.batchAll([asset.createTx, metadata.metadataTx])
- : null
- );
- }, [api, asset, metadata, team]);
return (
<>
@@ -52,79 +32,14 @@ function Create ({ assetIds, className }: Props): React.ReactElement {
onClick={toggleOpen}
/>
{isOpen && assetIds && (
- ('create asset {{step}}/{{steps}}', { replace: { step, steps: 3 } })}
- size='large'
- >
- {step === 1 && (
-
- )}
- {step === 2 && (
-
- )}
- {step === 3 && (
-
- )}
-
- {step === 1 &&
- ('Next')}
- onClick={nextStep}
- />
- }
- {step === 2 && (
- <>
- ('Prev')}
- onClick={prevStep}
- />
- ('Next')}
- onClick={nextStep}
- />
- >
- )}
- {step === 3 && (
- <>
- ('Prev')}
- onClick={prevStep}
- />
- ('Create')}
- onStart={toggleOpen}
- />
- >
- )}
-
-
+ onClose={toggleOpen}
+ />
)}
>
);
}
-export default React.memo(styled(Create)`
- .stepHidden.content {
- display: none !important;
- }
-`);
+export default React.memo(CreateButton);
diff --git a/packages/page-assets/src/Overview/Create/types.ts b/packages/page-assets/src/Overview/Create/types.ts
index 57824a326d..847a85bf41 100644
--- a/packages/page-assets/src/Overview/Create/types.ts
+++ b/packages/page-assets/src/Overview/Create/types.ts
@@ -8,12 +8,19 @@ export interface InfoState {
accountId: string;
assetId: BN;
createTx: SubmittableExtrinsic<'promise'>;
+ minBalance: BN;
}
export interface MetadataState {
+ assetDecimals: BN;
+ assetName: string;
+ assetSymbol: string;
metadataTx: SubmittableExtrinsic<'promise'>;
}
export interface TeamState {
+ adminId: string;
+ issuerId: string;
+ freezerId: string;
teamTx: SubmittableExtrinsic<'promise'> | null;
}
diff --git a/packages/page-assets/src/Overview/types.ts b/packages/page-assets/src/Overview/types.ts
index 6a236a7f16..efe42aa4e2 100644
--- a/packages/page-assets/src/Overview/types.ts
+++ b/packages/page-assets/src/Overview/types.ts
@@ -6,10 +6,10 @@ import type { AssetDetails, AssetId, AssetMetadata } from '@polkadot/types/inter
export interface AssetInfo {
details: AssetDetails | null;
id: AssetId;
- isAdmin: boolean;
- isOwner: boolean;
- isIssuer: boolean;
- isFreezer: boolean;
+ isAdminMe: boolean;
+ isIssuerMe: boolean;
+ isFreezerMe: boolean;
+ isOwnerMe: boolean;
key: string;
metadata: AssetMetadata | null;
}
diff --git a/packages/page-assets/src/Overview/useAssetInfos.ts b/packages/page-assets/src/Overview/useAssetInfos.ts
index 01cfbad8c0..5a42af9bf8 100644
--- a/packages/page-assets/src/Overview/useAssetInfos.ts
+++ b/packages/page-assets/src/Overview/useAssetInfos.ts
@@ -9,6 +9,13 @@ import { useMemo } from 'react';
import { useAccounts, useApi, useCall } from '@polkadot/react-hooks';
+const EMPTY_FLAGS = {
+ isAdminMe: false,
+ isFreezerMe: false,
+ isIssuerMe: false,
+ isOwnerMe: false
+};
+
function isAccount (allAccounts: string[], accountId: AccountId): boolean {
const address = accountId.toString();
@@ -19,12 +26,17 @@ function extractInfo (allAccounts: string[], id: AssetId, optDetails: Option