Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix referralCode for link open modal #3079

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/AccountDetails/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MyKyc } from 'state/kyc/actions'
import { ReactComponent as Edit } from '../../assets/images/edit.svg'
import { ReactComponent as DefaultAvatar } from '../../assets/images/default-avatar.svg'
import styled from 'styled-components'
import { useQueryParams } from 'hooks/useParams'

interface ModalProps {
isModalOpen: boolean
Expand All @@ -21,6 +22,7 @@ interface AvatarProps {
}

const Avatar: React.FC<AvatarProps> = ({ kyc, toggleWalletModal }) => {
const { objectParams } = useQueryParams<{ referralCode: string }>(['referralCode'])
const [modalProps, setModalProps] = useState<ModalProps>({ isModalOpen: false, referralCode: '' })

const closeModal = () => {
Expand All @@ -30,8 +32,8 @@ const Avatar: React.FC<AvatarProps> = ({ kyc, toggleWalletModal }) => {
setModalProps({
isModalOpen: true,
kycType,
referralCode: new URL(window.location.href).href?.split('=')[1]
? `/kyc/${kycType}?referralCode=${new URL(window.location.href).href?.split('=')[1]}`
referralCode: objectParams?.referralCode
? `/kyc/${kycType}?referralCode=${objectParams?.referralCode}`
: `/kyc/${kycType}`,
})
}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/pages/KYC/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { KYC_REWARD, LineRewardAction } from 'constants/lineRewards'
import { apiService as lineRewardApiService } from 'hooks/useLineReward'
import { linePoint } from 'services/apiUrls'
import { useLineReward } from 'providers/LineRewardProvider'
import { useQueryParams } from 'hooks/useParams'

interface DescriptionProps {
description: string | null
Expand Down Expand Up @@ -95,6 +96,7 @@ const Description: FC<DescriptionProps> = ({ description }: DescriptionProps) =>
)

const KYC = () => {
const { objectParams } = useQueryParams<{ referralCode: string }>(['referralCode'])
const { account } = useWeb3React()
const { chainId } = useAccount()
const [cookies] = useCookies(['annoucementsSeen'])
Expand Down Expand Up @@ -161,9 +163,7 @@ const KYC = () => {
setModalProps({
isModalOpen: true,
kycType,
referralCode: new URL(window.location.href).href?.split('=')[1]
? `/kyc/${kycType}?referralCode=${new URL(window.location.href).href?.split('=')[1]}`
: `/kyc/${kycType}`,
referralCode: objectParams?.referralCode ? `/kyc/${kycType}?referralCode=${objectParams?.referralCode}` : `/kyc/${kycType}`,
// Add more props as needed
})
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}