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

[Feat] Remove Backpack Usernames #236

Merged
merged 1 commit into from
Dec 4, 2023
Merged
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
30 changes: 5 additions & 25 deletions src/lib/components/account-header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,11 @@
{:else if usernames && usernames?.length > 0}
<div class="flex flex-wrap gap-2 pt-2">
{#each usernames as username}
{#if username.type === "backpack"}
<div
class="inline-block rounded-full bg-red-200/90 px-3 py-1 text-xs font-extrabold text-red-600/90"
>
<div
class="flex items-center justify-center gap-1"
>
<Icon
id="backpack"
size="sm"
/>
<!-- <span
class="flex items-center justify-center"
> -->
{username.username}
<!-- </span> -->
</div>
</div>
{:else}
<div
class="username-block inline-block rounded-full px-3 py-1 text-xs font-extrabold"
>
{username.username}
</div>
{/if}
<div
class="username-block inline-block rounded-full px-3 py-1 text-xs font-extrabold"
>
{username.username}
</div>
{/each}
</div>
{/if}
Expand Down
1 change: 0 additions & 1 deletion src/lib/components/search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
| "transaction"
| "bonfida-domain"
| "ans-domain"
| "backpack-username"
| null;

interface SearchResult {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/components/transactions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
}) =>
compressed
? client.cnftTransactions.createInfiniteQuery(input, {
getNextPageParam: (lastPage) => lastPage.oldest,
refetchOnMount: false,
refetchOnWindowFocus: false,
})
getNextPageParam: (lastPage) => lastPage.oldest,
refetchOnMount: false,
refetchOnWindowFocus: false,
})
: client.transactions.createInfiniteQuery(input, {
getNextPageParam: (lastPage) => lastPage.oldest,
refetchOnMount: false,
refetchOnWindowFocus: false,
});
getNextPageParam: (lastPage) => lastPage.oldest,
refetchOnMount: false,
refetchOnWindowFocus: false,
});

const loadMore = () => {
$transactions.fetchNextPage();
Expand Down
17 changes: 1 addition & 16 deletions src/lib/trpc/routes/account-usernames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,10 @@ import { z } from "zod";
const { HELIUS_API_KEY } = process.env;

interface Username {
type: "bonfida" | "backpack";
type: "bonfida";
username: string;
}

const getBackpackUsername = async (usernames: Username[], address = "") => {
const response = await fetch(
`https://xnft-api-server.xnfts.dev/v1/users/fromPubkey?publicKey=${address}&blockchain=solana`
);
const data = await response.json();

if (data?.user?.username) {
usernames.push({
type: "backpack",
username: data.user.username,
});
}
};

const getSolanaDomain = async (usernames: Username[], address = "") => {
const url = `https://api.helius.xyz/v0/addresses/${address}/names?api-key=${HELIUS_API_KEY}`;
const response = await fetch(url);
Expand Down Expand Up @@ -50,7 +36,6 @@ export const accountUsernames = t.procedure
)
.query(async ({ input: address }) => {
const usernames: Username[] = [];
await getBackpackUsername(usernames, address);
await getSolanaDomain(usernames, address);

return usernames || [];
Expand Down
23 changes: 1 addition & 22 deletions src/lib/xray/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type SearchResultType =
| "transaction"
| "bonfida-domain"
| "ans-domain"
| "backpack-username"
| null;

const searchDefaults: SearchResult = {
Expand Down Expand Up @@ -52,7 +51,7 @@ export const search = async (
network = "mainnet";
}
const isMainnetValue = network !== "devnet";
const probablyBackpackName = query.startsWith("@") && query.length > 1;

if (isValidPublicKey(query)) {
const pubkey = new PublicKey(query);
const account = await connection.getParsedAccountInfo(pubkey);
Expand Down Expand Up @@ -105,26 +104,6 @@ export const search = async (
} catch (error) {
return searchDefaults;
}
} else if (probablyBackpackName) {
const username = query?.slice(1)?.toLowerCase();

const url = `https://backpack-api.xnfts.dev/users/primarySolPubkey/${username}`;

const response = await fetch(url);

const { publicKey = "" } = await response.json();

if (!publicKey) {
return searchDefaults;
}

return {
address: query || "",
search: query,
type: "backpack-username",
url: `/account/${publicKey}`,
valid: true,
};
} else if (probablyAnsDomain) {
const owner = await ans.getOwnerFromDomainTld(query);

Expand Down
8 changes: 0 additions & 8 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@
>
<h1>🎒</h1>
</div>

<div>
<h1 class="text-xl font-bold">xNFT Backpack Support</h1>
<p class="opacity-50">
You can Lookup Backpack usernames by searching
"@yourname", like "@xray".
</p>
</div>
</div>
</div>
</div>
Expand Down