Skip to content

Commit

Permalink
fix: enhance collection form onInvalid, add ipfs hash to BaseFile typ…
Browse files Browse the repository at this point in the history
…e, remove console.log
  • Loading branch information
WaDadidou committed Jul 9, 2024
1 parent d9c75ca commit 01857aa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
13 changes: 0 additions & 13 deletions packages/hooks/useIpfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export const useIpfs = () => {
"Content-Type": "multipart/form-data",
},
});
console.log("responseFile.data.IpfsHash", responseFile.data.IpfsHash);

return {
ipfsCid: CID.parse(responseFile.data.IpfsHash).toV1().toString(),
ipfsHash: responseFile.data.IpfsHash,
Expand All @@ -102,31 +100,20 @@ export const useIpfs = () => {
pinataJWTKey,
});

console.log("############## pinFileToIPFSResult", pinFileToIPFSResult);
console.log("############## file", file);

const url = !pinFileToIPFSResult?.ipfsCid
? ""
: "ipfs://" + pinFileToIPFSResult.ipfsCid;
console.log("############## url", url);

if (file.thumbnailFileData) {
const pinThumbnailToIPFSResult = await pinataPinFileToIPFS({
file: file.thumbnailFileData,
pinataJWTKey,
});

console.log(
"############## pinThumbnailToIPFSResult",
pinThumbnailToIPFSResult,
);

const thumbnailUrl = !pinThumbnailToIPFSResult?.ipfsCid
? ""
: "ipfs://" + pinThumbnailToIPFSResult.ipfsCid;

// console.log('############## thumbnailUrl', thumbnailUrl)

return {
...omit(file, "file"),
url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
import React, { useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { FieldErrors, FormProvider, useForm } from "react-hook-form";
import { View } from "react-native";

import { BrandText } from "@/components/BrandText";
Expand All @@ -21,13 +21,15 @@ import { fontSemibold14, fontSemibold28 } from "@/utils/style/fonts";
import { layout } from "@/utils/style/layout";
import {
CollectionAssetsMetadatasFormValues,
CollectionFormValues,
ZodCollectionAssetsMetadatasFormValues,
} from "@/utils/types/launchpad";

export const LaunchpadCompleteScreen: ScreenFC<"LaunchpadComplete"> = ({
route,
}) => {
const isMobile = useIsMobile();
const { setToast } = useFeedbacks();
const { id: collectionId } = route.params;
const navigation = useAppNavigation();
const selectedWallet = useSelectedWallet();
Expand All @@ -36,11 +38,12 @@ export const LaunchpadCompleteScreen: ScreenFC<"LaunchpadComplete"> = ({
const assetsMetadatasForm = useForm<CollectionAssetsMetadatasFormValues>({
mode: "all",
resolver: zodResolver(ZodCollectionAssetsMetadatasFormValues),
defaultValues: { assetsMetadatas: [] },
});
const [isLoading, setLoading] = useState(false);
const { setLoadingFullScreen } = useFeedbacks();

const onPressComplete = async () => {
const onValid = async () => {
setLoading(true);
setLoadingFullScreen(true);
try {
Expand All @@ -64,6 +67,20 @@ export const LaunchpadCompleteScreen: ScreenFC<"LaunchpadComplete"> = ({
}, 1000);
};

const onInvalid = (fieldsErrors: FieldErrors<CollectionFormValues>) => {
console.error("Fields errors: ", fieldsErrors);
setToast({
mode: "normal",
type: "error",
title: "Unable to complete the collection",
message:
"Some fields are not correctly filled.\nPlease complete properly the mapping file.\nCheck the description for more information.",
});
};

const onPressComplete = () =>
assetsMetadatasForm.handleSubmit(onValid, onInvalid)();

return (
<ScreenContainer
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,20 @@ export const LaunchpadCreateScreen: ScreenFC<"LaunchpadCreate"> = () => {
}, 1000);
};

const onInvalid = () => {
setToast({
mode: "normal",
type: "error",
title: "Unable to create the collection",
message: "Some fields are not correctly filled",
});
};
const onInvalid = () =>
// fieldsErrors: FieldErrors<CollectionFormValues>
{
// FIXME: Show which step is concerned
// console.error('Fields errors: ', fieldsErrors)
setToast({
mode: "normal",
type: "error",
title: "Unable to create the collection",
message:
"Some fields are not correctly filled." +
"\nMaybe from the mapping file, please complete it properly.\nCheck the description for more information.",
});
};

const onPressSubmit = () => collectionForm.handleSubmit(onValid, onInvalid)();

Expand Down
1 change: 1 addition & 0 deletions packages/utils/types/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const ZodBaseFileData = z.object({
isCoverImage: z.boolean().optional(),
isThumbnailImage: z.boolean().optional(),
base64Image: z.string().optional(),
hash: z.string().optional(),
});

export const ZodLocalFileData = z
Expand Down

0 comments on commit 01857aa

Please sign in to comment.