-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split acre points logic into separate hooks
- Loading branch information
1 parent
1604fa2
commit 199689b
Showing
6 changed files
with
79 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useMutation } from "@tanstack/react-query" | ||
import { acreApi } from "#/utils" | ||
import { MODAL_TYPES } from "#/types" | ||
import { PostHogEvent } from "#/posthog/events" | ||
import { useWallet } from "./useWallet" | ||
import { useModal } from "./useModal" | ||
import { usePostHogCapture } from "./posthog/usePostHogCapture" | ||
import useUserPointsData from "./useUserPointsData" | ||
|
||
export default function useClaimPoints() { | ||
const { ethAddress = "" } = useWallet() | ||
const { openModal } = useModal() | ||
const { handleCapture, handleCaptureWithCause } = usePostHogCapture() | ||
const { refetch: userPointsDataRefetch } = useUserPointsData() | ||
|
||
return useMutation({ | ||
mutationFn: async () => acreApi.claimPoints(ethAddress), | ||
onSettled: async () => { | ||
await userPointsDataRefetch() | ||
}, | ||
onSuccess: (data) => { | ||
const claimedAmount = Number(data.claimed) | ||
const totalAmount = Number(data.total) | ||
|
||
openModal(MODAL_TYPES.ACRE_POINTS_CLAIM, { | ||
claimedAmount, | ||
totalAmount, | ||
}) | ||
|
||
handleCapture(PostHogEvent.PointsClaimSuccess, { | ||
claimedAmount, | ||
totalAmount, | ||
}) | ||
}, | ||
onError: (error) => { | ||
handleCaptureWithCause(error, PostHogEvent.PointsClaimFailure) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters