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 #2133 from gnosis/claim-fix-claim-hook
Browse files Browse the repository at this point in the history
[Claim] - Mod useUserHasSubmittedClaim
  • Loading branch information
W3stside authored Jan 13, 2022
2 parents 883daa4 + 8221231 commit f920236
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/claim/ClaimModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useActiveWeb3React } from '../../hooks/web3'
import { useModalOpen, useToggleSelfClaimModal } from '../../state/application/hooks'
import { ApplicationModal } from '../../state/application/reducer'
import { useClaimCallback, useUserClaimData, useUserUnclaimedAmount } from 'state/claim/hooks'
import { useUserHasSubmittedClaim } from '../../state/transactions/hooks'
import { useUserHasSubmittedClaim } from 'state/transactions/hooks'
import { CloseIcon, CustomLightSpinner, ExternalLink, TYPE, UniTokenAnimated } from '../../theme'
import { ExplorerDataType, getExplorerLink } from '../../utils/getExplorerLink'
import { ButtonPrimary } from '../Button'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export function useUserClaims(account: Account): UserClaims | null {
const createMockTx = (data: number[]) => ({
hash: '0x' + Math.round(Math.random() * 10).toString() + 'AxAFjAhG89G89AfnLK3CCxAfnLKQffQ782G89AfnLK3CCxxx123FF',
summary: `Claimed ${Math.random() * 3337} vCOW`,
claim: { recipient: '0xAdbfSdkjf87asdbgkxf283asf787123d' },
claim: { recipient: '0x97EC4fcD5F78cA6f6E4E1EAC6c0Ec8421bA518B7' },
data, // add the claim indices to state
})

Expand Down
22 changes: 22 additions & 0 deletions src/custom/state/transactions/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useMemo } from 'react'
import { useAllClaimingTransactions } from 'state/enhancedTransactions/hooks'
import { EnhancedTransactionDetails } from 'state/enhancedTransactions/reducer'

export * from '@src/state/transactions/hooks'

// watch for submissions to claim
// return null if not done loading, return undefined if not found
export function useUserHasSubmittedClaim(account?: string): {
claimSubmitted: boolean
claimTxn: EnhancedTransactionDetails | undefined
} {
const pendingClaims = useAllClaimingTransactions()
const claimTxn = useMemo(
() =>
// find one that is both the user's claim, AND not mined
pendingClaims.find((claim) => claim.claim?.recipient === account),
[account, pendingClaims]
)

return { claimSubmitted: !!claimTxn, claimTxn }
}

0 comments on commit f920236

Please sign in to comment.