From 45743827cbd7f4df9f741000a419e777ce7cf62a Mon Sep 17 00:00:00 2001 From: Ricardo Moguel Date: Thu, 22 Aug 2024 16:55:42 -0700 Subject: [PATCH] move the try/catch scope --- apps/web/src/utils/proofs/sybil_resistance.ts | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/apps/web/src/utils/proofs/sybil_resistance.ts b/apps/web/src/utils/proofs/sybil_resistance.ts index 53e8c97d3c..e9d09ee588 100644 --- a/apps/web/src/utils/proofs/sybil_resistance.ts +++ b/apps/web/src/utils/proofs/sybil_resistance.ts @@ -139,36 +139,36 @@ export async function sybilResistantUsernameSigning( (attestation) => JSON.parse(attestation.decodedDataJson)[0] as VerifiedAccount, ); - try { - let { linkedAddresses, idemKey } = await getLinkedAddresses(address as string); + let { linkedAddresses, idemKey } = await getLinkedAddresses(address as string); - const hasPreviouslyRegistered = await hasRegisteredWithDiscount(linkedAddresses, chainId); - // if any linked address registered previously return an error - if (hasPreviouslyRegistered) { - throw new ProofsException('You have already claimed a discounted basename (onchain).', 409); - } + const hasPreviouslyRegistered = await hasRegisteredWithDiscount(linkedAddresses, chainId); + // if any linked address registered previously return an error + if (hasPreviouslyRegistered) { + throw new ProofsException('You have already claimed a discounted basename (onchain).', 409); + } - const kvKey = `${previousClaimsKVPrefix}${idemKey}`; - //check kv for previous claim entries - let previousClaims = (await kv.get(kvKey)) ?? {}; - const previousClaim = previousClaims[discountType]; - if (previousClaim) { - if (previousClaim.address != address) { - throw new ProofsException( - 'You tried claiming this with a different address, wait a couple minutes to try again.', - 400, - ); - } - // return previously signed message - return { - signedMessage: previousClaim.signedMessage, - attestations: attestationsRes, - discountValidatorAddress, - expires: EXPIRY.toString(), - }; + const kvKey = `${previousClaimsKVPrefix}${idemKey}`; + //check kv for previous claim entries + let previousClaims = (await kv.get(kvKey)) ?? {}; + const previousClaim = previousClaims[discountType]; + if (previousClaim) { + if (previousClaim.address != address) { + throw new ProofsException( + 'You tried claiming this with a different address, wait a couple minutes to try again.', + 400, + ); } + // return previously signed message + return { + signedMessage: previousClaim.signedMessage, + attestations: attestationsRes, + discountValidatorAddress, + expires: EXPIRY.toString(), + }; + } - const expirationTimeUnix = Math.floor(Date.now() / 1000) + parseInt(EXPIRY); + const expirationTimeUnix = Math.floor(Date.now() / 1000) + parseInt(EXPIRY); + try { // generate and sign the message const signedMessage = await signMessageWithTrustedSigner( address,