Set address book suggestions

This commit is contained in:
Mati Dastugue 2020-06-23 10:36:30 -03:00
parent 6240afc07a
commit 6d2638410f
3 changed files with 39 additions and 13 deletions

View File

@ -50,7 +50,7 @@ const AddressBookInput = ({
}: any) => { }: any) => {
const addressBook = useSelector(getAddressBookListSelector) const addressBook = useSelector(getAddressBookListSelector)
const [isValidForm, setIsValidForm] = useState(true) const [isValidForm, setIsValidForm] = useState(true)
const [validationText, setValidationText] = useState<any>(true) const [validationText, setValidationText] = useState<any>('')
const [inputTouched, setInputTouched] = useState(false) const [inputTouched, setInputTouched] = useState(false)
const [blurred, setBlurred] = useState(pristine) const [blurred, setBlurred] = useState(pristine)
const [adbkList, setADBKList] = useState(List([])) const [adbkList, setADBKList] = useState(List([]))

View File

@ -1,7 +1,8 @@
import { makeStyles } from '@material-ui/core/styles' import { makeStyles } from '@material-ui/core/styles'
import React from 'react' import React, { useState } from 'react'
import { ScanQRWrapper } from 'src/components/ScanQRModal/ScanQRWrapper' import { ScanQRWrapper } from 'src/components/ScanQRModal/ScanQRWrapper'
import AddressBookInput from 'src/routes/safe/components/Balances/SendModal/screens/AddressBookInput'
import Field from 'src/components/forms/Field' import Field from 'src/components/forms/Field'
import TextField from 'src/components/forms/TextField' import TextField from 'src/components/forms/TextField'
import { import {
@ -22,12 +23,26 @@ export interface EthAddressProps {
name: string name: string
onScannedValue: (scannedValue: string) => void onScannedValue: (scannedValue: string) => void
text: string text: string
value?: string
pristine: boolean
} }
const EthAddressInput = ({ isContract = true, isRequired = true, name, onScannedValue, text }: EthAddressProps) => { const EthAddressInput = ({
isContract = true,
isRequired = true,
name,
onScannedValue,
text,
value,
pristine,
}: 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((_) => _))
const [selectedEntry, setSelectedEntry] = useState<{ address?: string; name?: string } | null>({
address: value,
name: '',
})
const handleScan = (value, closeQrModal) => { const handleScan = (value, closeQrModal) => {
let scannedAddress = value let scannedAddress = value
@ -44,6 +59,7 @@ const EthAddressInput = ({ isContract = true, isRequired = true, name, onScanned
<> <>
<Row margin="md"> <Row margin="md">
<Col xs={11}> <Col xs={11}>
{selectedEntry && selectedEntry.address ? (
<Field <Field
component={TextField} component={TextField}
name={name} name={name}
@ -53,6 +69,15 @@ const EthAddressInput = ({ isContract = true, isRequired = true, name, onScanned
type="text" type="text"
validate={validate} validate={validate}
/> />
) : (
<AddressBookInput
setSelectedEntry={setSelectedEntry}
setIsValidAddress={() => {}}
fieldMutator={onScannedValue}
isCustomTx
pristine={pristine}
/>
)}
</Col> </Col>
<Col center="xs" className={classes} middle="xs" xs={1}> <Col center="xs" className={classes} middle="xs" xs={1}>
<ScanQRWrapper handleScan={handleScan} /> <ScanQRWrapper handleScan={handleScan} />

View File

@ -100,15 +100,16 @@ const ContractInteraction: React.FC<ContractInteractionProps> = ({
> >
{(submitting, validating, rest, mutators) => { {(submitting, validating, rest, mutators) => {
setCallResults = mutators.setCallResults setCallResults = mutators.setCallResults
return ( return (
<> <>
<Block className={classes.formContainer}> <Block className={classes.formContainer}>
<SafeInfo /> <SafeInfo />
<FormDivisor /> <FormDivisor />
<EthAddressInput <EthAddressInput
value={rest.values.contractAddress}
name="contractAddress" name="contractAddress"
onScannedValue={mutators.setContractAddress} onScannedValue={mutators.setContractAddress}
pristine={rest.pristine}
text="Contract Address*" text="Contract Address*"
/> />
<ContractABI /> <ContractABI />