User-end update
- updated custom session for distributed system - Fetch node list and url from blockchain
This commit is contained in:
parent
9760710c18
commit
7dbe78c1cc
196
public/fn.js
196
public/fn.js
@ -1,4 +1,24 @@
|
|||||||
//console.log(document.cookie.toString());
|
//console.log(document.cookie.toString());
|
||||||
|
var nodeList, nodeURL, nodeKBucket; //Container for (backup) node list
|
||||||
|
|
||||||
|
function exchangeAPI(api, options) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let curPos = exchangeAPI.curPos || 0;
|
||||||
|
if (curPos >= nodeList.length)
|
||||||
|
return resolve('No Nodes online');
|
||||||
|
let url = nodeURL[nodeList[curPos]];
|
||||||
|
(options ? fetch(url + api, options) : fetch(url + api))
|
||||||
|
.then(result => resolve(result)).catch(error => {
|
||||||
|
console.debug(error);
|
||||||
|
console.warn(nodeList[curPos], 'is offline');
|
||||||
|
//try next node
|
||||||
|
exchangeAPI.curPos = curPos + 1;
|
||||||
|
exchangeAPI(api, options)
|
||||||
|
.then(result => resolve(result))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const tokenAPI = {
|
const tokenAPI = {
|
||||||
fetch_api: function(apicall) {
|
fetch_api: function(apicall) {
|
||||||
@ -74,10 +94,25 @@ function responseParse(response, json_ = true) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccount() {
|
function getAccount(floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch('/account')
|
let request = {
|
||||||
.then(result => responseParse(result)
|
floID: floID,
|
||||||
|
timestamp: Date.now()
|
||||||
|
};
|
||||||
|
request.sign = signRequest({
|
||||||
|
type: "get_account",
|
||||||
|
timestamp: data.timestamp
|
||||||
|
}, proxySecret);
|
||||||
|
console.debug(request);
|
||||||
|
|
||||||
|
exchangeAPI('/account', {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(request)
|
||||||
|
}).then(result => responseParse(result)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error)))
|
.catch(error => reject(error)))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
@ -86,7 +121,7 @@ function getAccount() {
|
|||||||
|
|
||||||
function getBuyList() {
|
function getBuyList() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch('/list-buyorders')
|
exchangeAPI('/list-buyorders')
|
||||||
.then(result => responseParse(result)
|
.then(result => responseParse(result)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error)))
|
.catch(error => reject(error)))
|
||||||
@ -96,7 +131,7 @@ function getBuyList() {
|
|||||||
|
|
||||||
function getSellList() {
|
function getSellList() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch('/list-sellorders')
|
exchangeAPI('/list-sellorders')
|
||||||
.then(result => responseParse(result)
|
.then(result => responseParse(result)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error)))
|
.catch(error => reject(error)))
|
||||||
@ -106,7 +141,7 @@ function getSellList() {
|
|||||||
|
|
||||||
function getTransactionList() {
|
function getTransactionList() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch('/list-transactions')
|
exchangeAPI('/list-transactions')
|
||||||
.then(result => responseParse(result)
|
.then(result => responseParse(result)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error)))
|
.catch(error => reject(error)))
|
||||||
@ -116,7 +151,7 @@ function getTransactionList() {
|
|||||||
|
|
||||||
function getRate() {
|
function getRate() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch('/get-rate')
|
exchangeAPI('/get-rate')
|
||||||
.then(result => responseParse(result, false)
|
.then(result => responseParse(result, false)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error)))
|
.catch(error => reject(error)))
|
||||||
@ -131,21 +166,35 @@ function signRequest(request, privKey) {
|
|||||||
return floCrypto.signData(req_str, privKey);
|
return floCrypto.signData(req_str, privKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function signUp(privKey, sid) {
|
function getLoginCode() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
exchangeAPI('/list-buyorders')
|
||||||
|
.then(result => responseParse(result)
|
||||||
|
.then(result => resolve(result))
|
||||||
|
.catch(error => reject(error)))
|
||||||
|
.catch(error => reject(error));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function signUp(privKey, code, hash) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!code || !hash)
|
||||||
|
return reject("Login Code missing")
|
||||||
let request = {
|
let request = {
|
||||||
pubKey: floCrypto.getPubKeyHex(privKey),
|
pubKey: floCrypto.getPubKeyHex(privKey),
|
||||||
floID: floCrypto.getFloID(privKey),
|
floID: floCrypto.getFloID(privKey),
|
||||||
|
code: code,
|
||||||
|
hash: hash,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "create_account",
|
type: "create_account",
|
||||||
random: sid,
|
random: code,
|
||||||
timestamp: request.timestamp
|
timestamp: request.timestamp
|
||||||
}, privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch("/signup", {
|
exchangeAPI("/signup", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -158,25 +207,28 @@ function signUp(privKey, sid) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function login(privKey, proxyKey, sid, rememberMe = false) {
|
function login(privKey, proxyKey, code, hash) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!code || !hash)
|
||||||
|
return reject("Login Code missing")
|
||||||
let request = {
|
let request = {
|
||||||
proxyKey: proxyKey,
|
proxyKey: proxyKey,
|
||||||
floID: floCrypto.getFloID(privKey),
|
floID: floCrypto.getFloID(privKey),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
saveSession: rememberMe
|
code: code,
|
||||||
|
hash: hash
|
||||||
};
|
};
|
||||||
if (!privKey || !request.floID)
|
if (!privKey || !request.floID)
|
||||||
return reject("Invalid Private key");
|
return reject("Invalid Private key");
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "login",
|
type: "login",
|
||||||
random: sid,
|
random: code,
|
||||||
proxyKey: request.proxyKey,
|
proxyKey: proxyKey,
|
||||||
timestamp: request.timestamp
|
timestamp: request.timestamp
|
||||||
}, privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch("/login", {
|
exchangeAPI("/login", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -189,23 +241,39 @@ function login(privKey, proxyKey, sid, rememberMe = false) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout(floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch("/logout")
|
let request = {
|
||||||
.then(result => responseParse(result, false)
|
floID: floID,
|
||||||
|
timestamp: Date.now()
|
||||||
|
};
|
||||||
|
request.sign = signRequest({
|
||||||
|
type: "logout",
|
||||||
|
timestamp: data.timestamp
|
||||||
|
}, proxySecret);
|
||||||
|
console.debug(request);
|
||||||
|
|
||||||
|
exchangeAPI("/logout", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(request)
|
||||||
|
}).then(result => responseParse(result, false)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error)))
|
.catch(error => reject(error)))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function buy(quantity, max_price, proxySecret) {
|
function buy(quantity, max_price, floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof quantity !== "number" || quantity <= 0)
|
if (typeof quantity !== "number" || quantity <= 0)
|
||||||
return reject(`Invalid quantity (${quantity})`);
|
return reject(`Invalid quantity (${quantity})`);
|
||||||
else if (typeof max_price !== "number" || max_price <= 0)
|
else if (typeof max_price !== "number" || max_price <= 0)
|
||||||
return reject(`Invalid max_price (${max_price})`);
|
return reject(`Invalid max_price (${max_price})`);
|
||||||
let request = {
|
let request = {
|
||||||
|
floID: floID,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
max_price: max_price,
|
max_price: max_price,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
@ -218,7 +286,7 @@ function buy(quantity, max_price, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/buy', {
|
exchangeAPI('/buy', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -232,13 +300,14 @@ function buy(quantity, max_price, proxySecret) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sell(quantity, min_price, proxySecret) {
|
function sell(quantity, min_price, floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof quantity !== "number" || quantity <= 0)
|
if (typeof quantity !== "number" || quantity <= 0)
|
||||||
return reject(`Invalid quantity (${quantity})`);
|
return reject(`Invalid quantity (${quantity})`);
|
||||||
else if (typeof min_price !== "number" || min_price <= 0)
|
else if (typeof min_price !== "number" || min_price <= 0)
|
||||||
return reject(`Invalid min_price (${min_price})`);
|
return reject(`Invalid min_price (${min_price})`);
|
||||||
let request = {
|
let request = {
|
||||||
|
floID: floID,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
min_price: min_price,
|
min_price: min_price,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
@ -251,7 +320,7 @@ function sell(quantity, min_price, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/sell', {
|
exchangeAPI('/sell', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -265,11 +334,12 @@ function sell(quantity, min_price, proxySecret) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelOrder(type, id, proxySecret) {
|
function cancelOrder(type, id, floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (type !== "buy" && type !== "sell")
|
if (type !== "buy" && type !== "sell")
|
||||||
return reject(`Invalid type (${type}): type should be sell (or) buy`);
|
return reject(`Invalid type (${type}): type should be sell (or) buy`);
|
||||||
let request = {
|
let request = {
|
||||||
|
floID: floID,
|
||||||
orderType: type,
|
orderType: type,
|
||||||
orderID: id,
|
orderID: id,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
@ -282,7 +352,7 @@ function cancelOrder(type, id, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/cancel', {
|
exchangeAPI('/cancel', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -295,12 +365,13 @@ function cancelOrder(type, id, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function depositFLO(quantity, userID, privKey, proxySecret) {
|
function depositFLO(quantity, floID, privKey, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof quantity !== "number" || quantity <= floGlobals.fee)
|
if (typeof quantity !== "number" || quantity <= floGlobals.fee)
|
||||||
return reject(`Invalid quantity (${quantity})`);
|
return reject(`Invalid quantity (${quantity})`);
|
||||||
floBlockchainAPI.sendTx(userID, floGlobals.adminID, quantity, privKey, 'Deposit FLO in market').then(txid => {
|
floBlockchainAPI.sendTx(floID, floGlobals.adminID, quantity, privKey, 'Deposit FLO in market').then(txid => {
|
||||||
let request = {
|
let request = {
|
||||||
|
floID: floID,
|
||||||
txid: txid,
|
txid: txid,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
@ -311,7 +382,7 @@ function depositFLO(quantity, userID, privKey, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/deposit-flo', {
|
exchangeAPI('/deposit-flo', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -325,9 +396,10 @@ function depositFLO(quantity, userID, privKey, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function withdrawFLO(quantity, proxySecret) {
|
function withdrawFLO(quantity, floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = {
|
let request = {
|
||||||
|
floID: floID,
|
||||||
amount: quantity,
|
amount: quantity,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
@ -338,7 +410,7 @@ function withdrawFLO(quantity, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/withdraw-flo', {
|
exchangeAPI('/withdraw-flo', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -351,12 +423,13 @@ function withdrawFLO(quantity, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function depositRupee(quantity, userID, privKey, proxySecret) {
|
function depositRupee(quantity, floID, privKey, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!floCrypto.verifyPrivKey(privKey, userID))
|
if (!floCrypto.verifyPrivKey(privKey, floID))
|
||||||
return reject("Invalid Private Key");
|
return reject("Invalid Private Key");
|
||||||
tokenAPI.sendToken(privKey, quantity, 'Deposit Rupee in market').then(txid => {
|
tokenAPI.sendToken(privKey, quantity, 'Deposit Rupee in market').then(txid => {
|
||||||
let request = {
|
let request = {
|
||||||
|
floID: floID,
|
||||||
txid: txid,
|
txid: txid,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
@ -367,7 +440,7 @@ function depositRupee(quantity, userID, privKey, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/deposit-rupee', {
|
exchangeAPI('/deposit-rupee', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -381,9 +454,10 @@ function depositRupee(quantity, userID, privKey, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function withdrawRupee(quantity, proxySecret) {
|
function withdrawRupee(quantity, floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = {
|
let request = {
|
||||||
|
floID: floID,
|
||||||
amount: quantity,
|
amount: quantity,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
@ -394,7 +468,7 @@ function withdrawRupee(quantity, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/withdraw-rupee', {
|
exchangeAPI('/withdraw-rupee', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -407,10 +481,11 @@ function withdrawRupee(quantity, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addUserTag(floID, tag, proxySecret) {
|
function addUserTag(tag_user, tag, floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = {
|
let request = {
|
||||||
user: floID,
|
floID: floID,
|
||||||
|
user: tag_user,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
@ -422,7 +497,7 @@ function addUserTag(floID, tag, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/add-tag', {
|
exchangeAPI('/add-tag', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -435,10 +510,11 @@ function addUserTag(floID, tag, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeUserTag(floID, tag, proxySecret) {
|
function removeUserTag(tag_user, tag, floID, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = {
|
let request = {
|
||||||
user: floID,
|
floID: floID,
|
||||||
|
user: tag_user,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
};
|
};
|
||||||
@ -450,7 +526,7 @@ function removeUserTag(floID, tag, proxySecret) {
|
|||||||
}, proxySecret);
|
}, proxySecret);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
fetch('/remove-tag', {
|
exchangeAPI('/remove-tag', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -462,3 +538,43 @@ function removeUserTag(floID, tag, proxySecret) {
|
|||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refreshDataFromBlockchain() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let nodes, lastTx;
|
||||||
|
try {
|
||||||
|
nodes = JSON.parse(localStorage.getItems('exhange-nodes'));
|
||||||
|
if (typeof nodes !== 'object')
|
||||||
|
throw Error('nodes must be an object')
|
||||||
|
else
|
||||||
|
lastTx = parseInt(localStorage.getItem('exchange-lastTx')) || 0;
|
||||||
|
} catch (error) {
|
||||||
|
nodes = {};
|
||||||
|
lastTx = 0;
|
||||||
|
}
|
||||||
|
floBlockchainAPI.readData(floGlobals.adminID, {
|
||||||
|
ignoreOld: lastTx,
|
||||||
|
sentOnly: true,
|
||||||
|
pattern: floGlobals.application
|
||||||
|
}).then(result => {
|
||||||
|
result.data.reverse().forEach(data => {
|
||||||
|
var content = JSON.parse(data)[floGlobals.application];
|
||||||
|
//Node List
|
||||||
|
if (content.Nodes) {
|
||||||
|
if (content.Nodes.remove)
|
||||||
|
for (let n of content.Nodes.remove)
|
||||||
|
delete nodes[n];
|
||||||
|
if (content.Nodes.add)
|
||||||
|
for (let n in content.Nodes.add)
|
||||||
|
nodes[n] = content.Nodes.add[n];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
localStorage.setItem('exhange-lastTx', result.totalTxs);
|
||||||
|
localStorage.setItem('exhange-nodes', JSON.stringify(nodes));
|
||||||
|
nodeURL = nodes;
|
||||||
|
nodeKBucket = new K_Bucket(floGlobals.adminID, Object.keys(nodeURL));
|
||||||
|
nodeList = nodeKBucket.order;
|
||||||
|
resolve(nodes);
|
||||||
|
}).catch(error => reject(error));
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -96,7 +96,8 @@
|
|||||||
Remember me
|
Remember me
|
||||||
</span>
|
</span>
|
||||||
</sm-checkbox>
|
</sm-checkbox>
|
||||||
<input type="text" id="sign_in_id" style="display: none;" hidden />
|
<input type="text" id="sign_in_code" style="display: none;" hidden />
|
||||||
|
<input type="text" id="sign_in_hash" style="display: none;" hidden />
|
||||||
<div id="login_button_wrapper" class="stateful-button-wrapper">
|
<div id="login_button_wrapper" class="stateful-button-wrapper">
|
||||||
<sm-button variant="primary" onclick="UI_evt.login();">Log in</sm-button>
|
<sm-button variant="primary" onclick="UI_evt.login();">Log in</sm-button>
|
||||||
</div>
|
</div>
|
||||||
@ -854,7 +855,7 @@
|
|||||||
let pageId
|
let pageId
|
||||||
let params
|
let params
|
||||||
if (targetPage === '') {
|
if (targetPage === '') {
|
||||||
if (typeof myFloID === "undefined") {
|
if (typeof proxy.userID === "undefined") {
|
||||||
pageId = 'landing'
|
pageId = 'landing'
|
||||||
} else {
|
} else {
|
||||||
pageId = 'home'
|
pageId = 'home'
|
||||||
@ -1206,13 +1207,13 @@
|
|||||||
const quantity = parseFloat(getRef('get_user_amount').value)
|
const quantity = parseFloat(getRef('get_user_amount').value)
|
||||||
try {
|
try {
|
||||||
showProcess('wallet_popup__cta_wrapper')
|
showProcess('wallet_popup__cta_wrapper')
|
||||||
const proxySecret = await proxy.secret
|
const proxySecret = await proxy.secret;
|
||||||
if (type === 'deposit') {
|
if (type === 'deposit') {
|
||||||
const privKey = getRef('get_private_key').value;
|
const privKey = getRef('get_private_key').value;
|
||||||
if (asset === 'FLO') {
|
if (asset === 'FLO') {
|
||||||
await depositFLO(quantity, userID, privKey, proxySecret)
|
await depositFLO(quantity, proxy.userID, privKey, proxySecret)
|
||||||
} else {
|
} else {
|
||||||
await depositRupee(quantity, userID, privKey, proxySecret)
|
await depositRupee(quantity, proxy.userID, privKey, proxySecret)
|
||||||
}
|
}
|
||||||
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
||||||
} else {
|
} else {
|
||||||
@ -1451,10 +1452,10 @@
|
|||||||
transactions.forEach(transaction => {
|
transactions.forEach(transaction => {
|
||||||
const { quantity, unitValue, tx_time, buyer, seller } = transaction
|
const { quantity, unitValue, tx_time, buyer, seller } = transaction
|
||||||
let type, other;
|
let type, other;
|
||||||
if (seller === userID) {
|
if (seller === proxy.userID) {
|
||||||
type = 'Sold';
|
type = 'Sold';
|
||||||
other = buyer === userID ? 'MySelf' : buyer;
|
other = buyer === proxy.userID ? 'MySelf' : buyer;
|
||||||
} else if (buyer === userID) {
|
} else if (buyer === proxy.userID) {
|
||||||
type = 'Bought';
|
type = 'Bought';
|
||||||
other = seller;
|
other = seller;
|
||||||
} else
|
} else
|
||||||
@ -1551,9 +1552,9 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
let userID; //container for user ID and proxy private-key
|
//container for user ID and proxy private-key
|
||||||
|
|
||||||
const proxy = {
|
const proxy = {
|
||||||
|
user: null,
|
||||||
private: null,
|
private: null,
|
||||||
public: null,
|
public: null,
|
||||||
async lock() {
|
async lock() {
|
||||||
@ -1576,9 +1577,23 @@
|
|||||||
},
|
},
|
||||||
clear() {
|
clear() {
|
||||||
localStorage.removeItem("proxy_secret");
|
localStorage.removeItem("proxy_secret");
|
||||||
|
localStorage.removeItem("user_ID");
|
||||||
|
this.user = null;
|
||||||
this.private = null;
|
this.private = null;
|
||||||
this.public = null;
|
this.public = null;
|
||||||
},
|
},
|
||||||
|
set userID(id){
|
||||||
|
localStorage.setItem("user_ID", id);
|
||||||
|
this.user = id;
|
||||||
|
},
|
||||||
|
get userID(){
|
||||||
|
if(this.user)
|
||||||
|
return this.user;
|
||||||
|
else{
|
||||||
|
let id = localStorage.getItem('user_ID');
|
||||||
|
return id ? this.user = id : undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
set secret(key) {
|
set secret(key) {
|
||||||
localStorage.setItem("proxy_secret", key);
|
localStorage.setItem("proxy_secret", key);
|
||||||
this.private = key;
|
this.private = key;
|
||||||
@ -1636,13 +1651,24 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refresh(init = false) {
|
function refresh(init = false) {
|
||||||
if (init)
|
if (init){
|
||||||
console.info("init");
|
console.info("init");
|
||||||
else
|
if(!proxy.userID){
|
||||||
|
getRef('home').classList.remove('signed-in');
|
||||||
|
getLoginCode().then(response => {
|
||||||
|
getRef("login_form").classList.remove('hide-completely');
|
||||||
|
document.querySelectorAll(".user-content").forEach(elem => elem.classList.add('hide-completely'))
|
||||||
|
getRef('sign_in_code').value = response.code;
|
||||||
|
getRef('sign_in_hash').value = response.hash;
|
||||||
|
proxy.clear();
|
||||||
|
}).catch(error => console.error(error))
|
||||||
|
}
|
||||||
|
} else
|
||||||
console.info("refresh");
|
console.info("refresh");
|
||||||
updateRate()
|
updateRate();
|
||||||
renderMarketOrders()
|
renderMarketOrders();
|
||||||
account();
|
if(proxy.userID)
|
||||||
|
account();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showBalance(type, availableBalance = 0, lockedBalance = 0) {
|
function showBalance(type, availableBalance = 0, lockedBalance = 0) {
|
||||||
@ -1662,7 +1688,7 @@
|
|||||||
|
|
||||||
let accountDetails = {}
|
let accountDetails = {}
|
||||||
function account() {
|
function account() {
|
||||||
getAccount().then(acc => {
|
getAccount(proxy.userID, await proxy.secret).then(acc => {
|
||||||
getRef("login_form").classList.add('hide-completely')
|
getRef("login_form").classList.add('hide-completely')
|
||||||
getRef('home').classList.add('signed-in')
|
getRef('home').classList.add('signed-in')
|
||||||
accountDetails = acc
|
accountDetails = acc
|
||||||
@ -1671,7 +1697,6 @@
|
|||||||
document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide-completely'))
|
document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide-completely'))
|
||||||
getRef('trade_form').classList.remove('hide-completely')
|
getRef('trade_form').classList.remove('hide-completely')
|
||||||
getRef("user_id").value = acc.floID;
|
getRef("user_id").value = acc.floID;
|
||||||
userID = acc.floID;
|
|
||||||
//FLO Balance
|
//FLO Balance
|
||||||
let flo_total = acc.coins.reduce((a, x) => a + x.quantity, 0);
|
let flo_total = acc.coins.reduce((a, x) => a + x.quantity, 0);
|
||||||
let flo_locked = acc.sellOrders.reduce((a, x) => a + x.quantity, 0);
|
let flo_locked = acc.sellOrders.reduce((a, x) => a + x.quantity, 0);
|
||||||
@ -1690,28 +1715,17 @@
|
|||||||
//My orders
|
//My orders
|
||||||
renderUserOrders();
|
renderUserOrders();
|
||||||
proxy.secret.then(_ => null).catch(_ => null);
|
proxy.secret.then(_ => null).catch(_ => null);
|
||||||
}).catch(error => {
|
}).catch(error => console.error(error))
|
||||||
getRef('home').classList.remove('signed-in')
|
|
||||||
if (error instanceof ResponseError) {
|
|
||||||
let response = JSON.parse(error.data)
|
|
||||||
console.log(error);
|
|
||||||
console.log(response);
|
|
||||||
getRef("login_form").classList.remove('hide-completely')
|
|
||||||
document.querySelectorAll(".user-content").forEach(elem => elem.classList.add('hide-completely'))
|
|
||||||
getRef('sign_in_id').value = response.sid;
|
|
||||||
proxy.clear();
|
|
||||||
} else
|
|
||||||
console.error(error);
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const UI_evt = {
|
const UI_evt = {
|
||||||
signup(privKey) {
|
signup(privKey) {
|
||||||
let sid = getRef('sign_in_id').value;
|
let code = getRef('sign_in_code').value,
|
||||||
|
hash = getRef('sign_in_hash').value;
|
||||||
if (!privKey)
|
if (!privKey)
|
||||||
privKey = getRef('get_registration_key').value.trim()
|
privKey = getRef('get_registration_key').value.trim()
|
||||||
if (privKey !== '') {
|
if (privKey !== '') {
|
||||||
signUp(privKey, sid).then(result => {
|
signUp(privKey, code, hash).then(result => {
|
||||||
console.info(result);
|
console.info(result);
|
||||||
notify("Account registered!", 'success')
|
notify("Account registered!", 'success')
|
||||||
hidePopup()
|
hidePopup()
|
||||||
@ -1722,9 +1736,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
getConfirmation('Log out?', { cancelText: 'Stay', confirmText: 'Log out' }).then(res => {
|
getConfirmation('Log out?', { cancelText: 'Stay', confirmText: 'Log out' }).then(async res => {
|
||||||
if (res) {
|
if (res) {
|
||||||
logout().then(result => {
|
logout(proxy.userID, await proxy.secret).then(result => {
|
||||||
console.warn(result);
|
console.warn(result);
|
||||||
proxy.clear();
|
proxy.clear();
|
||||||
location.reload();
|
location.reload();
|
||||||
@ -1736,12 +1750,16 @@
|
|||||||
login() {
|
login() {
|
||||||
showProcess('login_button_wrapper')
|
showProcess('login_button_wrapper')
|
||||||
let privKey = getRef('login_form__priv_key').value;
|
let privKey = getRef('login_form__priv_key').value;
|
||||||
let sid = getRef('sign_in_id').value;
|
let code = getRef('sign_in_code').value,
|
||||||
|
hash = getRef('sign_in_hash').value;
|
||||||
let rememberMe = getRef('remember_me').checked;
|
let rememberMe = getRef('remember_me').checked;
|
||||||
let tmpKey = floCrypto.generateNewID();
|
let tmpKey = floCrypto.generateNewID();
|
||||||
login(privKey, tmpKey.pubKey, sid, rememberMe).then(result => {
|
login(privKey, tmpKey.pubKey, code, hash).then(result => {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
proxy.secret = tmpKey.privKey;
|
proxy.secret = tmpKey.privKey;
|
||||||
|
proxy.userID = floCrypto.getFloID(privKey);
|
||||||
|
getRef('sign_in_code').value = null;
|
||||||
|
getRef('sign_in_hash').value = null;
|
||||||
account();
|
account();
|
||||||
}).catch(error => notify(error.data, 'error'))
|
}).catch(error => notify(error.data, 'error'))
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@ -1757,7 +1775,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', e => {
|
window.addEventListener('load', e => {
|
||||||
refresh(true);
|
refreshDataFromBlockchain().then(nodes => {
|
||||||
|
console.log(nodes);
|
||||||
|
refresh(true);
|
||||||
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user