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

Commit

Permalink
Merge pull request #1719 from gnosis/1573/properly-display-banners
Browse files Browse the repository at this point in the history
  • Loading branch information
matextrem authored Oct 29, 2021
2 parents af19f21 + 7087db2 commit 9265d61
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/custom/components/AffiliateStatusCheck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react'
import { useHistory } from 'react-router-dom'
import { useActiveWeb3React } from 'hooks/web3'
import NotificationBanner from 'components/NotificationBanner'
import { useReferralAddress, useResetReferralAddress, useUploadReferralDocAndSetDataHash } from 'state/affiliate/hooks'
import { useReferralAddress, useUploadReferralDocAndSetDataHash } from 'state/affiliate/hooks'
import { useAppDispatch } from 'state/hooks'
import { hasTrades } from 'utils/trade'
import { retry, RetryOptions } from 'utils/retry'
Expand All @@ -24,7 +24,6 @@ const DEFAULT_RETRY_OPTIONS: RetryOptions = { n: 3, minWait: 1000, maxWait: 3000

export default function AffiliateStatusCheck() {
const appDispatch = useAppDispatch()
const resetReferralAddress = useResetReferralAddress()
const uploadReferralDocAndSetDataHash = useUploadReferralDocAndSetDataHash()
const history = useHistory()
const { account, chainId } = useActiveWeb3React()
Expand All @@ -34,7 +33,6 @@ export default function AffiliateStatusCheck() {

const uploadDataDoc = useCallback(async () => {
setError('')

if (!chainId || !account || !referralAddress) {
return
}
Expand All @@ -44,7 +42,6 @@ export default function AffiliateStatusCheck() {
const userHasTrades = await retry(() => hasTrades(chainId, account), DEFAULT_RETRY_OPTIONS).promise

if (userHasTrades) {
resetReferralAddress()
setAffiliateState('ALREADY_TRADED')
return
}
Expand All @@ -62,7 +59,7 @@ export default function AffiliateStatusCheck() {
console.error(error)
setError('There was an error while uploading the referral document to IPFS. Please try again.')
}
}, [chainId, account, referralAddress, resetReferralAddress, uploadReferralDocAndSetDataHash])
}, [chainId, account, referralAddress, uploadReferralDocAndSetDataHash])

useEffect(() => {
if (!referralAddress) {
Expand All @@ -83,14 +80,13 @@ export default function AffiliateStatusCheck() {

if (referralAddress === account) {
// clean-up saved referral address if the user follows its own referral link
resetReferralAddress()
history.push('/profile')
setAffiliateState('OWN_LINK')
return
}

uploadDataDoc()
}, [referralAddress, account, resetReferralAddress, history, chainId, appDispatch, uploadDataDoc])
}, [referralAddress, account, history, chainId, appDispatch, uploadDataDoc])

if (error) {
return (
Expand Down

0 comments on commit 9265d61

Please sign in to comment.