Skip to content

Commit

Permalink
Use ref from url if user not logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Mar 5, 2024
1 parent 49dcd8d commit cee76ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/components/referral/ReferralUrlChanger.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import { useSelectProfileSpace } from 'src/rtk/app/hooks'
import { getCurrentSearchParams, getCurrentUrlWithoutQuery } from 'src/utils/url'
import { getCurrentSearchParams, getCurrentUrlWithoutQuery, getUrlQuery } from 'src/utils/url'
import { useMyAddress } from '../auth/MyAccountsContext'

export function useReferralId() {
const myAddress = useMyAddress()
const profileSpace = useSelectProfileSpace(myAddress)
return profileSpace?.spaceId ?? ''
return profileSpace?.spaceId || getUrlQuery('ref')
}

export function ReferralUrlChanger() {
Expand Down
16 changes: 0 additions & 16 deletions src/components/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import dayjs from 'dayjs'
import { CID } from 'ipfs-http-client'
import isbot from 'isbot'
import NextError from 'next/error'
import queryString from 'query-string'
import React, { useEffect, useMemo } from 'react'
import { IconBaseProps } from 'react-icons'
import config from 'src/config'
Expand All @@ -34,21 +33,6 @@ export const offchainApi = { ...offchain }
export const ZERO = new BN(0)
export const ONE = new BN(1)

// Substrate/Polkadot API utils
// --------------------------------------

// Parse URLs
// --------------------------------------

export function getUrlParam(
location: Location,
paramName: string,
deflt?: string,
): string | undefined {
const params = queryString.parse(location.search)
return params[paramName] ? (params[paramName] as string) : deflt
}

// Next.js utils
// --------------------------------------

Expand Down
7 changes: 7 additions & 0 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ export function getCurrentUrlOrigin() {
if (typeof window === 'undefined') return ''
return window.location.origin
}

export function getUrlQuery(queryName: string) {
if (isServerSide()) return ''
const query = window.location.search
const searchParams = new URLSearchParams(query)
return searchParams.get(queryName) ?? ''
}

0 comments on commit cee76ed

Please sign in to comment.