- fixed depositBTC throwing error when below 0.0002 value
- moved proxy values not accessable directly from outside the getter/setters
This commit is contained in:
sairajzero 2023-07-16 19:00:01 +05:30
parent 702bd11166
commit e349cd1d72

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
(function (EXPORTS) { //floTradeAPI v0.9.0 (function (EXPORTS) { //floTradeAPI v0.9.1
const tradeAPI = EXPORTS; const tradeAPI = EXPORTS;
const DEFAULT = { const DEFAULT = {
@ -9,6 +9,8 @@
currency: "BTC" //should come from blockchain config later currency: "BTC" //should come from blockchain config later
} }
const BTC_DUST_AMT = 546;
/*Kademlia DHT K-bucket implementation as a binary tree.*/ /*Kademlia DHT K-bucket implementation as a binary tree.*/
/** /**
* Implementation of a Kademlia DHT k-bucket used for storing * Implementation of a Kademlia DHT k-bucket used for storing
@ -601,7 +603,7 @@
TRADE: "trade" TRADE: "trade"
} }
tradeAPI.getSink = function (service = serviceList.TRADE) { const getSink = tradeAPI.getSink = function (service = serviceList.TRADE) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!(Object.values(serviceList).includes(service))) if (!(Object.values(serviceList).includes(service)))
return reject(MarketError(MarketError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_VALUE)); return reject(MarketError(MarketError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_VALUE));
@ -1034,7 +1036,7 @@
tradeAPI.depositBTC = function (quantity, floID, sinkID, privKey, proxySecret = null) { tradeAPI.depositBTC = function (quantity, floID, sinkID, privKey, proxySecret = null) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (typeof quantity !== "number" || quantity <= floGlobals.fee) if (typeof quantity !== "number" || quantity <= BTC_DUST_AMT)
return reject(MarketError(MarketError.BAD_REQUEST_CODE, `Invalid quantity (${quantity})`, errorCode.INVALID_NUMBER)); return reject(MarketError(MarketError.BAD_REQUEST_CODE, `Invalid quantity (${quantity})`, errorCode.INVALID_NUMBER));
else if (!floCrypto.verifyPrivKey(privKey, floID)) else if (!floCrypto.verifyPrivKey(privKey, floID))
return reject(MarketError(MarketError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY)); return reject(MarketError(MarketError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
@ -1371,12 +1373,10 @@
} }
//container for user ID and proxy private-key //container for user ID and proxy private-key
var _userID, _publicKey, _privateKey, _sinkID;
const proxy = tradeAPI.proxy = { const proxy = tradeAPI.proxy = {
user: null,
private: null,
public: null,
async lock() { async lock() {
if (!this.private) if (!_privateKey)
return notify("No proxy key found!", 'error'); return notify("No proxy key found!", 'error');
getPromptInput("Add password", 'This password applies to this browser only!', { getPromptInput("Add password", 'This password applies to this browser only!', {
isPassword: true, isPassword: true,
@ -1387,7 +1387,7 @@
else if (pwd.length < 4) else if (pwd.length < 4)
notify("Password minimum length is 4", 'error'); notify("Password minimum length is 4", 'error');
else { else {
let tmp = Crypto.AES.encrypt(this.private, pwd); let tmp = Crypto.AES.encrypt(_privateKey, pwd);
localStorage.setItem(_l('proxy_secret'), "?" + tmp); localStorage.setItem(_l('proxy_secret'), "?" + tmp);
notify("Successfully locked with Password", 'success'); notify("Successfully locked with Password", 'success');
} }
@ -1396,35 +1396,37 @@
clear() { clear() {
localStorage.removeItem(_l('proxy_secret')); localStorage.removeItem(_l('proxy_secret'));
localStorage.removeItem(_l('user_ID')); localStorage.removeItem(_l('user_ID'));
this.user = null; _userID = null;
this.private = null; _privateKey = null;
this.public = null; _publicKey = null;
},
set sinkID(id) {
_sinkID = id;
}, },
get sinkID() { get sinkID() {
return getRef("sink_id").value; return _sinkID;
}, },
set userID(id) { set userID(id) {
localStorage.setItem(_l('user_ID'), id); localStorage.setItem(_l('user_ID'), id);
this.user = id; _userID = id;
}, },
get userID() { get userID() {
if (this.user) if (_userID)
return this.user; return _userID;
else { else {
let id = localStorage.getItem(_l('user_ID')); let id = localStorage.getItem(_l('user_ID'));
return id ? this.user = id : undefined; return id ? _userID = id : undefined;
} }
}, },
set secret(key) { set secret(key) {
localStorage.setItem(_l('proxy_secret'), key); localStorage.setItem(_l('proxy_secret'), key);
this.private = key; _privateKey = key;
this.public = floCrypto.getPubKeyHex(key); _publicKey = floCrypto.getPubKeyHex(key);
}, },
get secret() { get secret() {
const self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (self.private) if (_privateKey)
return resolve(self.private); return resolve(_privateKey);
const Reject = reason => { const Reject = reason => {
notify(reason, 'error'); notify(reason, 'error');
@ -1432,9 +1434,9 @@
} }
const setValues = priv => { const setValues = priv => {
try { try {
self.private = priv; _privateKey = priv;
self.public = floCrypto.getPubKeyHex(priv); _publicKey = floCrypto.getPubKeyHex(priv);
resolve(self.private); resolve(_privateKey);
} catch (error) { } catch (error) {
Reject("Unable to fetch Proxy secret"); Reject("Unable to fetch Proxy secret");
} }