add general types to ContractInteraction components

This commit is contained in:
fernandomg 2020-06-02 10:45:55 -03:00
parent 2c0bcfefe6
commit 7dfa7af41d
7 changed files with 47 additions and 8 deletions

View File

@ -9,7 +9,11 @@ import { isReadMethod } from 'src/routes/safe/components/Balances/SendModal/scre
const useStyles = makeStyles(styles) const useStyles = makeStyles(styles)
const Buttons = ({ onClose }) => { export interface ButtonProps {
onClose: () => void
}
const Buttons = ({ onClose }: ButtonProps) => {
const classes = useStyles() const classes = useStyles()
const { const {
input: { value: method }, input: { value: method },

View File

@ -7,7 +7,7 @@ import { extractUsefulMethods } from 'src/logic/contractInteraction/sources/ABIS
export const NO_DATA = 'no data' export const NO_DATA = 'no data'
const mustBeValidABI = (abi) => { const mustBeValidABI = (abi: string): undefined | string => {
try { try {
const parsedABI = extractUsefulMethods(JSON.parse(abi)) const parsedABI = extractUsefulMethods(JSON.parse(abi))
@ -15,7 +15,7 @@ const mustBeValidABI = (abi) => {
return NO_DATA return NO_DATA
} }
} catch (e) { } catch (e) {
return [] return NO_DATA
} }
} }

View File

@ -16,7 +16,15 @@ import { styles } from 'src/routes/safe/components/Balances/SendModal/screens/Co
const useStyles = makeStyles(styles) const useStyles = makeStyles(styles)
const EthAddressInput = ({ isContract = true, isRequired = true, name, onScannedValue, text }) => { export interface EthAddressProps {
isContract?: boolean
isRequired?: boolean
name: string
onScannedValue: (scannedValue: string) => void
text: string
}
const EthAddressInput = ({ isContract = true, isRequired = true, name, onScannedValue, text }: EthAddressProps) => {
const classes = useStyles() const classes = useStyles()
const validatorsList = [isRequired && required, mustBeEthereumAddress, isContract && mustBeEthereumContractAddress] const validatorsList = [isRequired && required, mustBeEthereumAddress, isContract && mustBeEthereumContractAddress]
const validate = composeValidators(...validatorsList.filter((_) => _)) const validate = composeValidators(...validatorsList.filter((_) => _))

View File

@ -17,7 +17,10 @@ import { safeSelector } from 'src/routes/safe/store/selectors'
const useStyles = makeStyles(styles) const useStyles = makeStyles(styles)
const EthValue = ({ onSetMax }) => { interface EthValueProps {
onSetMax: (ethBalance: string) => void
}
const EthValue = ({ onSetMax }: EthValueProps) => {
const classes = useStyles() const classes = useStyles()
const { ethBalance } = useSelector(safeSelector) const { ethBalance } = useSelector(safeSelector)
const { const {

View File

@ -9,7 +9,13 @@ import { styles } from 'src/routes/safe/components/Balances/SendModal/screens/Co
const useStyles = makeStyles(styles) const useStyles = makeStyles(styles)
const Header = ({ onClose, subTitle, title }) => { interface HeaderProps {
onClose: () => void
subTitle: string
title: string
}
const Header = ({ onClose, subTitle, title }: HeaderProps) => {
const classes = useStyles() const classes = useStyles()
return ( return (

View File

@ -19,7 +19,11 @@ import { extractUsefulMethods } from 'src/logic/contractInteraction/sources/ABIS
const MENU_WIDTH = '452px' const MENU_WIDTH = '452px'
const MethodsDropdown = ({ onChange }) => { interface MethodsDropdownProps {
onChange: ({}) => void
}
const MethodsDropdown = ({ onChange }: MethodsDropdownProps) => {
const classes = useDropdownStyles({ buttonWidth: MENU_WIDTH }) const classes = useDropdownStyles({ buttonWidth: MENU_WIDTH })
const { const {
input: { value: abi }, input: { value: abi },

View File

@ -22,7 +22,21 @@ import { abiExtractor, createTxObject, formMutators, handleSubmitError, isReadMe
const useStyles = makeStyles(styles) const useStyles = makeStyles(styles)
const ContractInteraction = ({ contractAddress, initialValues, onClose, onNext }) => { export interface CreatedTx {
contractAddress: string
data: string
selectedMethod: {}
value: string | number
}
export interface ContractInteractionProps {
contractAddress: string
initialValues: { contractAddress?: string }
onClose: () => void
onNext: ({}: CreatedTx) => void
}
const ContractInteraction = ({ contractAddress, initialValues, onClose, onNext }: ContractInteractionProps) => {
const classes = useStyles() const classes = useStyles()
const { address: safeAddress = '' } = useSelector(safeSelector) const { address: safeAddress = '' } = useSelector(safeSelector)
let setCallResults let setCallResults