fix: authorization header and threshold logic

This commit is contained in:
Sérgio Salgado 2022-01-05 18:40:38 +00:00
parent 904c383431
commit 57aaa7fb11
3 changed files with 13 additions and 10 deletions

View file

@ -16,25 +16,22 @@ function getClient(account) {
const apiVersion = ctv1.slice(-2)
const authHeader = {
"Authorization": account
"Authorization": account.authorizationValue
}
return { apiVersion, authHeader }
}
function rateWallet(account, cryptoCode, address) {
const client = getClient(account)
console.log('client', client)
if (!_.includes(_.toUpper(cryptoCode), SUPPORTED_COINS) || _.isNil(client)) return Promise.resolve(null)
const { apiVersion, authHeader } = client
const score = Math.floor(Math.random() * (10 - 1 + 1)) + 1
const threshold = _.isNil(account.scoreThreshold) ? WALLET_SCORE_THRESHOLD : account.scoreThreshold
return Promise.resolve({ address, score, isValid: score < threshold })
const threshold = _.isNil(account) ? WALLET_SCORE_THRESHOLD : account.scoreThreshold
// return axios.get(`https://rest.ciphertrace.com/aml/${apiVersion}/${_.toLower(cryptoCode)}/risk?address=${address}`, {
// headers: authHeader
// })
// .then(res => ({ address, score: res.risk, isValid: res.risk <= SCORE_THRESHOLD }))
return axios.get(`https://rest.ciphertrace.com/aml/${apiVersion}/${_.toLower(cryptoCode)}/risk?address=${address}`, {
headers: authHeader
})
.then(res => ({ address, score: res.data.risk, isValid: res.data.risk < threshold }))
}
function isValidWalletScore(account, score) {