Skip to content

Commit

Permalink
fix: search of token accounts now redirect to the correct route
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Diaconu committed Dec 14, 2023
1 parent 08ce359 commit f693169
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/lib/xray/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,34 @@ export const search = async (
// handle server-side logic, or set a default value
network = "mainnet";
}
const isMainnetValue = network !== "devnet";

// For token symbols
const tokenSymbols = await getJupiterTokens();

if (isValidPublicKey(query)) {
const pubkey = new PublicKey(query);
const account = await connection.getParsedAccountInfo(pubkey);

// TODO Property 'program' does not exist on type 'Buffer | ParsedAccountData'.
// @ts-ignore
const program = account?.value?.data?.program;
// @ts-ignore
const parsedType = account?.value?.data?.parsed?.type;

/*
* spl-token -> spl token
* spl-token-2022 -> token 2022
* null -> compressed nft
*/
const isToken =
// @ts-ignore
account?.value?.data?.program === "spl-token" ||
// @ts-ignore
account?.value?.data?.program === "spl-token-2022" ||
const probablyToken =
program === "spl-token" ||
program === "spl-token-2022" ||
account?.value === null;

const addressType = isToken ? "token" : "account";
let addressType!: "token" | "account";
if (probablyToken) {
addressType = parsedType === "account" ? "account" : "token";
}
addressType ??= "account";

return {
address: query,
Expand Down

0 comments on commit f693169

Please sign in to comment.