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 users missing in search results when sending tokens #3646

Merged
merged 6 commits into from
Apr 8, 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
21 changes: 9 additions & 12 deletions backend/native/backpack-api/src/db/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,22 +331,24 @@ export const createUser = async (
export async function getUsersByPrefix({
usernamePrefix,
uuid,
limit,
limit = 25,
}: {
usernamePrefix: string;
uuid: string;
limit?: number;
}) {
const { auth_users } = await chain("query")(
const { auth_users_whose_username_matches: users } = await chain("query")(
{
auth_users: [
auth_users_whose_username_matches: [
{
args: {
prefix: usernamePrefix,
},
where: {
username: { _like: `${usernamePrefix}%` },
id: { _neq: uuid },
public_keys: { is_primary: { _eq: true } },
},
limit: limit || 25,
limit,
},
{
id: true,
Expand All @@ -364,7 +366,7 @@ export async function getUsersByPrefix({
{ operationName: "getUsersByPrefix" }
);

return auth_users;
return users;
}

/**
Expand Down Expand Up @@ -483,12 +485,7 @@ export async function updateUserAvatar({
export const getUserByPublicKeyAndChain = async (
publicKey: string,
blockchain: Blockchain
): Promise<
{
id: string;
username: string;
}[]
> => {
) => {
const response = await chain("query")(
{
auth_users: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ export const users = {
},
},
},
eth_only: {
ali: {
id: "fb14ab0c-f20f-4b5d-a8d9-f9409eb69380",
jwt: "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJmYjE0YWIwYy1mMjBmLTRiNWQtYThkOS1mOTQwOWViNjkzODAiLCJpc3MiOiJhdXRoLnhuZnRzLmRldiIsImF1ZCI6ImJhY2twYWNrIiwiaWF0IjoxNjgwNzAyMTAxfQ.ClllrJvRXQZzFKwmJJi_2Ek1JSad2VMugodEq9GEg0D40HNNak7iMLEOfYlaE7uZ6yq5nKIaHm6QUJ7mRbPrWBQq0Zr5GFnzt-16aL3reYAtt_o5ho-fijZ-TAZGL6dGCfJ05zzLMJGH7rjaEXAQkoOceWP6P8_FCdJds2XFraMTNUQzNvrNbsB6f3v2mAnIr1mWYykztWTW-EDzz3Bkpg0sOrccFOjI-rpO1GZ9OclOEuzYRb08WVQVbVsQc6VK0Z8FjE9xWNNPKj4swuNsXEnd3CZdVB4fniyHKVpXQg7QSb5LzBz60ywi9A64c1D7kfZX95zMQlRMoq1qYbD2eA",
public_keys: {
// ali is an eth-only user
ethereum: {
primary: 0,
keys: ["0x6Ecc980c2acB5aaCA12e3DBC2bdE2bC7dDc4d2D9"],
Expand Down
35 changes: 26 additions & 9 deletions backend/native/backpack-api/src/routes/v1/__tests__/users.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { expect, test } from "vitest";
import { describe, expect, test } from "vitest";

import { alice, bob, unregistered_user } from "./_constants";

test.todo("creating a user");

test("getting the primary solana public key", async () => {
expect((await bob.get("users/primarySolPubkey/alice")).publicKey).toEqual(
alice.public_keys.solana.keys[alice.public_keys.solana.primary]
);

expect((await bob.get("users/primarySolPubkey/eth_only")).msg).toEqual(
"No active pubkey on SOL for this user"
);
describe("getting the primary solana public key", async () => {
test("for a user with a primary solana public key", async () => {
expect((await bob.get("users/primarySolPubkey/alice")).publicKey).toEqual(
alice.public_keys.solana.keys[alice.public_keys.solana.primary]
);
});

test("for a user that doesn't have a primary solana public key", async () => {
expect((await bob.get("users/primarySolPubkey/ali")).msg).toEqual(
"No active pubkey on SOL for this user"
);
});
});

test("getting a user", async () => {
Expand All @@ -36,3 +40,16 @@ test("an unregistered user cannot get information about themselves", async () =>
const res = await unregistered_user.get(`users/me`);
expect(res.id).toBeFalsy();
});

test("getting users via prefix", async () => {
const res = await bob.get(`users?usernamePrefix=ali`);
expect(res.users.map((u) => u.username)).toStrictEqual(["ali", "alice"]);

const { public_keys } = res.users[1];
expect(public_keys).toOnlyIncludePrimaryPublicKeysFor(alice);

// Temporary, see https://github.com/coral-xyz/backpack/issues/3645
expect(public_keys.map((x) => x.public_key)).toStrictEqual(
public_keys.map((x) => x.publicKey)
);
});
6 changes: 5 additions & 1 deletion backend/native/backpack-api/src/routes/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ router.get("/", extractUserId, async (req, res) => {
areFriends: friendship?.areFriends || false,
searchedSolPubKey: isSolPublicKey ? usernamePrefix : undefined,
searchedEthPubKey: isEthPublicKey ? usernamePrefix : undefined,
public_keys,
// TODO: fix the disambiguation with snake_case and camelCase in API responses
public_keys: public_keys.map((pk) => ({
...pk,
publicKey: pk.public_key,
})),
};
});

Expand Down
29 changes: 29 additions & 0 deletions backend/native/zeus/src/zeus/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ export const AllTypesProps: Record<string, any> = {
_set: "auth_users_set_input",
where: "auth_users_bool_exp",
},
auth_users_whose_username_matches_args: {},
auth_xnft_preferences_bool_exp: {
_and: "auth_xnft_preferences_bool_exp",
_not: "auth_xnft_preferences_bool_exp",
Expand Down Expand Up @@ -1425,6 +1426,18 @@ export const AllTypesProps: Record<string, any> = {
auth_users_by_pk: {
id: "uuid",
},
auth_users_whose_username_matches: {
args: "auth_users_whose_username_matches_args",
distinct_on: "auth_users_select_column",
order_by: "auth_users_order_by",
where: "auth_users_bool_exp",
},
auth_users_whose_username_matches_aggregate: {
args: "auth_users_whose_username_matches_args",
distinct_on: "auth_users_select_column",
order_by: "auth_users_order_by",
where: "auth_users_bool_exp",
},
auth_xnft_preferences: {
distinct_on: "auth_xnft_preferences_select_column",
order_by: "auth_xnft_preferences_order_by",
Expand Down Expand Up @@ -1621,6 +1634,18 @@ export const AllTypesProps: Record<string, any> = {
cursor: "auth_users_stream_cursor_input",
where: "auth_users_bool_exp",
},
auth_users_whose_username_matches: {
args: "auth_users_whose_username_matches_args",
distinct_on: "auth_users_select_column",
order_by: "auth_users_order_by",
where: "auth_users_bool_exp",
},
auth_users_whose_username_matches_aggregate: {
args: "auth_users_whose_username_matches_args",
distinct_on: "auth_users_select_column",
order_by: "auth_users_order_by",
where: "auth_users_bool_exp",
},
auth_xnft_preferences: {
distinct_on: "auth_xnft_preferences_select_column",
order_by: "auth_xnft_preferences_order_by",
Expand Down Expand Up @@ -2294,6 +2319,8 @@ export const ReturnTypes: Record<string, any> = {
auth_users: "auth_users",
auth_users_aggregate: "auth_users_aggregate",
auth_users_by_pk: "auth_users",
auth_users_whose_username_matches: "auth_users",
auth_users_whose_username_matches_aggregate: "auth_users_aggregate",
auth_xnft_preferences: "auth_xnft_preferences",
auth_xnft_preferences_by_pk: "auth_xnft_preferences",
auth_xnft_secrets: "auth_xnft_secrets",
Expand Down Expand Up @@ -2351,6 +2378,8 @@ export const ReturnTypes: Record<string, any> = {
auth_users_aggregate: "auth_users_aggregate",
auth_users_by_pk: "auth_users",
auth_users_stream: "auth_users",
auth_users_whose_username_matches: "auth_users",
auth_users_whose_username_matches_aggregate: "auth_users_aggregate",
auth_xnft_preferences: "auth_xnft_preferences",
auth_xnft_preferences_by_pk: "auth_xnft_preferences",
auth_xnft_preferences_stream: "auth_xnft_preferences",
Expand Down
Loading