add decorator to extract eth address from ENS for contract address
This commit is contained in:
parent
3ac845106b
commit
78682a90af
|
@ -18,7 +18,7 @@ import Header from './Header'
|
||||||
import MethodsDropdown from './MethodsDropdown'
|
import MethodsDropdown from './MethodsDropdown'
|
||||||
import RenderInputParams from './RenderInputParams'
|
import RenderInputParams from './RenderInputParams'
|
||||||
import RenderOutputParams from './RenderOutputParams'
|
import RenderOutputParams from './RenderOutputParams'
|
||||||
import { abiExtractor, createTxObject, formMutators, handleSubmitError, isReadMethod } from './utils'
|
import { abiExtractor, createTxObject, formMutators, handleSubmitError, isReadMethod, ensResolver } from './utils'
|
||||||
|
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ const ContractInteraction = ({ contractAddress, initialValues, onClose, onNext }
|
||||||
<Header onClose={onClose} subTitle="1 of 2" title="Contract Interaction" />
|
<Header onClose={onClose} subTitle="1 of 2" title="Contract Interaction" />
|
||||||
<Hairline />
|
<Hairline />
|
||||||
<GnoForm
|
<GnoForm
|
||||||
decorators={[abiExtractor]}
|
decorators={[abiExtractor, ensResolver]}
|
||||||
formMutators={formMutators}
|
formMutators={formMutators}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
|
|
|
@ -6,8 +6,9 @@ import { mustBeEthereumAddress, mustBeEthereumContractAddress } from 'src/compon
|
||||||
import { getNetwork } from 'src/config'
|
import { getNetwork } from 'src/config'
|
||||||
import { getConfiguredSource } from 'src/logic/contractInteraction/sources'
|
import { getConfiguredSource } from 'src/logic/contractInteraction/sources'
|
||||||
import { AbiItemExtended } from 'src/logic/contractInteraction/sources/ABIService'
|
import { AbiItemExtended } from 'src/logic/contractInteraction/sources/ABIService'
|
||||||
import { getWeb3 } from 'src/logic/wallets/getWeb3'
|
import { getAddressFromENS, getWeb3 } from 'src/logic/wallets/getWeb3'
|
||||||
import { TransactionReviewType } from '../Review'
|
import { TransactionReviewType } from '../Review'
|
||||||
|
import { isValidEnsName } from 'src/logic/wallets/ethAddresses'
|
||||||
|
|
||||||
export const NO_CONTRACT = 'no contract'
|
export const NO_CONTRACT = 'no contract'
|
||||||
|
|
||||||
|
@ -29,6 +30,26 @@ export const abiExtractor = createDecorator({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const ensResolver = createDecorator({
|
||||||
|
field: 'contractAddress',
|
||||||
|
updates: {
|
||||||
|
contractAddress: async (contractAddress) => {
|
||||||
|
try {
|
||||||
|
const resolvedAddress = isValidEnsName(contractAddress) && (await getAddressFromENS(contractAddress))
|
||||||
|
|
||||||
|
if (resolvedAddress) {
|
||||||
|
return resolvedAddress
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message)
|
||||||
|
return contractAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
return contractAddress
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
export const formMutators = {
|
export const formMutators = {
|
||||||
setMax: (args, state, utils) => {
|
setMax: (args, state, utils) => {
|
||||||
utils.changeValue(state, 'value', () => args[0])
|
utils.changeValue(state, 'value', () => args[0])
|
||||||
|
|
Loading…
Reference in New Issue