Workflow updating files of flopay
This commit is contained in:
parent
d53bbb0673
commit
ae73389ccd
@ -1515,7 +1515,7 @@
|
|||||||
console.log("Starting the app! Please Wait!")
|
console.log("Starting the app! Please Wait!")
|
||||||
floDapps.setCustomPrivKeyInput(getSignedIn)
|
floDapps.setCustomPrivKeyInput(getSignedIn)
|
||||||
floDapps.setAppObjectStores({ savedIds: {}, savedUserData: {} })
|
floDapps.setAppObjectStores({ savedIds: {}, savedUserData: {} })
|
||||||
await floExchangeAPI.init("FMxYC7gYZhouzqtHZukGnPiQ8nvG4CMzXM", "exchange")
|
await floExchangeAPI.init("exchange")
|
||||||
console.log('Exchange API initialized!')
|
console.log('Exchange API initialized!')
|
||||||
floDapps.launchStartUp().then(result => {
|
floDapps.launchStartUp().then(result => {
|
||||||
console.log(`Welcome ${floDapps.user.id}`);
|
console.log(`Welcome ${floDapps.user.id}`);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(function (EXPORTS) { //floExchangeAPI v1.2.0a
|
(function (EXPORTS) { //floExchangeAPI v1.2.1
|
||||||
const exchangeAPI = EXPORTS;
|
const exchangeAPI = EXPORTS;
|
||||||
|
|
||||||
const DEFAULT = {
|
const DEFAULT = {
|
||||||
@ -608,7 +608,7 @@
|
|||||||
BOBS_FUND: "bobs-fund"
|
BOBS_FUND: "bobs-fund"
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeAPI.getSink = function (service = serviceList.EXCHANGE) {
|
const getSink = exchangeAPI.getSink = function (service = serviceList.EXCHANGE) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!(Object.values(serviceList).includes(service)))
|
if (!(Object.values(serviceList).includes(service)))
|
||||||
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_VALUE));
|
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_VALUE));
|
||||||
@ -1720,7 +1720,7 @@
|
|||||||
|
|
||||||
const _l = key => DEFAULT.marketApp + '-' + key;
|
const _l = key => DEFAULT.marketApp + '-' + key;
|
||||||
|
|
||||||
exchangeAPI.init = function refreshDataFromBlockchain() {
|
function refreshDataFromBlockchain() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let nodes, trusted = new Set(), assets, tags, lastTx;
|
let nodes, trusted = new Set(), assets, tags, lastTx;
|
||||||
try {
|
try {
|
||||||
@ -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 = {
|
const config = exchangeAPI.config = {
|
||||||
get trustedList() {
|
get trustedList() {
|
||||||
return new Set((localStorage.getItem(_l('trusted')) || "").split(','));
|
return new Set((localStorage.getItem(_l('trusted')) || "").split(','));
|
||||||
@ -1820,12 +1831,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//container for user ID and proxy private-key
|
//container for user ID and proxy private-key
|
||||||
|
var _userID, _publicKey, _privateKey, _sinkID;
|
||||||
const proxy = exchangeAPI.proxy = {
|
const proxy = exchangeAPI.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,
|
||||||
@ -1836,7 +1845,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');
|
||||||
}
|
}
|
||||||
@ -1845,35 +1854,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;
|
||||||
},
|
},
|
||||||
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;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
get user() {
|
||||||
|
return this.userID;
|
||||||
|
},
|
||||||
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');
|
||||||
@ -1881,9 +1892,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");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //floTokenAPI v1.2.0
|
(function (EXPORTS) { //floTokenAPI v1.2.1a
|
||||||
/* Token Operator to send/receive tokens via blockchain using API calls*/
|
/* Token Operator to send/receive tokens via blockchain using API calls*/
|
||||||
'use strict';
|
'use strict';
|
||||||
const tokenAPI = EXPORTS;
|
const tokenAPI = EXPORTS;
|
||||||
@ -68,9 +68,13 @@
|
|||||||
|
|
||||||
const getBalance = tokenAPI.getBalance = function (floID, token = DEFAULT.currency) {
|
const getBalance = tokenAPI.getBalance = function (floID, token = DEFAULT.currency) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch_api(`api/v2/floAddressInfo/${floID}`)
|
fetch_api(`api/v2/floAddressInfo/${floID}`).then(result => {
|
||||||
.then(result => resolve(result.floAddressBalances[token]?.balance || 0))
|
let token_balance = 0
|
||||||
.catch(error => reject(error))
|
if(result.floAddressBalances != null && typeof result.floAddressBalances == "object" && token in result.floAddressBalances){
|
||||||
|
token_balance = result.floAddressBalances[token]["balance"] || 0
|
||||||
|
}
|
||||||
|
resolve(token_balance)
|
||||||
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,10 +83,10 @@
|
|||||||
fetch_api(`api/v2/transactionDetails/${txID}`).then(res => {
|
fetch_api(`api/v2/transactionDetails/${txID}`).then(res => {
|
||||||
if (res.result === "error")
|
if (res.result === "error")
|
||||||
reject(res.description);
|
reject(res.description);
|
||||||
else if (!res.parsedFloData)
|
//else if (!res.parsedFloData)
|
||||||
reject("Data piece (parsedFloData) missing");
|
// reject("Data piece (parsedFloData) missing");
|
||||||
else if (!res.transactionDetails)
|
//else if (!res.transactionDetails)
|
||||||
reject("Data piece (transactionDetails) missing");
|
// reject("Data piece (transactionDetails) missing");
|
||||||
else
|
else
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -178,16 +182,16 @@
|
|||||||
|
|
||||||
const util = tokenAPI.util = {};
|
const util = tokenAPI.util = {};
|
||||||
|
|
||||||
util.parseTxData = function (txData) {
|
util.parseTxData = function (txData) {
|
||||||
let parsedData = {};
|
let parsedData = {};
|
||||||
for (let p in txData.parsedFloData)
|
for (let p in txData.parsedFloData)
|
||||||
parsedData[p] = txData.parsedFloData[p];
|
parsedData[p] = txData.parsedFloData[p];
|
||||||
parsedData.sender = txData.transactionDetails.vin[0].addr;
|
parsedData.sender = txData.vin[0].addresses[0];
|
||||||
for (let vout of txData.transactionDetails.vout)
|
for (let vout of txData.vout)
|
||||||
if (vout.scriptPubKey.addresses[0] !== parsedData.sender)
|
if (vout.scriptPubKey.addresses[0] !== parsedData.sender)
|
||||||
parsedData.receiver = vout.scriptPubKey.addresses[0];
|
parsedData.receiver = vout.scriptPubKey.addresses[0];
|
||||||
parsedData.time = txData.transactionDetails.time;
|
parsedData.time = txData.time;
|
||||||
return parsedData;
|
return parsedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
})('object' === typeof module ? module.exports : window.floTokenAPI = {});
|
})('object' === typeof module ? module.exports : window.floTokenAPI = {});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user