functions for unconfirmed deposits done
This commit is contained in:
parent
5928692dbe
commit
e70b2b3a3c
136
index.html
136
index.html
@ -140,8 +140,8 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<label class="input">
|
<label class="input">
|
||||||
<input id="deposited_rupee_upi" pattern="^[a-zA-z0-9]+@[a-zA-z0-9]+" type="text" disabled required>
|
<input id="deposited_rupee_txid" pattern="^[a-zA-z0-9]+" type="text" disabled required>
|
||||||
<div class="placeholder">Sender's UPI address</div>
|
<div class="placeholder">Transaction Id of the deposited amount</div>
|
||||||
</label>
|
</label>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -11143,6 +11143,12 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function diff_hours(dt2, dt1) {
|
||||||
|
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
|
||||||
|
diff /= (60 * 60);
|
||||||
|
return Math.abs(Math.round(diff));
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -11174,27 +11180,13 @@
|
|||||||
#!#TYPE_REQUEST_PAYMENT=REQUEST_PAYMENT_TEST${num}
|
#!#TYPE_REQUEST_PAYMENT=REQUEST_PAYMENT_TEST${num}
|
||||||
#!#TYPE_REQUEST_PAYMENT_DECLINED=REQUEST_PAYMENT_DECLINED_TEST${num}
|
#!#TYPE_REQUEST_PAYMENT_DECLINED=REQUEST_PAYMENT_DECLINED_TEST${num}
|
||||||
#!#TYPE_REQUEST_PAYMENT_APPROVED=REQUEST_PAYMENT_APPROVED_TEST${num}
|
#!#TYPE_REQUEST_PAYMENT_APPROVED=REQUEST_PAYMENT_APPROVED_TEST${num}
|
||||||
|
#!#TYPE_UNCONFIRMED_BALANCE_CLAIM_REQUESTS=TYPE_UNCONFIRMED_BALANCE_CLAIM_REQUESTS_TEST${num}
|
||||||
#!#vendors=FGtPEBu2NFFYkqFrA9NDBJJLpVhyuPubDj,
|
#!#vendors=FGtPEBu2NFFYkqFrA9NDBJJLpVhyuPubDj,
|
||||||
#!#helplineFloId=F9MAyvT5b9aSfsuukAungrbt1L5fgmJmuK
|
#!#helplineFloId=F9MAyvT5b9aSfsuukAungrbt1L5fgmJmuK
|
||||||
#!#cashiers=
|
#!#cashiers=
|
||||||
{
|
{
|
||||||
"FCja6sLv58e3RMy41T5AmWyvXEWesqBCkX": {
|
"FCja6sLv58e3RMy41T5AmWyvXEWesqBCkX": {
|
||||||
"upi_id": "8507742774@ybl"
|
"upi_id": "8507742774@ybl"
|
||||||
},
|
|
||||||
"FHW2kgYEhDt85vjAiMMF7bQqdP74L7iwvQ": {
|
|
||||||
"upi_id": "8340617958@ybl"
|
|
||||||
},
|
|
||||||
"FTmJ6QeBjDFjdqS6Zs4V5amac2X19AjXcF": {
|
|
||||||
"upi_id": "8902496422@ybl"
|
|
||||||
},
|
|
||||||
"FBun3694ZdxmD66os9oL5DxMrif3vyVjT3": {
|
|
||||||
"upi_id": "7004801428@ybl"
|
|
||||||
},
|
|
||||||
"FTpxFWdBDvYARGZuPWDhw9gke72J2pruvv": {
|
|
||||||
"upi_id": "aakriti1705sinha@okicici"
|
|
||||||
},
|
|
||||||
"FQ6udJuTbGDa2kWZAkmNpwgHaUEeYLPAtt": {
|
|
||||||
"upi_id": "krishraj1012-2@okicici"
|
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
text = removeWhiteSpaces(text);
|
text = removeWhiteSpaces(text);
|
||||||
@ -11459,6 +11451,9 @@
|
|||||||
|
|
||||||
floGlobals.appObjects["unconfirmed_rupee_deposits"] = {};
|
floGlobals.appObjects["unconfirmed_rupee_deposits"] = {};
|
||||||
floCloudAPI.resetObjectData("unconfirmed_rupee_deposits");
|
floCloudAPI.resetObjectData("unconfirmed_rupee_deposits");
|
||||||
|
|
||||||
|
floGlobals.appObjects["processed_unconfirmed_balance_claim_requests"] = {};
|
||||||
|
floCloudAPI.resetObjectData("processed_unconfirmed_balance_claim_requests");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function show_deposit_request() {
|
async function show_deposit_request() {
|
||||||
@ -11568,7 +11563,7 @@
|
|||||||
if (amount_of_tokens_to_transfer > 0) {
|
if (amount_of_tokens_to_transfer > 0) {
|
||||||
let flo_comment = `transfer ${amount_of_tokens_to_transfer} rupee#`;
|
let flo_comment = `transfer ${amount_of_tokens_to_transfer} rupee#`;
|
||||||
let flo_txid = await floBlockchainAPI.sendTx(myFloID, receiver_flo_id, 0.001, myPrivKey,
|
let flo_txid = await floBlockchainAPI.sendTx(myFloID, receiver_flo_id, 0.001, myPrivKey,
|
||||||
flo_comment)
|
flo_comment);
|
||||||
console.log(flo_txid);
|
console.log(flo_txid);
|
||||||
if (typeof flo_txid !== "string") {
|
if (typeof flo_txid !== "string") {
|
||||||
notify(`Transfer unsuccessfull.`);
|
notify(`Transfer unsuccessfull.`);
|
||||||
@ -11898,6 +11893,91 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function display_unconfirmed_balance_claim_requests() {
|
||||||
|
try {
|
||||||
|
// load all user cliams
|
||||||
|
await floCloudAPI.requestGeneralData(token_app.master_configurations
|
||||||
|
.TYPE_UNCONFIRMED_BALANCE_CLAIM_REQUESTS, {
|
||||||
|
receiverID: myFloID
|
||||||
|
});
|
||||||
|
const unconfirmed_cash_deposit_claims = floDapps.getNextGeneralData(token_app.master_configurations
|
||||||
|
.TYPE_UNCONFIRMED_BALANCE_CLAIM_REQUESTS, "0");
|
||||||
|
|
||||||
|
// load processed claims
|
||||||
|
await floCloudAPI.requestObjectData("processed_unconfirmed_balance_claim_requests", { receiverID:floGlobals.adminID });
|
||||||
|
const processed_unconfirmed_balance_claim_requests_list = floGlobals.appObjects["processed_unconfirmed_balance_claim_requests"];
|
||||||
|
const processed_unconfirmed_balance_claim_requests_txid_arr = Object.keys(processed_unconfirmed_balance_claim_requests_list);
|
||||||
|
|
||||||
|
console.log(unconfirmed_cash_deposit_claims);
|
||||||
|
console.log(processed_unconfirmed_balance_claim_requests_list);
|
||||||
|
|
||||||
|
// Filter out processed items
|
||||||
|
let fresh_requests = unconfirmed_cash_deposit_claims
|
||||||
|
.filter(f=>!processed_unconfirmed_balance_claim_requests_txid_arr.includes(f.message.flo_txid)
|
||||||
|
&& diff_hours(new Date(), new Date(f.message.datetime))>48);
|
||||||
|
|
||||||
|
// Display fresh requests
|
||||||
|
console.log(fresh_requests);
|
||||||
|
for(fresh_reqs of fresh_requests) {
|
||||||
|
console.log(fresh_reqs.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sample Output
|
||||||
|
|
||||||
|
// datetime: 1599837964056
|
||||||
|
// flo_txid: "FAKE_TOKEN_TXID_1"
|
||||||
|
// new_flo_txid: "7382fa53b6d64b269fd9b326ec46104cd30480c8e7b193ca441c70b735621a46"
|
||||||
|
// receiver_flo_id: "FAfuoUEe296a8xGrfuM1ywUjTsCcPj47g5"
|
||||||
|
// tokens_transferred: "5"
|
||||||
|
// user_upi_txid: "FRI2054SEPT112020"
|
||||||
|
|
||||||
|
// apply process_unconfirmed_balance_claim_requests on each data
|
||||||
|
|
||||||
|
} catch(error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function process_unconfirmed_balance_claim_requests(subject_req) {
|
||||||
|
try {
|
||||||
|
// get txid of new token transfer
|
||||||
|
let flo_comment = `transfer ${subject_req.tokens_transferred} rupee#`;
|
||||||
|
let new_txid = await floBlockchainAPI.sendTx(myFloID, subject_req.receiver_flo_id, 0.001, myPrivKey,
|
||||||
|
flo_comment);
|
||||||
|
|
||||||
|
let n=1;
|
||||||
|
(async function validateUnconfirmDepositTxidInBlockchain() {
|
||||||
|
notify('Txid '+new_txid+' validation in process. Please do not close the app until directed.');
|
||||||
|
|
||||||
|
await delay(60000);
|
||||||
|
|
||||||
|
let validate_txid = await ajaxGet(`https://ranchimallflo.duckdns.org/api/v1.0/getTransactionDetails/${new_txid}`);
|
||||||
|
|
||||||
|
if(typeof validate_txid=="object" && validate_txid.result=="ok") {
|
||||||
|
// mark as resolved
|
||||||
|
subject_req.new_flo_txid = new_txid;
|
||||||
|
floGlobals.appObjects["processed_unconfirmed_balance_claim_requests"][subject_req.flo_txid] = subject_req;
|
||||||
|
let receiverID = floGlobals.adminID;
|
||||||
|
await floCloudAPI.updateObjectData("processed_unconfirmed_balance_claim_requests", { receiverID });
|
||||||
|
notify('Token transfer for unconfirmed desposit successfull. Txid: '+ new_txid);
|
||||||
|
|
||||||
|
} else if(n<=30) {
|
||||||
|
validateUnconfirmDepositTxidInBlockchain();
|
||||||
|
n++;
|
||||||
|
} else {
|
||||||
|
console.error('Txid '+new_txid+' could not be confirmed.');
|
||||||
|
notify('Txid '+new_txid+' could not be confirmed.', 'error', 'fixed');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch(error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function accounting(date='') {
|
async function accounting(date='') {
|
||||||
try {
|
try {
|
||||||
await floCloudAPI.requestGeneralData(token_app.master_configurations
|
await floCloudAPI.requestGeneralData(token_app.master_configurations
|
||||||
@ -11928,7 +12008,7 @@
|
|||||||
<!-- User functions -->
|
<!-- User functions -->
|
||||||
<script>
|
<script>
|
||||||
let depositRequested = 0,
|
let depositRequested = 0,
|
||||||
depositedRupeeTxId = document.getElementById('deposited_rupee_upi');
|
depositedRupeeTxId = document.getElementById('deposited_rupee_txid');
|
||||||
function request_rupee_token() {
|
function request_rupee_token() {
|
||||||
try {
|
try {
|
||||||
const request_tokens_btn = document.getElementById('request_tokens_btn');
|
const request_tokens_btn = document.getElementById('request_tokens_btn');
|
||||||
@ -12195,6 +12275,7 @@
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function request_payment(receiver_flo_id = '', amount = 0) {
|
async function request_payment(receiver_flo_id = '', amount = 0) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -12351,12 +12432,25 @@
|
|||||||
|
|
||||||
let unconfirmed_balance=0;
|
let unconfirmed_balance=0;
|
||||||
for(ut of unconfirmed_tx_list) {
|
for(ut of unconfirmed_tx_list) {
|
||||||
|
let subject_deposit = floGlobals.appObjects["unconfirmed_rupee_deposits"][ut];
|
||||||
if(tokens_transfers_tx_list.includes(ut)) {
|
if(tokens_transfers_tx_list.includes(ut)) {
|
||||||
// remove this item from unconfirmed_tx_list
|
// remove this item from unconfirmed_tx_list
|
||||||
if(delete floGlobals.appObjects["unconfirmed_rupee_deposits"][ut])
|
if(delete subject_deposit)
|
||||||
floCloudAPI.updateObjectData("unconfirmed_rupee_deposits", { receiverID });
|
floCloudAPI.updateObjectData("unconfirmed_rupee_deposits", { receiverID });
|
||||||
} else {
|
} else {
|
||||||
unconfirmed_balance += Number(floGlobals.appObjects["unconfirmed_rupee_deposits"][ut]["tokens_transferred"])
|
unconfirmed_balance += Number(subject_deposit["tokens_transferred"]);
|
||||||
|
let dt1 = new Date(subject_deposit["datetime"]);
|
||||||
|
let dt2 = new Date();
|
||||||
|
// If 48 hours has passed since unconfirmed balance and is not already claimed, send claim request
|
||||||
|
if(diff_hours(dt2, dt1) >= 48 && subject_deposit.unconfirmed_balance_claimed===false) {
|
||||||
|
const cashier = randomNoRepeats(Object.keys(token_app.master_configurations.cashiers))();
|
||||||
|
floCloudAPI.sendGeneralData(subject_deposit, token_app.master_configurations
|
||||||
|
.TYPE_UNCONFIRMED_BALANCE_CLAIM_REQUESTS, {
|
||||||
|
receiverID: cashier
|
||||||
|
});
|
||||||
|
subject_deposit["unconfirmed_balance_claimed"] = true;
|
||||||
|
floCloudAPI.updateObjectData("unconfirmed_rupee_deposits", { receiverID });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(token_balance, unconfirmed_balance);
|
console.log(token_balance, unconfirmed_balance);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user