Contracts code cleanups (#3213)
This commit is contained in:
parent
654bc254dc
commit
088d22cd81
@ -30,14 +30,12 @@ function Code ({ className, code, onShowDeploy }: Props): React.ReactElement<Pro
|
||||
const { contractAbi, isAbiError, isAbiSupplied, isAbiValid, onChangeAbi, onRemoveAbi } = useAbi([code.json.abi || null, code.contractAbi || null], codeHash, true);
|
||||
|
||||
const _onShowDeploy = useCallback(
|
||||
(): void => onShowDeploy(codeHash)(),
|
||||
() => onShowDeploy(codeHash)(),
|
||||
[codeHash, onShowDeploy]
|
||||
);
|
||||
|
||||
const _onDeployConstructor = useCallback(
|
||||
(constructorIndex = 0): void => {
|
||||
codeHash && onShowDeploy && onShowDeploy(codeHash, constructorIndex)();
|
||||
},
|
||||
(constructorIndex = 0) => codeHash && onShowDeploy && onShowDeploy(codeHash, constructorIndex)(),
|
||||
[codeHash, onShowDeploy]
|
||||
);
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ function Call (props: Props): React.ReactElement<Props> | null {
|
||||
);
|
||||
|
||||
const _constructTx = useCallback(
|
||||
(): any[] => {
|
||||
(): unknown[] => {
|
||||
if (!accountId || !callMessage || !callMessage.fn || !callContract || !callContract.address) {
|
||||
return [];
|
||||
}
|
||||
@ -102,14 +102,12 @@ function Call (props: Props): React.ReactElement<Props> | null {
|
||||
);
|
||||
|
||||
const _onClearOutcomes = useCallback(
|
||||
(): void => setOutcomes([]),
|
||||
() => setOutcomes([]),
|
||||
[]
|
||||
);
|
||||
|
||||
const _onClearOutcome = useCallback(
|
||||
(outcomeIndex: number) => (): void => {
|
||||
setOutcomes(outcomes.slice(0, outcomeIndex).concat(outcomes.slice(outcomeIndex + 1)));
|
||||
},
|
||||
(outcomeIndex: number) => () => setOutcomes(outcomes.slice(0, outcomeIndex).concat(outcomes.slice(outcomeIndex + 1))),
|
||||
[outcomes]
|
||||
);
|
||||
|
||||
|
||||
@ -2,8 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { StringOrNull, VoidFn } from '@polkadot/react-components/types';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { CodecArg } from '@polkadot/types/types';
|
||||
import { CodeStored } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -73,38 +74,29 @@ function Deploy ({ allCodes, basePath, codeHash, constructorIndex = 0, isOpen, o
|
||||
return [];
|
||||
}
|
||||
|
||||
return contractAbi.abi.contract.constructors.map(
|
||||
(constr, index) => {
|
||||
return {
|
||||
key: `${index}`,
|
||||
text: (
|
||||
<MessageSignature
|
||||
asConstructor
|
||||
message={constr}
|
||||
/>
|
||||
),
|
||||
value: `${index}`
|
||||
};
|
||||
});
|
||||
return contractAbi.abi.contract.constructors.map((message, index) => ({
|
||||
key: `${index}`,
|
||||
text: (
|
||||
<MessageSignature
|
||||
asConstructor
|
||||
message={message}
|
||||
/>
|
||||
),
|
||||
value: `${index}`
|
||||
}));
|
||||
},
|
||||
[contractAbi]
|
||||
);
|
||||
|
||||
const [params, setParams] = useState<any[]>(
|
||||
contractAbi && constructorIndex >= 0 ? contractAbi.abi.contract.constructors[constructorIndex].args : []
|
||||
);
|
||||
const [params, setParams] = useState<unknown[]>(contractAbi && constructorIndex >= 0 ? contractAbi.abi.contract.constructors[constructorIndex].args : []);
|
||||
|
||||
useEffect(
|
||||
(): void => {
|
||||
setParams(contractAbi ? contractAbi.abi.contract.constructors[constructorIndex].args : []);
|
||||
},
|
||||
() => setParams(contractAbi ? contractAbi.abi.contract.constructors[constructorIndex].args : []),
|
||||
[constructorIndex, contractAbi]
|
||||
);
|
||||
|
||||
useEffect(
|
||||
(): void => {
|
||||
setName(t(defaultContractName(code.json.name)));
|
||||
},
|
||||
() => setName(t(defaultContractName(code.json.name))),
|
||||
[code, setName, t]
|
||||
);
|
||||
|
||||
@ -114,7 +106,7 @@ function Deploy ({ allCodes, basePath, codeHash, constructorIndex = 0, isOpen, o
|
||||
return [];
|
||||
}
|
||||
|
||||
return [endowment, weight, codeHash, contractAbi.constructors[constructorIndex](...params)];
|
||||
return [endowment, weight, codeHash, contractAbi.constructors[constructorIndex](...(params as CodecArg[]))];
|
||||
},
|
||||
[codeHash, constructorIndex, contractAbi, endowment, params, weight]
|
||||
);
|
||||
|
||||
@ -51,10 +51,9 @@ function CodeRow ({ buttons, children, className, code: { json }, isInline, with
|
||||
|
||||
const _onSaveTags = useCallback(
|
||||
(): void => {
|
||||
if (codeHash) {
|
||||
contracts.saveCode(createType(registry, 'Hash', codeHash), { tags })
|
||||
.catch((e): void => console.error(e));
|
||||
}
|
||||
codeHash && contracts
|
||||
.saveCode(createType(registry, 'Hash', codeHash), { tags })
|
||||
.catch((e): void => console.error(e));
|
||||
},
|
||||
[codeHash, tags]
|
||||
);
|
||||
|
||||
@ -29,7 +29,7 @@ function Params ({ isDisabled, onChange, onEnter, params: propParams }: Props):
|
||||
}, [propParams]);
|
||||
|
||||
const _onChange = useCallback(
|
||||
(values: RawParams) => onChange(values.map(({ value }): any => value)),
|
||||
(values: RawParams) => onChange(values.map(({ value }) => value)),
|
||||
[onChange]
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user