import * as React from "react" ; import { CivilContext , ICivilContext } from "../../context/CivilContext" ; import { CurrencyConverter } from "../../CurrencyConverter/CurrencyConverter" ; export interface UniswapCvlEthConverterProps { onConversion ( cvlValue , ethValue ) : void ; } export class UniswapCvlEthConverter extends React . Component < UniswapCvlEthConverterProps , any > { public static contextType : React . Context < ICivilContext > = CivilContext ; public constructor ( props ) { super ( props ) ; } public render ( ) { return ( < CurrencyConverter currencyCodeFrom = "CVL" currencyLabelFrom = "Enter amount of CVL to sell" currencyCodeTo = "ETH" currencyLabelTo = "Estimated ETH from sale" doConversion = { async ( cvlAmount ) => this . convertToETH ( cvlAmount ) } onConversion = { ( cvlValue , ethValue ) => this . props . onConversion ( cvlValue , ethValue ) } />); } private async convertToETH ( cvlAmount ) { const uniswap = this . context . uniswap ; const bn = uniswap . parseEther ( cvlAmount . toString ( ) ) ; const result = await uniswap . quoteCVLToETH ( bn ) ; return uniswap . weiToEtherNumber ( result ) ; } }