Skip to content

Commit 3c0dc2e

Browse files
committed
refactor(web): extract IPFS upload code
1 parent e92eaa0 commit 3c0dc2e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

web/src/utils/uploadFormDataToIPFS.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { toast, ToastContentProps } from "react-toastify";
2+
import { OPTIONS } from "utils/wrapWithToast";
3+
import { FetchError } from "node-fetch";
4+
5+
interface renderError extends ToastContentProps {
6+
data: FetchError;
7+
}
8+
9+
export function uploadFormDataToIPFS(formData: FormData) {
10+
return toast.promise(
11+
fetch("/.netlify/functions/uploadToIPFS", {
12+
method: "POST",
13+
body: formData,
14+
}),
15+
{
16+
pending: "Uploading evidence to IPFS...",
17+
success: "Uploaded to IPFS!",
18+
error: {
19+
render({ data }: renderError) {
20+
return `Upload failed ${data.message}`;
21+
},
22+
},
23+
},
24+
OPTIONS
25+
);
26+
}

web/src/utils/wrapWithToast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { toast, ToastPosition, Theme } from "react-toastify";
22
import { ContractTransaction } from "ethers";
33

4-
const OPTIONS = {
4+
export const OPTIONS = {
55
position: "top-center" as ToastPosition,
66
autoClose: 5000,
77
hideProgressBar: false,

0 commit comments

Comments
 (0)