Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix .solana not parsing properly #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading