Display badge creation info

This commit is contained in:
Serkan Reis 2023-02-13 17:58:28 +03:00
parent 4b1b64b656
commit e83df5ee67
4 changed files with 102 additions and 50 deletions

View File

@ -124,7 +124,7 @@ export const BadgeDetails = ({ onChange }: BadgeDetailsProps) => {
})) }))
.filter((attr) => attr.trait_type && attr.value) .filter((attr) => attr.trait_type && attr.value)
: undefined, : undefined,
expiry: timestamp ? timestamp.getTime() * 1000000 : undefined, expiry: timestamp ? timestamp.getTime() / 1000 : undefined,
max_supply: maxSupplyState.value || undefined, max_supply: maxSupplyState.value || undefined,
transferrable, transferrable,
image_data: imageDataState.value || undefined, image_data: imageDataState.value || undefined,

View File

@ -176,8 +176,8 @@ export const ImageUploadDetails = ({ onChange, mintRule }: ImageUploadDetailsPro
<Conditional test={uploadMethod === 'existing'}> <Conditional test={uploadMethod === 'existing'}>
<div className="ml-3 flex-column"> <div className="ml-3 flex-column">
<p className="mb-5 ml-5"> <p className="mb-5 ml-5">
Though the Badge Hub contract allows for off-chain metadata storage, it is recommended to use a Though the Badge Hub contract allows for off-chain image storage, it is recommended to use a decentralized
decentralized storage solution, such as IPFS. <br /> You may head over to{' '} storage solution, such as IPFS. <br /> You may head over to{' '}
<Anchor className="font-bold text-plumbus hover:underline" href="https://nft.storage"> <Anchor className="font-bold text-plumbus hover:underline" href="https://nft.storage">
NFT.Storage NFT.Storage
</Anchor>{' '} </Anchor>{' '}
@ -185,7 +185,7 @@ export const ImageUploadDetails = ({ onChange, mintRule }: ImageUploadDetailsPro
<Anchor className="font-bold text-plumbus hover:underline" href="https://www.pinata.cloud/"> <Anchor className="font-bold text-plumbus hover:underline" href="https://www.pinata.cloud/">
Pinata Pinata
</Anchor>{' '} </Anchor>{' '}
and upload your asset manually to get an image URL for your badge. and upload your image manually to get an image URL for your badge.
</p> </p>
<div> <div>
<TextInput {...imageUrlState} className="mt-2 ml-4 w-1/2" /> <TextInput {...imageUrlState} className="mt-2 ml-4 w-1/2" />

View File

@ -19,11 +19,13 @@ import { useWallet } from 'contexts/wallet'
import type { DispatchExecuteArgs as BadgeHubDispatchExecuteArgs } from 'contracts/badgeHub/messages/execute' import type { DispatchExecuteArgs as BadgeHubDispatchExecuteArgs } from 'contracts/badgeHub/messages/execute'
import { dispatchExecute as badgeHubDispatchExecute } from 'contracts/badgeHub/messages/execute' import { dispatchExecute as badgeHubDispatchExecute } from 'contracts/badgeHub/messages/execute'
import * as crypto from 'crypto' import * as crypto from 'crypto'
import { toPng } from 'html-to-image'
import type { NextPage } from 'next' import type { NextPage } from 'next'
import { NextSeo } from 'next-seo' import { NextSeo } from 'next-seo'
import { QRCodeSVG } from 'qrcode.react' import { QRCodeSVG } from 'qrcode.react'
import { useEffect, useMemo, useRef, useState } from 'react' import { useEffect, useMemo, useRef, useState } from 'react'
import { toast } from 'react-hot-toast' import { toast } from 'react-hot-toast'
import { FaCopy, FaSave } from 'react-icons/fa'
import * as secp256k1 from 'secp256k1' import * as secp256k1 from 'secp256k1'
import { upload } from 'services/upload' import { upload } from 'services/upload'
import { BADGE_HUB_ADDRESS, BLOCK_EXPLORER_URL, NETWORK } from 'utils/constants' import { BADGE_HUB_ADDRESS, BLOCK_EXPLORER_URL, NETWORK } from 'utils/constants'
@ -45,7 +47,6 @@ const BadgeCreationPage: NextPage = () => {
const [imageUploadDetails, setImageUploadDetails] = useState<ImageUploadDetailsDataProps | null>(null) const [imageUploadDetails, setImageUploadDetails] = useState<ImageUploadDetailsDataProps | null>(null)
const [badgeDetails, setBadgeDetails] = useState<BadgeDetailsDataProps | null>(null) const [badgeDetails, setBadgeDetails] = useState<BadgeDetailsDataProps | null>(null)
// const [baseMinterDetails, setBaseMinterDetails] = useState<BaseMinterDetailsDataProps | null>(null)
const [uploading, setUploading] = useState(false) const [uploading, setUploading] = useState(false)
const [creatingBadge, setCreatingBadge] = useState(false) const [creatingBadge, setCreatingBadge] = useState(false)
@ -56,6 +57,7 @@ const BadgeCreationPage: NextPage = () => {
const [imageUrl, setImageUrl] = useState<string | null>(null) const [imageUrl, setImageUrl] = useState<string | null>(null)
const [createdBadgeKey, setCreatedBadgeKey] = useState<string | undefined>(undefined) const [createdBadgeKey, setCreatedBadgeKey] = useState<string | undefined>(undefined)
const [transactionHash, setTransactionHash] = useState<string | null>(null) const [transactionHash, setTransactionHash] = useState<string | null>(null)
const qrRef = useRef<HTMLDivElement>(null)
const keyState = useInputState({ const keyState = useInputState({
id: 'key', id: 'key',
@ -145,6 +147,7 @@ const BadgeCreationPage: NextPage = () => {
} }
const data = await badgeHubDispatchExecute(payload) const data = await badgeHubDispatchExecute(payload)
console.log(data) console.log(data)
setCreatingBadge(false)
setTransactionHash(data.split(':')[0]) setTransactionHash(data.split(':')[0])
setBadgeId(data.split(':')[1]) setBadgeId(data.split(':')[1])
} catch (error: any) { } catch (error: any) {
@ -219,6 +222,24 @@ const BadgeCreationPage: NextPage = () => {
keyState.onChange(publicKey) keyState.onChange(publicKey)
} }
const handleDownloadQr = async () => {
const qrElement = qrRef.current
await toPng(qrElement as HTMLElement).then((dataUrl) => {
const link = document.createElement('a')
link.download = `badge-${badgeId as string}.png`
link.href = dataUrl
link.click()
})
}
// copy claim url to clipboard
const copyClaimURL = async () => {
const baseURL = NETWORK === 'testnet' ? 'https://badges.publicawesome.dev' : 'https://badges.stargaze.zone'
const claimURL = `${baseURL}/?id=${badgeId as string}&key=${createdBadgeKey as string}`
await navigator.clipboard.writeText(claimURL)
toast.success('Copied claim URL to clipboard')
}
const checkwalletBalance = () => { const checkwalletBalance = () => {
if (!wallet.initialized) throw new Error('Wallet not connected.') if (!wallet.initialized) throw new Error('Wallet not connected.')
// TODO: estimate creation cost and check wallet balance // TODO: estimate creation cost and check wallet balance
@ -258,49 +279,81 @@ const BadgeCreationPage: NextPage = () => {
<div className="mx-10" ref={scrollRef}> <div className="mx-10" ref={scrollRef}>
<Conditional test={badgeId !== null}> <Conditional test={badgeId !== null}>
<Alert className="mt-5" type="info"> <Alert className="mt-5" type="info">
<QRCodeSVG <div className="flex flex-row">
className="mx-auto" <div>
level="H" <div className="w-[384px] h-[384px]" ref={qrRef}>
size={256} <QRCodeSVG
value={`${ className="mx-auto"
NETWORK === 'testnet' ? 'https://badges.publicawesome.dev' : 'https://badges.stargaze.zone' level="H"
}/?id=${badgeId as string}&key=${createdBadgeKey as string}`} size={384}
/> value={`${
<br /> NETWORK === 'testnet' ? 'https://badges.publicawesome.dev' : 'https://badges.stargaze.zone'
<div> }/?id=${badgeId as string}&key=${createdBadgeKey as string}`}
Badge ID:{` ${badgeId as string}`} />
<br /> </div>
Transaction Hash: {' '} <div className="grid grid-cols-2 gap-2 mt-2 w-[384px]">
<Conditional test={NETWORK === 'testnet'}> <Button
<Anchor className="items-center w-full text-sm text-center rounded"
className="text-stargaze hover:underline" leftIcon={<FaSave />}
external onClick={() => void handleDownloadQr()}
href={`${BLOCK_EXPLORER_URL}/tx/${transactionHash as string}`} >
> Download QR Code
{transactionHash} </Button>
</Anchor> <Button
</Conditional> className="w-full text-sm text-center rounded"
<Conditional test={NETWORK === 'mainnet'}> isWide
<Anchor leftIcon={<FaCopy />}
className="text-stargaze hover:underline" onClick={() => void copyClaimURL()}
external variant="solid"
href={`${BLOCK_EXPLORER_URL}/txs/${transactionHash as string}`} >
> Copy Claim URL
{transactionHash} </Button>
</Anchor> </div>
</Conditional> </div>
<br /> <div className="ml-4 text-lg">
<Button> Badge ID:{` ${badgeId as string}`}
<Anchor <br />
className="text-white" Transaction Hash: {' '}
external <Conditional test={NETWORK === 'testnet'}>
href={`${ <Anchor
NETWORK === 'testnet' ? 'https://badges.publicawesome.dev' : 'https://badges.stargaze.zone' className="text-stargaze hover:underline"
}/?id=${badgeId as string}&key=${createdBadgeKey as string}`} external
> href={`${BLOCK_EXPLORER_URL}/tx/${transactionHash as string}`}
Claim Badge >
</Anchor> {transactionHash}
</Button> </Anchor>
</Conditional>
<Conditional test={NETWORK === 'mainnet'}>
<Anchor
className="text-stargaze hover:underline"
external
href={`${BLOCK_EXPLORER_URL}/txs/${transactionHash as string}`}
>
{transactionHash}
</Anchor>
</Conditional>
<br />
<div className="text-base">
<div className="flex-row pt-4 mt-4 border-t-2">
<span>
You may click{' '}
<Anchor
className="text-stargaze hover:underline"
external
href={`${
NETWORK === 'testnet' ? 'https://badges.publicawesome.dev' : 'https://badges.stargaze.zone'
}/?id=${badgeId as string}&key=${createdBadgeKey as string}`}
>
here
</Anchor>{' '}
or scan the QR code to claim a badge.
</span>
</div>
<br />
<span className="mt-4">You may download the QR code or copy the claim URL to share with others.</span>
</div>
<br />
</div>
</div> </div>
</Alert> </Alert>
</Conditional> </Conditional>
@ -409,7 +462,7 @@ const BadgeCreationPage: NextPage = () => {
<div className="flex justify-end w-full"> <div className="flex justify-end w-full">
<Button <Button
className="relative justify-center p-2 mt-4 mb-6 max-h-12 text-white bg-plumbus hover:bg-plumbus-light border-0" className="relative justify-center p-2 mt-2 mb-6 max-h-12 text-white bg-plumbus hover:bg-plumbus-light border-0"
isLoading={creatingBadge} isLoading={creatingBadge}
onClick={() => createNewBadge()} onClick={() => createNewBadge()}
variant="solid" variant="solid"

View File

@ -308,7 +308,6 @@ const BadgeHubExecutePage: NextPage = () => {
}) })
} }
// copy claim url to clipboard
const copyClaimURL = async () => { const copyClaimURL = async () => {
const baseURL = NETWORK === 'testnet' ? 'https://badges.publicawesome.dev' : 'https://badges.stargaze.zone' const baseURL = NETWORK === 'testnet' ? 'https://badges.publicawesome.dev' : 'https://badges.stargaze.zone'
const claimURL = `${baseURL}/?id=${createdBadgeId as string}&key=${createdBadgeKey as string}` const claimURL = `${baseURL}/?id=${createdBadgeId as string}&key=${createdBadgeKey as string}`