diff --git a/bot/index.js b/bot/index.js index 3b543c3..9bcc14a 100644 --- a/bot/index.js +++ b/bot/index.js @@ -37,29 +37,31 @@ const getAddress = function(req) { } const getLabel = function(req) { - return github.getLabels(req) - .then(labels => { - if (labels.length === 1) { - resolve(labels[0]); - } else { - // TODO: Handle error - } - }).catch(err => { + return github.getLabels(req).then(labels => { + if (labels.length === 1) { + resolve(labels[0]); + } else { // TODO: Handle error - }); + } + }).catch(err => { + // TODO: Handle error + }); } const getAmount = function(req) { - let tokenPricePromise = prices.getTokenPrice(config.token); - - let label = getLabel(req); - let amountToPayDollar = config.priceHour * config.workHours[label]; - - tokenPricePromise - .then((tokenPrice) => {return tokenPrice * config.amountToPayInDollars} ) - .catch((err) => {console.log("TODO-ERROR: Failed token price request throw log error")}); - // Check how to handle errors when promises does not arrive + return new Promise((resolve, reject) => { + let labelPromise = getLabel(req); + let tokenPricePromise = prices.getTokenPrice(config.token); + Promise.all([labelPromise, tokenPricePromise]).then(function(values) { + let label = values[0]; + let tockenPrice = values[1]; + let amountToPayDollar = config.priceHour * config.workHours[label]; + reslove(config.amountToPayDollar/tockenPrice); + }).catch(error => { + // TODO: Handle error + }); + }); } const getGasPrice = function(req) {