Skip to content

Commit

Permalink
[all] add ipfsfetch
Browse files Browse the repository at this point in the history
  • Loading branch information
XueMoMo committed Oct 18, 2024
1 parent 4bc3794 commit 4705d21
Show file tree
Hide file tree
Showing 5 changed files with 2,321 additions and 3,393 deletions.
21 changes: 21 additions & 0 deletions components/common/IpfsImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createVerifiedFetch, VerifiedFetch } from "@helia/verified-fetch";
import { GatewayBase } from "@lib/config";
import { CSSProperties } from "react";
import { useAsyncRetry } from "react-use";

let verifiedFetch: VerifiedFetch;

export function IpfsImage(p: { className?: string; style?: CSSProperties; cid: string }) {
const res = useAsyncRetry(async () => {
if (!verifiedFetch) verifiedFetch = await createVerifiedFetch({ gateways: [GatewayBase, "https://gw.crust-gateway.com", "https://gw.crust-gateway.xyz"] });
const response = await verifiedFetch(p.cid.startsWith("ipfs://") ? p.cid : `ipfs://${p.cid}`, {});
const blob = await response.blob();
return URL.createObjectURL(blob);
}, [p.cid]);
return (
<div className={p.className} style={p.style}>
{Boolean(res.value) && <img className={p.className} style={p.style} src={res.value} />}
{res.loading && <div className={`${p.className} bg-slate-500 animate-pulse`} style={p.style} />}
</div>
);
}
4 changes: 3 additions & 1 deletion components/pages/main/Buckets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useAccount } from "wagmi";
import { MainLayout } from "./MainLayout";
import classnames from "classnames";
import algoWallet from "@lib/algorand/algoWallet";
import { IpfsImage } from "@components/common/IpfsImage";

const BucketCard = React.memo((p: { data: BucketDTO; className?: string }) => {
const { data, className } = p;
Expand All @@ -31,7 +32,8 @@ const BucketCard = React.memo((p: { data: BucketDTO; className?: string }) => {
};
return (
<div className={classnames("h-min p-5 md:p-2 border border-solid border-black-1", className)}>
<img className="w-full aspect-[360/531] object-contain" src={ipfsUrl(data.metadata.image.replace("ipfs://", ""))} />
{/* <img className="w-full aspect-[360/531] object-contain" src={ipfsUrl(data.metadata.image.replace("ipfs://", ""))} /> */}
<IpfsImage className="w-full aspect-[360/531] object-contain" cid={data.metadata.image}/>
<div className=" text-lg font-semibold mt-[0.625rem] truncate">{`W3BUCKET(${bucketId})`}</div>
<div className="flex text-sm my-[2px] justify-between">
<div>Current Usage</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/useW3BucketAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ export function useW3BucketAbi() {
"setBucketEditionPrices"
),
};
}, [pc, pc.chain?.id, writeContractAsync]);
}, [pc, pc?.chain?.id, writeContractAsync]);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@decooio/crust-fonts": "1.1.0",
"@emotion/react": "11.10.5",
"@emotion/styled": "11.10.5",
"@helia/verified-fetch": "^2.0.0",
"@metamask/detect-provider": "1.2.0",
"@next/font": "13.0.6",
"@perawallet/connect": "1.3.4",
Expand Down
Loading

0 comments on commit 4705d21

Please sign in to comment.