Skip to content

Commit

Permalink
Fix: Use correct chain for discoutn code (#1107)
Browse files Browse the repository at this point in the history
* use correct chain

* use dynamic chain
  • Loading branch information
kirkas authored Oct 21, 2024
1 parent 928a0cc commit c05a8df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions apps/web/pages/api/proofs/discountCode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { logger } from 'apps/web/src/utils/logger';
import { withTimeout } from 'apps/web/pages/api/decorators';
import { Address, Hash, stringToHex } from 'viem';
import { USERNAME_DISCOUNT_CODE_VALIDATORS } from 'apps/web/src/addresses/usernames';
import { baseSepolia } from 'viem/chains';
import { getDiscountCode } from 'apps/web/src/utils/proofs/discount_code_storage';

export type DiscountCodeResponse = {
Expand All @@ -26,6 +25,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
return res.status(validationErr.status).json({ error: validationErr.error });
}

const chainId = parseInt(chain as string);

if (!code || typeof code !== 'string') {
return res.status(500).json({ error: 'Discount code invalid' });
}
Expand Down Expand Up @@ -58,14 +59,13 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const signature = await signDiscountMessageWithTrustedSigner(
address as Address,
couponCodeUuid,
// TODO: Set variable chain
USERNAME_DISCOUNT_CODE_VALIDATORS[baseSepolia.id],
USERNAME_DISCOUNT_CODE_VALIDATORS[chainId],
expirationTimeUnix,
);

// 4. Return the discount data
const result: DiscountCodeResponse = {
discountValidatorAddress: USERNAME_DISCOUNT_CODE_VALIDATORS[baseSepolia.id],
discountValidatorAddress: USERNAME_DISCOUNT_CODE_VALIDATORS[chainId],
address: address as Address,
signedMessage: signature,
};
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/utils/proofs/sybil_resistance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const discountTypes: DiscountTypesByChainId = {
[DiscountType.EARLY_ACCESS]: {
discountValidatorAddress: USERNAME_EA_DISCOUNT_VALIDATORS[base.id],
},
[DiscountType.DISCOUNT_CODE]: {
discountValidatorAddress: USERNAME_DISCOUNT_CODE_VALIDATORS[base.id],
},
},
[baseSepolia.id]: {
[DiscountType.CB]: {
Expand Down

0 comments on commit c05a8df

Please sign in to comment.