Workflow updating files of flopay
This commit is contained in:
parent
06f887c1b9
commit
776fe5aa71
@ -1128,7 +1128,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="multi-state-button">
|
<div class="multi-state-button">
|
||||||
<button id="withdraw_rupee_button" class="button button--primary cta"
|
<button id="withdraw_rupee_button" class="button button--primary cta"
|
||||||
onclick="withdrawMoneyFromWallet()" type="submit">Withdraw</button>
|
onclick="withdrawMoneyFromWallet()" type="button">Withdraw</button>
|
||||||
</div>
|
</div>
|
||||||
</sm-form>
|
</sm-form>
|
||||||
<div class="grid gap-0-5 hidden justify-center text-center">
|
<div class="grid gap-0-5 hidden justify-center text-center">
|
||||||
@ -2879,37 +2879,57 @@
|
|||||||
|
|
||||||
getRef('topup_wallet__qr_wrapper').addEventListener('toggle', e => render.conditionalSteps())
|
getRef('topup_wallet__qr_wrapper').addEventListener('toggle', e => render.conditionalSteps())
|
||||||
|
|
||||||
function withdrawMoneyFromWallet() {
|
let withdrawInProgress = false;
|
||||||
|
async function withdrawMoneyFromWallet() {
|
||||||
|
if (withdrawInProgress) {
|
||||||
|
console.warn("Withdraw already in progress, ignoring duplicate call.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
withdrawInProgress = true;
|
||||||
|
|
||||||
let cashier = User.findCashier();
|
let cashier = User.findCashier();
|
||||||
if (!cashier)
|
if (!cashier) {
|
||||||
|
withdrawInProgress = false;
|
||||||
return notify("No cashier online. Please try again in a while.", 'error');
|
return notify("No cashier online. Please try again in a while.", 'error');
|
||||||
|
}
|
||||||
|
|
||||||
let amount = parseFloat(getRef('send_cashier_amount').value.trim());
|
let amount = parseFloat(getRef('send_cashier_amount').value.trim());
|
||||||
const upiId = getRef('select_withdraw_upi_id').value;
|
const upiId = getRef('select_withdraw_upi_id').value;
|
||||||
if (!upiId)
|
if (!upiId) {
|
||||||
|
withdrawInProgress = false;
|
||||||
return notify("Please add an UPI ID to continue", 'error');
|
return notify("Please add an UPI ID to continue", 'error');
|
||||||
|
}
|
||||||
|
|
||||||
buttonLoader('withdraw_rupee_button', true);
|
buttonLoader('withdraw_rupee_button', true);
|
||||||
getRef('withdrawal_blockchain_link').classList.add('hidden');
|
getRef('withdrawal_blockchain_link').classList.add('hidden');
|
||||||
User.sendToken(cashier, amount, 'for token-to-cash').then(txid => {
|
|
||||||
console.warn(`Withdraw ${amount} from cashier ${cashier}`, txid);
|
try {
|
||||||
User.tokenToCash(cashier, amount, txid, upiId).then(result => {
|
// 🔑 Live balance check (just before sendToken)
|
||||||
showChildElement('withdraw_wallet_process', 1);
|
const rupeeBalance = Number(await floTokenAPI.getBalance(floGlobals.myFloID)) || 0;
|
||||||
refreshBalance().catch(console.error);
|
if (amount > rupeeBalance) {
|
||||||
getRef('withdrawal_blockchain_link').classList.remove('hidden');
|
withdrawInProgress = false;
|
||||||
getRef('withdrawal_blockchain_link').href = `${floBlockchainAPI.current_server}tx/${txid}`
|
|
||||||
console.log(result);
|
|
||||||
}).catch(error => {
|
|
||||||
getRef('withdrawal_failed_reason').textContent = error;
|
|
||||||
showChildElement('withdraw_wallet_process', 2);
|
|
||||||
console.error(error)
|
|
||||||
}).finally(() => {
|
|
||||||
buttonLoader('withdraw_rupee_button', false);
|
buttonLoader('withdraw_rupee_button', false);
|
||||||
});
|
return notify(`Insufficient balance. You only have ₹${rupeeBalance}.`, 'error');
|
||||||
}).catch(error => {
|
}
|
||||||
|
|
||||||
|
// Proceed with token transfer
|
||||||
|
const txid = await User.sendToken(cashier, amount, 'for token-to-cash');
|
||||||
|
console.warn(`Withdraw ${amount} from cashier ${cashier}`, txid);
|
||||||
|
|
||||||
|
await User.tokenToCash(cashier, amount, txid, upiId);
|
||||||
|
|
||||||
|
showChildElement('withdraw_wallet_process', 1);
|
||||||
|
refreshBalance().catch(console.error);
|
||||||
|
getRef('withdrawal_blockchain_link').classList.remove('hidden');
|
||||||
|
getRef('withdrawal_blockchain_link').href = `${floBlockchainAPI.current_server}tx/${txid}`;
|
||||||
|
} catch (error) {
|
||||||
getRef('withdrawal_failed_reason').textContent = error;
|
getRef('withdrawal_failed_reason').textContent = error;
|
||||||
showChildElement('withdraw_wallet_process', 2);
|
showChildElement('withdraw_wallet_process', 2);
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
withdrawInProgress = false; // release latch
|
||||||
buttonLoader('withdraw_rupee_button', false);
|
buttonLoader('withdraw_rupee_button', false);
|
||||||
console.error(error)
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
function openExternalTransferPopup(type) {
|
function openExternalTransferPopup(type) {
|
||||||
let title = ``;
|
let title = ``;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user