import { Injectable } from '@angular/core' ; import { Web3WalletService } from '../web3-wallet.service' ; @ Injectable ( ) export class TokenDistributionEventService { protected instance : any ; constructor ( protected web3Wallet ) { } async buy ( ethAmount , rate , gasPriceGwei = this . web3Wallet . config . default_gas_price || 1 , message = '' ) { if ( this . web3Wallet . isUnavailable ( ) ) { throw new Error ( 'No Ethereum wallets available on your browser.' ) ; } else if ( ! ( await this . web3Wallet . unlock ( ) ) ) { throw new Error ( 'Your Ethereum wallet is locked or connected to another network.' ) ; } let wallet = await this . web3Wallet . getCurrentWallet ( true ) ; if ( ! wallet ) { throw new Error ( "Client is locked, there are no wallets available, or you're on a different network" ) ; } return this . web3Wallet . sendTransaction ( { from : wallet , to : this . web3Wallet . config . token_distribution_event_address , value : this . web3Wallet . toWei ( ethAmount , 'ether' ) , gasPrice : this . web3Wallet . toWei ( gasPriceGwei , 'gwei' ) , gasLimit : 210000 , data : '0x' , } , `purchase of ${ ethAmount } ETH worth Minds Tokens. ${ message }` . trim ( ) ) ; } static _ ( web3Wallet ) { return new TokenDistributionEventService ( web3Wallet ) ; } }