fix: verify if wallet scoring is enabled

This commit is contained in:
josepfo 2022-11-04 15:56:15 +00:00
parent 69a4d52753
commit 727544344b
6 changed files with 79 additions and 37 deletions

View file

@ -174,6 +174,9 @@ function doesTxReuseAddress (tx) {
}
function getWalletScore (tx, pi) {
pi.isWalletScoringEnabled(tx)
.then(isEnabled => {
if(!isEnabled) return null
if (!tx.fiat || tx.fiat.isZero()) {
return pi.rateWallet(tx.cryptoCode, tx.toAddress)
}
@ -184,6 +187,7 @@ function getWalletScore (tx, pi) {
score: tx.walletScore,
isValid
}))
})
}
function monitorPending (settings) {

View file

@ -122,6 +122,9 @@ function getWalletScore (tx, pi) {
return tx
// Transaction shows up on the blockchain, we can request the sender address
return pi.isWalletScoringEnabled(tx)
.then(isEnabled => {
if (!isEnabled) return tx
return pi.getTransactionHash(tx)
.then(rejectEmpty("No transaction hashes"))
.then(txHashes => pi.getInputAddresses(tx, txHashes))
@ -146,6 +149,7 @@ function getWalletScore (tx, pi) {
errorCode: 'ciphertraceError',
dispense: true
}))
})
}
function monitorLiveIncoming (settings) {

View file

@ -850,6 +850,10 @@ function plugins (settings, deviceId) {
return walletScoring.getInputAddresses(settings, tx.cryptoCode, txHashes)
}
function isWalletScoringEnabled (tx) {
return walletScoring.isWalletScoringEnabled(settings, tx.cryptoCode)
}
return {
getRates,
recordPing,
@ -882,7 +886,8 @@ function plugins (settings, deviceId) {
rateWallet,
isValidWalletScore,
getTransactionHash,
getInputAddresses
getInputAddresses,
isWalletScoringEnabled
}
}

View file

@ -126,10 +126,19 @@ function getInputAddresses (account, cryptoCode, txHashes) {
})
}
function isWalletScoringEnabled (account, cryptoCode) {
if (!SUPPORTED_COINS.includes(cryptoCode)) {
return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
}
return Promise.resolve(!_.isNil(account) && account.enabled)
}
module.exports = {
NAME,
rateWallet,
isValidWalletScore,
getTransactionHash,
getInputAddresses
getInputAddresses,
isWalletScoringEnabled
}

View file

@ -36,10 +36,20 @@ function getInputAddresses (account, cryptoCode, txHashes) {
})
}
function isWalletScoringEnabled (account, cryptoCode) {
return new Promise((resolve, _) => {
setTimeout(() => {
return resolve(true)
}, 100)
})
}
module.exports = {
NAME,
rateWallet,
isValidWalletScore,
getTransactionHash,
getInputAddresses
getInputAddresses,
isWalletScoringEnabled
}

View file

@ -47,9 +47,19 @@ function getInputAddresses (settings, cryptoCode, txHashes) {
})
}
function isWalletScoringEnabled (settings, cryptoCode) {
return Promise.resolve()
.then(() => {
const { plugin, account } = loadWalletScoring(settings)
return plugin.isWalletScoringEnabled(account, cryptoCode)
})
}
module.exports = {
rateWallet,
isValidWalletScore,
getTransactionHash,
getInputAddresses
getInputAddresses,
isWalletScoringEnabled
}