HenryNguyen5 41f8ab8966 Auto token add (#1808)
* Add support for decimal and symbol getters

* Make custom token form interactive via address lookup

* Add balance field, improve error handling

* Fix lint errors

* Fix erc20 interface

* Expand method name

* Normalize parameter name

* Remove extra variable

* Stricten typing for decimals

* Use common input field between decimal and symbol fields

* use mycrypto-nano-result
2018-06-15 16:10:30 -05:00

40 lines
1.2 KiB
TypeScript

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<string>): void;
}
export class SymbolField extends React.Component<OwnProps> {
public render() {
return (
<FieldInput
fieldName={translateRaw('TOKEN_SYMBOL')}
fieldToFetch={'symbol'}
shouldEnableAutoField={req => !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<string> = validSymbol
? Result.from({ res: userInput })
: Result.from({ err: 'A token with this symbol already exists' });
return symbol;
};
}