diff --git a/app/assets/v2/js/pages/new_bounty.js b/app/assets/v2/js/pages/new_bounty.js
index 13989c680ca..525563af85f 100644
--- a/app/assets/v2/js/pages/new_bounty.js
+++ b/app/assets/v2/js/pages/new_bounty.js
@@ -672,46 +672,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');
- unloading_button($('.js-submit'));
- } 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 83e9588d0c6..40378e0809b 100644
--- a/app/assets/v2/js/shared.js
+++ b/app/assets/v2/js/shared.js
@@ -995,39 +995,46 @@ window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});
-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);
}
});
+ }
+};
- } else if ($('.alert')) {
+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) {
+
+ var success = function(denomination, tokenAddress) {
$('.alert').remove();
- document.alert_enable_token_shown = false;
- }
+ };
+
+ callMethodIfTokenIsAuthed(success, promptForAuthFailure);
};
var setUsdAmount = function(event) {