diff --git a/hooks/useDestination.ts b/hooks/useDestination.ts index 32a17395..08f73b3c 100644 --- a/hooks/useDestination.ts +++ b/hooks/useDestination.ts @@ -1,3 +1,4 @@ +import { splitDomainTld, TldParser } from '@onsol/tldparser' import { Connection, PublicKey } from '@solana/web3.js' import { tryParseDomain, tryParseKey } from '@tools/validators/pubkey' import { debounce } from '@utils/debounce' @@ -12,12 +13,24 @@ const getDestination = async (connection: Connection, address: string) => { let pubKey: PublicKey | null = null let account: TokenProgramAccount | undefined = undefined - if (address?.trim().toLowerCase().endsWith('.sol')) { - pubKey = await tryParseDomain(address) + if (address.length >= 4 && address.split(".").length === 2) { + const [tld] = splitDomainTld(address); + if (tld === '.sol') { + pubKey = await tryParseDomain(address) + } else { + const parser = new TldParser(connection) + try { + const owner = await parser.getOwnerFromDomainTld(address) + pubKey = owner ?? null; + } catch (error) { + console.warn('Error resolving domain:', error) + pubKey = null + } + } } else { pubKey = tryParseKey(address) } - + console.log(pubKey?.toString()) if (pubKey) { account = await tryGetTokenAccount(connection, pubKey) } diff --git a/pages/dao/[symbol]/proposal/components/instructions/Mint.tsx b/pages/dao/[symbol]/proposal/components/instructions/Mint.tsx index 7df9ff1c..3f4e0b1e 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Mint.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Mint.tsx @@ -141,7 +141,9 @@ const Mint = ({ const destinationAccountName = destinationAccount?.publicKey && getAccountName(destinationAccount?.account.address) - const destinationAddressParsed = address.endsWith('.sol') + + let isDomain = address.length >= 4 && address.split(".").length === 2 + const destinationAddressParsed = isDomain ? form.destinationAccount : undefined const schema = getMintSchema({ form, connection }) diff --git a/utils/domains.ts b/utils/domains.ts index 67cf2b47..bda37922 100644 --- a/utils/domains.ts +++ b/utils/domains.ts @@ -6,7 +6,7 @@ import { NAME_TOKENIZER_ID, performReverseLookupBatch, } from '@bonfida/spl-name-service' -import { TldParser } from '@onsol/tldparser' +import { splitDomainTld, TldParser } from '@onsol/tldparser' import { Connection, ParsedAccountData, PublicKey } from '@solana/web3.js' interface Domain { @@ -21,8 +21,9 @@ export const resolveDomain = async ( domainName: string ) => { try { + const [tld] = splitDomainTld(domainName); // Get the public key for the domain - if (domainName.includes('.sol')) { + if (tld === '.sol') { const { pubkey } = await getDomainKey(domainName) // Check if the domain is an NFT