feat: reuse last address option
This commit is contained in:
parent
a16abfb709
commit
e6ffcacb78
2 changed files with 25 additions and 1 deletions
|
|
@ -1009,6 +1009,11 @@ function addExternalCompliance(customerId, service, id) {
|
|||
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 = {
|
||||
add,
|
||||
addWithEmail,
|
||||
|
|
@ -1035,4 +1040,5 @@ module.exports = {
|
|||
updateLastAuthAttempt,
|
||||
addExternalCompliance,
|
||||
checkExternalCompliance,
|
||||
getLastUsedAddress,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,7 +311,13 @@ function getExternalComplianceLink(req, res, next) {
|
|||
.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 maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers)
|
||||
|
||||
|
|
@ -346,6 +352,14 @@ function addOrUpdateCustomer(customerData, deviceId, config, isEmailAuth) {
|
|||
.getCustomerActiveIndividualDiscount(customer.id)
|
||||
.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) {
|
||||
|
|
@ -354,6 +368,7 @@ function getOrAddCustomerPhone(req, res, next) {
|
|||
|
||||
const pi = plugins(req.settings, deviceId)
|
||||
const phone = req.body.phone
|
||||
const cryptoCode = req.query.cryptoCode
|
||||
|
||||
return pi
|
||||
.getPhoneCode(phone)
|
||||
|
|
@ -363,6 +378,7 @@ function getOrAddCustomerPhone(req, res, next) {
|
|||
deviceId,
|
||||
req.settings.config,
|
||||
false,
|
||||
cryptoCode,
|
||||
).then(customer => respond(req, res, { code, customer }))
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
@ -375,6 +391,7 @@ function getOrAddCustomerPhone(req, res, next) {
|
|||
function getOrAddCustomerEmail(req, res, next) {
|
||||
const deviceId = req.deviceId
|
||||
const customerData = req.body
|
||||
const cryptoCode = req.query.cryptoCode
|
||||
|
||||
const pi = plugins(req.settings, req.deviceId)
|
||||
const email = req.body.email
|
||||
|
|
@ -387,6 +404,7 @@ function getOrAddCustomerEmail(req, res, next) {
|
|||
deviceId,
|
||||
req.settings.config,
|
||||
true,
|
||||
cryptoCode,
|
||||
).then(customer => respond(req, res, { code, customer }))
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue