Skip to content

Commit

Permalink
use hash to transfer inputBytes accross pages
Browse files Browse the repository at this point in the history
  • Loading branch information
maerzhase committed Jul 19, 2023
1 parent 856bce8 commit f647c42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const _GenerativeDisplayIteration = ({
const isParamsToken = !!objkt.inputBytes
const exploreParamsQuery = useMemo(() => {
if (!isParamsToken) return null
return `fxhash=${objkt.generationHash}&fxparams=${objkt.inputBytes}`
return `fxhash=${objkt.generationHash}#0x${objkt.inputBytes}`
}, [objkt, isParamsToken])
const minter = objkt.minter
const isProjectRedeemable = objkt.issuer.redeemables?.length > 0
Expand Down
4 changes: 3 additions & 1 deletion src/containers/MintWithTicket/MintWithTicketPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export function MintWithTicketPageRoot({ token, ticketId, mode }: Props) {
minter: minterAddress,
context: fxcontext,
iteration: getRandomIteration(token.supply, token.balance),
inputBytes: router.query.fxparams as string | undefined,
inputBytes: global?.window?.location?.hash?.replace("#0x", "") as
| string
| undefined,
snippetVersion: token.metadata.snippetVersion,
},
{
Expand Down
14 changes: 10 additions & 4 deletions src/hooks/useRuntimeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ const iframeHandler: TRuntimeContextConnector = (iframeRef) => {
useSync(runtimeUrl: string, controlsUrl: string) {
// every time the runtime URL changes, refresh the iframe
useEffect(() => {
console.log(runtimeUrl)
const iframe = iframeRef.current?.getHtmlIframe()
if (iframe && lastUrl !== runtimeUrl) {
iframe.contentWindow?.location.replace(runtimeUrl)
Expand Down Expand Up @@ -290,13 +289,20 @@ export const useRuntimeController: TUseRuntimeController = (
})
}, [runtime.details.definitionHash.params])

const updateQueryParams = (query: { fxhash: string; fxparams: string }) =>
const updateQueryParams = ({
fxhash,
fxparams,
}: {
fxhash: string
fxparams: string
}) =>
router.replace(
{
query: {
...router.query,
...query,
fxhash,
},
hash: `0x${fxparams}`,
},
undefined,
{ shallow: true }
Expand All @@ -306,7 +312,7 @@ export const useRuntimeController: TUseRuntimeController = (
useEffect(() => {
updateQueryParams({
fxhash: runtime.state.hash,
fxparams: runtime.details.params.inputBytes || "",
fxparams: runtime.details.params.inputBytes || project.inputBytes || "",
})
}, [runtime.state.hash, runtime.details.params.inputBytes])

Expand Down

0 comments on commit f647c42

Please sign in to comment.