import React from 'react'; import { translateRaw } from 'translations'; import { IGenerateSymbolLookup } from './AddCustomTokenForm'; import { Result } from 'mycrypto-nano-result'; import { FieldInput } from './FieldInput'; interface OwnProps { address?: string; symbolLookup: IGenerateSymbolLookup; onChange(symbol: Result): void; } export class SymbolField extends React.Component { public render() { return ( !req.err()} address={this.props.address} userInputValidator={this.isValidUserInput} fetchedFieldValidator={field => field ? Result.from({ res: field }) : Result.from({ err: 'No Symbol found, please input the token symbol manually' }) } onChange={this.props.onChange} /> ); } private isValidUserInput = (userInput: string) => { const validSymbol = !this.props.symbolLookup[userInput]; const symbol: Result = validSymbol ? Result.from({ res: userInput }) : Result.from({ err: 'A token with this symbol already exists' }); return symbol; }; }