Skip to content

Commit

Permalink
feat: referral link from BE to have og image (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv authored Jul 12, 2024
1 parent 4f399a3 commit 4b1cabd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/pages/Campaign/components/JoinReferral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { useEffect, useRef, useState } from 'react'
import { X } from 'react-feather'
import { useSearchParams } from 'react-router-dom'
import { Box, Flex, Text } from 'rebass'
import { useGetParticipantQuery, useJoinCampaignMutation, useLazyGetNonceQuery } from 'services/referral'
import {
useCreateShareMutation,
useGetParticipantQuery,
useJoinCampaignMutation,
useLazyGetNonceQuery,
} from 'services/referral'
import { SiweMessage } from 'siwe'

import { NotificationType } from 'components/Announcement/type'
Expand All @@ -27,6 +32,18 @@ export default function JoinReferal() {
const [refCode, setRefCode] = useState(searchParams.get('code') || '')

const { data, isLoading, error, refetch } = useGetParticipantQuery({ wallet: account || '' }, { skip: !account })
const userRefCode = data?.data?.participant?.referralCode
const [refLink, setRefLink] = useState('')

const [createShareLink] = useCreateShareMutation()

useEffect(() => {
if (account && userRefCode) {
createShareLink({ code: userRefCode, account }).then(res => {
if ((res as any)?.data?.data?.link) setRefLink((res as any).data.data.link)
})
}
}, [userRefCode, createShareLink, account])

const code = searchParams.get('code')

Expand Down Expand Up @@ -155,10 +172,10 @@ export default function JoinReferal() {
</Text>

<Box sx={{ position: 'relative', marginTop: '24px' }}>
<Input style={{ paddingRight: '40px' }} value={domain} />
<Input style={{ paddingRight: '40px' }} value={refLink || domain} />

<Box sx={{ position: 'absolute', right: '12px', top: '12px' }}>
<CopyHelper toCopy={domain} />
<CopyHelper toCopy={refLink || domain} />
</Box>
</Box>

Expand Down
30 changes: 28 additions & 2 deletions src/services/referral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,36 @@ const referralApi = createApi({
}`,
}),
}),

getShare: builder.query({
query: code => ({
url: `/v3/shared-links/${code}`,
}),
}),

createShare: builder.mutation({
query: ({ code, account }) => ({
url: `/v3/shared-links`,
method: 'POST',
body: {
type: 'ARB_STIP',
redirectURL: `https://kyberswap.com/campaigns/referrals?code=${code}`,
metaImageURL: 'https://i.imgur.com/KRrAZWc.png',
referredByCode: code,
createdBy: account,
},
}),
}),
}),
})

export const { useGetParticipantQuery, useLazyGetNonceQuery, useJoinCampaignMutation, useGetDashboardQuery } =
referralApi
export const {
useGetParticipantQuery,
useLazyGetNonceQuery,
useJoinCampaignMutation,
useGetDashboardQuery,
useCreateShareMutation,
useGetShareQuery,
} = referralApi

export default referralApi

0 comments on commit 4b1cabd

Please sign in to comment.