From f3db72c677fb2ce6a7815415f88b7348eb7fd68f Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Wed, 5 Apr 2023 14:54:34 +0300 Subject: [PATCH 1/3] Validate splits contract address on Collection Creation > Royalty Details --- pages/collections/create.tsx | 56 +++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/pages/collections/create.tsx b/pages/collections/create.tsx index 5e32151..7d5433a 100644 --- a/pages/collections/create.tsx +++ b/pages/collections/create.tsx @@ -5,6 +5,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ +import { toUtf8 } from '@cosmjs/encoding' import { coin } from '@cosmjs/proto-signing' import clsx from 'clsx' import { Alert } from 'components/Alert' @@ -113,16 +114,22 @@ const CollectionCreationPage: NextPage = () => { checkUploadDetails() checkCollectionDetails() checkMintingDetails() - checkRoyaltyDetails() - checkWhitelistDetails() + void checkRoyaltyDetails() .then(() => { - checkwalletBalance() - setReadyToCreateVm(true) + checkWhitelistDetails() + .then(() => { + checkwalletBalance() + setReadyToCreateVm(true) + }) + .catch((err) => { + if (String(err.message).includes('Insufficient wallet balance')) + toast.error(`${err.message}`, { style: { maxWidth: 'none' } }) + else toast.error(`Error in Whitelist Configuration: ${err.message}`, { style: { maxWidth: 'none' } }) + setReadyToCreateVm(false) + }) }) .catch((err) => { - if (String(err.message).includes('Insufficient wallet balance')) - toast.error(`${err.message}`, { style: { maxWidth: 'none' } }) - else toast.error(`Error in Whitelist Configuration: ${err.message}`, { style: { maxWidth: 'none' } }) + toast.error(`Error in Royalty Details: ${err.message}`, { style: { maxWidth: 'none' } }) setReadyToCreateVm(false) }) } catch (error: any) { @@ -136,15 +143,21 @@ const CollectionCreationPage: NextPage = () => { try { setReadyToCreateBm(false) checkUploadDetails() - checkRoyaltyDetails() checkCollectionDetails() - checkWhitelistDetails() + void checkRoyaltyDetails() .then(() => { - checkwalletBalance() - setReadyToCreateBm(true) + checkWhitelistDetails() + .then(() => { + checkwalletBalance() + setReadyToCreateBm(true) + }) + .catch((err) => { + toast.error(`${err.message}`, { style: { maxWidth: 'none' } }) + setReadyToCreateBm(false) + }) }) .catch((err) => { - toast.error(`${err.message}`, { style: { maxWidth: 'none' } }) + toast.error(`Error in Royalty Configuration: ${err.message}`, { style: { maxWidth: 'none' } }) setReadyToCreateBm(false) }) } catch (error: any) { @@ -868,7 +881,7 @@ const CollectionCreationPage: NextPage = () => { } } - const checkRoyaltyDetails = () => { + const checkRoyaltyDetails = async () => { if (!royaltyDetails) throw new Error('Please fill out the royalty details') if (royaltyDetails.royaltyType === 'new') { if (royaltyDetails.share === 0) throw new Error('Royalty share percentage is required') @@ -880,6 +893,23 @@ const CollectionCreationPage: NextPage = () => { } throw new Error('Invalid royalty payment address') } + const contractInfoResponse = await wallet.client + ?.queryContractRaw( + royaltyDetails.paymentAddress, + toUtf8(Buffer.from(Buffer.from('contract_info').toString('hex'), 'hex').toString()), + ) + .catch((e) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + if (e.message.includes('bech32')) throw new Error('Invalid royalty payment address.') + console.log(e.message) + }) + if (contractInfoResponse !== undefined) { + const contractInfo = JSON.parse(new TextDecoder().decode(contractInfoResponse as Uint8Array)) + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + if (contractInfo && !contractInfo.contract.includes('splits')) + throw new Error('The provided royalty payment address does not belong to a splits contract.') + else console.log(contractInfo) + } } } From fe3875579779907de758563d66ae0edec4dd0243 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Wed, 5 Apr 2023 16:46:18 +0300 Subject: [PATCH 2/3] Validate splits contract address on Collection Actions > Update Collection Info --- components/collections/actions/Action.tsx | 25 +++++++++++++++++++++++ pages/collections/create.tsx | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/components/collections/actions/Action.tsx b/components/collections/actions/Action.tsx index 9cdfad6..40f6dee 100644 --- a/components/collections/actions/Action.tsx +++ b/components/collections/actions/Action.tsx @@ -1,3 +1,4 @@ +import { toUtf8 } from '@cosmjs/encoding' import { AirdropUpload } from 'components/AirdropUpload' import { Button } from 'components/Button' import type { DispatchExecuteArgs } from 'components/collections/actions/actions' @@ -347,6 +348,30 @@ export const CollectionActions = ({ throw new Error('Royalty payment address and share percentage are both required') } + if ( + type === 'update_collection_info' && + royaltyPaymentAddressState.value && + !royaltyPaymentAddressState.value.trim().endsWith('.stars') + ) { + const contractInfoResponse = await wallet.client + ?.queryContractRaw( + royaltyPaymentAddressState.value.trim(), + toUtf8(Buffer.from(Buffer.from('contract_info').toString('hex'), 'hex').toString()), + ) + .catch((e) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + if (e.message.includes('bech32')) throw new Error('Invalid royalty payment address.') + console.log(e.message) + }) + if (contractInfoResponse !== undefined) { + const contractInfo = JSON.parse(new TextDecoder().decode(contractInfoResponse as Uint8Array)) + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + if (contractInfo && !contractInfo.contract.includes('splits')) + throw new Error('The provided royalty payment address does not belong to a splits contract.') + else console.log(contractInfo) + } + } + const txHash = await toast.promise(dispatchExecute(payload), { error: `${type.charAt(0).toUpperCase() + type.slice(1)} execute failed!`, loading: 'Executing message...', diff --git a/pages/collections/create.tsx b/pages/collections/create.tsx index 7d5433a..17e4db7 100644 --- a/pages/collections/create.tsx +++ b/pages/collections/create.tsx @@ -427,7 +427,7 @@ const CollectionCreationPage: NextPage = () => { let royaltyInfo = null if (royaltyDetails?.royaltyType === 'new') { royaltyInfo = { - payment_address: royaltyDetails.paymentAddress, + payment_address: royaltyDetails.paymentAddress.trim(), share: (Number(royaltyDetails.share) / 100).toString(), } } @@ -496,7 +496,7 @@ const CollectionCreationPage: NextPage = () => { let royaltyInfo = null if (royaltyDetails?.royaltyType === 'new') { royaltyInfo = { - payment_address: royaltyDetails.paymentAddress, + payment_address: royaltyDetails.paymentAddress.trim(), share: (Number(royaltyDetails.share) / 100).toString(), } } @@ -887,7 +887,7 @@ const CollectionCreationPage: NextPage = () => { if (royaltyDetails.share === 0) throw new Error('Royalty share percentage is required') if (royaltyDetails.share > 100 || royaltyDetails.share < 0) throw new Error('Invalid royalty share percentage') if (royaltyDetails.paymentAddress === '') throw new Error('Royalty payment address is required') - if (!isValidAddress(royaltyDetails.paymentAddress)) { + if (!isValidAddress(royaltyDetails.paymentAddress.trim())) { if (royaltyDetails.paymentAddress.trim().endsWith('.stars')) { throw new Error('Royalty payment address could not be resolved') } @@ -895,7 +895,7 @@ const CollectionCreationPage: NextPage = () => { } const contractInfoResponse = await wallet.client ?.queryContractRaw( - royaltyDetails.paymentAddress, + royaltyDetails.paymentAddress.trim(), toUtf8(Buffer.from(Buffer.from('contract_info').toString('hex'), 'hex').toString()), ) .catch((e) => { From 5bf2d83c4cd35f6ad6e0c69618b4c8972728d734 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Wed, 5 Apr 2023 16:47:11 +0300 Subject: [PATCH 3/3] Bump Studio version --- .env.example | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 8188a34..2136b8d 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -APP_VERSION=0.5.6 +APP_VERSION=0.5.7 NEXT_PUBLIC_PINATA_ENDPOINT_URL=https://api.pinata.cloud/pinning/pinFileToIPFS NEXT_PUBLIC_SG721_CODE_ID=1911 diff --git a/package.json b/package.json index 33da66c..766941c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stargaze-studio", - "version": "0.5.6", + "version": "0.5.7", "workspaces": [ "packages/*" ],