From f860de5ee033bbd5c36169b6d01ba14d0faffd39 Mon Sep 17 00:00:00 2001 From: crypt0miester Date: Thu, 19 Dec 2024 15:18:50 +0400 Subject: [PATCH] fix .solana not parsing properly --- hooks/useDestination.ts | 19 ++++++++++++++++--- .../proposal/components/instructions/Mint.tsx | 4 +++- utils/domains.ts | 5 +++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/hooks/useDestination.ts b/hooks/useDestination.ts index 32a173953..08f73b3c2 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 7df9ff1c0..3f4e0b1e5 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 67cf2b47b..bda37922e 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