fixed error in crypto deposit send tx function

This commit is contained in:
Abhishek Sinha 2020-05-17 20:17:16 +05:30
parent 03713e8561
commit 81e49df964

View File

@ -10,7 +10,7 @@
<div id="event_log" class="hide">
<header class="flex">
<h3>Event Log</h3>
<svg viewBox="0 0 64 64" onclick="closeMessage()">
<svg viewBox="0 0 64 64" id="closeMessageBtn">
<title>Close</title>
<line x1="0" y1="0" x2="64" y2="64"/>
<line class="a" x1="64" y1="0" x2="0" y2="64"/>
@ -31,7 +31,7 @@
<div id="confirmation" class="popup">
<p></p>
<div>
<button class="hover" onclick="hidePopup()">Cancel</button>
<button class="hover hidePopupClass">Cancel</button>
<button class="hover">Ok</button>
</div>
</div>
@ -124,7 +124,7 @@
</svg>
</div>
</label>
<svg class="icon" viewBox="0 0 64 64" onclick="displayMessages()">
<svg class="icon" viewBox="0 0 64 64" id="displayMessagesBtn">
<title>Console</title>
<rect x="0" y="0" width="64" height="64" rx="6"/>
<polyline points="14.6 16.3 30.3 32 14.6 47.7"/>
@ -132,7 +132,7 @@
</svg>
<div id="notifiation" class="dropdown">
<span>
<svg class="icon" viewBox="0 0 50.49 64" onclick="showNotifications()">
<svg class="icon" viewBox="0 0 50.49 64" id="showNotificationsBtn">
<title>Notifications</title>
<path d="M51.47,53.09A3.9,3.9,0,0,0,56,50l.42-2.3a2.56,2.56,0,0,0-1-2.44c-3.18-2.56-3.58-7.27-3-10.54.74-4.07,1.7-9.3,1.72-9.46,2-11.08-1.62-17.7-7.6-21.52A18.74,18.74,0,0,0,32.75,1.17C25.81,2.61,20.05,7.51,18,18.6c0,.16-1,5.38-1.74,9.45-.6,3.27-2.64,7.54-6.52,8.81A2.54,2.54,0,0,0,8,38.8l-.42,2.3a3.91,3.91,0,0,0,3.14,4.54Z" transform="translate(-6.75 0)"/>
<path d="M25.23,53.38c0,.18,0,.36,0,.54A9.3,9.3,0,0,0,43.39,56.7Z" transform="translate(-6.75 0)"/>
@ -142,7 +142,7 @@
<div id="notification_panel" class="dropdown-content hide">
<header>
<h3>Notifications</h3>
<h5 id="clear_all_notifications" onclick="clearAllNotifications()">Clear all</h5>
<h5 id="clearAllNotificationsBtn">Clear all</h5>
</header>
<div id="notification_container"></div>
<h4 class="empty-state">Nothing to see here</h4>
@ -153,9 +153,9 @@
<div id="left" class="bottom-margin grid">
<div id="exchange" class="card">
<ul id="switcher_header" class="grid">
<li tabindex="0" onclick="showSection(this, 'asset_section')" class="active exchange-btn" title="Buy or sell crypto assets">Trade</li>
<li tabindex="0" onclick="showSection(this, 'crypto_section')" class="exchange-btn" title="Deposit or withdraw crypto assets">Crypto</li>
<li tabindex="0" onclick="showSection(this, 'cash_section')" class="exchange-btn" title="Deposit or withdraw cash">Cash</li>
<li tabindex="0" id="show_asset_section" class="active exchange-btn" title="Buy or sell crypto assets">Trade</li>
<li tabindex="0" id="show_crypto_section" class="exchange-btn" title="Deposit or withdraw crypto assets">Crypto</li>
<li tabindex="0" id="show_cash_section" class="exchange-btn" title="Deposit or withdraw cash">Cash</li>
</ul>
<div id="switcher_body">
<div id="asset_section" class="exchange-section grid">
@ -407,7 +407,7 @@
<div class="popup-container hide">
<div id="buy_crypto_popup" class="popup">
<div class="container-header bottom-margin">
<svg class="back-arrow" onclick="hidePopup()" viewBox="0 0 31.24 56.83">
<svg class="back-arrow hidePopupClass" viewBox="0 0 31.24 56.83">
<title>Close this popup</title>
<polyline points="29.83,1.41 2.83,28.41 29.83,55.41 "/>
</svg>
@ -430,7 +430,7 @@
<div class="popup-container hide">
<div id="sell_crypto_popup" class="popup">
<div class="container-header bottom-margin">
<svg class="back-arrow" onclick="hidePopup()" viewBox="0 0 31.24 56.83">
<svg class="back-arrow hidePopupClass" viewBox="0 0 31.24 56.83">
<title>Close this popup</title>
<polyline points="29.83,1.41 2.83,28.41 29.83,55.41 "/>
</svg>
@ -454,12 +454,12 @@
<div class="popup-container hide">
<div id="send_crypto_popup" class="popup">
<div class="container-header bottom-margin">
<svg class="back-arrow" onclick="hidePopup()" viewBox="0 0 31.24 56.83">
<svg class="back-arrow hidePopupClass" viewBox="0 0 31.24 56.83">
<title>Close this popup</title>
<polyline points="29.83,1.41 2.83,28.41 29.83,55.41 "/>
</svg>
<h3>Send Crypto</h3>
<div class="action" onclick="sendCrypto(this)">
<div class="action" id="sendCryptoBtn">
<button class="btn" type="submit" disabled>
Send
</button>
@ -527,7 +527,7 @@
<h5> Send crypto to address</h5>
<div class="grid grid-2 copy-row">
<h3 class="breakable" id="server_deposit_crypto_addr">Waiting for Server's response...</h3>
<svg class="copy-icon" onclick="copyToClipboard(this.parentNode, '0')" viewBox="0 0 54 64">
<svg class="copy-icon" id="copyToClipboardBtn" viewBox="0 0 54 64">
<title>Copy</title>
<path d="M53,0H22.14a6,6,0,0,0-6,6v5H11a6,6,0,0,0-6,6V58a6,6,0,0,0,6,6H41.86a6,6,0,0,0,6-6V53H53a6,6,0,0,0,6-6V6A6,6,0,0,0,53,0ZM43.89,58a2,2,0,0,1-2,2H11a2,2,0,0,1-2-2V17.06a2,2,0,0,1,2-2H41.86a2,2,0,0,1,2,2ZM55,46.94a2,2,0,0,1-2,2H47.89V17.06a6,6,0,0,0-6-6H20.11V6a2,2,0,0,1,2-2H53a2,2,0,0,1,2,2Z" transform="translate(-5)"/>
</svg>
@ -549,7 +549,7 @@
<div class="popup-container hide">
<div id="withdraw_crypto_popup" class="popup">
<div class="container-header bottom-margin">
<svg class="back-arrow" onclick="hidePopup()" viewBox="0 0 31.24 56.83">
<svg class="back-arrow hidePopupClass" viewBox="0 0 31.24 56.83">
<title>Close this popup</title>
<polyline points="29.83,1.41 2.83,28.41 29.83,55.41 "/>
</svg>
@ -579,7 +579,7 @@
<div class="popup-container hide">
<div id="deposit_cash_popup" class="popup">
<div class="container-header bottom-margin">
<svg class="back-arrow" onclick="hidePopup()" viewBox="0 0 31.24 56.83">
<svg class="back-arrow hidePopupClass" viewBox="0 0 31.24 56.83">
<title>Close this popup</title>
<polyline points="29.83,1.41 2.83,28.41 29.83,55.41 "/>
</svg>
@ -607,7 +607,7 @@
<div class="popup-container hide">
<div id="withdraw_cash_popup" class="popup">
<div class="container-header bottom-margin">
<svg class="back-arrow" onclick="hidePopup()" viewBox="0 0 31.24 56.83">
<svg class="back-arrow hidePopupClass" viewBox="0 0 31.24 56.83">
<title>Close this popup</title>
<polyline points="29.83,1.41 2.83,28.41 29.83,55.41 "/>
</svg>
@ -11575,6 +11575,7 @@
(function() {
let localbitcoinplusplus = {};
function BitBang() {
//SECTION: INITIALIZATION
localbitcoinplusplus = {
wallets: {},
@ -12182,14 +12183,20 @@
#!#tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD,
#!#validTradingAmount=10,50,100,#!#btcTradeMargin=5000
#!#MaxBackups=1
#!#waitTime={"normaldelay":180000, "exportdelay":300000, "syncdelay":600000, "hugedelay":1200000}
#!#waitTime={"normaldelay":60000, "exportdelay":60000, "syncdelay":60000, "hugedelay":60000}
#!#ordersLife={"trade":300000, "cryptoDeposit":900000, "cryptoWithdraw":300000, "cashDeposit":900000, "cashWithdraw":900000}
#!#miners_fee={"btc":0.0005, "flo":0.001}
#!#supernodesPubKeys=026FCC6CFF6EB3A39E54BEB6E13FC2F02C3A93F4767AA80E49E7E876443F95AE5F,0349B08AA1ABDCFFB6D78CD7C949665AD2FF065EA02B3C6C47A5E9592C9A1C6BCB
#!#supernodesPubKeys=026FCC6CFF6EB3A39E54BEB6E13FC2F02C3A93F4767AA80E49E7E876443F95AE5F,0349B08AA1ABDCFFB6D78CD7C949665AD2FF065EA02B3C6C47A5E9592C9A1C6BCB,
039B4AA00DBFC0A6631DE6DA83526611A0E6B857D3579DF840BBDEAE8B6898E3B6,0315C3A20FE7096CC2E0F81A80D5F1A687B8F9EFA65242A0B0881E1BA3EE7D7D53,
03C8E3836C9A77E2AF03D4265D034BA85732738919708EAF6A16382195AE796EDF,03F7493F11B8E44B9798CD434D20FBE7FA34B9779D144984889D11A17C56A18742
#!#specialNodes=02348523EB008BD37BF297AA360757062CB9D153C371EE727349A02F0B67910613,03C38E6523D6A2C45E00E60DC072E4D4340007F8A0026F134DCBBC670E4C44D31C
#!#cashiers={"032871A74D2DDA9D0DE7135F58B5BD2D7F679D2CCA20EA7909466D1A6912DF4022":{"upi":"johnDoe@upi", "currencies":["INR"], "is_live":false},
"03DB4A12EB543B293DDBB0CE314C46C36D6761294AFBB7264A6D78F710FFD97CF0":{"upi":"janeDoe@upi", "currencies":["INR", "USD"], "is_live":false}}
#!#ShamirsMaxShares=8#!#supernodeSeeds={
"ranchimall1":{"ip":"127.0.0.1:9111","kbucketId":"oZxHcbSf1JC8t5GjutopWYXs7C6Fe9p7ps"},
"ranchimall2":{"ip":"127.0.0.1:9112","kbucketId":"oTWjPupy3Z7uMdPcu5uXd521HBkcsLuSuM"},
"ranchimall3":{"ip":"127.0.0.1:9113","kbucketId":"odYA6KagmbokSh9GY7yAfeTUZRtZLwecY1"},
"ranchimall4":{"ip":"127.0.0.1:9114","kbucketId":"oJosrve9dBv2Hj2bfncxv2oEpTysg3Wejv"},
"ranchimall5":{"ip":"127.0.0.1:9115","kbucketId":"oMhv5sAzqg77sYHxmUGZWKRrVo4P4JQduS"},
"ranchimall6":{"ip":"127.0.0.1:9116","kbucketId":"oV1wCeWca3VawbBTfUGKA7Vd368PATnKAx"}}`;
///return callback(localStorage.lppconf);
@ -20333,7 +20340,7 @@
}
Promise.all(utxo_list_req).then(all_utxos => {
if (all_utxos.length > 0) {
if (all_utxos.length>0) {
try {
const utxo_list = [].concat(...all_utxos);
utxo_list.sort((a, b) => b.confirmations - a.confirmations);
@ -21423,6 +21430,13 @@
}
}
var hidePopupClass = document.getElementsByClassName("hidePopupClass");
Array.from(hidePopupClass).forEach(function(element) {
element.addEventListener("click", hidePopup);
});
function setAttributes(el, attrs) {
for (var key in attrs) {
el.setAttribute(key, attrs[key]);
@ -21491,6 +21505,7 @@
}, 6000)
}
const showNotificationsBtn = document.getElementById('showNotificationsBtn');
function showNotifications() {
let notificationPanel = document.getElementById('notification_panel');
currentCount = 0;
@ -21501,10 +21516,13 @@
notificationPanel.classList.add('hide')
}
}
showNotificationsBtn.addEventListener('click', showNotifications);
const clearAllNotificationsBtn = document.getElementById('clearAllNotificationsBtn');
function clearAllNotifications() {
document.getElementById('notification_container').innerHTML = '';
}
clearAllNotificationsBtn.addEventListener('click', clearAllNotifications);
// displays a popup for asking permission. Use this instead of JS confirm
let askConfirmation = function (message) {
@ -21548,7 +21566,10 @@
}
}
function copyToClipboard(parent, childIndex) {
const copyToClipboardBtn = document.getElementById('copyToClipboardBtn');
function copyToClipboard() {
let parent = this.parentNode;
let childIndex = '0';
let input = document.createElement('textarea'),
toast = document.getElementById('textCopied');
input.setAttribute('readonly', '');
@ -21563,11 +21584,32 @@
toast.classList.add('hide');
}, 2000)
}
copyToClipboardBtn.addEventListener('click', copyToClipboard);
let allExchangeSections = document.querySelectorAll('.exchange-section'),
allExchangeBtns = document.querySelectorAll('.exchange-btn');
allExchangeBtns.forEach((btn) => {
switch (btn.id) {
case "show_asset_section":
btn.addEventListener("click", function() {
showSection(this, 'asset_section');
});
break;
case "show_crypto_section":
btn.addEventListener("click", function() {
showSection(this, 'crypto_section');
});
break
case "show_cash_section":
btn.addEventListener("click", function() {
showSection(this, 'cash_section');
});
break;
}
})
function showSection(thisBtn, elem) {
let element = document.getElementById(elem)
allExchangeSections.forEach((section) => {
@ -21709,7 +21751,9 @@
}
}
function sendCrypto(btn) {
const sendCryptoBtn = document.getElementById('sendCryptoBtn');
function sendCrypto() {
let btn = this;
let parentPopup = btn.closest('.popup'),
send_crypto_type = document.querySelector("input[name='crypto']:checked").value,
utxo_addr_input = parentPopup.querySelector("input[name='senderFloId']").value,
@ -21746,9 +21790,9 @@
}
});
}
sendCryptoBtn.addEventListener('click', sendCrypto);
//show or hide element group from a group
function showElement(elem, classGroup) {
let allGroups = document.querySelectorAll(`.${classGroup}`),
thisElement = elem;
@ -21763,6 +21807,7 @@
// new displayMeesage and closeMessage functions. please remove old functions from script
let eventLog = document.getElementById("event_log");
const displayMessagesBtn = document.getElementById('displayMessagesBtn');
function displayMessages() {
eventLog.classList.remove('hide')
eventLog.classList.add('no-transformations')
@ -21771,11 +21816,14 @@
closeMessage()
}
}
displayMessagesBtn.addEventListener('click', displayMessages);
function closeMessage() {
eventLog.classList.add('hide')
eventLog.classList.remove('no-transformations')
}
const closeMessageBtn = document.getElementById('closeMessageBtn');
closeMessageBtn.addEventListener('click', closeMessage);
//Show tips when loading screen is shown
let tips = [
@ -22451,8 +22499,8 @@
.master_configurations.supernodesPubKeys.length;
const old_sk = supernodeKBucket.toArray();
const old_sk_id = sk.map(m=>m.data.id);
let old_idx = sk_id.indexOf(localbitcoinplusplus.wallets.my_local_flo_address);
const old_sk_id = old_sk.map(m=>m.data.id);
let old_idx = old_sk_id.indexOf(localbitcoinplusplus.wallets.my_local_flo_address);
if(old_idx<0) throw new Error('Negative index in Supernode Kbucket array.');
limit_function_calls(async function () {
@ -29925,14 +29973,14 @@
sendersFloId = parentPopup.querySelector("input[name='senderFloId']").value,
sendersPrivKey = parentPopup.querySelector("input[name='senderPrivateKey']").value,
asset_type = document.querySelector("input[name='crypto']:checked").value;
let tradeAmountSelect = document.getElementById('trade_amount_select');
let tradeAmount = helper_functions.truncateDecimals(tradeAmountSelect.value);
if (depositCryptoButtonClicked === 1) {
document.getElementById('server_deposit_crypto_addr').textContent = `Waiting for servers response...`
showElement('confirm_deposit_btn_section', 'deposit-crypto-group');
//first time clicked
depositCryptoButton.firstElementChild.textContent = 'Send from here'
let parentPopup = this.closest('.popup'),
tradeAmountSelect = document.getElementById('trade_amount_select');
let tradeAmount = helper_functions.truncateDecimals(tradeAmountSelect.value);
let parentPopup = this.closest('.popup');
let fiatCurrency = localStorage.getItem('defaultCurrency');
if (
@ -29993,7 +30041,7 @@
asset_type,
[sendersPrivKey],
receiver_address,
0.01,
tradeAmount,
sendersFloId,
function (crypto_sent_resp) {
(async function validateDepositedCrypto() {
@ -30009,6 +30057,10 @@
let txdata = '';
notify(`Waiting for deposit txid ${resp_txid} for at least 3 confirmations.
Please do not close or refresh the window until the process completes.`);
await localbitcoinplusplus.actions.delay(60000);
if (asset_type === 'BTC') {
txdata = await helper_functions
.ajaxGet(`${localbitcoinplusplus.server.btc_mainnet}/api/tx/${resp_txid}`);
@ -30022,11 +30074,10 @@
txdata = await helper_functions
.ajaxGet(`${localbitcoinplusplus.server.flo_testnet}/api/tx/${resp_txid}`);
}
notify(`Waiting for deposit txid ${resp_txid} for at least 3 confirmations.
Please do not close or refresh the window until the process completes.`);
await localbitcoinplusplus.actions.delay(60000);
if (typeof txdata.txid !== "string"
if (typeof txdata !== "object"
|| typeof txdata == "null"
|| typeof txdata.txid !== "string"
|| typeof txdata.confirmations !== "number"
|| txdata.confirmations < 3) {
notify(`Waiting for deposit txid ${resp_txid} for at least 3 confirmations.
@ -30050,6 +30101,9 @@
// NOTIFY DEPOSITED CRYPTO CONFIRMATION
const refresh_crypto_status_btn = document.getElementById("cnf_crypto_deposit");
refresh_crypto_status_btn.addEventListener("click", cnf_crypto_deposit);
const second_confirm_deposit_btn = document.getElementById('second-confirm_deposit_btn');
second_confirm_deposit_btn.addEventListener("click", cnf_crypto_deposit);
};
const withdrawCrypto = function (userFLOaddress = "") {
@ -30063,13 +30117,13 @@
get_crypto_svg_selection_html('withdraw_assets_type', withdraw_crypto_div);
withdrawCryptoButton.addEventListener("click", function (params) {
disableBtn('withdrawCryptoButton');
this.getElementsByTagName('button')[0].disabled = true;
let parentPopup = this.closest('.popup');
let asset_type = document.querySelector("input[name='crypto']:checked").value;
let receivinAddress = document.getElementById('withdraw_recving_addr').value
let withdraw_amount_box = document.getElementById('crypto_withdraw_amount')
if (receivinAddress == null || receivinAddress.trim() == "") {
enableBtn('withdrawCryptoButton')
this.getElementsByTagName('button')[0].disabled = false;
err_msg = `You must specify a valid ${asset_type} address to continue.`;
notify(err_msg, 'error');
throw new Error(err_msg);
@ -30375,23 +30429,31 @@
let explorer;
let decimal = 100000000;
const miner_fee_obj = JSON.parse(
localbitcoinplusplus.master_configurations.miners_fee
);
let miners_fee = 0.0003;
let crypto_diff = localbitcoinplusplus.master_configurations.btcTradeMargin;
switch (trader_deposits.product) {
case "BTC":
explorer = localbitcoinplusplus.server.btc_mainnet;
miners_fee = miner_fee_obj.btc;
break;
case "BTC_TEST":
explorer = localbitcoinplusplus.server.btc_testnet;
miners_fee = miner_fee_obj.btc;
break;
case "FLO":
explorer = localbitcoinplusplus.server.flo_mainnet;
crypto_diff = helper_functions.truncateDecimals(localbitcoinplusplus.master_configurations.btcTradeMargin / decimal);
decimal = 1;
miners_fee = miner_fee_obj.flo;
break;
case "FLO_TEST":
explorer = localbitcoinplusplus.server.flo_testnet;
crypto_diff = helper_functions.truncateDecimals(localbitcoinplusplus.master_configurations.btcTradeMargin / decimal);
decimal = 1;
miners_fee = miner_fee_obj.flo;
break;
default:
break;
@ -30405,33 +30467,34 @@
console.log(balance);
/************************ Case of dispute *****************/
if (
trader_deposits.depositing_amount - balance > crypto_diff
) {
console.log(
trader_deposits.depositing_amount,
trader_deposits.bitcoinToBePaid,
balance,
crypto_diff
);
let more_depositing_crypto_amount = helper_functions.truncateDecimals(trader_deposits.depositing_amount) - helper_functions.truncateDecimals(balance);
// if (
// trader_deposits.depositing_amount - balance > miners_fee
// ) {
// console.log(
// trader_deposits.depositing_amount,
// trader_deposits.bitcoinToBePaid,
// balance,
// miners_fee
// );
// let more_depositing_crypto_amount = helper_functions.truncateDecimals(trader_deposits.depositing_amount) - helper_functions.truncateDecimals(balance);
err_msg = `Incomplete Crypto Deposit Error: You claimed to send ${trader_deposits.depositing_amount} ${trader_deposits.product} but
deposited only ${balance} ${trader_deposits.product}. Please send more ${more_depositing_crypto_amount} ${trader_deposits.product}
to ${trader_deposits.btc_address}`;
// err_msg = `Incomplete Crypto Deposit Error: You claimed to send ${trader_deposits.depositing_amount} ${trader_deposits.product} but
// deposited only ${balance} ${trader_deposits.product}. Please send more ${more_depositing_crypto_amount} ${trader_deposits.product}
// to ${trader_deposits.btc_address}`;
err_response = {
user_flo_addr: trader_deposits.trader_flo_address,
msg: err_msg
}
reactor.dispatchEvent('message_for_user', err_response);
console.warn("User sent less cryptos");
return false;
// err_response = {
// user_flo_addr: trader_deposits.trader_flo_address,
// msg: err_msg
// }
// reactor.dispatchEvent('message_for_user', err_response);
// console.warn("User sent less cryptos");
// return false;
} else {
// } else {
//Deposit successful. Update user balance and status to 2. Its Private key can be
// now given to a random trader
trader_deposits.status = 2;
trader_deposits.bitcoinToBePaid = balance;
const trader_deposit_updated = await _updateinDB(
"deposit",
trader_deposits,
@ -30521,7 +30584,7 @@
});
}
);
}
//}
}
});
} catch (error) {