improved disableBtn enableBtn functions

This commit is contained in:
Abhishek Sinha 2020-05-25 11:34:40 +05:30
parent b58b7b37f5
commit 603736b6ce

View File

@ -16846,7 +16846,7 @@
// Check how much Cash user can withdraw // Check how much Cash user can withdraw
const trader_cash_id = `${params.trader_flo_address}_${params.currency}`; const trader_cash_id = `${params.trader_flo_address}_${params.currency}`;
readDB("cash_balances", trader_cash_id).then(function ( readDB("cash_balances", trader_cash_id).then(async function (
cash_balances_res cash_balances_res
) { ) {
try { try {
@ -18628,7 +18628,7 @@
const trader_cash_id = `${params.trader_flo_address}_${params.currency}`; const trader_cash_id = `${params.trader_flo_address}_${params.currency}`;
backup_server_db_instance backup_server_db_instance
.backup_readDB("cash_balances", trader_cash_id) .backup_readDB("cash_balances", trader_cash_id)
.then(function (cash_balances_res) { .then(async function (cash_balances_res) {
try { try {
if ( if (
typeof cash_balances_res == "object" && typeof cash_balances_res == "object" &&
@ -21770,6 +21770,10 @@
btn = document.getElementById(btn); btn = document.getElementById(btn);
if (btn.disabled) if (btn.disabled)
btn.disabled = false; btn.disabled = false;
if(btn.nodeName!=="BUTTON") {
let childbtn=btn.getElementsByTagName('button')[0];
childbtn.disabled=false;
}
} }
function disableBtn(btn) { function disableBtn(btn) {
@ -21777,6 +21781,10 @@
btn = document.getElementById(btn); btn = document.getElementById(btn);
if (!btn.disabled) if (!btn.disabled)
btn.disabled = true; btn.disabled = true;
if(btn.nodeName!=="BUTTON") {
let childbtn=btn.getElementsByTagName('button')[0];
childbtn.disabled=true;
}
} }
function btnLoading(btn, option) { function btnLoading(btn, option) {
if (typeof btn === 'string') if (typeof btn === 'string')
@ -24640,7 +24648,7 @@
break; break;
case "update_all_cash_deposit_success": case "update_all_cash_deposit_success":
if (res_obj.params[0].trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_public_key if (res_obj.params[0].trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address
|| ||
!localbitcoinplusplus.master_configurations.supernodesPubKeys.includes( !localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
res_obj.nodePubKey) res_obj.nodePubKey)
@ -24666,7 +24674,8 @@
update_cash_balance_obj_res_verification === true) { update_cash_balance_obj_res_verification === true) {
updateinDB('cash_balances', deposit_success_response.depositor_cash_data, updateinDB('cash_balances', deposit_success_response.depositor_cash_data,
deposit_success_response.depositor_cash_data.id, false, false); deposit_success_response.depositor_cash_data.id, false, false)
.then(res=>displayBalances(localbitcoinplusplus.wallets.my_local_flo_address));
removeinDB('cash_deposits', deposit_success_response.deposit_req_id); removeinDB('cash_deposits', deposit_success_response.deposit_req_id);
return true; return true;
@ -30612,13 +30621,13 @@
get_crypto_svg_selection_html('withdraw_assets_type', withdraw_crypto_div); get_crypto_svg_selection_html('withdraw_assets_type', withdraw_crypto_div);
withdrawCryptoButton.addEventListener("click", function (params) { withdrawCryptoButton.addEventListener("click", function (params) {
this.getElementsByTagName('button')[0].disabled = true; try {
disableBtn('withdrawCryptoButton');
let parentPopup = this.closest('.popup'); let parentPopup = this.closest('.popup');
let asset_type = document.querySelector("input[name='crypto']:checked").value; let asset_type = document.querySelector("input[name='crypto']:checked").value;
let receivinAddress = document.getElementById('withdraw_recving_addr').value let receivinAddress = document.getElementById('withdraw_recving_addr').value
let withdraw_amount_box = document.getElementById('crypto_withdraw_amount') let withdraw_amount_box = document.getElementById('crypto_withdraw_amount')
if (receivinAddress == null || receivinAddress.trim() == "") { if (receivinAddress == null || receivinAddress.trim() == "") {
this.getElementsByTagName('button')[0].disabled = false;
err_msg = `You must specify a valid ${asset_type} address to continue.`; err_msg = `You must specify a valid ${asset_type} address to continue.`;
notify(err_msg, 'error'); notify(err_msg, 'error');
throw new Error(err_msg); throw new Error(err_msg);
@ -30631,7 +30640,6 @@
typeof userFLOaddress == undefined || typeof userFLOaddress == undefined ||
userFLOaddress.trim().length < 1 userFLOaddress.trim().length < 1
) { ) {
enableBtn('withdrawCryptoButton')
err_msg = "Invalid or empty user FLO address."; err_msg = "Invalid or empty user FLO address.";
notify(err_msg, 'error'); notify(err_msg, 'error');
throw new Error(err_msg); throw new Error(err_msg);
@ -30653,11 +30661,13 @@
); );
localbitcoinplusplus.actions.delay(60000).then(() => enableBtn('withdrawCryptoButton')); localbitcoinplusplus.actions.delay(60000).then(() => enableBtn('withdrawCryptoButton'));
} else { } else {
enableBtn('withdrawCryptoButton')
err_msg = `Error: Withdraw of Crypto failed. Invalid asset type ${asset_type} provided.`; err_msg = `Error: Withdraw of Crypto failed. Invalid asset type ${asset_type} provided.`;
notify(err_msg, 'error'); notify(err_msg, 'error');
throw new Error(err_msg); throw new Error(err_msg);
} }
} catch(e) {
enableBtn('withdrawCryptoButton')
}
}); });
} }
@ -30672,7 +30682,8 @@
let user_deposited_cash = 0; // false let user_deposited_cash = 0; // false
depositCashButton.addEventListener("click", function () { depositCashButton.addEventListener("click", function () {
disableBtn('withdrawCashButton'); try {
disableBtn('depositCashButton');
user_deposited_cash === 0 ? user_deposited_cash = 1 : user_deposited_cash = 0; user_deposited_cash === 0 ? user_deposited_cash = 1 : user_deposited_cash = 0;
if (user_deposited_cash == 1) { if (user_deposited_cash == 1) {
this.firstElementChild.textContent = 'done'; this.firstElementChild.textContent = 'done';
@ -30681,7 +30692,6 @@
tradeAmount = parentPopup.querySelector("input[name='amount']").value; tradeAmount = parentPopup.querySelector("input[name='amount']").value;
if (typeof user_upi !== "string" || user_upi.length < 1) { if (typeof user_upi !== "string" || user_upi.length < 1) {
enableBtn('withdrawCashButton')
err_msg = "Invalid or empty UPI id."; err_msg = "Invalid or empty UPI id.";
notify(err_msg, 'error'); notify(err_msg, 'error');
throw new Error(err_msg); throw new Error(err_msg);
@ -30693,7 +30703,6 @@
typeof userFLOaddress == undefined || typeof userFLOaddress == undefined ||
userFLOaddress.trim().length < 1 userFLOaddress.trim().length < 1
) { ) {
enableBtn('withdrawCashButton')
err_msg = "Invalid or empty user FLO address."; err_msg = "Invalid or empty user FLO address.";
notify(err_msg, 'error'); notify(err_msg, 'error');
throw new Error(err_msg); throw new Error(err_msg);
@ -30711,9 +30720,8 @@
userFLOaddress, userFLOaddress,
user_upi user_upi
); );
localbitcoinplusplus.actions.delay(60000).then(() => enableBtn('withdrawCashButton')); localbitcoinplusplus.actions.delay(20000).then(() => enableBtn('depositCashButton'));
} else { } else {
enableBtn('withdrawCashButton')
err_msg = "Error: Deposit of Cash failed."; err_msg = "Error: Deposit of Cash failed.";
notify(err_msg, 'error'); notify(err_msg, 'error');
throw new Error(err_msg); throw new Error(err_msg);
@ -30724,11 +30732,15 @@
hidePopup() hidePopup()
return; return;
} }
} catch(e) {
enableBtn('depositCashButton');
}
}); });
// Withdraw Cash function // Withdraw Cash function
withdrawCashButton.addEventListener("click", function (params) { withdrawCashButton.addEventListener("click", function (params) {
try {
disableBtn('withdrawCashButton');
let parentPopup = this.closest('.popup') let parentPopup = this.closest('.popup')
let receivinAddress = parentPopup.querySelector("input[name='upiAddr']").value; let receivinAddress = parentPopup.querySelector("input[name='upiAddr']").value;
if (receivinAddress == null || receivinAddress.trim == "") { if (receivinAddress == null || receivinAddress.trim == "") {
@ -30766,7 +30778,6 @@
localbitcoinplusplus.master_configurations.tradableAsset2 localbitcoinplusplus.master_configurations.tradableAsset2
.includes(asset_type) .includes(asset_type)
) { ) {
btnLoading(this, 'start');
RM_TRADE.withdrawAsset( RM_TRADE.withdrawAsset(
asset_type, asset_type,
tradeAmount, tradeAmount,
@ -30774,12 +30785,15 @@
userFLOaddress, userFLOaddress,
fiatCurrency fiatCurrency
); );
localbitcoinplusplus.actions.delay(20000).then(() => enableBtn('withdrawCashButton'));
} else { } else {
err_msg = "Error: Withdraw cash failed. Invalid currency specified."; err_msg = "Error: Withdraw cash failed. Invalid currency specified.";
notify(err_msg, 'error'); notify(err_msg, 'error');
throw new Error(err_msg); throw new Error(err_msg);
} }
} catch (e) {
enableBtn('withdrawCashButton');
}
}); });
} }