import { toWei } from 'web3-utils' ; import Exchange from '../Exchange' ; export interface ValueTypes { value ? : string ; ether ? : string ; } export interface ExchangeParams extends ValueTypes { account : string ; } export interface EstimateReturn { estimate : string ; estimateInfo ? : null | string ; } interface PairConstructor { assetA : string ; assetB : string ; } export default abstract class Pair { public assetA : string ; public assetB : string ; private _exchange : Exchange | null ; constructor ( { assetA , assetB } ) { this . assetA = assetA ; this . assetB = assetB ; this . _exchange = null ; } abstract exchangeAtoB ( { account , value , ether } ) ; abstract exchangeBtoA ( { account , value , ether } ) ; abstract estimateAtoB ( value ) ; abstract estimateBtoA ( value ) ; setExchange ( newExchange ) { this . _exchange = newExchange ; } getExchange ( ) { if ( ! this . _exchange ) { throw new Error ( 'Exchange not set' ) ; } return this . _exchange ; } _getValue ( { value , ether } ) { if ( ! value && ! ether ) { throw new Error ( 'Must provide value for transfer' ) ; } if ( value ) { return value ; } return toWei ( ether as string , 'ether' ) ; } getLoadingMessage ( ) { return 'Exchanging assets...' ; } }