Names support for Collection Actions > Queries
This commit is contained in:
parent
468bf95cc2
commit
7669c5ebfe
@ -344,7 +344,6 @@ export const CollectionActions = ({
|
||||
|
||||
const airdropFileOnChange = (data: AirdropAllocation[]) => {
|
||||
setAirdropAllocationArray(data)
|
||||
console.log('airdrop allocation array: ', data)
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -11,6 +11,8 @@ import type { VendingMinterInstance } from 'contracts/vendingMinter'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { useQuery } from 'react-query'
|
||||
|
||||
import { useWallet } from '../../../contexts/wallet'
|
||||
import { resolveAddress } from '../../../utils/resolveAddress'
|
||||
import type { MinterType } from '../actions/Combobox'
|
||||
|
||||
interface CollectionQueriesProps {
|
||||
@ -29,6 +31,8 @@ export const CollectionQueries = ({
|
||||
baseMinterMessages,
|
||||
minterType,
|
||||
}: CollectionQueriesProps) => {
|
||||
const wallet = useWallet()
|
||||
|
||||
const comboboxState = useQueryComboboxState()
|
||||
const type = comboboxState.value?.id
|
||||
|
||||
@ -57,20 +61,26 @@ export const CollectionQueries = ({
|
||||
async ({ queryKey }) => {
|
||||
const [_sg721Messages, _baseMinterMessages_, _vendingMinterMessages, _type, _tokenId, _address] = queryKey
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const result = await dispatchQuery({
|
||||
tokenId: _tokenId,
|
||||
vendingMinterMessages: _vendingMinterMessages,
|
||||
baseMinterMessages: _baseMinterMessages_,
|
||||
sg721Messages: _sg721Messages,
|
||||
address: _address,
|
||||
type: _type,
|
||||
const res = await resolveAddress(_address, wallet).then(async (resolvedAddress) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const result = await dispatchQuery({
|
||||
tokenId: _tokenId,
|
||||
vendingMinterMessages: _vendingMinterMessages,
|
||||
baseMinterMessages: _baseMinterMessages_,
|
||||
sg721Messages: _sg721Messages,
|
||||
address: resolvedAddress,
|
||||
type: _type,
|
||||
})
|
||||
return result
|
||||
})
|
||||
return result
|
||||
return res
|
||||
},
|
||||
{
|
||||
placeholderData: null,
|
||||
onError: (error: any) => {
|
||||
toast.error(error.message, { style: { maxWidth: 'none' } })
|
||||
if (addressState.value.length > 12 && !addressState.value.includes('.')) {
|
||||
toast.error(error.message, { style: { maxWidth: 'none' } })
|
||||
}
|
||||
},
|
||||
enabled: Boolean(sg721ContractAddress && minterContractAddress && type),
|
||||
retry: false,
|
||||
|
@ -6,7 +6,7 @@ import { SG721_NAME_ADDRESS } from './constants'
|
||||
import { isValidAddress } from './isValidAddress'
|
||||
|
||||
export const resolveAddress = async (name: string, wallet: KeplrWalletStore): Promise<string> => {
|
||||
if (!name.trim().endsWith('.stars')) return name
|
||||
if (!name.trim().endsWith('.stars')) return name.trim()
|
||||
|
||||
if (wallet.client) {
|
||||
const tokenUri = await wallet.client
|
||||
@ -15,7 +15,7 @@ export const resolveAddress = async (name: string, wallet: KeplrWalletStore): Pr
|
||||
toUtf8(
|
||||
Buffer.from(
|
||||
`0006${Buffer.from('tokens').toString('hex')}${Buffer.from(
|
||||
name.substring(0, name.lastIndexOf('.')),
|
||||
name.trim().substring(0, name.trim().lastIndexOf('.')),
|
||||
).toString('hex')}`,
|
||||
'hex',
|
||||
).toString(),
|
||||
@ -25,12 +25,12 @@ export const resolveAddress = async (name: string, wallet: KeplrWalletStore): Pr
|
||||
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}`)
|
||||
toast.error(`Resolved address is empty or invalid for the name: ${name.trim()}`)
|
||||
return name
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
toast.error(`Error resolving address for the name: ${name}`)
|
||||
toast.error(`Error resolving address for the name: ${name.trim()}`)
|
||||
return name
|
||||
})
|
||||
return tokenUri
|
||||
|
Loading…
Reference in New Issue
Block a user