feat: reuse last address option

This commit is contained in:
Rafael Taranto 2025-05-28 07:11:37 +01:00
parent a16abfb709
commit e6ffcacb78
2 changed files with 25 additions and 1 deletions

View file

@ -1009,6 +1009,11 @@ function addExternalCompliance(customerId, service, id) {
return db.none(sql, [customerId, id, service]) return db.none(sql, [customerId, id, service])
} }
function getLastUsedAddress(id, cryptoCode) {
const sql = `SELECT to_address FROM cash_in_txs WHERE customer_id=$1 AND crypto_code=$2 AND fiat > 0 ORDER BY created DESC LIMIT 1`
return db.oneOrNone(sql, [id, cryptoCode]).then(it => it?.to_address)
}
module.exports = { module.exports = {
add, add,
addWithEmail, addWithEmail,
@ -1035,4 +1040,5 @@ module.exports = {
updateLastAuthAttempt, updateLastAuthAttempt,
addExternalCompliance, addExternalCompliance,
checkExternalCompliance, checkExternalCompliance,
getLastUsedAddress,
} }

View file

@ -311,7 +311,13 @@ function getExternalComplianceLink(req, res, next) {
.then(url => respond(req, res, { url })) .then(url => respond(req, res, { url }))
} }
function addOrUpdateCustomer(customerData, deviceId, config, isEmailAuth) { function addOrUpdateCustomer(
customerData,
deviceId,
config,
isEmailAuth,
cryptoCode,
) {
const triggers = configManager.getTriggers(config) const triggers = configManager.getTriggers(config)
const maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers) const maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers)
@ -346,6 +352,14 @@ function addOrUpdateCustomer(customerData, deviceId, config, isEmailAuth) {
.getCustomerActiveIndividualDiscount(customer.id) .getCustomerActiveIndividualDiscount(customer.id)
.then(discount => ({ ...customer, discount })) .then(discount => ({ ...customer, discount }))
}) })
.then(customer => {
if (!cryptoCode) return customer
return customers
.getLastUsedAddress(customer.id, cryptoCode)
.then(lastUsedAddress => {
return { ...customer, lastUsedAddress }
})
})
} }
function getOrAddCustomerPhone(req, res, next) { function getOrAddCustomerPhone(req, res, next) {
@ -354,6 +368,7 @@ function getOrAddCustomerPhone(req, res, next) {
const pi = plugins(req.settings, deviceId) const pi = plugins(req.settings, deviceId)
const phone = req.body.phone const phone = req.body.phone
const cryptoCode = req.query.cryptoCode
return pi return pi
.getPhoneCode(phone) .getPhoneCode(phone)
@ -363,6 +378,7 @@ function getOrAddCustomerPhone(req, res, next) {
deviceId, deviceId,
req.settings.config, req.settings.config,
false, false,
cryptoCode,
).then(customer => respond(req, res, { code, customer })) ).then(customer => respond(req, res, { code, customer }))
}) })
.catch(err => { .catch(err => {
@ -375,6 +391,7 @@ function getOrAddCustomerPhone(req, res, next) {
function getOrAddCustomerEmail(req, res, next) { function getOrAddCustomerEmail(req, res, next) {
const deviceId = req.deviceId const deviceId = req.deviceId
const customerData = req.body const customerData = req.body
const cryptoCode = req.query.cryptoCode
const pi = plugins(req.settings, req.deviceId) const pi = plugins(req.settings, req.deviceId)
const email = req.body.email const email = req.body.email
@ -387,6 +404,7 @@ function getOrAddCustomerEmail(req, res, next) {
deviceId, deviceId,
req.settings.config, req.settings.config,
true, true,
cryptoCode,
).then(customer => respond(req, res, { code, customer })) ).then(customer => respond(req, res, { code, customer }))
}) })
.catch(err => { .catch(err => {