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

View File

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

View File

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

View File

@ -58,12 +58,15 @@ const ContractInteraction: React.FC<ContractInteractionProps> = ({
}
}, [contractAddress, initialValues.contractAddress])
const saveForm = async (values) => {
const saveForm = async (values: CreatedTx): Promise<void> => {
await handleSubmit(values, false)
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)) {
try {
const txObject = createTxObject(selectedMethod, contractAddress, values)