Skip to content

Commit

Permalink
update floTokenAPI and floExchangeAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
sairajzero committed Aug 15, 2024
1 parent 3f7314e commit 2c2d862
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
59 changes: 35 additions & 24 deletions scripts/floExchangeAPI.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

(function (EXPORTS) { //floExchangeAPI v1.2.0a
(function (EXPORTS) { //floExchangeAPI v1.2.1
const exchangeAPI = EXPORTS;

const DEFAULT = {
Expand Down Expand Up @@ -608,7 +608,7 @@
BOBS_FUND: "bobs-fund"
}

exchangeAPI.getSink = function (service = serviceList.EXCHANGE) {
const getSink = exchangeAPI.getSink = function (service = serviceList.EXCHANGE) {
return new Promise((resolve, reject) => {
if (!(Object.values(serviceList).includes(service)))
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_VALUE));
Expand Down Expand Up @@ -1720,7 +1720,7 @@

const _l = key => DEFAULT.marketApp + '-' + key;

exchangeAPI.init = function refreshDataFromBlockchain() {
function refreshDataFromBlockchain() {
return new Promise((resolve, reject) => {
let nodes, trusted = new Set(), assets, tags, lastTx;
try {
Expand Down Expand Up @@ -1796,6 +1796,17 @@
})
}

exchangeAPI.init = function (service = serviceList.EXCHANGE) {
return new Promise((resolve, reject) => {
refreshDataFromBlockchain().then(nodes => {
getSink(service)
.then(sinkID => floCrypto.validateAddr(sinkID) ? _sinkID = sinkID : undefined)
.catch(error => console.warn("Unable to fetch sinkID", error))
.finally(_ => resolve(nodes))
}).catch(error => reject(error))
})
}

const config = exchangeAPI.config = {
get trustedList() {
return new Set((localStorage.getItem(_l('trusted')) || "").split(','));
Expand All @@ -1820,12 +1831,10 @@
}

//container for user ID and proxy private-key
var _userID, _publicKey, _privateKey, _sinkID;
const proxy = exchangeAPI.proxy = {
user: null,
private: null,
public: null,
async lock() {
if (!this.private)
if (!_privateKey)
return notify("No proxy key found!", 'error');
getPromptInput("Add password", 'This password applies to this browser only!', {
isPassword: true,
Expand All @@ -1836,7 +1845,7 @@
else if (pwd.length < 4)
notify("Password minimum length is 4", 'error');
else {
let tmp = Crypto.AES.encrypt(this.private, pwd);
let tmp = Crypto.AES.encrypt(_privateKey, pwd);
localStorage.setItem(_l('proxy_secret'), "?" + tmp);
notify("Successfully locked with Password", 'success');
}
Expand All @@ -1845,45 +1854,47 @@
clear() {
localStorage.removeItem(_l('proxy_secret'));
localStorage.removeItem(_l('user_ID'));
this.user = null;
this.private = null;
this.public = null;
_userID = null;
_privateKey = null;
_publicKey = null;
},
get sinkID() {
return getRef("sink_id").value;
return _sinkID;
},
set userID(id) {
localStorage.setItem(_l('user_ID'), id);
this.user = id;
_userID = id;
},
get userID() {
if (this.user)
return this.user;
if (_userID)
return _userID;
else {
let id = localStorage.getItem(_l('user_ID'));
return id ? this.user = id : undefined;
return id ? _userID = id : undefined;
}
},
get user() {
return this.userID;
},
set secret(key) {
localStorage.setItem(_l('proxy_secret'), key);
this.private = key;
this.public = floCrypto.getPubKeyHex(key);
_privateKey = key;
_publicKey = floCrypto.getPubKeyHex(key);
},
get secret() {
const self = this;
return new Promise((resolve, reject) => {
if (self.private)
return resolve(self.private);
if (_privateKey)
return resolve(_privateKey);

const Reject = reason => {
notify(reason, 'error');
reject(reason);
}
const setValues = priv => {
try {
self.private = priv;
self.public = floCrypto.getPubKeyHex(priv);
resolve(self.private);
_privateKey = priv;
_publicKey = floCrypto.getPubKeyHex(priv);
resolve(_privateKey);
} catch (error) {
Reject("Unable to fetch Proxy secret");
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/floTokenAPI.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2c2d862

Please sign in to comment.