From 5c0ef9f6e2224a903b5f962f87d3c0ac712fb3e2 Mon Sep 17 00:00:00 2001 From: thi-investax Date: Thu, 16 Jan 2025 16:27:42 +0700 Subject: [PATCH] Check valid referral code --- src/pages/App.tsx | 7 ++++++- src/utils/index.ts | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index fc6c95efb..fff84b5b6 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -48,7 +48,7 @@ import { setJumpTaskState } from 'state/jumpTask' import { CHAINS } from 'components/Web3Provider/constants' const Launchpad = lazy(() => import('pages/Launchpad')) import KYC from 'pages/KYC' -import { isLineLiff } from 'utils' +import { isLineLiff, isValidReferralCode } from 'utils' import { useLiff } from './LiffProvider' import TaskSuccessModal from 'components/Rewards/TaskSuccessModal' import { useLineReward } from 'providers/LineRewardProvider' @@ -259,6 +259,11 @@ export default function App() { if (!code) { return } + + if (!isValidReferralCode(code)) { + return + } + const storedReferralCode = localStorage.getItem('referralCode') if (!storedReferralCode) { localStorage.setItem('referralCode', code) diff --git a/src/utils/index.ts b/src/utils/index.ts index d8f464004..d4859b228 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -186,3 +186,9 @@ export function tryClearIndexedDB() { export const isLineLiff = window.location.hostname.includes('line-liff.ixswap.io') || window.location.hostname.includes('localhost') + +export const isValidReferralCode = (code: string) => { + // Define the regex pattern for 6 characters, only alphabets and digits + const pattern = /^[A-Za-z0-9]{6}$/ + return pattern.test(code) +}