-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix multirender api route, add decoding, update Token type * remove multirender comment * remove comment * update local render, pages/index * update local rendering to match multirender * update * add error handling back to api routes
- Loading branch information
Showing
12 changed files
with
101 additions
and
88 deletions.
There are no files selected for viewing
Submodule forge-std
updated
from 982560 to 27e14b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
import { useState, useEffect } from "react"; | ||
import { NFTStatus, trait } from "../types"; | ||
import { FetchStatus, Token } from "../types"; | ||
import { decodeTokenURI } from "../util"; | ||
|
||
// returns the entire tokenURI | ||
const RENDER_ENDPOINT = "/api/render"; | ||
|
||
const defaultState = { | ||
name: "", | ||
image: "", | ||
attributes: [], | ||
|
||
tokenId: null, | ||
svg: null, | ||
}; | ||
|
||
export const useLocalRender = () => { | ||
const [tokenURI, setTokenURI] = useState<string>(null); | ||
const [status, setStatus] = useState<NFTStatus>(NFTStatus.UNFETCHED); | ||
const [token, setToken] = useState<Token>(defaultState); | ||
const [status, setStatus] = useState<FetchStatus>(FetchStatus.UNFETCHED); | ||
|
||
const handleFetchNFT = async () => { | ||
if (status == NFTStatus.FETCHING) return; | ||
const handleLocalRender = async () => { | ||
if (status == FetchStatus.FETCHING) return; | ||
|
||
setStatus(NFTStatus.FETCHING); | ||
setStatus(FetchStatus.FETCHING); | ||
|
||
const response = await fetch(RENDER_ENDPOINT); | ||
|
||
// handle fetch error | ||
if (response.status != 200) { | ||
console.log("fetch error: ", response.status); | ||
return setStatus(NFTStatus.UNFETCHED); | ||
return setStatus(FetchStatus.UNFETCHED); | ||
} | ||
|
||
const tokenURI = await response.text(); | ||
console.log("tokenURI", tokenURI); | ||
setTokenURI(tokenURI); | ||
setStatus(NFTStatus.FETCHED); | ||
const tokenURI = await response.json(); | ||
|
||
setToken(decodeTokenURI(tokenURI)); | ||
setStatus(FetchStatus.FETCHED); | ||
}; | ||
|
||
useEffect(() => { | ||
handleFetchNFT(); | ||
handleLocalRender(); | ||
}, []); | ||
|
||
return { tokenURI, status, handleFetchNFT }; | ||
return { token, status, handleLocalRender }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
#!/usr/bin/env bash | ||
# Notice: run from root directory. | ||
|
||
DEPLOYMENTS_PATH=./deployment/deployments.json | ||
|
||
get_libraries() { | ||
LIBRARIES="" | ||
for NAME in "$@" | ||
do | ||
ADDRESS=$(jq -r '.'$NAME'' $DEPLOYMENTS_PATH) | ||
LIBRARIES="$LIBRARIES --libraries src/libraries/$NAME.sol:$NAME:$ADDRESS" | ||
done | ||
echo $LIBRARIES | ||
} | ||
|
||
extract_token_URI() { | ||
echo "$1" | grep "tokenURI: string" | cut -d " " -f 3 | tr -d '"' | ||
extract_json_output() { | ||
echo "$1" | grep "{" | ||
} | ||
|
||
LOCAL_RENDER_SCRIPT_PATH="src/scripts/local_render.sol" | ||
SCRIPT_OUTPUT="$(forge script $LOCAL_RENDER_SCRIPT_PATH:local_render)" | ||
# extract the bibos address return value from SCRIPT_OUTPUT | ||
TOKEN_URI="$(extract_token_URI "$SCRIPT_OUTPUT")" | ||
|
||
|
||
SCRIPT_OUTPUT="$(forge script local_render --json)" | ||
JSON_OUTPUT="$(extract_json_output "$SCRIPT_OUTPUT")" | ||
|
||
# return tokenURI | ||
echo "$TOKEN_URI" | ||
echo "$JSON_OUTPUT" | jq .returns.tokenURI.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters