-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Claim bug fix #6182
Claim bug fix #6182
Changes from 2 commits
7a42d65
cca92af
8dadb23
44d5acc
629ee84
b879d0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React, { useState } from 'react'; | ||
import { ClaimResponse, SponsoredClaimable } from '@/resources/addys/claimables/types'; | ||
import { Claimable, ClaimResponse, SponsoredClaimable } from '@/resources/addys/claimables/types'; | ||
import { ClaimingClaimableSharedUI, ClaimStatus } from './ClaimingClaimableSharedUI'; | ||
import { logger, RainbowError } from '@/logger'; | ||
import { queryClient } from '@/react-query'; | ||
|
@@ -9,12 +9,15 @@ import { useMutation } from '@tanstack/react-query'; | |
import { getProvider } from '@/handlers/web3'; | ||
import { useAccountSettings } from '@/hooks'; | ||
import { haptics } from '@/utils'; | ||
import { delay } from 'lodash'; | ||
|
||
export const ClaimingSponsoredClaimable = ({ claimable }: { claimable: SponsoredClaimable }) => { | ||
const { accountAddress, nativeCurrency } = useAccountSettings(); | ||
|
||
const [claimStatus, setClaimStatus] = useState<ClaimStatus>('idle'); | ||
|
||
const queryKey = claimablesQueryKey({ address: accountAddress, currency: nativeCurrency }); | ||
|
||
const { mutate: claimClaimable } = useMutation({ | ||
mutationFn: async () => { | ||
const provider = getProvider({ chainId: claimable.chainId }); | ||
|
@@ -59,15 +62,16 @@ export const ClaimingSponsoredClaimable = ({ claimable }: { claimable: Sponsored | |
setClaimStatus('error'); | ||
logger.error(new RainbowError('[ClaimSponsoredClaimable]: sponsored claim api call returned unsuccessful response')); | ||
} else { | ||
haptics.notificationSuccess(); | ||
|
||
if (response.data.payload.claim_transaction_status?.transaction_hash) { | ||
haptics.notificationSuccess(); | ||
setClaimStatus('success'); | ||
} else { | ||
haptics.notificationSuccess(); | ||
setClaimStatus('pending'); | ||
} | ||
// Clear and refresh claimables data | ||
queryClient.invalidateQueries(claimablesQueryKey({ address: accountAddress, currency: nativeCurrency })); | ||
|
||
// Immediately remove the claimable from cached data | ||
queryClient.setQueryData(queryKey, (oldData: Claimable[] | undefined) => oldData?.filter(c => c.uniqueId !== claimable.uniqueId)); | ||
} | ||
}, | ||
onError: e => { | ||
|
@@ -86,6 +90,10 @@ export const ClaimingSponsoredClaimable = ({ claimable }: { claimable: Sponsored | |
); | ||
} | ||
}, | ||
onSettled: () => { | ||
// Clear and refresh claimables data 30s after claim button is pressed, regardless of success or failure | ||
delay(() => queryClient.invalidateQueries(queryKey), 20_000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk I feel like why a lib if it's already in the platform? |
||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 20s or 30s? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eyes of an eagle |
||
}); | ||
|
||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naur