Skip to content

Commit

Permalink
useArcadiansApi instead of usenft
Browse files Browse the repository at this point in the history
  • Loading branch information
polats committed May 25, 2023
1 parent 0ecd377 commit b343601
Show file tree
Hide file tree
Showing 8 changed files with 7,815 additions and 29,915 deletions.
2 changes: 1 addition & 1 deletion assets/nftCollections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default [
[
"0xc3c8a1e1ce5386258176400541922c414e1b35fd",
"0xf08378b8B21ccfA76b7D75B859B7d8D0B861433F",
"Arcadians",
"https://opensea.io/collection/arcadians-by-opgames",
],
Expand Down
2 changes: 1 addition & 1 deletion avatar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function findNodeInOra(part) {

export function loadNFT(nft) {

nft.rawData.attributes.map( (part) => {
nft.attributes.map( (part) => {
let partPath = findNodeInOra(part);
if (partPath) {
updateBabylonParts(part.trait_type, partPath);
Expand Down
16 changes: 9 additions & 7 deletions components/oraglbviewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import type { NftMetadata } from "use-nft"

import { useEffect, useRef, useState } from "react";
import { useNft } from "use-nft"
import { useArcadiansApi } from "../../hooks/useArcadiansApi";
import { Engine, Scene } from "@babylonjs/core";
import * as AvatarBuilder from "../../avatar/";



export const colors = {
background: "#111111",
accent: "#a669a2",
Expand Down Expand Up @@ -35,7 +38,7 @@ let loadedNft:NftMetadata;
tokenId
} : OraGlbViewerProps )
{
const { nft, loading, error, reload } = useNft(contract, tokenId)
const { data, isLoading, error } = useArcadiansApi(tokenId)
const reactCanvasBabylon = useRef(null);
const [ canvasSize, setCanvasSize ] = useState(
{
Expand Down Expand Up @@ -167,18 +170,17 @@ let loadedNft:NftMetadata;
<>
<canvas height={canvasSize.height} width={canvasSize.width} ref={reactCanvasBabylon} />
{(() => {
if (loading) {
if (isLoading) {
return <NftLoading />
}
if (error) {
return <NftError error={error} reload={reload} />
return <NftError error={error} />
}

loadedNft = nft;
loadedNft = data;

return (
<>
<AnimatedNFT nft={nft} />
</>
)

Expand All @@ -197,13 +199,13 @@ function NftLoading() {
)
}

function NftError({ error, reload }: { error: Error; reload: () => void }) {
function NftError({ error }: { error: Error }) {
return (
<div
>
<p>
Loading error.
<br /> <button onClick={reload}>Retry?</button>
<br />
</p>
</div>
)
Expand Down
34 changes: 34 additions & 0 deletions hooks/useArcadiansApi/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import useSWR from "swr";

const ARCADIANS_API = "https://arcadians.dev.outplay.games/v2/arcadians/"

const fetchTokenMetadata = async(uri) : Promise<any> => {

const uriWithId = `${ARCADIANS_API}${uri}?refreshMetadata=true`;

const response = await fetch(uriWithId);
const data = await response.json();
return data;
};

export const useArcadiansApi = (uri) => {
const { data, error, mutate, isLoading } = useSWR(
uri,
fetchTokenMetadata
);

return {
data,
error,
isLoading,
mutate,
contracts: data || [],
isError: !!error,
};




};


1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-dom": "18.2.0",
"react-spring": "^9.4.4",
"sharp": "^0.32.0",
"swr": "^2.1.5",
"use-nft": "^0.12.0",
"xml2js": "^0.5.0"
},
Expand Down
Loading

1 comment on commit b343601

@vercel
Copy link

@vercel vercel bot commented on b343601 May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.