fix: misusing promises
This commit is contained in:
parent
8837da0b56
commit
52676b8603
1 changed files with 26 additions and 24 deletions
|
|
@ -20,7 +20,8 @@ const TYPE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function rate (account, objectType, cryptoCode, objectId) {
|
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 threshold = account.scoreThreshold
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
@ -36,17 +37,18 @@ function rate (account, objectType, cryptoCode, objectId) {
|
||||||
'X-API-KEY': account.apiKey,
|
'X-API-KEY': account.apiKey,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
return axios.post(`https://api.scorechain.com/v1/scoringAnalysis`, payload, { headers })
|
return axios.post(`https://api.scorechain.com/v1/scoringAnalysis`, payload, {headers})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const resScore = res.data?.analysis?.assigned?.result?.score
|
const resScore = res.data?.analysis?.assigned?.result?.score
|
||||||
if (!resScore) throw new Error('Failed to get score from Scorechain API')
|
if (!resScore) throw new Error('Failed to get score from Scorechain API')
|
||||||
|
|
||||||
// normalize score to 0-10 where 0 is the lowest risk
|
// normalize score to 0-10 where 0 is the lowest risk
|
||||||
return { score: (100 - resScore) / 10, isValid: resScore >= threshold }
|
return {score: (100 - resScore) / 10, isValid: resScore >= threshold}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function rateTransaction (account, cryptoCode, transactionId) {
|
function rateTransaction (account, cryptoCode, transactionId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue