Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Remove Loading Component added on 1753
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypalacios committed Nov 3, 2021
1 parent ac23c67 commit 72d5bc2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
43 changes: 36 additions & 7 deletions src/custom/hooks/useFetchProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,51 @@ import { useEffect, useState } from 'react'
import { getProfileData } from 'api/gnosisProtocol'
import { ProfileData } from 'api/gnosisProtocol/api'

export default function useFetchProfile() {
type FetchProfileState = {
profileData: ProfileData | null
error: string
isLoading: boolean
}

const emptyState: FetchProfileState = {
profileData: null,
error: '',
isLoading: false,
}

const FETCH_INTERVAL_IN_MINUTES = 5

export default function useFetchProfile(): FetchProfileState {
const { account, chainId } = useActiveWeb3React()
const [profileData, setProfileData] = useState<ProfileData | null>(null)
const [profile, setProfile] = useState<FetchProfileState>(emptyState)

useEffect(() => {
setProfile({ ...emptyState, isLoading: true })
async function fetchAndSetProfileData() {
if (chainId && account) {
if (!chainId || !account) {
setProfile((prevState: FetchProfileState) => {
return { ...prevState, isLoading: false }
})
return
}

try {
const profileData = await getProfileData(chainId, account)
setProfileData(profileData)
} else {
setProfileData(null)
setProfile((prevState: FetchProfileState) => {
return { ...prevState, isLoading: false, profileData }
})
} catch (e) {
setProfile((prevState: FetchProfileState) => {
return { ...prevState, isLoading: false, error: 'Error getting profileData' }
})
}
}

const intervalId = setInterval(fetchAndSetProfileData, FETCH_INTERVAL_IN_MINUTES * 60_000)

fetchAndSetProfileData()
return () => clearInterval(intervalId)
}, [account, chainId])

return profileData
return profile
}
25 changes: 19 additions & 6 deletions src/custom/pages/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,27 @@ import { SupportedChainId as ChainId } from 'constants/chains'

export default function Profile() {
const referralLink = useReferralLink()
const { profileData, error } = useFetchProfile()
const { account, chainId } = useActiveWeb3React()
const profileData = useFetchProfile()
const lastUpdated = useTimeAgo(profileData?.lastUpdated)

const renderNotificationMessages = () => {
return (
<>
{error && (
<StyledNotificationBanner isVisible level="error" canClose={false}>
There was an error loading your profile data. Please try again later.
</StyledNotificationBanner>
)}
{chainId && chainId !== ChainId.MAINNET && (
<StyledNotificationBanner isVisible level="info" canClose={false}>
Profile data is only available for mainnet. Please change the network to see it.
</StyledNotificationBanner>
)}
</>
)
}

return (
<Wrapper>
<GridWrap>
Expand All @@ -55,11 +72,7 @@ export default function Profile() {
</Txt>
)}
</CardHead>
{chainId && chainId !== ChainId.MAINNET && (
<StyledNotificationBanner isVisible level="info" canClose={false}>
Profile data is only available for mainnet. Please change the network to see it.
</StyledNotificationBanner>
)}
{renderNotificationMessages()}
<ChildWrapper>
<Txt fs={16}>
<strong>Your referral url</strong>
Expand Down

0 comments on commit 72d5bc2

Please sign in to comment.