fixed errors in cash functions

This commit is contained in:
Abhishek Sinha 2020-04-09 15:00:24 +05:30
parent 301e26bbae
commit 721647e1f9
2 changed files with 37 additions and 33 deletions

View File

@ -13845,6 +13845,7 @@
localbitcoinplusplus.supernode_conns[sn.data.id].readyState===1) {
req_body.requesting_supernode = sn.data.id;
req_body.receiver_flo_address = sn.data.id;
websocket_name = localbitcoinplusplus.supernode_conns[sn.data.id];
break;
}
@ -13878,7 +13879,7 @@
const RM_WALLET = new localbitcoinplusplus.wallets;
Array.from(recv_deposit_btn).forEach(function(element) {
element.addEventListener("click", async function(evt) {
//let btn = this;
let btn = this;
evt.preventDefault();
const deposit_id = this.value;
const req_info = document.getElementById(`depositSpan${deposit_id}`);
@ -13902,7 +13903,7 @@
let flo_txid = '';
const flo_tx = await RM_WALLET.sendTransaction(
localbitcoinplusplus.assets.FLO,
localbitcoinplusplus.BASE_BLOCKCHAIN,
localbitcoinplusplus.wallets.my_local_flo_address,
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY,
requesting_supernode,
@ -13940,6 +13941,7 @@
.flo_api_testnet}/api/v1.0/getTransactionDetails/${flo_txid}`;
}
console.log(this);
let n=1;
(async function validateTxidInBlockchain() {
// Validate Flo txid
@ -13955,10 +13957,10 @@
.call(this, "cashier_confirms_user_cash_deposit", req_body)
.then(resp => doSend(websocket_conn, resp));
this.classList.remove('cnf_deposits');
this.classList.remove('btn-info');
this.classList.add('btn-success');
this.innerText = "Success";
btn.classList.remove('cnf_deposits');
btn.classList.remove('btn-info');
btn.classList.add('btn-success');
btn.innerText = "Success";
return true;
@ -13969,14 +13971,14 @@
// Failed to validate token transfer. Save in local db
await addDB('failed_deposit_confirms', req_body, req_body.flo_txid);
this.classList.remove('cnf_deposits');
this.classList.remove('btn-info');
this.classList.add('btn-danger');
this.innerText = "Failed to inform Supernode. Please contact the Admin.";
btn.classList.remove('cnf_deposits');
btn.classList.remove('btn-info');
btn.classList.add('btn-danger');
btn.innerText = "Failed to inform Supernode. Please contact the Admin.";
throw new Error(`Failed to inform Supernode of cash deposit: ${flo_txid}`);
}
}.bind(this))()
}.bind(btn))()
});
});
@ -13990,7 +13992,7 @@
element.addEventListener("click", function(evt) {
evt.preventDefault();
//let btn = this;
let btn = this;
const withdraw_id = this.value;
const req_info = document.getElementById(`withdrawSpan${withdraw_id}`);
const req_info_arr = req_info.value.split("_");
@ -14018,14 +14020,14 @@
})
.then(resp => doSend(websocket_conn, resp));
this.classList.remove('cnf_withdrawal');
this.classList.remove('btn-info');
this.classList.add('btn-success');
this.innerText = "Success";
btn.classList.remove('cnf_withdrawal');
btn.classList.remove('btn-info');
btn.classList.add('btn-success');
btn.innerText = "Success";
return true;
}.bind(this));
}.bind(btn));
});
}

View File

@ -19413,17 +19413,12 @@
updateUserBalance = await _updateinDB("cash_balances", cash_obj);
}
// Delete data from deposits
if (typeof updateUserBalance!=="object" && updateUserBalance==null)
throw new Error(`Error: Failed to update balance of User Cash Id: ${user_cash_id}.`);
if (localbitcoinplusplus.wallets.my_local_flo_address!==parent_supernode) {
user_deposit_req.token_transfer_txid = params.flo_txid;
_updateinDB("cash_deposits", user_deposit_req);
} else {
_removeinDB("cash_deposits", params.deposit_id);
}
// Delete data from deposits
await _removeinDB("cash_deposits", params.deposit_id);
// Broadcast deposit and cash balances datastore data to backups
let update_cash_balance_obj = {
depositor_cash_data: updateUserBalance,
@ -19486,8 +19481,6 @@
typeof localbitcoinplusplus.newBackupDatabase.db[parent_supernode] ==
"object"
) {
// Cash Withdraw or deposit not allowed in backup mode
return;
const foreign_db =
localbitcoinplusplus.newBackupDatabase.db[parent_supernode];
_readDB = foreign_db.backup_readDB.bind(foreign_db);
@ -19505,9 +19498,7 @@
if(typeof updated_withdraw_req.id !=="string")
throw new Error(`Error: Failed to update "cashier_confirms_user_cash_withdraw" data.`);
return;
// Broadcast to backups
RM_RPC
.send_rpc
@ -19515,6 +19506,11 @@
"record_upi_tx_of_successfull_withdraw",
updated_withdraw_req)
.then(resp=> doSend(resp));
// Delete the request after 24 hours
localbitcoinplusplus.actions.delay(24 * 60 * 60 * 1000).then(function() {
_removeinDB("withdraw_cash", withdraw_req.id);
});
} catch (error) {
throw new Error(error);
@ -24347,9 +24343,11 @@
readDB("localbitcoinUser", "00-01").then(function(user) {
if (
typeof user == "object" &&
user.myLocalFLOAddress == resp.data.trader_flo_address || resp.receiver_flo_address
(user.myLocalFLOAddress == resp.data.trader_flo_address
|| user.myLocalFLOAddress == resp.receiver_flo_address)
) {
let counterTraderAccountAddress = resp.msg;
let counterTraderAccountAddress = `Please pay ${resp.data.currency} ${resp.data.depositing_amount} to following UPI ID:
${resp.msg}`;
showMessage(counterTraderAccountAddress);
modalWindow(counterTraderAccountAddress);
}
@ -27838,7 +27836,6 @@
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
const successfull_withdraw_resp = res_obj.params[0];
console.log(successfull_withdraw_resp);
localbitcoinplusplus.kademlia.determineClosestSupernode(
successfull_withdraw_resp.trader_flo_address
@ -27849,9 +27846,14 @@
localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
_removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
_updateinDB('withdraw_cash', successfull_withdraw_resp,
successfull_withdraw_resp.id, true, false);
localbitcoinplusplus.actions.delay(24 * 60 * 60 * 1000).then(function() {
_removeinDB('withdraw_cash', successfull_withdraw_resp.id);
})
});
}