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

Commit

Permalink
Claim invest general error msg (#2254)
Browse files Browse the repository at this point in the history
# Summary

Waterfalls onto #2250 

Hide/show investment error msg when there are errors
Also updated the msg to be more general.

![Screen Shot 2022-01-21 at 15 15 47](https://user-images.githubusercontent.com/43217/150612049-ec644178-2dce-4823-9f6d-566659883f0f.png)

Of course feel free to suggest something else

  # To Test

1. Try to claim something paid and make sure to fail the validation
  • Loading branch information
alfetopito authored Jan 22, 2022
1 parent b9523af commit ca3b4bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/custom/pages/Claim/FooterNavButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useMemo } from 'react'
import { Trans } from '@lingui/macro'
import { isAddress } from '@ethersproject/address'
import { useClaimDispatchers, useClaimState } from 'state/claim/hooks'
import { useClaimDispatchers, useClaimState, useHasClaimInvestmentFlowError } from 'state/claim/hooks'
import { ButtonPrimary, ButtonSecondary } from 'components/Button'
import { ClaimStatus } from 'state/claim/actions'
import { FooterNavButtons as FooterNavButtonsWrapper } from 'pages/Claim/styled'
Expand Down Expand Up @@ -34,7 +33,6 @@ export default function FooterNavButtons({
// claiming
claimStatus,
// investment
investFlowData,
investFlowStep,
isInvestFlowActive,
// table select change
Expand All @@ -47,9 +45,7 @@ export default function FooterNavButtons({
setIsInvestFlowActive,
} = useClaimDispatchers()

const hasError = useMemo(() => {
return investFlowData.some(({ error }) => Boolean(error))
}, [investFlowData])
const hasError = useHasClaimInvestmentFlowError()

const isInputAddressValid = isAddress(resolvedAddress || '')

Expand Down
12 changes: 10 additions & 2 deletions src/custom/pages/Claim/InvestmentFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import { ClaimSummaryView } from 'pages/Claim/ClaimSummary'

import { Stepper } from 'components/Stepper'

import { ClaimType, useClaimState, useUserEnhancedClaimData, useClaimDispatchers } from 'state/claim/hooks'
import {
ClaimType,
useClaimState,
useUserEnhancedClaimData,
useClaimDispatchers,
useHasClaimInvestmentFlowError,
} from 'state/claim/hooks'
import { ClaimStatus } from 'state/claim/actions'
import { InvestClaim } from 'state/claim/reducer'
import { calculateInvestmentAmounts } from 'state/claim/hooks/utils'
Expand Down Expand Up @@ -119,6 +125,8 @@ export default function InvestmentFlow({ hasClaims, isAirdropOnly, ...tokenAppro
const { initInvestFlowData } = useClaimDispatchers()
const claimData = useUserEnhancedClaimData(activeClaimAccount)

const hasError = useHasClaimInvestmentFlowError()

// Filtering and splitting claims into free and selected paid claims
// `selectedClaims` are used on step 1 and 2
// `freeClaims` are used on step 2
Expand Down Expand Up @@ -202,7 +210,7 @@ export default function InvestmentFlow({ hasClaims, isAirdropOnly, ...tokenAppro
/>
))}

<InvestFlowValidation>Approve all investment tokens before continuing</InvestFlowValidation>
{hasError && <InvestFlowValidation>Fix the errors before continuing</InvestFlowValidation>}
</InvestContent>
) : null}
{/* Invest flow: Step 2 > Review summary */}
Expand Down
11 changes: 11 additions & 0 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,17 @@ export function useClaimState() {
return useSelector((state: AppState) => state.claim)
}

/**
* Returns a boolean indicating whehter there's an error on claim investment flow
*/
export function useHasClaimInvestmentFlowError(): boolean {
const { investFlowData } = useClaimState()

return useMemo(() => {
return investFlowData.some(({ error }) => Boolean(error))
}, [investFlowData])
}

/**
* Gets an array of available claims parsed and sorted for the UI
*
Expand Down

0 comments on commit ca3b4bd

Please sign in to comment.