Merge pull request #1873 from RafaelTaranto/feat/reuse-last-address

LAM-1433 feat: reuse last address option
This commit is contained in:
Rafael Taranto 2025-05-28 15:36:21 +01:00 committed by GitHub
commit 007320cfbc
4 changed files with 57 additions and 1 deletions

View file

@ -36,6 +36,7 @@ const AdvancedWalletSchema = Yup.object().shape({
cryptoUnits: Yup.string().required(),
feeMultiplier: Yup.string().required(),
allowTransactionBatching: Yup.boolean(),
enableLastUsedAddress: Yup.boolean(),
})
const OverridesSchema = Yup.object().shape({
@ -127,6 +128,17 @@ const getAdvancedWalletElements = () => {
labelProp: 'display',
},
},
{
name: 'enableLastUsedAddress',
header: `Allow last used address prompt`,
size: 'sm',
stripe: true,
width: 260,
view: (_, ite) => {
return ite.enableLastUsedAddress ? 'Yes' : `No`
},
input: Checkbox,
},
]
}

View file

@ -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,
}

View file

@ -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,18 @@ function addOrUpdateCustomer(customerData, deviceId, config, isEmailAuth) {
.getCustomerActiveIndividualDiscount(customer.id)
.then(discount => ({ ...customer, discount }))
})
.then(customer => {
const enableLastUsedAddress = !!configManager.getWalletSettings(
cryptoCode,
config,
).enableLastUsedAddress
if (!cryptoCode || !enableLastUsedAddress) return customer
return customers
.getLastUsedAddress(customer.id, cryptoCode)
.then(lastUsedAddress => {
return { ...customer, lastUsedAddress }
})
})
}
function getOrAddCustomerPhone(req, res, next) {
@ -354,6 +372,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 +382,7 @@ function getOrAddCustomerPhone(req, res, next) {
deviceId,
req.settings.config,
false,
cryptoCode,
).then(customer => respond(req, res, { code, customer }))
})
.catch(err => {
@ -375,6 +395,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 +408,7 @@ function getOrAddCustomerEmail(req, res, next) {
deviceId,
req.settings.config,
true,
cryptoCode,
).then(customer => respond(req, res, { code, customer }))
})
.catch(err => {

View file

@ -0,0 +1,16 @@
const { saveConfig } = require('../lib/new-settings-loader')
exports.up = function (next) {
const newConfig = {
wallets_advanced_enableLastUsedAddress: false,
}
return saveConfig(newConfig)
.then(next)
.catch(err => {
return next(err)
})
}
module.exports.down = function (next) {
next()
}