Skip to content

Commit

Permalink
add toast for fund
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Feb 25, 2024
1 parent 3fd32d3 commit 0ac6ea1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion trade.renegade.fi/app/api/fund/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function GET(request: Request) {
})
if (balance >= ethAmount) {
return new Response("Already funded", {
status: 200,
status: 208,
})
}

Expand Down
11 changes: 1 addition & 10 deletions trade.renegade.fi/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,7 @@ export function Providers({
<RenegadeProvider>
<ExchangeProvider>
<AppProvider tokenIcons={icons}>
<Toaster
position="bottom-center"
toastOptions={{
style: {
background: "black",
borderColor: "#262626",
color: "inherit",
},
}}
/>
<Toaster position="bottom-center" />
{children}
</AppProvider>
</ExchangeProvider>
Expand Down
17 changes: 17 additions & 0 deletions trade.renegade.fi/contexts/Renegade/renegade-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
OrderId,
TaskId,
} from "@renegade-fi/renegade-js"
import { toast } from "sonner"
import { useLocalStorage } from "usehooks-ts"
import { useAccount } from "wagmi"

Expand Down Expand Up @@ -161,6 +162,22 @@ function RenegadeProvider({ children }: React.PropsWithChildren) {
refreshAccount(accountId)
fetch(`/api/fund?address=${address}`, {
method: "GET",
}).then((response) => {
if (response.status === 208) {
return
} else if (response.ok) {
return response.text().then(() => {
toast.success("Your account has been funded with test funds.", {
description: "Try depositing some funds to start trading.",
duration: 10000,
})
return
})
} else {
toast.error(
"Funding failed: An unexpected error occurred. Please try again."
)
}
})
})
}
Expand Down

0 comments on commit 0ac6ea1

Please sign in to comment.