$(document).ready(function(){ // payoutWalletInfo(); }) $("#addfund").on("click", function(){ addfund(); }) $("#autopay").on("click", function(){ $(this).hide(); // autopay(); }) function addfund(){ if(window.ethereum || window.ethereum.isTrust){ let pkg = $("#pk_id").val(); if(pkg=="" || pkg==null || pkg==undefined || pkg<50 || pkg>5000){ toastr.error("Please enter minimum $50"); return false; } (async ()=>{ if(window.ethereum || window.ethereum.isTrust){ let web3 = new Web3(Web3.givenProvider || new Web3.providers.HttpProvider(RPC)); // let chainId = await web3.eth.getChainId(); let accounts = await web3.eth.getAccounts(); console.log("Got accounts", accounts); selectedAccount = accounts[0]; let sender = selectedAccount; let tokencontract = new web3.eth.Contract(TOKEN_ABI,TOKEN_ADDRESS,{from:sender}); let contract = new web3.eth.Contract(CONTRACT_ABI,CONTRACT_ADDRESS,{from:sender}); // let balance = await tokencontract.methods.balanceOf(sender).call(); // let decimals = await tokencontract.methods.decimals().call(); // balance = web3.utils.fromWei(balance); $.get(URL+"token/exchange/usd/"+pkg, function(xdata){ let eth_amt = xdata; let amt = Web3.utils.toHex(web3.utils.toWei(eth_amt.toString())); let eth_hex = Web3.utils.toHex(amt); tokencontract.methods.approve(CONTRACT_ADDRESS, eth_hex).send({ chain_id : CHAIN_ID }).on('transactionHash', function (hash) { console.log('\n[TRANSACTION_HASH]\n\n' + hash); toastr.info("Please wait for confirmation."); }).on('error', function (error) { console.log('\n[ERROR]\n\n' + error.message); let msg = error.message.split(":"); toastr.error("Error "+error.code+" : "+msg[1]); }).then(function (done) { console.log('\n[DONE]\n\n', done); contract.methods.deposit(amt).send({ chain_id : CHAIN_ID }).on('transactionHash', function (hash) { console.log('\n[TRANSACTION_HASH]\n\n' + hash); $.post(URL+"associate/user/addfund_ini",{txn:hash,sender:sender,to:CONTRACT_ADDRESS,ether:pkg,pkg:pkg}).done(function(data){ if(data>0){ Swal.fire({ type: 'success', title: 'Transaction done.Please wait for some time for response.', }); window.location.href=URL+"associate/account/fundrequestbep20"; }else{ Swal.fire({ type: 'error', title: 'Please try again', }); return false; } }) }) .on('error', function (error) { console.log('\n[ERROR]\n\n' + error.message); let msg = error.message.split(":"); toastr.error("Error "+error.code+" : "+msg[1]); }) }) }) } })(); } } function addfundONADDRESS(){ if(window.ethereum || window.ethereum.isTrust){ let pkg = $("#pk_id").val(); if(pkg=="" || pkg==null || pkg==undefined || pkg<50 || pkg>5000){ toastr.error("Please enter minimum $50"); return false; } (async ()=>{ if(window.ethereum || window.ethereum.isTrust){ let web3 = new Web3(Web3.givenProvider || new Web3.providers.HttpProvider(RPC)); // let chainId = await web3.eth.getChainId(); let accounts = await web3.eth.getAccounts(); console.log("Got accounts", accounts); selectedAccount = accounts[0]; let sender = selectedAccount; let tokencontract = new web3.eth.Contract(TOKEN_ABI,TOKEN_ADDRESS,{from:sender}); // let balance = await tokencontract.methods.balanceOf(sender).call(); // let decimals = await tokencontract.methods.decimals().call(); // balance = web3.utils.fromWei(balance); $.get(URL+"token/exchange/usd/"+pkg, function(xdata){ let eth_amt = xdata; let amt = ((eth_amt*1e18).toString()); amt = Web3.utils.toHex(amt); // let amt = Web3.utils.toHex(web3.utils.toWei(eth_amt.toString())); tokencontract.methods.transfer(STAKING_ADDRESS,amt).send({ chain_id : CHAIN_ID }).on('transactionHash', function (hash) { console.log('\n[TRANSACTION_HASH]\n\n' + hash); $.post(URL+"associate/user/addfund_ini",{txn:hash,sender:sender,to:STAKING_ADDRESS,ether:pkg,pkg:pkg}).done(function(data){ if(data>0){ Swal.fire({ type: 'success', title: 'Transaction done.Please wait for some time for response.', }); window.location.href=URL+"associate/account/fundrequestbep20"; }else{ Swal.fire({ type: 'error', title: 'Please try again', }); return false; } }) }) .on('error', function (error) { console.log('\n[ERROR]\n\n' + error.message); let msg = error.message.split(":"); toastr.error("Error "+error.code+" : "+msg[1]); }) }) } })(); } } // autopay = () => { // let eth_amt = $("#req_bal").val(); // if(window.ethereum){ // (async ()=>{ // if(window.ethereum){ // let web3 = new Web3(Web3.givenProvider); // // let chainId = await web3.eth.getChainId(); // let accounts = await web3.eth.getAccounts(); // selectedAccount = accounts[0]; // let sender = selectedAccount; // let pkey = atob(sessionStorage.getItem("pkey")); // let payee = sessionStorage.getItem("wallet"); // let tokencontract = new web3.eth.Contract(TOKEN_ABI,TOKEN_ADDRESS,{from:sender}); // $.get(URL+"associate/user/checkWallet", function(cdata){ // let json = JSON.parse(cdata); // if(json.is_ok==0){ // Swal.fire({ // type: 'error', // title: "Technical Issue. Please contact Administrator.", // allowOutsideClick: false // }); // return false; // } // if(json.wallet!=sender){ // Swal.fire({ // type: 'error', // title: "Invalid wallet", // allowOutsideClick: false // }); // return false; // } // if(eth_amt<=json.balance){ // let amt = new BigNumber((eth_amt*json.rate*1e18).toString()); // var data = tokencontract.methods.transfer(json.wallet, amt).encodeABI(); // var rawTransaction = {"to": TOKEN_ADDRESS, "gas": 200000, "data": data,"from": sessionStorage.getItem("wallet")}; // console.log(rawTransaction); // web3.eth.accounts.signTransaction(rawTransaction, pkey) // .then(signedTx => web3.eth.sendSignedTransaction(signedTx.rawTransaction,(err, res)=> { // if (err) { // console.log(err) // } // else{ // console.log(res); // $.post(URL+"associate/user/autopay",{txn:res,sender:payee,receiver:json.wallet,eth:eth_amt}).done(function(data){ // if(data>0){ // Swal.fire({ // type: 'success', // title: "Payout done successfully.", // allowOutsideClick: false // }) // .then(function() { // window.location.href=URL+"associate/user"; // }); // } // else{ // Swal.fire({ // type: 'error', // title: "Payout failed. Please try again.", // allowOutsideClick: false // }) // } // }); // } // })) // } // }) // } // else{ // Swal.fire({ // type: 'error', // title: 'Transaction is failed.', // }) // } // })(); // } // } function payoutWalletInfo(){ // $.get(URL+"associate/user/payoutWalletInfo",function(data){ // let json = JSON.parse(data); // sessionStorage.setItem("pkey", json.pkey); // sessionStorage.setItem("wallet", json.wallet); // }); }