From 15aee7ab90ccca3f5c05362bf6aefc1cbea13780 Mon Sep 17 00:00:00 2001 From: Owocki Date: Thu, 13 Jun 2019 14:31:33 -0400 Subject: [PATCH 1/2] token warnings --- app/assets/v2/js/pages/new_bounty.js | 64 ++++++++++++++-------------- app/assets/v2/js/shared.js | 43 +++++++++++-------- 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/app/assets/v2/js/pages/new_bounty.js b/app/assets/v2/js/pages/new_bounty.js index 6d9315b0dcb..b98f3a11c81 100644 --- a/app/assets/v2/js/pages/new_bounty.js +++ b/app/assets/v2/js/pages/new_bounty.js @@ -650,45 +650,47 @@ $('#submitBounty').validate({ } var do_bounty = function(callback) { - const fee = Number((Number(data.amount) * FEE_PERCENTAGE).toFixed(4)); - const to_address = '0x00De4B13153673BCAE2616b67bf822500d325Fc3'; - const gas_price = web3.toHex($('#gasPrice').val() * Math.pow(10, 9)); - - indicateMetamaskPopup(); - if (FEE_PERCENTAGE == 0) { - deductBountyAmount(fee, ''); - } else { - if (isETH) { - web3.eth.sendTransaction({ - to: to_address, - from: web3.eth.coinbase, - value: web3.toWei(fee, 'ether'), - gasPrice: gas_price - }, function(error, txnId) { - indicateMetamaskPopup(true); - if (error) { - _alert({ message: gettext('Unable to pay bounty fee. Please try again.') }, 'error'); - } else { - deductBountyAmount(fee, txnId); - } - }); + callMethodIfTokenIsAuthed(function(x, y){ + const fee = Number((Number(data.amount) * FEE_PERCENTAGE).toFixed(4)); + const to_address = '0x00De4B13153673BCAE2616b67bf822500d325Fc3'; + const gas_price = web3.toHex($('#gasPrice').val() * Math.pow(10, 9)); + + indicateMetamaskPopup(); + if (FEE_PERCENTAGE == 0) { + deductBountyAmount(fee, ''); } else { - const amountInWei = fee * 1.0 * Math.pow(10, token.decimals); - const token_contract = web3.eth.contract(token_abi).at(tokenAddress); - - token_contract.transfer(to_address, amountInWei, { gasPrice: gas_price }, - function(error, txnId) { + if (isETH) { + web3.eth.sendTransaction({ + to: to_address, + from: web3.eth.coinbase, + value: web3.toWei(fee, 'ether'), + gasPrice: gas_price + }, function(error, txnId) { indicateMetamaskPopup(true); if (error) { _alert({ message: gettext('Unable to pay bounty fee. Please try again.') }, 'error'); - unloading_button($('.js-submit')); } else { deductBountyAmount(fee, txnId); } - } - ); + }); + } else { + const amountInWei = fee * 1.0 * Math.pow(10, token.decimals); + const token_contract = web3.eth.contract(token_abi).at(tokenAddress); + + token_contract.transfer(to_address, amountInWei, { gasPrice: gas_price }, + function(error, txnId) { + indicateMetamaskPopup(true); + if (error) { + _alert({ message: gettext('Unable to pay bounty fee. Please try again.') }, 'error'); + unloading_button($('.js-submit')); + } else { + deductBountyAmount(fee, txnId); + } + } + ); + } } - } + }, promptForAuthFailure); }; const deductBountyAmount = function(fee, txnId) { diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index 9a933a9dffe..3e6bd248f98 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -1044,39 +1044,46 @@ window.addEventListener('load', function() { attach_close_button(); }); -var promptForAuth = function(event) { +var callMethodIfTokenIsAuthed = function(success, failure) { var denomination = $('#token option:selected').text(); var tokenAddress = $('#token option:selected').val(); if (!denomination) { - return; - } - - if (denomination !== 'ETH') { + failure(denomination, tokenAddress); + } else if (denomination == 'ETH') { + success(denomination, tokenAddress); + } else { var token_contract = web3.eth.contract(token_abi).at(tokenAddress); var from = web3.eth.coinbase; var to = bounty_address(); token_contract.allowance.call(from, to, function(error, result) { if (error || result.toNumber() == 0) { - if (!document.alert_enable_token_shown) { - _alert( - gettext(`To enable this token, go to the - - Token Settings page and enable it. - This is only needed once per token.`), - 'warning' - ); - } - document.alert_enable_token_shown = true; - + failure(denomination, tokenAddress); + } else { + success(denomination, tokenAddress); } }); + } +} + +var promptForAuthFailure = function(denomination, tokenAddress){ + _alert( + gettext(`To enable this token, go to the + + Token Settings page and enable it. + This is only needed once per token.`), + 'warning' + ); +} + +var promptForAuth = function(event) { - } else if ($('.alert')) { + var success = function(denomination, tokenAddress){ $('.alert').remove(); - document.alert_enable_token_shown = false; } + + callMethodIfTokenIsAuthed(success, promptForAuthFailure); }; var setUsdAmount = function(event) { From fef373b87ae3e4102c912269b583c3bdf1927ca6 Mon Sep 17 00:00:00 2001 From: octavioamu Date: Wed, 17 Jul 2019 11:53:52 -0300 Subject: [PATCH 2/2] fix lint --- app/assets/v2/js/pages/new_bounty.js | 2 +- app/assets/v2/js/shared.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/v2/js/pages/new_bounty.js b/app/assets/v2/js/pages/new_bounty.js index ebecca1a385..525563af85f 100644 --- a/app/assets/v2/js/pages/new_bounty.js +++ b/app/assets/v2/js/pages/new_bounty.js @@ -672,7 +672,7 @@ $('#submitBounty').validate({ } var do_bounty = function(callback) { - callMethodIfTokenIsAuthed(function(x, y){ + callMethodIfTokenIsAuthed(function(x, y) { const fee = Number((Number(data.amount) * FEE_PERCENTAGE).toFixed(4)); const to_address = '0x00De4B13153673BCAE2616b67bf822500d325Fc3'; const gas_price = web3.toHex($('#gasPrice').val() * Math.pow(10, 9)); diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index 1f6d0c8cdb9..40378e0809b 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -1016,9 +1016,9 @@ var callMethodIfTokenIsAuthed = function(success, failure) { } }); } -} +}; -var promptForAuthFailure = function(denomination, tokenAddress){ +var promptForAuthFailure = function(denomination, tokenAddress) { _alert( gettext(`To enable this token, go to the @@ -1026,13 +1026,13 @@ var promptForAuthFailure = function(denomination, tokenAddress){ This is only needed once per token.`), 'warning' ); -} +}; var promptForAuth = function(event) { - var success = function(denomination, tokenAddress){ + var success = function(denomination, tokenAddress) { $('.alert').remove(); - } + }; callMethodIfTokenIsAuthed(success, promptForAuthFailure); };