import { Form , Input } from 'antd' ; import React from 'react' ; import { contexts , MintParser , tryParseKey } from '@oyster/common' ; const { useConnection } = contexts . Connection ; export function MintFormItem ( { name , label , required = true , onChange , } ) { const connection = useConnection ( ) ; const mintValidator = async ( rule , value ) => { if ( rule . required && ! value ) { throw new Error ( `Please provide a ${ label }` ) ; } else { const pubkey = tryParseKey ( value ) ; if ( ! pubkey ) { throw new Error ( 'Provided value is not a valid mint address' ) ; } await connection . getAccountInfo ( pubkey ) . then ( data => { if ( ! data ) { throw new Error ( 'Account not found' ) ; } try { MintParser ( pubkey , data ) ; } catch { throw new Error ( 'Account is not a valid mint' ) ; } } ) ; } } ; return ( < Form . Item name = { name } label = { label } rules = { [ { required : required , validator : mintValidator } ] } > < Input allowClear = { true } onChange = { e => onChange && onChange ( e . target . value ) } /> < /Form.Item>); }