diff --git a/app/assets/onepager/js/receive.js b/app/assets/onepager/js/receive.js index 60b85662e13..1739f6757dd 100644 --- a/app/assets/onepager/js/receive.js +++ b/app/assets/onepager/js/receive.js @@ -41,7 +41,9 @@ window.onload = function() { } } else if (!$('#forwarding_address').val()) { - $('#forwarding_address').val(web3.eth.coinbase); + web3.eth.getCoinbase(function(_, coinbase) { + $('#forwarding_address').val(coinbase); + }); } $('#network').val(document.web3network); }); diff --git a/app/assets/v2/js/avatar_builder.js b/app/assets/v2/js/avatar_builder.js index 645e7236d36..f8bb55aef65 100644 --- a/app/assets/v2/js/avatar_builder.js +++ b/app/assets/v2/js/avatar_builder.js @@ -200,37 +200,39 @@ function purchaseOption(option, value, target) { to_address = '0x00De4B13153673BCAE2616b67bf822500d325Fc3'; // TODO: make dynamic indicateMetamaskPopup(); - web3.eth.sendTransaction({ - 'from': web3.eth.coinbase, - 'to': to_address, - 'value': cost_wei - }, function(error, result) { - indicateMetamaskPopup(true); - if (error) { - _alert('There was an error.', 'error'); - return; - } - showBusyOverlay(); - _alert('Waiting for tx to mine...', 'info'); - callFunctionWhenTransactionMined(result, function() { - var request_url = '/revenue/attestations/new'; - var txid = result; - var data = { - 'txid': txid, - 'amount': cost_eth, - 'network': document.web3network, - 'from_address': web3.eth.coinbase, - 'to_address': to_address, - 'type': 'avatar', - 'option': option, - 'value': value - }; - - $.post(request_url, data).then(function(result) { - hideBusyOverlay(); - _alert('Success ✅ Loading your purchase now.', 'success'); - setTimeout(function() { - location.reload(); + web3.eth.getCoinbase(function(_, coinbase) { + web3.eth.sendTransaction({ + 'from': coinbase, + 'to': to_address, + 'value': cost_wei + }, function(error, result) { + indicateMetamaskPopup(true); + if (error) { + _alert('There was an error.', 'error'); + return; + } + showBusyOverlay(); + _alert('Waiting for tx to mine...', 'info'); + callFunctionWhenTransactionMined(result, function() { + var request_url = '/revenue/attestations/new'; + var txid = result; + var data = { + 'txid': txid, + 'amount': cost_eth, + 'network': document.web3network, + 'from_address': coinbase, + 'to_address': to_address, + 'type': 'avatar', + 'option': option, + 'value': value + }; + + $.post(request_url, data).then(function(result) { + hideBusyOverlay(); + _alert('Success ✅ Loading your purchase now.', 'success'); + setTimeout(function() { + location.reload(); + }); }); }); }); diff --git a/app/assets/v2/js/event_ethdenver2019/kudos_bulk_receive.js b/app/assets/v2/js/event_ethdenver2019/kudos_bulk_receive.js index bc7f618de10..cd24cd2aced 100644 --- a/app/assets/v2/js/event_ethdenver2019/kudos_bulk_receive.js +++ b/app/assets/v2/js/event_ethdenver2019/kudos_bulk_receive.js @@ -19,7 +19,9 @@ $(document).ready(function() { _alert({ message: gettext('You are not on the right web3 network. Please switch to ') + document.network }, 'error'); $('#receive').attr('disabled', 'disabled'); } else { - $('#forwarding_address').val(web3.eth.coinbase); + web3.eth.getCoinbase(function(_, coinbase) { + $('#forwarding_address').val(coinbase); + }); } }); diff --git a/app/assets/v2/js/pages/bounty_details.js b/app/assets/v2/js/pages/bounty_details.js index 1f78b3dacc0..69c8c522483 100644 --- a/app/assets/v2/js/pages/bounty_details.js +++ b/app/assets/v2/js/pages/bounty_details.js @@ -563,14 +563,14 @@ waitforWeb3(function() { if (typeof document.lastCoinbase == 'undefined') { - try { - // invoke infura synchronous call, if it fails metamask is locked - document.lastCoinbase = web3.eth.coinbase; - } catch (error) { - document.lastCoinbase = null; - // catch error so sentry doesn't alert on metamask call failure - console.log('web3.eth.coinbase could not be loaded'); - } + web3.eth.getCoinbase(function(error, coinbase) { + if (error) { + console.log('web3.eth.coinbase could not be loaded'); + document.lastCoinbase = null; + return; + } + document.lastCoinbase = coinbase; + }); return; } diff --git a/app/assets/v2/js/pages/bounty_request_form.js b/app/assets/v2/js/pages/bounty_request_form.js index a1347c04935..34a57f1742f 100644 --- a/app/assets/v2/js/pages/bounty_request_form.js +++ b/app/assets/v2/js/pages/bounty_request_form.js @@ -3,12 +3,13 @@ var trigger_form_hooks = function() { callFunctionWhenweb3Available( function() { - const addr = web3.eth.coinbase; - const input = $('[name=eth_address]'); + web3.eth.getCoinbase(function(_, addr) { + const input = $('[name=eth_address]'); - if (addr && !input.val()) { - input.val(addr); - } + if (addr && !input.val()) { + input.val(addr); + } + }); } ); }; diff --git a/app/assets/v2/js/pages/bulk_payout.js b/app/assets/v2/js/pages/bulk_payout.js index 645dd158af8..bff7dd9231a 100644 --- a/app/assets/v2/js/pages/bulk_payout.js +++ b/app/assets/v2/js/pages/bulk_payout.js @@ -96,12 +96,14 @@ $(document).ready(function($) { _alert(msg, 'info'); sendTransaction(i + 1); - // tell frontend that this issue has a pending tx - localStorage[$('#issueURL').text()] = JSON.stringify({ - timestamp: timestamp(), - dataHash: null, - issuer: web3.eth.coinbase, - txid: txid + web3.eth.getCoinbase(function(_, coinbase) { + // tell frontend that this issue has a pending tx + localStorage[$('#issueURL').text()] = JSON.stringify({ + timestamp: timestamp(), + dataHash: null, + issuer: coinbase, + txid: txid + }); }); } }; diff --git a/app/assets/v2/js/pages/cancel_bounty/ETH.js b/app/assets/v2/js/pages/cancel_bounty/ETH.js index 4d6a0cf37e1..251c942888e 100644 --- a/app/assets/v2/js/pages/cancel_bounty/ETH.js +++ b/app/assets/v2/js/pages/cancel_bounty/ETH.js @@ -66,56 +66,60 @@ const ethCancelBounty = data => { errormsg = gettext( 'No active funded issue found at this address. Are you sure this is an active funded issue?' ); - } else if (fromAddress != web3.eth.coinbase) { - errormsg = gettext( - 'Only the address that submitted this funded issue may kill the bounty.' - ); } - if (errormsg) { - _alert({ message: errormsg }); - unloading_button($('.js-submit')); - return; - } + web3.eth.getCoinbase(function(_, coinbase) { + if (fromAddress != coinbase) { + errormsg = gettext( + 'Only the address that submitted this funded issue may kill the bounty.' + ); + } - const final_callback = function(error, result) { - indicateMetamaskPopup(true); - const next = function() { - web3.eth.getAccounts(function(_, accounts) { - // setup inter page state - localStorage[issueURL] = JSON.stringify({ - timestamp: timestamp(), - dataHash: null, - issuer: accounts[0], - txid: result + if (errormsg) { + _alert({ message: errormsg }); + unloading_button($('.js-submit')); + return; + } + + const final_callback = function(error, result) { + indicateMetamaskPopup(true); + const next = function() { + web3.eth.getAccounts(function(_, accounts) { + // setup inter page state + localStorage[issueURL] = JSON.stringify({ + timestamp: timestamp(), + dataHash: null, + issuer: accounts[0], + txid: result + }); }); - }); - _alert({ message: gettext('Cancel bounty submitted to web3.') }, 'info'); - setTimeout(() => { - document.location.href = '/funding/details/?url=' + issueURL; - }, 1000); + _alert({ message: gettext('Cancel bounty submitted to web3.') }, 'info'); + setTimeout(() => { + document.location.href = '/funding/details/?url=' + issueURL; + }, 1000); + }; + + if (error) { + console.error('err', error); + _alert({ message: gettext('There was an error') }); + unloading_button($('.js-submit')); + } else { + next(); + } }; - if (error) { - console.error('err', error); - _alert({ message: gettext('There was an error') }); - unloading_button($('.js-submit')); - } else { - next(); - } - }; - - indicateMetamaskPopup(); - web3.eth.getAccounts(function(_, accounts) { - bounty.killBounty( - bountyId, - { - from: accounts[0], - gasPrice: web3.toHex($('#gasPrice').val() * Math.pow(10, 9)) - }, - final_callback - ); + indicateMetamaskPopup(); + web3.eth.getAccounts(function(_, accounts) { + bounty.killBounty( + bountyId, + { + from: accounts[0], + gasPrice: web3.toHex($('#gasPrice').val() * Math.pow(10, 9)) + }, + final_callback + ); + }); }); }; diff --git a/app/assets/v2/js/pages/change_bounty.js b/app/assets/v2/js/pages/change_bounty.js index 1f629d3f1d6..1312ddb62ff 100644 --- a/app/assets/v2/js/pages/change_bounty.js +++ b/app/assets/v2/js/pages/change_bounty.js @@ -310,28 +310,30 @@ $(document).ready(function() { const payFeaturedBounty = function() { indicateMetamaskPopup(); - web3.eth.sendTransaction({ - to: '0x00De4B13153673BCAE2616b67bf822500d325Fc3', - from: web3.eth.coinbase, - value: web3.toWei(ethFeaturedPrice, 'ether'), - gasPrice: web3.toHex(5 * Math.pow(10, 9)), - gas: web3.toHex(318730), - gasLimit: web3.toHex(318730) - }, - function(error, result) { - indicateMetamaskPopup(true); - if (error) { - _alert({ message: gettext('Unable to upgrade to featured bounty. Please try again.') }, 'error'); - console.log(error); - } else { - saveAttestationData( - result, - ethFeaturedPrice, - '0x00De4B13153673BCAE2616b67bf822500d325Fc3', - 'featuredbounty' - ); - saveBountyChanges(); - } + web3.eth.getCoinbase(function(_, coinbase) { + web3.eth.sendTransaction({ + to: '0x00De4B13153673BCAE2616b67bf822500d325Fc3', + from: coinbase, + value: web3.toWei(ethFeaturedPrice, 'ether'), + gasPrice: web3.toHex(5 * Math.pow(10, 9)), + gas: web3.toHex(318730), + gasLimit: web3.toHex(318730) + }, + function(error, result) { + indicateMetamaskPopup(true); + if (error) { + _alert({ message: gettext('Unable to upgrade to featured bounty. Please try again.') }, 'error'); + console.log(error); + } else { + saveAttestationData( + result, + ethFeaturedPrice, + '0x00De4B13153673BCAE2616b67bf822500d325Fc3', + 'featuredbounty' + ); + saveBountyChanges(); + } + }); }); }; diff --git a/app/assets/v2/js/pages/create_bounty/ETH.js b/app/assets/v2/js/pages/create_bounty/ETH.js index 084c1e3b04b..f11cebcaf4c 100644 --- a/app/assets/v2/js/pages/create_bounty/ETH.js +++ b/app/assets/v2/js/pages/create_bounty/ETH.js @@ -3,7 +3,20 @@ * Data is stored on IPFS + the data is stored in * standard bounties contract on the ethereum blockchain */ -const ethCreateBounty = data => { + +const promisify = (fun, params=[]) => { + return new Promise((resolve, reject) => { + fun(...params, (err, data) => { + if (err) { + reject(err); + } else { + resolve(data); + } + }); + }); +}; + +const ethCreateBounty = async (data) => { try { bounty_address(); } catch (exception) { @@ -96,7 +109,7 @@ const ethCreateBounty = data => { // to the node.js package. github.com/ethereum/web3.js const isETH = tokenAddress == '0x0000000000000000000000000000000000000000'; web3.eth.contract(token_abi).at(tokenAddress); - const account = web3.eth.coinbase; + const account = await promisify(web3.eth.getCoinbase); const amountNoDecimal = amount; amount = amount * decimalDivisor; @@ -228,7 +241,7 @@ const ethCreateBounty = data => { if (isETH) { web3.eth.sendTransaction({ to: to_address, - from: web3.eth.coinbase, + from: account, value: web3.toWei(fee, 'ether'), gasPrice: gas_price }, function(error, txnId) { @@ -322,7 +335,7 @@ const ethCreateBounty = data => { indicateMetamaskPopup(); web3.eth.sendTransaction({ to: '0x00De4B13153673BCAE2616b67bf822500d325Fc3', - from: web3.eth.coinbase, + from: web3.account, value: web3.toWei(ethFeaturedPrice, 'ether'), gasPrice: web3.toHex($('#gasPrice').val() * Math.pow(10, 9)), gas: web3.toHex(318730), @@ -369,7 +382,7 @@ const ethCreateBounty = data => { function check_balance_and_alert_user_if_not_enough(tokenAddress, amount, msg) { const token_contract = web3.eth.contract(token_abi).at(tokenAddress); - const from = web3.eth.coinbase; + const from = account; const token_details = tokenAddressToDetails(tokenAddress); const token_decimals = token_details['decimals']; const token_name = token_details['name']; diff --git a/app/assets/v2/js/pages/increase_bounty.js b/app/assets/v2/js/pages/increase_bounty.js index e34ca8d18cd..ef534d80a56 100644 --- a/app/assets/v2/js/pages/increase_bounty.js +++ b/app/assets/v2/js/pages/increase_bounty.js @@ -7,15 +7,30 @@ load_tokens(); const FEE_PERCENTAGE = document.FEE_PERCENTAGE / 100.0; -const is_funder = () => { - if (web3 && web3.eth && web3.coinbase) - return document.is_funder_github_user_same && $('input[name=bountyOwnerAddress]').val() == web3.eth.coinbase; +const promisify = (fun, params = []) => { + return new Promise((resolve, reject) => { + fun(...params, (err, data) => { + if (err) { + reject(err); + } else { + resolve(data); + } + }); + }); +}; + +const is_funder = async() => { + if (web3 && web3.eth && web3.coinbase) { + const coinbase = await promisify(web3.eth.getCoinbase); + + return document.is_funder_github_user_same && $('input[name=bountyOwnerAddress]').val() == coinbase; + } return document.is_funder_github_user_same; }; -$(document).ready(function() { +$(document).ready(async function() { - if (!is_funder()) { + if (!await is_funder()) { $('#total-section').hide(); $('#fee-section').hide(); } @@ -23,8 +38,8 @@ $(document).ready(function() { populateBountyTotal(); waitforWeb3(actions_page_warn_if_not_on_same_network); - waitforWeb3(function() { - if (!is_funder()) { + waitforWeb3(async function() { + if (!await is_funder()) { $('input, select').removeAttr('disabled'); $('#increase_funding_explainer').html("Your transaction is secured by the Gitcoin's crowdfunding technology on the Ethereum blockchain. Learn more here."); } @@ -51,7 +66,7 @@ $(document).ready(function() { }); // submit bounty button click - $('#increaseFunding').on('click', function(e) { + $('#increaseFunding').on('click', async function(e) { try { bounty_address(); } catch (exception) { @@ -107,7 +122,7 @@ $(document).ready(function() { var decimalDivisor = Math.pow(10, decimals); var tokenName = token['name']; var token_contract = web3.eth.contract(token_abi).at(tokenAddress); - var account = web3.eth.coinbase; + var account = await promisify(web3.eth.getCoinbase); amount = amount * decimalDivisor; // Create the bounty object. @@ -225,7 +240,7 @@ $(document).ready(function() { if (isETH) { web3.eth.sendTransaction({ to: to_address, - from: web3.eth.coinbase, + from: account, value: web3.toWei(fee, 'ether'), gasPrice: gas_price }, function(error, txnId) { diff --git a/app/assets/v2/js/pages/kudos_bulk_receive.js b/app/assets/v2/js/pages/kudos_bulk_receive.js index cadee2177eb..374bc45a174 100644 --- a/app/assets/v2/js/pages/kudos_bulk_receive.js +++ b/app/assets/v2/js/pages/kudos_bulk_receive.js @@ -10,7 +10,9 @@ $(document).ready(function() { _alert({ message: gettext('You are not on the right web3 network. Please switch to ') + document.network }, 'error'); $('#receive').attr('disabled', 'disabled'); } else { - $('#forwarding_address').val(web3.eth.coinbase); + web3.eth.getCoinbase(function(_, coinbase) { + $('#forwarding_address').val(coinbase); + }); } }); diff --git a/app/assets/v2/js/pages/kudos_details.js b/app/assets/v2/js/pages/kudos_details.js index df3e1efaa21..137e1a62e41 100644 --- a/app/assets/v2/js/pages/kudos_details.js +++ b/app/assets/v2/js/pages/kudos_details.js @@ -2,12 +2,13 @@ var cloneKudos = function(name, numClones) { console.log('name: ' + name); console.log('numClones: ' + numClones); - var account = web3.eth.coinbase; var kudosContractInstance = web3.eth.contract(kudos_abi).at(kudos_address()); - kudosContractInstance.clone(name, numClones, {from: account, value: new web3.BigNumber(1000000000000000)}, function(error, txid) { - console.log('txid:' + txid); - return true; + web3.eth.getCoinbase(function(_, account) { + kudosContractInstance.clone(name, numClones, {from: account, value: new web3.BigNumber(1000000000000000)}, function(error, txid) { + console.log('txid:' + txid); + return true; + }); }); }; diff --git a/app/assets/v2/js/pages/kudos_receive.js b/app/assets/v2/js/pages/kudos_receive.js index e1faedfb0e0..893d9331fd7 100644 --- a/app/assets/v2/js/pages/kudos_receive.js +++ b/app/assets/v2/js/pages/kudos_receive.js @@ -50,7 +50,9 @@ window.onload = function() { _alert({ message: gettext('You are not on the right web3 network. Please switch to ') + document.network }, 'error'); } } else if (!$('#forwarding_address').val()) { - $('#forwarding_address').val(web3.eth.coinbase); + web3.eth.getCoinbase(function(_, coinbase) { + $('#forwarding_address').val(coinbase); + }); } $('#network').val(document.web3network); }); diff --git a/app/assets/v2/js/pages/kudos_send.js b/app/assets/v2/js/pages/kudos_send.js index a0e0520f4e4..3e3a5be496f 100644 --- a/app/assets/v2/js/pages/kudos_send.js +++ b/app/assets/v2/js/pages/kudos_send.js @@ -220,7 +220,7 @@ $(document).ready(function() { _alert({ message: gettext('You must have a web3 enabled browser to do this. Please download Metamask.') }, 'warning'); return; } - if (!web3.eth.coinbase) { + if (!web3.eth.getCoinbase) { _alert({ message: gettext('Please unlock metamask.') }, 'warning'); return; } @@ -449,170 +449,172 @@ function sendKudos(email, github_url, from_name, username, amountInEth, comments if ($('.redemptions select').length) { num_redemptions = $('.redemptions select').val(); } - var formbody = { - username: username, - email: email, - tokenName: tokenName, - amount: amountInEth, - comments_priv: comments_priv, - comments_public: comments_public, - expires_date: expires, - github_url: github_url, - from_email: from_email, - from_name: from_name, - to_eth_address: to_eth_address, - kudosId: kudosId, - tokenId: tokenId, - network: document.web3network, - from_address: web3.eth.coinbase, - is_for_bounty_fulfiller: is_for_bounty_fulfiller, - metadata: metadata, - send_type: send_type, - num_redemptions: num_redemptions - }; - - if (send_type == 'airdrop') { - formbody['pk'] = document.account['private']; - } - + + web3.eth.getCoinbase(function(_, account) { + var formbody = { + username: username, + email: email, + tokenName: tokenName, + amount: amountInEth, + comments_priv: comments_priv, + comments_public: comments_public, + expires_date: expires, + github_url: github_url, + from_email: from_email, + from_name: from_name, + to_eth_address: to_eth_address, + kudosId: kudosId, + tokenId: tokenId, + network: document.web3network, + from_address: account, + is_for_bounty_fulfiller: is_for_bounty_fulfiller, + metadata: metadata, + send_type: send_type, + num_redemptions: num_redemptions + }; + + if (send_type == 'airdrop') { + formbody['pk'] = document.account['private']; + } - fetch(url, { - method: 'POST', - credentials: 'include', - body: JSON.stringify(formbody) - }).then(function(response) { - // console.log(response) - return response.json(); - }).then(function(json) { - var is_success = json['status'] == 'OK'; - var _class = is_success ? 'info' : 'error'; - - if (!is_success) { - _alert(json['message'], _class); - failure_callback(); - } else { - // Step 8 - // A json object with SUCCESS is received from the back-end - var is_direct_to_recipient = metadata['is_direct'] || to_eth_address; - var destinationAccount = to_eth_address ? to_eth_address : metadata['address']; - if (json['url']) { - document.airdrop_url = json['url']; - } + fetch(url, { + method: 'POST', + credentials: 'include', + body: JSON.stringify(formbody) + }).then(function(response) { + // console.log(response) + return response.json(); + }).then(function(json) { + var is_success = json['status'] == 'OK'; + var _class = is_success ? 'info' : 'error'; + + if (!is_success) { + _alert(json['message'], _class); + failure_callback(); + } else { + // Step 8 + // A json object with SUCCESS is received from the back-end + var is_direct_to_recipient = metadata['is_direct'] || to_eth_address; + var destinationAccount = to_eth_address ? to_eth_address : metadata['address']; - var post_send_callback = function(errors, txid, kudos_id) { - indicateMetamaskPopup(true); - if (errors) { - _alert({ message: gettext('There was an error.') }, 'warning'); - failure_callback(); - } else { - const url = '/kudos/send/4/'; - - fetch(url, { - method: 'POST', - credentials: 'include', - body: JSON.stringify({ - destinationAccount: destinationAccount, - txid: txid, - kudos_id: kudos_id, - is_direct_to_recipient: is_direct_to_recipient, - creation_time: creation_time, - salt: salt - }) - }).then(function(response) { - return response.json(); - }).then(function(json) { - var is_success = json['status'] == 'OK'; - - if (!is_success) { - _alert(json, _class); - } else { - clear_metadata(); - set_metadata(); - // Step 11 - // LAST STEP - success_callback(txid); - } - }); + if (json['url']) { + document.airdrop_url = json['url']; } - }; - // end post_send_callback - - // Pull up Kudos contract instance - var kudos_contract = web3.eth.contract(kudos_abi).at(kudos_address()); - var numClones = 1; - var account = web3.eth.coinbase; + var post_send_callback = function(errors, txid, kudos_id) { + indicateMetamaskPopup(true); + if (errors) { + _alert({ message: gettext('There was an error.') }, 'warning'); + failure_callback(); + } else { + const url = '/kudos/send/4/'; + + fetch(url, { + method: 'POST', + credentials: 'include', + body: JSON.stringify({ + destinationAccount: destinationAccount, + txid: txid, + kudos_id: kudos_id, + is_direct_to_recipient: is_direct_to_recipient, + creation_time: creation_time, + salt: salt + }) + }).then(function(response) { + return response.json(); + }).then(function(json) { + var is_success = json['status'] == 'OK'; + + if (!is_success) { + _alert(json, _class); + } else { + clear_metadata(); + set_metadata(); + // Step 11 + // LAST STEP + success_callback(txid); + } + }); + } + }; + // end post_send_callback - console.log('destinationAccount:' + destinationAccount); + // Pull up Kudos contract instance + var kudos_contract = web3.eth.contract(kudos_abi).at(kudos_address()); - var kudosPriceInEth = parseFloat($('#kudosPrice').attr('data-ethprice')) || $('.kudos-search').select2('data')[0].price_finney; - var kudosPriceInWei = new web3.BigNumber((kudosPriceInEth * 1.0 * Math.pow(10, 18)).toString()); + var numClones = 1; - if (is_direct_to_recipient) { - // Step 9 - // Kudos Direct Send (KDS) - console.log('Using Kudos Direct Send (KDS)'); + console.log('destinationAccount:' + destinationAccount); + var kudosPriceInEth = parseFloat($('#kudosPrice').attr('data-ethprice')) || $('.kudos-search').select2('data')[0].price_finney; + var kudosPriceInWei = new web3.BigNumber((kudosPriceInEth * 1.0 * Math.pow(10, 18)).toString()); - kudos_contract.clone(destinationAccount, tokenId, numClones, {from: account, value: kudosPriceInWei, gasPrice: web3.toHex(get_gas_price()) - }, function(cloneError, cloneTxid) { - // getLatestId yields the last kudos_id - kudos_contract.getLatestId(function(error, kudos_id) { - post_send_callback(cloneError, cloneTxid, kudos_id); - }); - }); + if (is_direct_to_recipient) { + // Step 9 + // Kudos Direct Send (KDS) + console.log('Using Kudos Direct Send (KDS)'); - // Send Indirectly - } else { - // Step 9 - // Kudos Indirect Send (KIS) - // estimate gas for cloning the kudos - console.log('Using Kudos Indirect Send (KIS)'); - - params = { - tokenId: tokenId, - numClones: numClones, - from: account, - value: kudosPriceInWei.toString() - }; - kudos_contract.clone.estimateGas(destinationAccount, tokenId, numClones, {from: account, value: kudosPriceInWei, gasPrice: web3.toHex(get_gas_price()) - }, function(err, kudosGasEstimate) { - if (err) { - unloading_button($('#send')); - _alert('Got an error back from RPC node. Please try again or contact support'); - throw (err); - } + kudos_contract.clone(destinationAccount, tokenId, numClones, {from: account, value: kudosPriceInWei, gasPrice: web3.toHex(get_gas_price()) + }, function(cloneError, cloneTxid) { + // getLatestId yields the last kudos_id + kudos_contract.getLatestId(function(error, kudos_id) { + post_send_callback(cloneError, cloneTxid, kudos_id); + }); + }); - console.log('kudosGasEstimate: ' + kudosGasEstimate); - // Multiply gas * gas_price_gwei to get gas cost in wei. - kudosGasEstimateInWei = kudosGasEstimate * get_gas_price(); - _alert({ message: gettext('You will now be asked to confirm a transaction to cover the cost of the Kudos and the gas money.') }, 'info'); - money = { - gas_money: gas_money, - kudosGasEstimateInWei: kudosGasEstimateInWei, - kudosPriceInWei: kudosPriceInWei.toNumber() + // Send Indirectly + } else { + // Step 9 + // Kudos Indirect Send (KIS) + // estimate gas for cloning the kudos + console.log('Using Kudos Indirect Send (KIS)'); + + params = { + tokenId: tokenId, + numClones: numClones, + from: account, + value: kudosPriceInWei.toString() }; - console.log(money); - indicateMetamaskPopup(); - var num_redemptions = 1; - if ($('.redemptions select').length) { - num_redemptions = $('.redemptions select').val(); - } - var total_send = ((gas_money + kudosGasEstimateInWei + kudosPriceInWei.toNumber()) * new web3.BigNumber(num_redemptions)).toString(); + kudos_contract.clone.estimateGas(destinationAccount, tokenId, numClones, {from: account, value: kudosPriceInWei, gasPrice: web3.toHex(get_gas_price()) + }, function(err, kudosGasEstimate) { + if (err) { + unloading_button($('#send')); + _alert('Got an error back from RPC node. Please try again or contact support'); + throw (err); + } - web3.eth.sendTransaction({ - from: account, - to: destinationAccount, - // Add gas_money + gas cost for kudos contract transaction + cost of kudos token (Gitcoin keeps this amount?) - value: total_send, - gasPrice: web3.toHex(get_gas_price()) - }, post_send_callback); - }); + console.log('kudosGasEstimate: ' + kudosGasEstimate); + // Multiply gas * gas_price_gwei to get gas cost in wei. + kudosGasEstimateInWei = kudosGasEstimate * get_gas_price(); + _alert({ message: gettext('You will now be asked to confirm a transaction to cover the cost of the Kudos and the gas money.') }, 'info'); + money = { + gas_money: gas_money, + kudosGasEstimateInWei: kudosGasEstimateInWei, + kudosPriceInWei: kudosPriceInWei.toNumber() + }; + console.log(money); + indicateMetamaskPopup(); + var num_redemptions = 1; + + if ($('.redemptions select').length) { + num_redemptions = $('.redemptions select').val(); + } + var total_send = ((gas_money + kudosGasEstimateInWei + kudosPriceInWei.toNumber()) * new web3.BigNumber(num_redemptions)).toString(); + + web3.eth.sendTransaction({ + from: account, + to: destinationAccount, + // Add gas_money + gas cost for kudos contract transaction + cost of kudos token (Gitcoin keeps this amount?) + value: total_send, + gasPrice: web3.toHex(get_gas_price()) + }, post_send_callback); + }); + } } - } + }); }); }; diff --git a/app/assets/v2/js/pages/new_bounty.js b/app/assets/v2/js/pages/new_bounty.js index dd3e40370f4..d25e332a027 100644 --- a/app/assets/v2/js/pages/new_bounty.js +++ b/app/assets/v2/js/pages/new_bounty.js @@ -283,16 +283,17 @@ const handleTokenAuth = () => { resolve(isTokenAuthed); } else { const token_contract = web3.eth.contract(token_abi).at(tokenAddress); - const from = web3.eth.coinbase; const to = bounty_address(); - token_contract.allowance.call(from, to, (error, result) => { + web3.eth.getCoinbase(function(_, from) { + token_contract.allowance.call(from, to, (error, result) => { - if (error || result.toNumber() == 0) { - isTokenAuthed = false; - } - tokenAuthAlert(isTokenAuthed, tokenName); - resolve(isTokenAuthed); + if (error || result.toNumber() == 0) { + isTokenAuthed = false; + } + tokenAuthAlert(isTokenAuthed, tokenName); + resolve(isTokenAuthed); + }); }); } }); diff --git a/app/assets/v2/js/pages/onboard.js b/app/assets/v2/js/pages/onboard.js index b1cdf99d42f..a78bee7e1a9 100644 --- a/app/assets/v2/js/pages/onboard.js +++ b/app/assets/v2/js/pages/onboard.js @@ -74,7 +74,7 @@ onboard.watchMetamask = function() { ` ); - } else if (!web3.eth.coinbase) { + } else if (!web3.eth.getCoinbase) { $('.step #metamask').html(`