added min % difference logic between eqCrypto and user balance in tradeSell
This commit is contained in:
parent
9e7efd4cbf
commit
11bd902246
@ -12411,11 +12411,10 @@
|
|||||||
localbitcoinplusplus.master_configurations.supernodeSeeds;
|
localbitcoinplusplus.master_configurations.supernodeSeeds;
|
||||||
if (typeof supernodeSeeds !== "object")
|
if (typeof supernodeSeeds !== "object")
|
||||||
reject("Failed to get supernode seeds.");
|
reject("Failed to get supernode seeds.");
|
||||||
let supernodeSeedsObj = JSON.parse(supernodeSeeds);
|
nearestSupernodeAddresslist = Object.values(supernodeSeeds);
|
||||||
nearestSupernodeAddresslist = Object.values(supernodeSeedsObj);
|
|
||||||
nearestSupernodeAddresslist.map((m, i) => {
|
nearestSupernodeAddresslist.map((m, i) => {
|
||||||
m.id = i + 1;
|
let sl = Object.assign({id: i+1}, m);
|
||||||
updateinDB("supernodesList", m).catch(e => {
|
updateinDB("supernodesList", sl).catch(e => {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -12848,7 +12847,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateinDB(
|
function updateinDB(
|
||||||
tablename,
|
tablename,
|
||||||
Obj,
|
Obj,
|
||||||
key,
|
key,
|
||||||
@ -12857,43 +12856,51 @@
|
|||||||
) {
|
) {
|
||||||
// updateByVectorClock==true will not return Obj back.
|
// updateByVectorClock==true will not return Obj back.
|
||||||
// Return value will be undefined
|
// Return value will be undefined
|
||||||
try {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof Obj.vectorClock == "undefined") {
|
|
||||||
Obj.vectorClock = 0;
|
try {
|
||||||
} else if (increaseVectorClock === false) {
|
if (typeof Obj.vectorClock == "undefined") {
|
||||||
// leave the vector clock field unchanged
|
Obj.vectorClock = 0;
|
||||||
} else {
|
} else if (increaseVectorClock === false) {
|
||||||
Obj.vectorClock += 1;
|
// leave the vector clock field unchanged
|
||||||
}
|
} else {
|
||||||
if (typeof Obj.timestamp !== "number") {
|
Obj.vectorClock += 1;
|
||||||
Obj.timestamp = +new Date();
|
|
||||||
}
|
|
||||||
var request = db.transaction([tablename], "readwrite");
|
|
||||||
let store = request.objectStore(tablename);
|
|
||||||
if (updateByVectorClock === true) {
|
|
||||||
if (typeof key == "undefined") {
|
|
||||||
key = Obj[store.keyPath];
|
|
||||||
}
|
|
||||||
let objectStoreRequest = store.get(key);
|
|
||||||
objectStoreRequest.onsuccess = async function(event) {
|
|
||||||
var myRecord = objectStoreRequest.result;
|
|
||||||
if (typeof myRecord !== "object") {
|
|
||||||
Obj.vectorClock = 1;
|
|
||||||
await store.put(Obj);
|
|
||||||
await request.complete;
|
|
||||||
} else if (myRecord.vectorClock + 1 < Obj.vectorClock) {
|
|
||||||
await store.put(Obj);
|
|
||||||
await request.complete;
|
|
||||||
}
|
}
|
||||||
};
|
if (typeof Obj.timestamp !== "number") {
|
||||||
} else {
|
Obj.timestamp = +new Date();
|
||||||
await store.put(Obj);
|
}
|
||||||
await request.complete;
|
var request = db.transaction([tablename], "readwrite");
|
||||||
|
let store = request.objectStore(tablename);
|
||||||
|
if (updateByVectorClock === true) {
|
||||||
|
if (typeof key == "undefined") {
|
||||||
|
key = Obj[store.keyPath];
|
||||||
|
}
|
||||||
|
let objectStoreRequest = store.get(key);
|
||||||
|
objectStoreRequest.onsuccess = async function(event) {
|
||||||
|
var myRecord = objectStoreRequest.result;
|
||||||
|
if (typeof myRecord !== "object") {
|
||||||
|
Obj.vectorClock = 1;
|
||||||
|
store.put(Obj);
|
||||||
|
} else if (myRecord.vectorClock + 1 < Obj.vectorClock) {
|
||||||
|
store.put(Obj);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
store.put(Obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
store.onsuccess = function() {
|
||||||
|
resolve(Obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
store.onerror = function(e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
reject(error);
|
||||||
|
return new Error(error);
|
||||||
}
|
}
|
||||||
return Obj;
|
});
|
||||||
} catch (error) {
|
|
||||||
return new Error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeinDB(tablename, id) {
|
async function removeinDB(tablename, id) {
|
||||||
|
|||||||
@ -546,10 +546,9 @@
|
|||||||
Close
|
Close
|
||||||
</div>
|
</div>
|
||||||
<pre id="log">
|
<pre id="log">
|
||||||
Event information log
|
Event information log
|
||||||
=====================
|
=====================
|
||||||
</pre
|
</pre>
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="w3-button w3-teal w3-xlarge" onclick="displayMessages()">
|
<div class="w3-button w3-teal w3-xlarge" onclick="displayMessages()">
|
||||||
☰
|
☰
|
||||||
@ -13963,6 +13962,7 @@ Event information log
|
|||||||
|
|
||||||
function showMessage(msg = "", t = 10000) {
|
function showMessage(msg = "", t = 10000) {
|
||||||
if (msg.length > 0) LogEvent(msg);
|
if (msg.length > 0) LogEvent(msg);
|
||||||
|
console.trace(msg);
|
||||||
displayMessages();
|
displayMessages();
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
closeMessage();
|
closeMessage();
|
||||||
@ -14871,6 +14871,19 @@ Event information log
|
|||||||
params.currency,
|
params.currency,
|
||||||
params.product
|
params.product
|
||||||
);
|
);
|
||||||
|
// If margin is > 2% discontinue the trade
|
||||||
|
const diffPercent = Math.floor(((eqCrypto- trade_margin.remaining_crypto_credit)
|
||||||
|
/trade_margin.remaining_crypto_credit)*100);
|
||||||
|
console.log(trade_margin.remaining_crypto_credit, eqCrypto);
|
||||||
|
console.info(diffPercent);
|
||||||
|
|
||||||
|
if(diffPercent<=2) {
|
||||||
|
eqCrypto = trade_margin.remaining_crypto_credit;
|
||||||
|
} else {
|
||||||
|
console.info(`Info: Difference between Crypto balance and trading amount is too high: ${diffPercent}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
trade_margin.remaining_crypto_credit > 0 &&
|
trade_margin.remaining_crypto_credit > 0 &&
|
||||||
trade_margin.remaining_crypto_credit >= eqCrypto
|
trade_margin.remaining_crypto_credit >= eqCrypto
|
||||||
@ -16478,6 +16491,16 @@ Event information log
|
|||||||
params.currency,
|
params.currency,
|
||||||
params.product
|
params.product
|
||||||
);
|
);
|
||||||
|
const diffPercent = Math.floor(((eqCrypto- trade_margin.remaining_crypto_credit)
|
||||||
|
/trade_margin.remaining_crypto_credit)*100);
|
||||||
|
|
||||||
|
if(diffPercent<=2) {
|
||||||
|
eqCrypto=trade_margin.remaining_crypto_credit;
|
||||||
|
} else {
|
||||||
|
console.info(`Info: Difference between Crypto balance and trading amount is too high: ${diffPercent}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
trade_margin.remaining_crypto_credit > 0 &&
|
trade_margin.remaining_crypto_credit > 0 &&
|
||||||
trade_margin.remaining_crypto_credit >= eqCrypto
|
trade_margin.remaining_crypto_credit >= eqCrypto
|
||||||
@ -20799,7 +20822,10 @@ Event information log
|
|||||||
if (isDataSignedBySuperNode === true) {
|
if (isDataSignedBySuperNode === true) {
|
||||||
// Add buy order
|
// Add buy order
|
||||||
addDB("buyOrders", buyOrders_data).then(() => {
|
addDB("buyOrders", buyOrders_data).then(() => {
|
||||||
showMessage(`Your buy order is placed successfully.`);
|
if(localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
|
===buyOrders_data.trader_flo_address) {
|
||||||
|
showMessage(`Your buy order is placed successfully.`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20832,9 +20858,13 @@ Event information log
|
|||||||
if (isDataSignedBySuperNode === true) {
|
if (isDataSignedBySuperNode === true) {
|
||||||
// Add buy order
|
// Add buy order
|
||||||
addDB("sellOrders", sellOrders_data).then(() => {
|
addDB("sellOrders", sellOrders_data).then(() => {
|
||||||
showMessage(
|
if(localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
|
===sellOrders_data.trader_flo_address) {
|
||||||
|
showMessage(
|
||||||
`Your sell order is placed successfully.`
|
`Your sell order is placed successfully.`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22584,7 +22614,10 @@ Event information log
|
|||||||
if (isDataSignedBySuperNode === true) {
|
if (isDataSignedBySuperNode === true) {
|
||||||
// Add buy order
|
// Add buy order
|
||||||
addDB("buyOrders", buyOrders_data).then(() => {
|
addDB("buyOrders", buyOrders_data).then(() => {
|
||||||
showMessage(`Your buy order is placed successfully.`);
|
if(localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
|
===buyOrders_data.trader_flo_address) {
|
||||||
|
showMessage(`Your buy order is placed successfully.`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22626,9 +22659,12 @@ Event information log
|
|||||||
if (isDataSignedBySuperNode === true) {
|
if (isDataSignedBySuperNode === true) {
|
||||||
// Add buy order
|
// Add buy order
|
||||||
addDB("sellOrders", sellOrders_data).then(() => {
|
addDB("sellOrders", sellOrders_data).then(() => {
|
||||||
showMessage(
|
if(localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
|
===sellOrders_data.trader_flo_address) {
|
||||||
|
showMessage(
|
||||||
`Your sell order is placed successfully.`
|
`Your sell order is placed successfully.`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24610,10 +24646,7 @@ Event information log
|
|||||||
|
|
||||||
// Add buy order
|
// Add buy order
|
||||||
backup_server_db_instance
|
backup_server_db_instance
|
||||||
.backup_addDB("buyOrders", buyOrders_data)
|
.backup_addDB("buyOrders", buyOrders_data);
|
||||||
.then(() => {
|
|
||||||
showMessage(`Your buy order is placed successfully.`);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -24653,12 +24686,7 @@ Event information log
|
|||||||
|
|
||||||
// Add buy order
|
// Add buy order
|
||||||
backup_server_db_instance
|
backup_server_db_instance
|
||||||
.backup_addDB("sellOrders", sellOrders_data)
|
.backup_addDB("sellOrders", sellOrders_data);
|
||||||
.then(() => {
|
|
||||||
showMessage(
|
|
||||||
`Your sell order is placed successfully.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26783,7 +26811,7 @@ Event information log
|
|||||||
|
|
||||||
var db;
|
var db;
|
||||||
const DBName = "localbitcoinDB";
|
const DBName = "localbitcoinDB";
|
||||||
const request = window.indexedDB.open(DBName, 5);
|
const request = window.indexedDB.open(DBName, 1);
|
||||||
|
|
||||||
request.onerror = function(event) {
|
request.onerror = function(event) {
|
||||||
//https://stackoverflow.com/questions/13972385/invalidstateerror-while-opening-indexeddb-in-firefox
|
//https://stackoverflow.com/questions/13972385/invalidstateerror-while-opening-indexeddb-in-firefox
|
||||||
@ -28059,6 +28087,9 @@ Event information log
|
|||||||
// Deposit / Withdraw asset
|
// Deposit / Withdraw asset
|
||||||
depositWithdrawAsset(idbData.myLocalFLOAddress);
|
depositWithdrawAsset(idbData.myLocalFLOAddress);
|
||||||
|
|
||||||
|
// Deposit / Withdraw Fiat
|
||||||
|
depositWithdrawFiat(idbData.myLocalFLOAddress);
|
||||||
|
|
||||||
// User's Trade Details
|
// User's Trade Details
|
||||||
displayTradeOrders(idbData.myLocalFLOAddress);
|
displayTradeOrders(idbData.myLocalFLOAddress);
|
||||||
|
|
||||||
@ -28389,7 +28420,7 @@ Event information log
|
|||||||
|
|
||||||
<!-- Deposit/Withdraw Crypto -->
|
<!-- Deposit/Withdraw Crypto -->
|
||||||
<script>
|
<script>
|
||||||
const depositWithdrawAsset = function(userFLOaddress) {
|
const depositWithdrawAsset = function(userFLOaddress="") {
|
||||||
const RM_TRADE = new localbitcoinplusplus.trade();
|
const RM_TRADE = new localbitcoinplusplus.trade();
|
||||||
const RM_RPC = new localbitcoinplusplus.rpc();
|
const RM_RPC = new localbitcoinplusplus.rpc();
|
||||||
|
|
||||||
@ -28403,24 +28434,15 @@ Event information log
|
|||||||
asset_box.appendChild(assetTypeInput);
|
asset_box.appendChild(assetTypeInput);
|
||||||
if (
|
if (
|
||||||
typeof localbitcoinplusplus.master_configurations.tradableAsset1 !==
|
typeof localbitcoinplusplus.master_configurations.tradableAsset1 !==
|
||||||
"undefined" &&
|
"undefined") {
|
||||||
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !==
|
|
||||||
"undefined"
|
|
||||||
) {
|
|
||||||
let assetTypeSelectArray1 = JSON.parse(
|
let assetTypeSelectArray1 = JSON.parse(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset1
|
localbitcoinplusplus.master_configurations.tradableAsset1
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
let assetTypeSelectArray2 = JSON.parse(
|
|
||||||
JSON.stringify(
|
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset2
|
|
||||||
)
|
|
||||||
);
|
|
||||||
let assetTypeSelectArray = assetTypeSelectArray1
|
let assetTypeSelectArray = assetTypeSelectArray1
|
||||||
.concat(assetTypeSelectArray2)
|
|
||||||
.filter((item, pos, finalArray) => finalArray.indexOf(item) == pos);
|
.filter((item, pos, finalArray) => finalArray.indexOf(item) == pos);
|
||||||
assetTypeSelectArray.unshift("Select Asset Type");
|
assetTypeSelectArray.unshift("Select Crypto");
|
||||||
for (var i = 0; i < assetTypeSelectArray.length; i++) {
|
for (var i = 0; i < assetTypeSelectArray.length; i++) {
|
||||||
var option = document.createElement("option");
|
var option = document.createElement("option");
|
||||||
option.value = assetTypeSelectArray[i];
|
option.value = assetTypeSelectArray[i];
|
||||||
@ -28429,22 +28451,6 @@ Event information log
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a select input for trade amount
|
|
||||||
// let tradeAmountSelect = document.createElement('select');
|
|
||||||
// tradeAmountSelect.id = "trade_amount_select";
|
|
||||||
// asset_box.appendChild(tradeAmountSelect);
|
|
||||||
// if (typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined' &&
|
|
||||||
// localbitcoinplusplus.master_configurations.validTradingAmount.length > 0) {
|
|
||||||
// let tradeAmountSelectArray = JSON.parse(JSON.stringify(localbitcoinplusplus.master_configurations.validTradingAmount));
|
|
||||||
// tradeAmountSelectArray.unshift("Select Asset Amount");
|
|
||||||
// for (var i = 0; i < tradeAmountSelectArray.length; i++) {
|
|
||||||
// var option = document.createElement("option");
|
|
||||||
// option.value = tradeAmountSelectArray[i];
|
|
||||||
// option.text = tradeAmountSelectArray[i];
|
|
||||||
// tradeAmountSelect.appendChild(option);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
let tradeAmountSelect = document.createElement("input");
|
let tradeAmountSelect = document.createElement("input");
|
||||||
tradeAmountSelect.setAttribute("type", "text");
|
tradeAmountSelect.setAttribute("type", "text");
|
||||||
tradeAmountSelect.setAttribute("placeholder", "Specify Asset Amount");
|
tradeAmountSelect.setAttribute("placeholder", "Specify Asset Amount");
|
||||||
@ -28459,14 +28465,9 @@ Event information log
|
|||||||
"undefined" &&
|
"undefined" &&
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset2.length > 0
|
localbitcoinplusplus.master_configurations.tradableAsset2.length > 0
|
||||||
) {
|
) {
|
||||||
let fiatList = localbitcoinplusplus.master_configurations.tradableAsset2.filter(
|
let fiatList = localbitcoinplusplus.master_configurations.tradableAsset2;
|
||||||
asset =>
|
|
||||||
!localbitcoinplusplus.master_configurations.tradableAsset1.includes(
|
|
||||||
asset
|
|
||||||
)
|
|
||||||
);
|
|
||||||
let fiatListArray = JSON.parse(JSON.stringify(fiatList));
|
let fiatListArray = JSON.parse(JSON.stringify(fiatList));
|
||||||
fiatListArray.unshift("Select Fiat Currency");
|
fiatListArray.unshift("Select Fiat Currency (for exchange rates)");
|
||||||
for (var i = 0; i < fiatListArray.length; i++) {
|
for (var i = 0; i < fiatListArray.length; i++) {
|
||||||
var option = document.createElement("option");
|
var option = document.createElement("option");
|
||||||
option.value = fiatListArray[i];
|
option.value = fiatListArray[i];
|
||||||
@ -28504,11 +28505,6 @@ Event information log
|
|||||||
.tradableAsset1 !== "undefined" &&
|
.tradableAsset1 !== "undefined" &&
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset1.includes(
|
localbitcoinplusplus.master_configurations.tradableAsset1.includes(
|
||||||
asset_type
|
asset_type
|
||||||
)) ||
|
|
||||||
(typeof localbitcoinplusplus.master_configurations
|
|
||||||
.tradableAsset2 !== "undefined" &&
|
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset2.includes(
|
|
||||||
asset_type
|
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
RM_TRADE.depositAsset(
|
RM_TRADE.depositAsset(
|
||||||
@ -28526,11 +28522,10 @@ Event information log
|
|||||||
|
|
||||||
withdrawAssetButton.addEventListener("click", function(params) {
|
withdrawAssetButton.addEventListener("click", function(params) {
|
||||||
let receivinAddress = prompt(
|
let receivinAddress = prompt(
|
||||||
"Please enter a valid Crypto address or UPI id."
|
`Please enter your ${asset_type} receiving address.`
|
||||||
);
|
);
|
||||||
if (receivinAddress == null || receivinAddress.trim == "") {
|
if (receivinAddress == null || receivinAddress.trim == "") {
|
||||||
err_msg =
|
err_msg =`You must specify a valid ${asset_type} address to continue.`;
|
||||||
"You must specify either a Bitcoin address to withdraw Bitcoin or your bank detail to withdraw cash.";
|
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
@ -28547,30 +28542,10 @@ Event information log
|
|||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset2.includes(
|
|
||||||
asset_type
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
typeof localbitcoinplusplus.master_configurations
|
|
||||||
.validTradingAmount !== "undefined" &&
|
|
||||||
!localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
|
||||||
tradeAmount
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
err_msg = "Invalid Fiat Value.";
|
|
||||||
showMessage(err_msg);
|
|
||||||
throw new Error(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
typeof localbitcoinplusplus.master_configurations.tradableAsset1 !==
|
typeof localbitcoinplusplus.master_configurations.tradableAsset1 !==
|
||||||
"undefined" &&
|
"undefined" &&
|
||||||
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !==
|
|
||||||
"undefined" &&
|
|
||||||
localbitcoinplusplus.master_configurations.tradableAsset1
|
localbitcoinplusplus.master_configurations.tradableAsset1
|
||||||
.concat(localbitcoinplusplus.master_configurations.tradableAsset2)
|
|
||||||
.includes(asset_type)
|
.includes(asset_type)
|
||||||
) {
|
) {
|
||||||
RM_TRADE.withdrawAsset(
|
RM_TRADE.withdrawAsset(
|
||||||
@ -28581,7 +28556,7 @@ Event information log
|
|||||||
fiatCurrency
|
fiatCurrency
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err_msg = "Error while depositing your address.";
|
err_msg = `Error: Withdraw of Crypto failed. Invalid asset type ${asset_type} provided.`;
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
@ -28610,7 +28585,7 @@ Event information log
|
|||||||
|
|
||||||
<!-- Deposit/Withdraw Cash -->
|
<!-- Deposit/Withdraw Cash -->
|
||||||
<script>
|
<script>
|
||||||
function depositWithdrawFiat() {
|
function depositWithdrawFiat(userFLOaddress="") {
|
||||||
const RM_TRADE = new localbitcoinplusplus.trade();
|
const RM_TRADE = new localbitcoinplusplus.trade();
|
||||||
const RM_RPC = new localbitcoinplusplus.rpc();
|
const RM_RPC = new localbitcoinplusplus.rpc();
|
||||||
|
|
||||||
@ -28644,34 +28619,34 @@ Event information log
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a select input for trade amount
|
// Create a select input for trade amount
|
||||||
let tradeAmountSelect = document.createElement("select");
|
// let tradeAmountSelect = document.createElement("select");
|
||||||
tradeAmountSelect.id = "trade_amount_select";
|
|
||||||
asset_box.appendChild(tradeAmountSelect);
|
|
||||||
if (
|
|
||||||
typeof localbitcoinplusplus.master_configurations
|
|
||||||
.validTradingAmount !== "undefined" &&
|
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount.length >
|
|
||||||
0
|
|
||||||
) {
|
|
||||||
let tradeAmountSelectArray = JSON.parse(
|
|
||||||
JSON.stringify(
|
|
||||||
localbitcoinplusplus.master_configurations.validTradingAmount
|
|
||||||
)
|
|
||||||
);
|
|
||||||
tradeAmountSelectArray.unshift("Select Asset Amount");
|
|
||||||
for (var i = 0; i < tradeAmountSelectArray.length; i++) {
|
|
||||||
var option = document.createElement("option");
|
|
||||||
option.value = tradeAmountSelectArray[i];
|
|
||||||
option.text = tradeAmountSelectArray[i];
|
|
||||||
tradeAmountSelect.appendChild(option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// let tradeAmountSelect = document.createElement('input');
|
|
||||||
// tradeAmountSelect.setAttribute("type", "text");
|
|
||||||
// tradeAmountSelect.setAttribute("placeholder", "Specify Asset Amount");
|
|
||||||
// tradeAmountSelect.id = "trade_amount_select";
|
// tradeAmountSelect.id = "trade_amount_select";
|
||||||
// asset_box.appendChild(tradeAmountSelect);
|
// asset_box.appendChild(tradeAmountSelect);
|
||||||
|
// if (
|
||||||
|
// typeof localbitcoinplusplus.master_configurations
|
||||||
|
// .validTradingAmount !== "undefined" &&
|
||||||
|
// localbitcoinplusplus.master_configurations.validTradingAmount.length >
|
||||||
|
// 0
|
||||||
|
// ) {
|
||||||
|
// let tradeAmountSelectArray = JSON.parse(
|
||||||
|
// JSON.stringify(
|
||||||
|
// localbitcoinplusplus.master_configurations.validTradingAmount
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// tradeAmountSelectArray.unshift("Select Asset Amount");
|
||||||
|
// for (var i = 0; i < tradeAmountSelectArray.length; i++) {
|
||||||
|
// var option = document.createElement("option");
|
||||||
|
// option.value = tradeAmountSelectArray[i];
|
||||||
|
// option.text = tradeAmountSelectArray[i];
|
||||||
|
// tradeAmountSelect.appendChild(option);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
let tradeAmountSelect = document.createElement('input');
|
||||||
|
tradeAmountSelect.setAttribute("type", "text");
|
||||||
|
tradeAmountSelect.setAttribute("placeholder", "Specify Asset Amount");
|
||||||
|
tradeAmountSelect.id = "trade_amount_select";
|
||||||
|
asset_box.appendChild(tradeAmountSelect);
|
||||||
|
|
||||||
// let currencySelect = document.createElement('select');
|
// let currencySelect = document.createElement('select');
|
||||||
// currencySelect.id = `withdraw_fiat_currency`;
|
// currencySelect.id = `withdraw_fiat_currency`;
|
||||||
@ -28693,14 +28668,16 @@ Event information log
|
|||||||
// Create a deposit and withdraw button
|
// Create a deposit and withdraw button
|
||||||
let depositAssetButton = document.createElement("button");
|
let depositAssetButton = document.createElement("button");
|
||||||
depositAssetButton.className += ` button bg-transparent fs-16 mg-5 `;
|
depositAssetButton.className += ` button bg-transparent fs-16 mg-5 `;
|
||||||
let depositAssetButtonText = document.createTextNode("Deposit");
|
let depositAssetButtonText = document.createTextNode("Deposit Cash");
|
||||||
depositAssetButton.appendChild(depositAssetButtonText);
|
depositAssetButton.appendChild(depositAssetButtonText);
|
||||||
// let withdrawAssetButton = document.createElement('button');
|
|
||||||
// withdrawAssetButton.className += ` button bg-transparent fs-16 mg-5 `;
|
let withdrawAssetButton = document.createElement('button');
|
||||||
// let withdrawAssetButtonText = document.createTextNode('Withdraw');
|
withdrawAssetButton.className += ` button bg-transparent fs-16 mg-5 `;
|
||||||
// withdrawAssetButton.appendChild(withdrawAssetButtonText);
|
let withdrawAssetButtonText = document.createTextNode('Withdraw Cash');
|
||||||
// asset_button_box.appendChild(depositAssetButton);
|
withdrawAssetButton.appendChild(withdrawAssetButtonText);
|
||||||
// asset_button_box.appendChild(withdrawAssetButton);
|
|
||||||
|
asset_button_box.appendChild(depositAssetButton);
|
||||||
|
asset_button_box.appendChild(withdrawAssetButton);
|
||||||
|
|
||||||
depositAssetButton.addEventListener("click", function() {
|
depositAssetButton.addEventListener("click", function() {
|
||||||
const user_upi = prompt(
|
const user_upi = prompt(
|
||||||
@ -28736,11 +28713,73 @@ Event information log
|
|||||||
user_upi
|
user_upi
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err_msg = "Error while depositing your address.";
|
err_msg = "Error: Deposit of Cash failed.";
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Withdraw Cash function
|
||||||
|
withdrawAssetButton.addEventListener("click", function(params) {
|
||||||
|
let receivinAddress = prompt("Please enter a valid UPI id.");
|
||||||
|
if (receivinAddress == null || receivinAddress.trim == "") {
|
||||||
|
err_msg = "You must specify your valid UPI Id to withdraw cash.";
|
||||||
|
showMessage(err_msg);
|
||||||
|
throw new Error(err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const asset_type = assetTypeInput.value;
|
||||||
|
const tradeAmount = parseFloat(tradeAmountSelect.value);
|
||||||
|
const fiatCurrency = asset_type;
|
||||||
|
//const fiatCurrency = currencySelect.value;
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof userFLOaddress == undefined ||
|
||||||
|
userFLOaddress.trim().length < 1
|
||||||
|
) {
|
||||||
|
err_msg = "Invalid or empty user FLO address.";
|
||||||
|
showMessage(err_msg);
|
||||||
|
throw new Error(err_msg);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
localbitcoinplusplus.master_configurations.tradableAsset2.includes(
|
||||||
|
asset_type
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
// typeof localbitcoinplusplus.master_configurations
|
||||||
|
// .validTradingAmount !== "undefined" &&
|
||||||
|
// !localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||||
|
// tradeAmount
|
||||||
|
// )
|
||||||
|
tradeAmount<=0
|
||||||
|
) {
|
||||||
|
err_msg = "Invalid Fiat Value.";
|
||||||
|
showMessage(err_msg);
|
||||||
|
throw new Error(err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !==
|
||||||
|
"undefined" &&
|
||||||
|
localbitcoinplusplus.master_configurations.tradableAsset2
|
||||||
|
.includes(asset_type)
|
||||||
|
) {
|
||||||
|
RM_TRADE.withdrawAsset(
|
||||||
|
asset_type,
|
||||||
|
tradeAmount,
|
||||||
|
receivinAddress,
|
||||||
|
userFLOaddress,
|
||||||
|
fiatCurrency
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
err_msg = "Error: Withdraw cash failed. Invalid currency specified.";
|
||||||
|
showMessage(err_msg);
|
||||||
|
throw new Error(err_msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user