import * as React from "react" ; import makeAsyncScriptLoader from "react-async-script" ; import { airswapScript , getAirswapCvlAddress , getAirswapEnv } from "@joincivil/utils" ; import { Button } from "../../Button" ; export interface BuyCVLProps { buyFromAddress ? : string ; buyCVLBtnText ? : string | JSX . Element ; network : string ; amount ? : number ; onClick ? ( index ) : void ; onComplete ( ) : void ; } class BuyCVLBase extends React . Component < BuyCVLProps > { public render ( ) { return < Button onClick = { ( ) => this . displayAirswap ( ) } > { this . props . buyCVLBtnText || "Buy CVL" } < /Button>; } private displayAirswap ( ) { const environment = getAirswapEnv ( this . props . network ) ; const tokenAddress = getAirswapCvlAddress ( this . props . network ) ; const buyFromAddress = this . props . buyFromAddress || "" ; const amount = this . props . amount || 0 ; const amountString = Math . ceil ( amount ) . toString ( ) + "000000000000000000" ; console . log ( "amountString" , amountString ) ; window . AirSwap . Trader . render ( { mode : "buy" , env : environment , token : tokenAddress , address : buyFromAddress , onComplete : ( ) => { this . props . onComplete ( ) ; } , onCancel : ( ) => { console . info ( "Trade cancelled" ) ; } , } , "body" ) ; } } export const AirswapBuyCVL = makeAsyncScriptLoader ( airswapScript ) ( BuyCVLBase ) ;