Fix TS types

This commit is contained in:
Mati Dastugue 2020-06-19 14:24:28 -03:00
parent 45ca501c60
commit 4241d1fa96
6 changed files with 26 additions and 25 deletions

View File

@ -30,7 +30,7 @@ export const required = (value?: string) => {
export const mustBeInteger = (value: string) => export const mustBeInteger = (value: string) =>
!Number.isInteger(Number(value)) || value.includes('.') ? 'Must be an integer' : undefined !Number.isInteger(Number(value)) || value.includes('.') ? 'Must be an integer' : undefined
export const mustBeFloat = (value: string) => (value && Number.isNaN(Number(value)) ? 'Must be a number' : undefined) export const mustBeFloat = (value: string) => (value && Number.isNaN(Number(value)) ? 'Must be a number' : undefined)
export const greaterThan = (min: number | string) => (value: string) => { export const greaterThan = (min: number | string) => (value: string) => {
if (Number.isNaN(Number(value)) || Number.parseFloat(value) > Number(min)) { if (Number.isNaN(Number(value)) || Number.parseFloat(value) > Number(min)) {

View File

@ -59,12 +59,12 @@ const SendModal = ({ activeScreenType, isOpen, onClose, recipientAddress, select
setTx(txInfo) setTx(txInfo)
} }
const handleContractInteractionCreation = (contractInteractionInfo, submit) => { const handleContractInteractionCreation = (contractInteractionInfo: any, submit: boolean): void => {
setTx(contractInteractionInfo) setTx(contractInteractionInfo)
if (submit) setActiveScreen('contractInteractionReview') if (submit) setActiveScreen('contractInteractionReview')
} }
const handleCustomTxCreation = (customTxInfo, submit) => { const handleCustomTxCreation = (customTxInfo: any, submit: boolean): void => {
setTx(customTxInfo) setTx(customTxInfo)
if (submit) setActiveScreen('reviewCustomTx') if (submit) setActiveScreen('reviewCustomTx')
} }
@ -74,7 +74,7 @@ const SendModal = ({ activeScreenType, isOpen, onClose, recipientAddress, select
setTx(txInfo) setTx(txInfo)
} }
const handleSwitchMethod = () => { const handleSwitchMethod = (): void => {
setIsABI(!isABI) setIsABI(!isABI)
} }

View File

@ -50,7 +50,7 @@ const ContractInteractionReview = ({ onClose, onPrev, tx }: Props) => {
useEffect(() => { useEffect(() => {
let isCurrent = true let isCurrent = true
const estimateGas = async () => { const estimateGas = async (): Promise<void> => {
const { fromWei, toBN } = getWeb3().utils const { fromWei, toBN } = getWeb3().utils
const txData = tx.data ? tx.data.trim() : '' const txData = tx.data ? tx.data.trim() : ''

View File

@ -68,7 +68,7 @@ const ReviewCustomTx = ({ onClose, onPrev, tx }: Props) => {
} }
}, [safeAddress, tx.data, tx.contractAddress]) }, [safeAddress, tx.data, tx.contractAddress])
const submitTx = async () => { const submitTx = async (): Promise<void> => {
const web3 = getWeb3() const web3 = getWeb3()
const txRecipient = tx.contractAddress const txRecipient = tx.contractAddress
const txData = tx.data ? tx.data.trim() : '' const txData = tx.data ? tx.data.trim() : ''

View File

@ -33,10 +33,16 @@ import AddressBookInput from 'src/routes/safe/components/Balances/SendModal/scre
import { safeSelector } from 'src/routes/safe/store/selectors' import { safeSelector } from 'src/routes/safe/store/selectors'
import { sm } from 'src/theme/variables' import { sm } from 'src/theme/variables'
export interface CreatedTx {
contractAddress: string
data: string
value: string | number
}
type Props = { type Props = {
initialValues: { contractAddress?: string } initialValues: { contractAddress?: string }
onClose: () => void onClose: () => void
onNext: (any, submit: boolean) => void onNext: (tx: CreatedTx, submit: boolean) => void
isABI: boolean isABI: boolean
switchMethod: () => void switchMethod: () => void
contractAddress: string contractAddress: string
@ -44,14 +50,7 @@ type Props = {
const useStyles = makeStyles(styles) const useStyles = makeStyles(styles)
const SendCustomTx: React.FC<Props> = ({ const SendCustomTx: React.FC<Props> = ({ initialValues, onClose, onNext, contractAddress, switchMethod, isABI }) => {
initialValues,
onClose,
onNext,
contractAddress,
switchMethod,
isABI,
}: Props) => {
const classes = useStyles() const classes = useStyles()
const { ethBalance } = useSelector(safeSelector) const { ethBalance } = useSelector(safeSelector)
const [qrModalOpen, setQrModalOpen] = useState<boolean>(false) const [qrModalOpen, setQrModalOpen] = useState<boolean>(false)
@ -59,15 +58,8 @@ const SendCustomTx: React.FC<Props> = ({
address: contractAddress || initialValues.contractAddress, address: contractAddress || initialValues.contractAddress,
name: '', name: '',
}) })
const [pristine, setPristine] = useState<boolean>(true)
const [isValidAddress, setIsValidAddress] = useState<boolean>(true) const [isValidAddress, setIsValidAddress] = useState<boolean>(true)
React.useMemo(() => {
if (selectedEntry === null && pristine) {
setPristine(false)
}
}, [selectedEntry, pristine])
const saveForm = async (values) => { const saveForm = async (values) => {
await handleSubmit(values, false) await handleSubmit(values, false)
switchMethod() switchMethod()
@ -108,9 +100,15 @@ const SendCustomTx: React.FC<Props> = ({
</IconButton> </IconButton>
</Row> </Row>
<Hairline /> <Hairline />
<GnoForm formMutators={formMutators} initialValues={initialValues} onSubmit={handleSubmit}> <GnoForm
formMutators={formMutators}
initialValues={initialValues}
subscription={{ submitting: true, pristine: true, values: true }}
onSubmit={handleSubmit}
>
{(...args) => { {(...args) => {
const mutators = args[3] const mutators = args[3]
const pristine = args[2].pristine
let shouldDisableSubmitButton = !isValidAddress let shouldDisableSubmitButton = !isValidAddress
if (selectedEntry) { if (selectedEntry) {
shouldDisableSubmitButton = !selectedEntry.address shouldDisableSubmitButton = !selectedEntry.address

View File

@ -58,12 +58,15 @@ const ContractInteraction: React.FC<ContractInteractionProps> = ({
} }
}, [contractAddress, initialValues.contractAddress]) }, [contractAddress, initialValues.contractAddress])
const saveForm = async (values) => { const saveForm = async (values: CreatedTx): Promise<void> => {
await handleSubmit(values, false) await handleSubmit(values, false)
switchMethod() switchMethod()
} }
const handleSubmit = async ({ contractAddress, selectedMethod, value, ...values }, submit = true) => { const handleSubmit = async (
{ contractAddress, selectedMethod, value, ...values },
submit = true,
): Promise<void | any> => {
if (value || (contractAddress && selectedMethod)) { if (value || (contractAddress && selectedMethod)) {
try { try {
const txObject = createTxObject(selectedMethod, contractAddress, values) const txObject = createTxObject(selectedMethod, contractAddress, values)