// Copyright 2017-2020 @polkadot/app-staking authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import { CodeStored } from '../types'; import React, { useCallback } from 'react'; import styled from 'styled-components'; import { Button, Card, Expander, Forget } from '@polkadot/react-components'; import { useToggle } from '@polkadot/react-hooks'; import { ABI, CodeRow } from '../shared'; import RemoveABI from '../RemoveABI'; import store from '../store'; import useAbi from '../useAbi'; import { useTranslation } from '../translate'; interface Props { className?: string; code: CodeStored; onShowDeploy: (codeHash?: string, constructorIndex?: number) => () => void; } function Code ({ className, code, onShowDeploy }: Props): React.ReactElement { const { json: { codeHash } } = code; const { t } = useTranslation(); const [isAbiOpen, toggleIsAbiOpen] = useToggle(); const [isForgetOpen, toggleIsForgetOpen] = useToggle(); const [isRemoveABIOpen, toggleIsRemoveABIOpen] = useToggle(); const { contractAbi, isAbiError, isAbiSupplied, isAbiValid, onChangeAbi, onRemoveAbi } = useAbi([code.json.abi || null, code.contractAbi || null], codeHash, true); const _onShowDeploy = useCallback( (): void => onShowDeploy(codeHash)(), [codeHash, onShowDeploy] ); const _onDeployConstructor = useCallback( (constructorIndex = 0): void => { codeHash && onShowDeploy && onShowDeploy(codeHash, constructorIndex)(); }, [codeHash, onShowDeploy] ); const _onForget = useCallback( (): void => { if (!codeHash) { return; } try { store.forgetCode(codeHash); } catch (error) { console.error(error); } finally { toggleIsForgetOpen(); } }, [codeHash, toggleIsForgetOpen] ); const abiNode = ( ); return (