// Copyright 2017-2022 @polkadot/app-parachains authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { OwnedId, OwnerInfo } from './types'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { Dropdown, InputAddress, MarkError, Modal } from '@polkadot/react-components'; import { useTranslation } from './translate'; interface Props { noCodeCheck?: boolean; onChange: (owner: OwnerInfo) => void; ownedIds: OwnedId[]; } function InputOwner ({ noCodeCheck, onChange, ownedIds }: Props): React.ReactElement { const { t } = useTranslation(); const [accountId, setAccountId] = useState(null); const [paraId, setParaId] = useState(0); useEffect((): void => { onChange( accountId && paraId ? { accountId, paraId } : { accountId: null, paraId: 0 } ); }, [accountId, onChange, ownedIds, paraId]); const owners = useMemo( () => ownedIds.map(({ manager }) => manager), [ownedIds] ); const optIds = useMemo( () => ownedIds .filter(({ manager }) => manager === accountId) .map(({ paraId }) => ({ text: paraId.toString(), value: paraId.toNumber() })), [accountId, ownedIds] ); const _setParaId = useCallback( (id: number) => setParaId( noCodeCheck || ownedIds.some(({ hasCode, paraId }) => paraId.eq(id) && hasCode) ? id : 0 ), [noCodeCheck, ownedIds] ); return (

{t('This account that has been used to register the parachain. This will pay all associated fees.')}

{t('The parachain id is associated with the selected account via parathread registration.')}

} > ('parachain owner')} onChange={setAccountId} type='account' value={accountId} /> {accountId && ( ('parachain id')} onChange={_setParaId} options={optIds} /> )} {!noCodeCheck && !paraId && ( ('Before using this registered paraId, you need to have a WASM validation function registered on-chain')} /> )}
); } export default React.memo(InputOwner);