Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token warnings #4639

Merged
merged 3 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 26 additions & 19 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
<a style="padding-left:5px;" href="/settings/tokens">
Token Settings page and enable it.
</a> 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
<a style="padding-left:5px;" href="/settings/tokens">
Token Settings page and enable it.
</a> 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) {
Expand Down