fixed bugs in deposit withdraw cash

This commit is contained in:
Abhishek Sinha 2019-09-10 17:35:28 +05:30
parent 8e93485d97
commit df82a2b094
2 changed files with 72 additions and 88 deletions

View File

@ -114,7 +114,7 @@
<header> <header>
<!-- Fixed navbar --> <!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Fixed navbar</a> <a class="navbar-brand" href="#">Localbitcoinplusplus Cash Handling Page</a>
<button <button
class="navbar-toggler" class="navbar-toggler"
type="button" type="button"
@ -169,9 +169,9 @@
</div> </div>
</div> </div>
<h1 class="mt-5">Ranchi Mall Cash Handling Page</h1> <h1 class="mt-5">Localbitcoinplusplus Cash Handling Page</h1>
<p class="lead"> <p class="lead">
This page is to be used by <code>Ranchi Mall Cashiers</code> as a tool This page is to be used by <code>Localbitcoinplusplus Cashiers</code> as a tool
to manage cash deposits and withdraws. to manage cash deposits and withdraws.
</p> </p>
@ -205,6 +205,7 @@
<th>User FLO Id</th> <th>User FLO Id</th>
<th>Depositing Amount</th> <th>Depositing Amount</th>
<th>Currency</th> <th>Currency</th>
<th>Action</th>
</tr> </tr>
</table> </table>
</div> </div>
@ -236,6 +237,7 @@
<th>Withdrawal Amount</th> <th>Withdrawal Amount</th>
<th>Currency</th> <th>Currency</th>
<th>Txid</th> <th>Txid</th>
<th>Action</th>
</tr> </tr>
</table> </table>
</div> </div>
@ -243,7 +245,7 @@
<footer class="footer"> <footer class="footer">
<div class="container"> <div class="container">
<span class="text-muted"> &copy; Ranchi Mall </span> <span class="text-muted"> Localbitcoinplusplus Trading Software </span>
</div> </div>
</footer> </footer>
@ -13064,6 +13066,7 @@
t += `</tr>`; t += `</tr>`;
}); });
deposits_table.insertAdjacentHTML("beforeend", t); deposits_table.insertAdjacentHTML("beforeend", t);
confirmDepositReceivedFromUser();
} else { } else {
showMessage(`INFO: No pending deposits found.`); showMessage(`INFO: No pending deposits found.`);
} }
@ -13094,6 +13097,7 @@
t += `</tr>`; t += `</tr>`;
}); });
withdraws_table.insertAdjacentHTML("beforeend", t); withdraws_table.insertAdjacentHTML("beforeend", t);
confirmCashierTransferredMoneyToWithdrawer();
} else { } else {
showMessage(`INFO: No pending withdrawals found.`); showMessage(`INFO: No pending withdrawals found.`);
} }
@ -13222,11 +13226,11 @@
function showMessage(msg = "", t = 10000) { function showMessage(msg = "", t = 10000) {
if (msg.length > 0) LogEvent(msg); if (msg.length > 0) LogEvent(msg);
console.info(msg); console.info(msg);
displayMessages(); // displayMessages();
setTimeout(function() { // setTimeout(function() {
closeMessage(); // closeMessage();
clearTimeout(); // clearTimeout();
}, t); // }, t);
} }
function displayMessages() { function displayMessages() {
@ -13300,14 +13304,6 @@
} }
} }
function loadPendingDeposits() {
console.info("Load pending deposits");
}
function loadPendingWithdrawals() {
console.info("Load pending withdrawals");
}
// Connect to Supernode // Connect to Supernode
function loadSupernodesConnectUi() { function loadSupernodesConnectUi() {
let supernodeSeedsObj = let supernodeSeedsObj =
@ -13359,8 +13355,9 @@
function send_deposit_withdraw_req(evt) { function send_deposit_withdraw_req(evt) {
evt.preventDefault(); evt.preventDefault();
if ( if (
localbitcoinplusplus.MY_UPI_ID.length < 1 || localbitcoinplusplus.MY_UPI_ID.length < 1
localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS.length < 1 || typeof localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS !== "string"
|| localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS.length < 1
) { ) {
showMessage( showMessage(
`WARNING: Your UPI Id or connected Supernode is not set.` `WARNING: Your UPI Id or connected Supernode is not set.`
@ -13420,15 +13417,14 @@
const flo_txid = prompt("Enter Deposit Token Transfer Flo Txid: "); const flo_txid = prompt("Enter Deposit Token Transfer Flo Txid: ");
if (flo_txid.length < 1) return; if (flo_txid.length < 1) return;
const upi_txid = prompt("Enter Received Cash UPI Txid: "); let cash_recvd_from_user = prompt(
if (upi_txid.length < 1) return;
const cash_recvd_from_user = prompt(
"Enter Amount Received in Cash: " "Enter Amount Received in Cash: "
); );
cash_recvd_from_user = Number(cash_recvd_from_user);
if ( if (
typeof cash_recvd_from_user !== "number" || cash_recvd_from_user === NaN ||
cash_recvd_from_user < 1 typeof cash_recvd_from_user !== "number" ||
cash_recvd_from_user < 1
) )
return; return;
@ -13531,12 +13527,6 @@
// Load Supernodes Connection Select UI // Load Supernodes Connection Select UI
loadSupernodesConnectUi(); loadSupernodesConnectUi();
// Load Pending Deposits UI
loadPendingDeposits();
// Load Pending Withdrawals UI
loadPendingWithdrawals();
// Fetch Deposits // Fetch Deposits
AskSupernodeForLatestDepositsAndWithdrawalsData(); AskSupernodeForLatestDepositsAndWithdrawalsData();

View File

@ -14939,7 +14939,7 @@ Event information log
case "deposit_asset_request": case "deposit_asset_request":
RM_RPC.filter_legit_requests( RM_RPC.filter_legit_requests(
params.trader_flo_address, params.trader_flo_address,
function(is_valid_request) { async function(is_valid_request) {
if (is_valid_request !== true) return false; if (is_valid_request !== true) return false;
// This code will only run for supernodes // This code will only run for supernodes
@ -14963,12 +14963,11 @@ Event information log
typeof params.trader_flo_address == "string" && typeof params.trader_flo_address == "string" &&
params.trader_flo_address.length > 0 params.trader_flo_address.length > 0
) { ) {
RM_WALLET.getUserPublicKey( const requester_public_key = request.nodePubKey;
params.trader_flo_address,
async function(requester_public_key) {
if ( if (
requester_public_key == undefined || requester_public_key == undefined ||
requester_public_key == null requester_public_key == null ||
requester_public_key.length < 1
) { ) {
err_msg = "Failed to get public key of the user."; err_msg = "Failed to get public key of the user.";
showMessage(err_msg); showMessage(err_msg);
@ -15177,8 +15176,7 @@ Event information log
return false; return false;
} }
}
);
} else { } else {
err_msg = "deposit asset request error"; err_msg = "deposit asset request error";
showMessage(err_msg); showMessage(err_msg);
@ -16576,23 +16574,17 @@ Event information log
typeof params.trader_flo_address == "string" && typeof params.trader_flo_address == "string" &&
params.trader_flo_address.length > 0 params.trader_flo_address.length > 0
) { ) {
const requester_public_req = await backup_server_db_instance.backup_readDB( const requester_public_key = request.nodePubKey;
"userPublicData", if (
params.trader_flo_address requester_public_key == undefined ||
); requester_public_key == null ||
if (typeof requester_public_req !== "object") return; requester_public_key.length < 1
const requester_public_key = ) {
requester_public_req.trader_flo_pubKey; err_msg = "Failed to get public key of the user.";
showMessage(err_msg);
if ( throw new Error(err_msg);
typeof requester_public_key == "undefined" || }
requester_public_key == null params.depositor_public_key = requester_public_key;
) {
err_msg = "Failed to get public key of the user.";
showMessage(err_msg);
throw new Error(err_msg);
}
params.depositor_public_key = requester_public_key;
await RM_TRADE.resolve_current_crypto_price_in_fiat( await RM_TRADE.resolve_current_crypto_price_in_fiat(
params.product, params.product,
@ -16876,10 +16868,9 @@ Event information log
receivedTradeInfo.cashier_upi = receivedTradeInfo.cashier_upi =
cashiersList[getAPaymentHandler]; cashiersList[getAPaymentHandler];
receivedTradeInfo.cashier_pubKey = getAPaymentHandler; receivedTradeInfo.cashier_pubKey = getAPaymentHandler;
const receivedTradeInfoResp = await addDB(
"cash_deposits", const receivedTradeInfoResp = await backup_server_db_instance
receivedTradeInfo .backup_addDB("cash_deposits", receivedTradeInfo);
);
let deposit_response_object = { let deposit_response_object = {
error: false, error: false,
@ -17938,21 +17929,22 @@ Event information log
if (typeof params == "object" && typeof method == "string") { if (typeof params == "object" && typeof method == "string") {
if ( if (
typeof request.globalParams !== "object" typeof request.globalParams !== "object"
|| !Object.keys( || (!Object.keys(
JSON.parse(localbitcoinplusplus.master_configurations.cashiers) JSON.parse(localbitcoinplusplus.master_configurations.cashiers)
).includes(request.nodePubKey) ).includes(request.nodePubKey)
&& !(localbitcoinplusplus.master_configurations.supernodesPubKeys)
.includes(request.nodePubKey)
)
|| (typeof request.globalParams.receiversList == "object" && || (typeof request.globalParams.receiversList == "object" &&
!request.globalParams.receiversList.includes( !request.globalParams.receiversList.includes(
localbitcoinplusplus.wallets.my_local_flo_address localbitcoinplusplus.wallets.my_local_flo_address
)) ))
|| !(localbitcoinplusplus.master_configurations.supernodesPubKeys)
.includes(request.nodePubKey)
) )
return; return;
/************************************ /************************************
#todo: VALIDATE CASHIER'S SIGNATURE HERE #todo: VALIDATE CASHIER'S SIGNATURE HERE
*************************************/ *************************************/
const RM_WALLET = new localbitcoinplusplus.wallets(); const RM_WALLET = new localbitcoinplusplus.wallets();
const RM_RPC = new localbitcoinplusplus.rpc(); const RM_RPC = new localbitcoinplusplus.rpc();
@ -18021,12 +18013,12 @@ Event information log
try { try {
const cash_deposited_by_user = Number(params.cash_deposited); const cash_deposited_by_user = Number(params.cash_deposited);
if (params.flo_txid===null if (params.flo_txid===null
|| params.flo_txid.length<1 || params.flo_txid.length<1
|| params.deposit_id==null || params.deposit_id==null
|| params.deposit_id.length<1 || params.deposit_id.length<1
|| typeof cash_deposited_by_user == NaN || typeof cash_deposited_by_user == NaN
|| params.cash_deposited < 1 || cash_deposited_by_user < 1
) { ) {
throw new Error(`Error: Incomplete or invalid data received for Cash Deposit Id: ${params.deposit_id}`); throw new Error(`Error: Incomplete or invalid data received for Cash Deposit Id: ${params.deposit_id}`);
} }
@ -18034,7 +18026,7 @@ Event information log
// Validate deposit_id // Validate deposit_id
const user_deposit_req = await readDB("cash_deposits", params.deposit_id); const user_deposit_req = await readDB("cash_deposits", params.deposit_id);
if (typeof user_deposit_req!=="object" if (typeof user_deposit_req!=="object"
|| user_deposit_req.length<1) return; || user_deposit_req===null) return;
// Validate Flo txid // Validate Flo txid
const validate_flo_txid = await helper_functions const validate_flo_txid = await helper_functions
@ -18043,10 +18035,10 @@ Event information log
if(typeof validate_flo_txid !== "object" if(typeof validate_flo_txid !== "object"
|| typeof validate_flo_txid.transactionDetails !== "object" || typeof validate_flo_txid.transactionDetails !== "object"
|| typeof validate_flo_txid.transactionDetails.floData !== "string" || typeof validate_flo_txid.transactionDetails.floData !== "string"
|| validate_flo_txid.transactionDetails.floData.length < 1 || validate_flo_txid.transactionDetails.floData.length < 5 // without ':text'
) throw new Error(`Error: Txid ${params.flo_txid} not found in Blockchain.`); ) throw new Error(`Error: Txid ${params.flo_txid} not found in Blockchain.`);
let amount_deposited = Number(validate_flo_txid.transactionDetails.floData.match(/\d+/g))[0]; let amount_deposited = Number(validate_flo_txid.transactionDetails.floData.match(/\d+/g)[0]);
if(typeof amount_deposited !== "number" || amount_deposited < 1 || amount_deposited===NaN) { if(typeof amount_deposited !== "number" || amount_deposited < 1 || amount_deposited===NaN) {
amount_deposited = cash_deposited_by_user; amount_deposited = cash_deposited_by_user;
} }
@ -18134,9 +18126,9 @@ Event information log
withdraw_req.upi_txid = params.upi_txid; withdraw_req.upi_txid = params.upi_txid;
withdraw_req.status = 2; // Cashier sent money to Withdrawer withdraw_req.status = 2; // Cashier sent money to Withdrawer
const updated_withdraw_req = await updateinDB('withdraw_cash', params, params.withdraw_id); const updated_withdraw_req = await updateinDB('withdraw_cash', withdraw_req, withdraw_req.id);
if(typeof updated_withdraw_req !=="object") if(typeof updated_withdraw_req.id !=="string")
throw new Error(`Error: Failed to update "cashier_confirms_user_cash_withdraw" data.`); throw new Error(`Error: Failed to update "cashier_confirms_user_cash_withdraw" data.`);
// Broadcast to backups // Broadcast to backups
@ -22825,8 +22817,8 @@ Event information log
typeof user == "object" && typeof user == "object" &&
user.myLocalFLOAddress == resp.data.trader_flo_address user.myLocalFLOAddress == resp.data.trader_flo_address
) { ) {
let counterTraderAccountAddress = `Please pay the amount to following UPI ID: let counterTraderAccountAddress =
${resp.msg}`; `Please pay the amount to following UPI ID: ${resp.msg}`;
showMessage(counterTraderAccountAddress); showMessage(counterTraderAccountAddress);
modalWindow(counterTraderAccountAddress); modalWindow(counterTraderAccountAddress);
} }
@ -26370,7 +26362,7 @@ Event information log
const deposit_success_response = res_obj.params[0]; const deposit_success_response = res_obj.params[0];
let update_cash_balance_obj_res = { let update_cash_balance_obj_res = {
depositor_cash_data: deposit_success_response.depositor_cash_data, depositor_cash_data: deposit_success_response.depositor_cash_data,
deposit_req_id: deposit_success_response.depositor_cash_data.deposit_id deposit_req_id: deposit_success_response.deposit_req_id
} }
let update_cash_balance_obj_res_str = JSON.stringify(update_cash_balance_obj_res); let update_cash_balance_obj_res_str = JSON.stringify(update_cash_balance_obj_res);
let update_cash_balance_obj_res_hash = Crypto.SHA256( let update_cash_balance_obj_res_hash = Crypto.SHA256(
@ -26382,10 +26374,10 @@ Event information log
if ((update_cash_balance_obj_res_hash === deposit_success_response.hash) && if ((update_cash_balance_obj_res_hash === deposit_success_response.hash) &&
update_cash_balance_obj_res_verification === true) { update_cash_balance_obj_res_verification === true) {
const my_closest_su_list = localbitcoinplusplus.kademlia const my_closest_su_list = await localbitcoinplusplus.kademlia
.determineClosestSupernode( .determineClosestSupernode(
res_obj.params[0].trader_flo_address res_obj.params[0].trader_flo_address
) );
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id; const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
const foreign_db = const foreign_db =
localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser]; localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
@ -26393,8 +26385,9 @@ Event information log
_removeinDB = foreign_db.backup_removeinDB.bind(foreign_db); _removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db); _updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
_updateinDB('cash_balances', deposit_success_response.depositor_cash_data); _updateinDB('cash_balances', deposit_success_response.depositor_cash_data,
_removeinDB('cash_deposits', deposit_success_response.depositor_cash_data.deposit_id); deposit_success_response.depositor_cash_data.id, false, false);
_removeinDB('cash_deposits', deposit_success_response.deposit_req_id);
return true; return true;
} }
@ -26416,17 +26409,18 @@ Event information log
const successfull_withdraw_resp = res_obj.params[0]; const successfull_withdraw_resp = res_obj.params[0];
console.log(successfull_withdraw_resp); console.log(successfull_withdraw_resp);
const my_closest_su_list = localbitcoinplusplus.kademlia localbitcoinplusplus.kademlia.determineClosestSupernode(
.determineClosestSupernode(
successfull_withdraw_resp.trader_flo_address successfull_withdraw_resp.trader_flo_address
); ).then(my_closest_su_list=>{
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id; if(typeof my_closest_su_list[0]!=="object") return;
const foreign_db = const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser]; const foreign_db =
localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db); _updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
_updateinDB('withdraw_cash', successfull_withdraw_resp); _updateinDB('withdraw_cash', successfull_withdraw_resp);
});
} }
break; break;