Names support for Collection Actions > Recipient Address, Royalty Payment Address
This commit is contained in:
parent
c6ea1baf04
commit
f1a2c153e0
@ -22,6 +22,7 @@ import { toast } from 'react-hot-toast'
|
||||
import { FaArrowRight } from 'react-icons/fa'
|
||||
import { useMutation } from 'react-query'
|
||||
import type { AirdropAllocation } from 'utils/isValidAccountsFile'
|
||||
import { resolveAddress } from 'utils/resolveAddress'
|
||||
|
||||
import type { CollectionInfo } from '../../../contracts/sg721/contract'
|
||||
import { TextInput } from '../../forms/FormInput'
|
||||
@ -54,6 +55,7 @@ export const CollectionActions = ({
|
||||
const [airdropArray, setAirdropArray] = useState<string[]>([])
|
||||
const [collectionInfo, setCollectionInfo] = useState<CollectionInfo>()
|
||||
const [explicitContent, setExplicitContent] = useState<ExplicitContentType>(undefined)
|
||||
const [resolvedRecipientAddress, setResolvedRecipientAddress] = useState<string>('')
|
||||
|
||||
const actionComboboxState = useActionsComboboxState()
|
||||
const type = actionComboboxState.value?.id
|
||||
@ -188,13 +190,43 @@ export const CollectionActions = ({
|
||||
vendingMinterMessages,
|
||||
baseMinterMessages,
|
||||
sg721Messages,
|
||||
recipient: recipientState.value,
|
||||
recipient: resolvedRecipientAddress,
|
||||
recipients: airdropArray,
|
||||
txSigner: wallet.address,
|
||||
type,
|
||||
price: priceState.value.toString(),
|
||||
collectionInfo,
|
||||
}
|
||||
const resolveRecipientAddress = async () => {
|
||||
await resolveAddress(recipientState.value.trim(), wallet).then((resolvedAddress) => {
|
||||
setResolvedRecipientAddress(resolvedAddress as string)
|
||||
})
|
||||
}
|
||||
useEffect(() => {
|
||||
void resolveRecipientAddress()
|
||||
}, [recipientState.value])
|
||||
|
||||
const resolveRoyaltyPaymentAddress = async () => {
|
||||
await resolveAddress(royaltyPaymentAddressState.value.trim(), wallet).then((resolvedAddress) => {
|
||||
setCollectionInfo({
|
||||
description: descriptionState.value || undefined,
|
||||
image: imageState.value || undefined,
|
||||
explicit_content: explicitContent,
|
||||
external_link: externalLinkState.value || undefined,
|
||||
royalty_info:
|
||||
royaltyPaymentAddressState.value && royaltyShareState.value
|
||||
? {
|
||||
payment_address: resolvedAddress as string,
|
||||
share: (Number(royaltyShareState.value) / 100).toString(),
|
||||
}
|
||||
: undefined,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
void resolveRoyaltyPaymentAddress()
|
||||
}, [royaltyPaymentAddressState.value])
|
||||
|
||||
useEffect(() => {
|
||||
setCollectionInfo({
|
||||
|
40
utils/resolveAddress.ts
Normal file
40
utils/resolveAddress.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { toUtf8 } from '@cosmjs/encoding'
|
||||
import toast from 'react-hot-toast'
|
||||
|
||||
import type { KeplrWalletStore } from '../contexts/wallet'
|
||||
import { SG721_NAME_ADDRESS } from './constants'
|
||||
import { isValidAddress } from './isValidAddress'
|
||||
|
||||
export const resolveAddress = async (name: string, wallet: KeplrWalletStore): Promise<string | undefined> => {
|
||||
if (!name.trim().endsWith('.stars')) return name
|
||||
|
||||
if (wallet.client) {
|
||||
const tokenUri = await wallet.client
|
||||
.queryContractRaw(
|
||||
SG721_NAME_ADDRESS,
|
||||
toUtf8(
|
||||
Buffer.from(
|
||||
`0006${Buffer.from('tokens').toString('hex')}${Buffer.from(
|
||||
name.substring(0, name.lastIndexOf('.')),
|
||||
).toString('hex')}`,
|
||||
'hex',
|
||||
).toString(),
|
||||
),
|
||||
)
|
||||
.then((res) => {
|
||||
const parsedTokenUri = JSON.parse(new TextDecoder().decode(res as Uint8Array)).token_uri
|
||||
console.log(parsedTokenUri)
|
||||
if (parsedTokenUri && isValidAddress(parsedTokenUri)) return parsedTokenUri as string
|
||||
toast.error(`Resolved address is empty or invalid for the name: ${name}`)
|
||||
return name
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
toast.error(`Error resolving address for the name: ${name}`)
|
||||
return name
|
||||
})
|
||||
return tokenUri
|
||||
}
|
||||
toast.error('Wallet is not connected. Unable to resolve address.')
|
||||
return name
|
||||
}
|
Loading…
Reference in New Issue
Block a user