Skip to content

Commit

Permalink
fix .solana not parsing properly (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
crypt0miester authored Dec 22, 2024
1 parent eb9e4c1 commit ba37804
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
19 changes: 16 additions & 3 deletions hooks/useDestination.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -12,12 +13,24 @@ const getDestination = async (connection: Connection, address: string) => {
let pubKey: PublicKey | null = null
let account: TokenProgramAccount<TokenAccount> | 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)
}
Expand Down
4 changes: 3 additions & 1 deletion pages/dao/[symbol]/proposal/components/instructions/Mint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
5 changes: 3 additions & 2 deletions utils/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit ba37804

Please sign in to comment.