Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion apps/faucet/src/services/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransactionManager, TransactionStatus } from "@happy.tech/txm"
import type { Address } from "@happy.tech/common"
import { TransactionManager } from "@happy.tech/txm"
import { type Result, err, ok } from "neverthrow"
import { env } from "../env"
import { FaucetRateLimitError } from "../errors"
Expand Down Expand Up @@ -44,6 +44,16 @@ export class FaucetService {

await this.txm.sendTransactions([tx])

const result = await tx.waitForFinalization(10_000)

if (result.isErr()) {
return err(result.error)
}

if (result.value.status !== TransactionStatus.Success) {
return err(new Error("Transaction failed"))
}

return ok(undefined)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useQueryClient } from "@tanstack/react-query"
import { useAtomValue } from "jotai"
import { useCallback, useRef, useState } from "react"
import { getBalanceQueryKey } from "wagmi/query"
import { Button } from "#src/components/primitives/button/Button"
import { useTurnstile } from "#src/hooks/useTurnstile"
import { userAtom } from "#src/state/user"
Expand All @@ -10,6 +12,7 @@ const FAUCET_ENDPOINT = import.meta.env.VITE_FAUCET_ENDPOINT!

const FaucetView = () => {
const user = useAtomValue(userAtom)
const queryClient = useQueryClient()
const [status, setStatus] = useState<"idle" | "loading" | "success" | "error">("idle")
const [message, setMessage] = useState("")
const turnstileRef = useRef<HTMLDivElement | null>(null)
Expand Down Expand Up @@ -37,6 +40,10 @@ const FaucetView = () => {
if (!res.ok) throw new Error(data?.message || "Unknown error")
setStatus("success")
setMessage(data?.message || "Tokens sent!")

queryClient.invalidateQueries({
queryKey: getBalanceQueryKey({ address: user.address }),
})
} catch (err: unknown) {
if (err instanceof Error) {
setStatus("error")
Expand All @@ -47,7 +54,7 @@ const FaucetView = () => {
}
}
},
[getToken, user, turnstileLoading],
[getToken, user, turnstileLoading, queryClient],
)

if (!user) return <UserNotFoundWarning />
Expand Down
Loading