ethers.utils.isAddress(v) ? true : `Invalid address`, checkMyAccount: (v) => v !== userData?.account ? true : `Transfer to your own wallet is not possible.`, }, }}"> ethers.utils.isAddress(v) ? true : `Invalid address`, checkMyAccount: (v) => v !== userData?.account ? true : `Transfer to your own wallet is not possible.`, }, }}"> ethers.utils.isAddress(v) ? true : `Invalid address`, checkMyAccount: (v) => v !== userData?.account ? true : `Transfer to your own wallet is not possible.`, }, }}">
https://github.com/jquense/yup
<Controller
name="to"
control={control}
rules={{
required: {
value: true,
message:`Receiver address is required`
},
validate: {
checkEthers: (v) =>
ethers.utils.isAddress(v) ? true : `Invalid address`,
checkMyAccount: (v) =>
v !== userData?.account
? true
: `Transfer to your own wallet is not possible.`,
},
}}
→
const sendToSchema = () => {
return yup.object().shape({
to: yup
.string()
.required(`Receiver address is required`)
.test(`checkEthers`, `Invalid address`, (value) => {
return ethers.utils.isAddress(value);
})
.test(
`checkMyAccount`,
`Transfer to your own wallet is not possible`,
(value, { parent }) => {
return value !== parent.userData?.account;
},
),
});
};