diff --git a/lib/plugins/wallet-scoring/scorechain/scorechain.js b/lib/plugins/wallet-scoring/scorechain/scorechain.js index 5a3bd76f..3a64d4b8 100644 --- a/lib/plugins/wallet-scoring/scorechain/scorechain.js +++ b/lib/plugins/wallet-scoring/scorechain/scorechain.js @@ -20,33 +20,35 @@ const TYPE = { } function rate (account, objectType, cryptoCode, objectId) { - if (!isWalletScoringEnabled(account, cryptoCode)) return Promise.resolve(null) + return isWalletScoringEnabled(account, cryptoCode).then(isEnabled => { + if (!isEnabled) return Promise.resolve(null) - const threshold = account.scoreThreshold - const payload = { - analysisType: 'ASSIGNED', - objectType, - objectId, - blockchain: SUPPORTED_COINS[cryptoCode], - coin: "ALL" - } + const threshold = account.scoreThreshold + const payload = { + analysisType: 'ASSIGNED', + objectType, + objectId, + blockchain: SUPPORTED_COINS[cryptoCode], + coin: "ALL" + } - const headers = { - 'accept': 'application/json', - 'X-API-KEY': account.apiKey, - 'Content-Type': 'application/json' - } - return axios.post(`https://api.scorechain.com/v1/scoringAnalysis`, payload, { headers }) - .then(res => { - const resScore = res.data?.analysis?.assigned?.result?.score - if (!resScore) throw new Error('Failed to get score from Scorechain API') + const headers = { + 'accept': 'application/json', + 'X-API-KEY': account.apiKey, + 'Content-Type': 'application/json' + } + return axios.post(`https://api.scorechain.com/v1/scoringAnalysis`, payload, {headers}) + .then(res => { + const resScore = res.data?.analysis?.assigned?.result?.score + if (!resScore) throw new Error('Failed to get score from Scorechain API') - // normalize score to 0-10 where 0 is the lowest risk - return { score: (100 - resScore) / 10, isValid: resScore >= threshold } - }) - .catch(err => { - throw err - }) + // normalize score to 0-10 where 0 is the lowest risk + return {score: (100 - resScore) / 10, isValid: resScore >= threshold} + }) + .catch(err => { + throw err + }) + }) } function rateTransaction (account, cryptoCode, transactionId) {