added function to fetch prices and balance
This commit is contained in:
parent
d51afa90e6
commit
b3c1d3106f
127
index.html
127
index.html
@ -955,16 +955,13 @@
|
|||||||
|
|
||||||
document.getElementById('refresh_market_price').addEventListener('click', () => {
|
document.getElementById('refresh_market_price').addEventListener('click', () => {
|
||||||
btnLoading('refresh_market_price', 'start')
|
btnLoading('refresh_market_price', 'start')
|
||||||
setTimeout(() => {
|
localbitcoinplusplus.actions.request_live_prices_from_server();
|
||||||
updateMarketPrice(800000, 1.30)
|
|
||||||
}, 1000)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('refresh_bal').addEventListener('click', (e) => {
|
document.getElementById('refresh_bal').addEventListener('click', (e) => {
|
||||||
btnLoading('refresh_bal', 'start')
|
btnLoading('refresh_bal', 'start')
|
||||||
setTimeout(() => {
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
updateBalance(40000, 50, 600)
|
RM_WALLET.get_current_user_balance();
|
||||||
}, 1000)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let notificationsContainer = document.getElementById('notification_container');
|
let notificationsContainer = document.getElementById('notification_container');
|
||||||
@ -977,18 +974,13 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
//call these functions inside your already created functions and provide new value as parameters
|
//call these functions inside your already created functions and provide new value as parameters
|
||||||
function updateMarketPrice(btcPrice, floPrice){
|
function updateMarketPrice(crypto_code, price) {
|
||||||
btnLoading('refresh_market_price', 'stop')
|
btnLoading('refresh_market_price', 'stop')
|
||||||
document.getElementById('btc_market_price').textContent = '₹'+ btcPrice;
|
if(crypto_code=="BTC") {
|
||||||
document.getElementById('flo_market_price').textContent = '₹'+ floPrice;
|
document.getElementById('btc_market_price').textContent = '₹'+ price;
|
||||||
}
|
} else if(crypto_code=="FLO") {
|
||||||
|
document.getElementById('flo_market_price').textContent = '₹'+ price;
|
||||||
function updateBalance(inrBal, btcBal, floBal){
|
}
|
||||||
btnLoading('refresh_bal', 'stop')
|
|
||||||
document.getElementById('user_cash_bal').textContent = '₹'+inrBal;
|
|
||||||
document.getElementById('user_btc_bal').textContent = btcBal;
|
|
||||||
document.getElementById('user_flo_bal').textContent = floBal;
|
|
||||||
notify('balance updated')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendCrypto(btn){
|
function sendCrypto(btn){
|
||||||
@ -15265,7 +15257,7 @@
|
|||||||
"btc_address",
|
"btc_address",
|
||||||
deposit_dl.btc_address
|
deposit_dl.btc_address
|
||||||
);
|
);
|
||||||
if(typeof res!=="object" || typeof res[0].id!=="string") {
|
if(typeof res[0]!=="object" || typeof res[0].id!=="string") {
|
||||||
removeinDB("deposit", deposit_dl.id);
|
removeinDB("deposit", deposit_dl.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -15892,6 +15884,20 @@
|
|||||||
throw new Error(error)
|
throw new Error(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
get_current_user_balance: function(user=localbitcoinplusplus.wallets.my_local_flo_address) {
|
||||||
|
try {
|
||||||
|
const RM_RPC = new localbitcoinplusplus.rpc();
|
||||||
|
RM_RPC.send_rpc
|
||||||
|
.call(this, "fetch_user_balance", {
|
||||||
|
trader_flo_address: user,
|
||||||
|
job: "FETCH_USER_BALANCE",
|
||||||
|
receiver_flo_address: localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS,
|
||||||
|
})
|
||||||
|
.then(sync_request => doSend(sync_request));
|
||||||
|
} catch (error) {
|
||||||
|
notify(`Failed to get your balance from the server. Please try again.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -16277,6 +16283,32 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(method=="fetch_user_balance") {
|
||||||
|
RM_RPC.filter_legit_requests(params.trader_flo_address,
|
||||||
|
async function(is_valid_request) {
|
||||||
|
if (
|
||||||
|
is_valid_request === true &&
|
||||||
|
params.trader_flo_address.length > 0
|
||||||
|
) {
|
||||||
|
let bal_promises = [];
|
||||||
|
const crypto_bal = await readDBbyIndex('crypto_balances', 'trader_flo_address', params.trader_flo_address)
|
||||||
|
const cash_bal = await readDBbyIndex('cash_balances', 'trader_flo_address', params.trader_flo_address)
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
crypto_balances: crypto_bal,
|
||||||
|
cash_balances: cash_bal,
|
||||||
|
trader_flo_address: params.trader_flo_address,
|
||||||
|
receiver_flo_address: params.trader_flo_address
|
||||||
|
}
|
||||||
|
RM_RPC.send_rpc
|
||||||
|
.call(this, "fetch_user_balance_response", response)
|
||||||
|
.then(server_response =>
|
||||||
|
doSend(server_response)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
RM_RPC.filter_legit_requests(
|
RM_RPC.filter_legit_requests(
|
||||||
params.trader_flo_address,
|
params.trader_flo_address,
|
||||||
async function(is_valid_request) {
|
async function(is_valid_request) {
|
||||||
@ -24004,18 +24036,58 @@
|
|||||||
if(server_live_trading_prices.receiver_flo_address===localbitcoinplusplus.wallets.my_local_flo_address) {
|
if(server_live_trading_prices.receiver_flo_address===localbitcoinplusplus.wallets.my_local_flo_address) {
|
||||||
console.log(server_live_trading_prices);
|
console.log(server_live_trading_prices);
|
||||||
for(commodity of Object.values(server_live_trading_prices.live_trading_prices)) {
|
for(commodity of Object.values(server_live_trading_prices.live_trading_prices)) {
|
||||||
if(commodity.crypto_code==="BTC") {
|
if(commodity.crypto_code==="BTC"&&commodity.currency_code=="INR") {
|
||||||
document.getElementById('btc_market_price').innerText = `${commodity.currency_code} ${commodity.rate}`;
|
updateMarketPrice(commodity.crypto_code, commodity.rate);
|
||||||
} else if(commodity.crypto_code==="FLO") {
|
} else if(commodity.crypto_code==="FLO"&&commodity.currency_code=="INR") {
|
||||||
document.getElementById('flo_market_price').innerText = `${commodity.currency_code} ${commodity.rate}`;
|
updateMarketPrice(commodity.crypto_code, commodity.rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showMessage('Failed to fetch live trading prices.')
|
notify('Failed to fetch current crypto prices.');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "fetch_user_balance":
|
||||||
|
response_from_sever = RM_RPC.receive_rpc_response.call(
|
||||||
|
this,
|
||||||
|
JSON.stringify(res_obj)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "fetch_user_balance_response":
|
||||||
|
if(typeof res_obj.params[0]=="object") {
|
||||||
|
const server_balance_resp = res_obj.params[0];
|
||||||
|
if(server_balance_resp.receiver_flo_address
|
||||||
|
===localbitcoinplusplus.wallets.my_local_flo_address) {
|
||||||
|
let usr_bal_promises = []
|
||||||
|
for (const cryptobal of server_balance_resp.crypto_balances) {
|
||||||
|
usr_bal_promises.push(updateinDB(
|
||||||
|
'crypto_balances',
|
||||||
|
cryptobal,
|
||||||
|
cryptobal.id,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
))
|
||||||
|
}
|
||||||
|
for (const cashbal of server_balance_resp.cash_balances) {
|
||||||
|
usr_bal_promises.push(updateinDB(
|
||||||
|
'crypto_balances',
|
||||||
|
cashbal,
|
||||||
|
cashbal.id,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Promise.all(usr_bal_promises)
|
||||||
|
.then(()=>{
|
||||||
|
displayBalances(server_balance_resp.receiver_flo_address);
|
||||||
|
btnLoading('refresh_bal', 'stop')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -28661,6 +28733,13 @@
|
|||||||
} else {
|
} else {
|
||||||
if(!exception_datastores.includes(tablename)) {
|
if(!exception_datastores.includes(tablename)) {
|
||||||
if(verifyDBData(originalObj)===true) {
|
if(verifyDBData(originalObj)===true) {
|
||||||
|
if(typeof localbitcoinplusplus.wallets.my_local_flo_public_key=="string"
|
||||||
|
&& localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) {
|
||||||
|
request = db.transaction([tablename], "readwrite")
|
||||||
|
.objectStore(tablename).put(originalObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Obj = signDBData(Obj);
|
Obj = signDBData(Obj);
|
||||||
} else {
|
} else {
|
||||||
if(typeof localbitcoinplusplus.wallets.my_local_flo_public_key=="string"
|
if(typeof localbitcoinplusplus.wallets.my_local_flo_public_key=="string"
|
||||||
@ -29270,8 +29349,6 @@
|
|||||||
// leave the vector clock field unchanged
|
// leave the vector clock field unchanged
|
||||||
} else {
|
} else {
|
||||||
Obj.vectorClock += 1;
|
Obj.vectorClock += 1;
|
||||||
// If vectorClock is increased, also update timestamp
|
|
||||||
//Obj.timestamp = +new Date();
|
|
||||||
}
|
}
|
||||||
if (typeof Obj.timestamp !== "number") {
|
if (typeof Obj.timestamp !== "number") {
|
||||||
Obj.timestamp = +new Date();
|
Obj.timestamp = +new Date();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user