Use sinkID for deposits

- Send Sink ID to users on get-account request
- In user page, store sink ID and use it for deposit FLO/Rupee
This commit is contained in:
sairajzero 2022-01-26 16:08:30 +05:30
parent cdc55dbdc9
commit 827bdcd793
3 changed files with 13 additions and 7 deletions

View File

@ -52,7 +52,7 @@ const tokenAPI = {
}).catch(error => reject(error))
})
},
sendToken: function(privKey, amount, message = "", receiverID = floGlobals.adminID, token = 'rupee') {
sendToken: function(privKey, amount, receiverID, message = "", token = 'rupee') {
return new Promise((resolve, reject) => {
let senderID = floCrypto.getFloID(privKey);
if (typeof amount !== "number" || amount <= 0)
@ -364,11 +364,11 @@ function cancelOrder(type, id, floID, proxySecret) {
})
}
function depositFLO(quantity, floID, privKey, proxySecret) {
function depositFLO(quantity, floID, sinkID, privKey, proxySecret) {
return new Promise((resolve, reject) => {
if (typeof quantity !== "number" || quantity <= floGlobals.fee)
return reject(`Invalid quantity (${quantity})`);
floBlockchainAPI.sendTx(floID, floGlobals.adminID, quantity, privKey, 'Deposit FLO in market').then(txid => {
floBlockchainAPI.sendTx(floID, sinkID, quantity, privKey, 'Deposit FLO in market').then(txid => {
let request = {
floID: floID,
txid: txid,
@ -422,11 +422,11 @@ function withdrawFLO(quantity, floID, proxySecret) {
})
}
function depositRupee(quantity, floID, privKey, proxySecret) {
function depositRupee(quantity, floID, sinkID, privKey, proxySecret) {
return new Promise((resolve, reject) => {
if (!floCrypto.verifyPrivKey(privKey, floID))
return reject("Invalid Private Key");
tokenAPI.sendToken(privKey, quantity, 'Deposit Rupee in market').then(txid => {
tokenAPI.sendToken(privKey, quantity, sinkID, 'Deposit Rupee in market').then(txid => {
let request = {
floID: floID,
txid: txid,

View File

@ -382,6 +382,7 @@
<h4 id="wallet_popup__title" class="capitalize"></h4>
</header>
<sm-form id="wallet_form">
<input type="text" id="sink_id" style="display: none;" hidden />
<sm-input id="get_user_amount" variant="outlined" placeholder="Quantity" type="number" min="0.01"
step="0.00001" required hiderequired animate>
</sm-input>
@ -1194,9 +1195,9 @@
if (type === 'deposit') {
const privKey = getRef('get_private_key').value;
if (asset === 'FLO') {
await depositFLO(quantity, proxy.userID, privKey, proxySecret)
await depositFLO(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
} else {
await depositRupee(quantity, proxy.userID, privKey, proxySecret)
await depositRupee(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
}
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
} else {
@ -1565,6 +1566,9 @@
this.private = null;
this.public = null;
},
get sinkID(){
return getRef("sink_id").value;
},
set userID(id){
localStorage.setItem("user_ID", id);
this.user = id;
@ -1680,6 +1684,7 @@
document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide-completely'))
getRef('trade_form').classList.remove('hide-completely')
getRef("user_id").value = acc.floID;
getRef("sink_id").value = acc.sinkID;
//FLO Balance
let flo_total = acc.coins.reduce((a, x) => a + x.quantity, 0);
let flo_locked = acc.sellOrders.reduce((a, x) => a + x.quantity, 0);

View File

@ -278,6 +278,7 @@ function Account(req, res) {
timestamp: data.timestamp
}, data.sign, data.floID).then(req_str => {
market.getAccountDetails(data.floID).then(result => {
result.sinkID = global.sinkID;
if (trustedIDs.includes(data.floID))
result.subAdmin = true;
res.send(result);