From bf23336749bf72c61f23fecf0ad7a7c9da39da1e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 13 May 2020 17:38:09 +0200 Subject: [PATCH] fix flow between claim and attest --- packages/page-claims/src/Attest.tsx | 4 +- packages/page-claims/src/Claim.tsx | 18 ++++----- packages/page-claims/src/index.tsx | 63 +++++++++-------------------- 3 files changed, 30 insertions(+), 55 deletions(-) diff --git a/packages/page-claims/src/Attest.tsx b/packages/page-claims/src/Attest.tsx index a728dbc6f8ce..f247f4b9dab4 100644 --- a/packages/page-claims/src/Attest.tsx +++ b/packages/page-claims/src/Attest.tsx @@ -18,9 +18,9 @@ function Attest ({ accountId, className }: Props): React.ReactElement | n const { t } = useTranslation(); return ( - +
- {t('By signing this transaction, you agree with attestation available at the following address: XXX')} + {t('By signing this transaction, you agree with the attestation available at the following address: XXX')}

{addrToChecksum(accountId)}

| null { +function Claim ({ accountId, className, ethereumAddress, ethereumSignature, isOldClaimProcess }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); const [claimValue, setClaimValue] = useState(null); @@ -87,7 +87,7 @@ function Claim ({ accountId, className, ethereumAddress, ethereumSignature, isCl icon='send' isPrimary label={t('Claim')} - {...constructTx(accountId, ethereumSignature, isClaimAttest)} + {...constructTx(accountId, ethereumSignature, isOldClaimProcess)} /> diff --git a/packages/page-claims/src/index.tsx b/packages/page-claims/src/index.tsx index aecfcd92a8f6..ce11392628aa 100644 --- a/packages/page-claims/src/index.tsx +++ b/packages/page-claims/src/index.tsx @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Option } from '@polkadot/types'; -import { Balance, EcdsaSignature, EthereumAddress } from '@polkadot/types/interfaces'; +import { EcdsaSignature, EthereumAddress } from '@polkadot/types/interfaces'; import { AppProps, I18nProps } from '@polkadot/react-components/types'; import { ApiProps } from '@polkadot/react-api/types'; @@ -69,7 +69,6 @@ const Signature = styled.textarea` const ClaimsApp = (props: Props): React.ReactElement => { const [isOldClaimProcess, setIsOldClaimProcess] = useState(true); - const [claim, setClaim] = useState(null); const [didCopy, setDidCopy] = useState(false); const [ethereumAddress, setEthereumAddress] = useState(null); const [signature, setSignature] = useState(null); @@ -80,7 +79,7 @@ const ClaimsApp = (props: Props): React.ReactElement => { const [isPreclaimed, setIsPreclaimed] = useState(false); useEffect(() => { - if (isApiReady && typeof api.query.claims.claimAttest !== undefined) { + if (isApiReady && typeof api.query.claims.claimAttest !== 'undefined') { setIsOldClaimProcess(false); } @@ -95,29 +94,33 @@ const ClaimsApp = (props: Props): React.ReactElement => { } }, [didCopy]); + const goToStepSign = useCallback(() => { + setStep(Step.Sign); + }, []); + + const goToStepClaim = useCallback(() => { + setStep(Step.Claim); + }, []); + useEffect(() => { if (isApiReady && accountId) { api.query.claims .preclaims>(accountId) .then((opt): void => { setIsPreclaimed(opt.isSome); + + if (opt.isSome) { + goToStepClaim(); + } else { + goToStepSign(); + } }); } - }, [accountId, api.query.claims, isApiReady]); - - const goToStepSign = useCallback(() => { - setStep(Step.Sign); - }, []); - - const goToStepClaim = useCallback(() => { - setStep(Step.Claim); - }, []); + }, [accountId, api.query.claims, goToStepClaim, goToStepSign, isApiReady]); const onChangeAccount = useCallback((newAccountId) => { setAccountId(newAccountId); - // FIXME Amaury It should not be Step.Sign - goToStepSign(); - }, [goToStepSign]); + }, []); const onChangeSignature = useCallback((event: React.SyntheticEvent) => { const { value: signatureJson } = event.target as HTMLInputElement; @@ -219,41 +222,13 @@ const ClaimsApp = (props: Props): React.ReactElement => { accountId={accountId} ethereumAddress={ethereumAddress} ethereumSignature={signature} - // Use claims.claimAttest is chain supports it - isClaimAttest={!!api.query.claims.claimAttest} + isOldClaimProcess={isOldClaimProcess} /> )} ); - - // FIXME Amaury Below are from the old component - // How to use TxModalNew? - // } - - // protected isDisabled = (): boolean => { - // const { accountId, signature } = this.state; - - // return !accountId || !signature; - // } - - // protected isUnsigned = (): boolean => true; - - // protected submitLabel = (): React.ReactNode => this.props.t('Redeem'); - - // protected txMethod = (): string => 'claims.claim'; - - // protected txParams = (): [string | null, EcdsaSignature | null] => { - // const { accountId, signature } = this.state; - - // return [ - // accountId ? accountId.toString() : null, - // signature || null - // ]; - // } - - // } }; export default withMulti(