From 547b4baf6ac00821034b5c94e53a3609ba8a218c Mon Sep 17 00:00:00 2001 From: Satoshi Nakamoto Date: Thu, 26 Oct 2023 12:03:34 -0400 Subject: [PATCH] Ensure cost uses latest me.name and not a cached name from session disable submit button while form is submitting --- api/resolvers/user.js | 8 ++++++++ components/fee-button.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api/resolvers/user.js b/api/resolvers/user.js index 04be6d688..bad81b760 100644 --- a/api/resolvers/user.js +++ b/api/resolvers/user.js @@ -105,6 +105,12 @@ export const getNameCost = async ({ name, me, models }) => { if (me?.name === name) { return 0 } + + if (me && (await models.user.findUnique({ where: { id: me.id } })).name === name) { + // This handles the case where a user has changed their nym in the current session, so `me.name` is old + return 0 + } + const distanceResult = await models.$queryRawUnsafe('select name, levenshtein(name, $1) as dist from users where id <> $2 order by dist asc limit 1;', name, me?.id ?? -1) const { dist } = distanceResult[0] let cost = 100000 / Math.pow(10, dist - 1) @@ -539,6 +545,8 @@ export default { models.$queryRawUnsafe('SELECT 1 FROM edit_nym($1::INTEGER, $2::TEXT, $3::BIGINT);', me.id, name, cost), { models, lnd, me, hash, hmac } ) + // update name in server session + me.name = name return name } catch (error) { if (error.code === 'P2002') { diff --git a/components/fee-button.js b/components/fee-button.js index 8ab1f6a6c..659e9360b 100644 --- a/components/fee-button.js +++ b/components/fee-button.js @@ -189,7 +189,7 @@ export const EditNymFeeButton = ({ onClick }) => { return (
- save{cost > 0 && show && {numWithUnits(cost, { abbreviate: false, format: true })}} + save{cost > 0 && show && {numWithUnits(cost, { abbreviate: false, format: true })}} {cost > 0 && show &&