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

Commit

Permalink
Enhance messages for Affiliate program (#2414)
Browse files Browse the repository at this point in the history
# Summary

Fixes #2409
- [x] Remove 'already traded' message.
- [x] Enhance all the rest messages.

  # To Test

1.  Open the page `Profile`
  • Loading branch information
alongoni authored Feb 17, 2022
1 parent d42aabe commit 7319d6c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/custom/components/AffiliateStatusCheck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ import useParseReferralQueryParam from 'hooks/useParseReferralQueryParam'
import useRecentActivity from 'hooks/useRecentActivity'
import { OrderStatus } from 'state/orders/actions'

type AffiliateStatus = 'NOT_CONNECTED' | 'OWN_LINK' | 'ALREADY_TRADED' | 'ACTIVE' | 'UNSUPPORTED_NETWORK'
type AffiliateStatus = 'NOT_CONNECTED' | 'OWN_LINK' | 'ACTIVE' | 'UNSUPPORTED_NETWORK'

const STATUS_TO_MESSAGE_MAPPING: Record<AffiliateStatus, string> = {
NOT_CONNECTED: 'Affiliate program: Please connect your wallet to participate.',
OWN_LINK:
'Affiliate program: Your affiliate code works! Any new user following this link would credit you their trading volume.',
ALREADY_TRADED:
'Invalid affiliate code: The currently connected wallet has traded before or is already part of the affiliate program.',
ACTIVE: 'Valid affiliate code: You can now do your first trade to join the program.',
UNSUPPORTED_NETWORK: 'Affiliate program: Only Mainnet is supported. Please change the network to participate.',
'Affiliate program: Your affiliate code works! By sharing it, others would credit you their trading volume.',
ACTIVE: 'Valid affiliate code: Please do your first trade to join the program!',
UNSUPPORTED_NETWORK: 'Affiliate program works in Ethereum only. Please change the network to participate.',
}

const DEFAULT_RETRY_OPTIONS: RetryOptions = { n: 3, minWait: 1000, maxWait: 3000 }
Expand Down Expand Up @@ -59,7 +57,7 @@ export default function AffiliateStatusCheck() {
}

if (!referralAddress.isValid) {
setError('The referral address is invalid.')
setError('Affiliate program: The referral address is invalid.')
return
}

Expand All @@ -75,14 +73,14 @@ export default function AffiliateStatusCheck() {
// we first validate that the user hasn't already traded
const userHasTrades = await retry(() => hasTrades(chainId, account), DEFAULT_RETRY_OPTIONS).promise
if (userHasTrades) {
setAffiliateState('ALREADY_TRADED')
return
}
} catch (error) {
console.error(error)
setError('There was an error validating existing trades. Please try again later.')
setError('Affiliate program: There was an error loading trades. Please try again later.')
return
}

setAffiliateState('ACTIVE')
isFirstTrade.current = true
}, [referralAddress, chainId, account, fulfilledActivity.length, history, resetReferralAddress])
Expand All @@ -95,7 +93,7 @@ export default function AffiliateStatusCheck() {
appDispatch(updateAppDataHash(appDataHash))
} catch (e) {
console.error(e)
setError('There was an error while uploading the referral document to IPFS. Please try again later.')
setError('Affiliate program: There was an error while uploading your referral data. Please try again later.')
}
}
if (affiliateState === 'ACTIVE') handleReferralAddress(referralAddress)
Expand Down Expand Up @@ -135,7 +133,7 @@ export default function AffiliateStatusCheck() {
if (error) {
return (
<NotificationBanner isVisible level="error">
Affiliate program error: {error}
{error}
</NotificationBanner>
)
}
Expand Down

0 comments on commit 7319d6c

Please sign in to comment.