Fix group referrals not working
This commit is contained in:
parent
f8a74aa438
commit
e700697423
|
@ -18,10 +18,14 @@ export const useSaveReferral = (
|
||||||
referrer?: string
|
referrer?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const actualReferrer = referrer || options?.defaultReferrer
|
const referrerOrDefault = referrer || options?.defaultReferrer
|
||||||
|
|
||||||
if (!user && router.isReady && actualReferrer) {
|
if (!user && router.isReady && referrerOrDefault) {
|
||||||
writeReferralInfo(actualReferrer, options?.contractId, options?.groupId)
|
writeReferralInfo(referrerOrDefault, {
|
||||||
|
contractId: options?.contractId,
|
||||||
|
overwriteReferralUsername: referrer,
|
||||||
|
groupId: options?.groupId,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [user, router, options])
|
}, [user, router, options])
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,22 +96,25 @@ const CACHED_REFERRAL_GROUP_ID_KEY = 'CACHED_REFERRAL_GROUP_KEY'
|
||||||
|
|
||||||
export function writeReferralInfo(
|
export function writeReferralInfo(
|
||||||
defaultReferrerUsername: string,
|
defaultReferrerUsername: string,
|
||||||
contractId?: string,
|
otherOptions?: {
|
||||||
referralUsername?: string,
|
contractId?: string
|
||||||
groupId?: string
|
overwriteReferralUsername?: string
|
||||||
|
groupId?: string
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
const local = safeLocalStorage()
|
const local = safeLocalStorage()
|
||||||
const cachedReferralUser = local?.getItem(CACHED_REFERRAL_USERNAME_KEY)
|
const cachedReferralUser = local?.getItem(CACHED_REFERRAL_USERNAME_KEY)
|
||||||
|
const { contractId, overwriteReferralUsername, groupId } = otherOptions || {}
|
||||||
// Write the first referral username we see.
|
// Write the first referral username we see.
|
||||||
if (!cachedReferralUser)
|
if (!cachedReferralUser)
|
||||||
local?.setItem(
|
local?.setItem(
|
||||||
CACHED_REFERRAL_USERNAME_KEY,
|
CACHED_REFERRAL_USERNAME_KEY,
|
||||||
referralUsername || defaultReferrerUsername
|
overwriteReferralUsername || defaultReferrerUsername
|
||||||
)
|
)
|
||||||
|
|
||||||
// If an explicit referral query is passed, overwrite the cached referral username.
|
// If an explicit referral query is passed, overwrite the cached referral username.
|
||||||
if (referralUsername)
|
if (overwriteReferralUsername)
|
||||||
local?.setItem(CACHED_REFERRAL_USERNAME_KEY, referralUsername)
|
local?.setItem(CACHED_REFERRAL_USERNAME_KEY, overwriteReferralUsername)
|
||||||
|
|
||||||
// Always write the most recent explicit group invite query value
|
// Always write the most recent explicit group invite query value
|
||||||
if (groupId) local?.setItem(CACHED_REFERRAL_GROUP_ID_KEY, groupId)
|
if (groupId) local?.setItem(CACHED_REFERRAL_GROUP_ID_KEY, groupId)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user