Skip to content

Commit bde0b2d

Browse files
authored
chore: Make sure we can create/read/update labels for wallets/admins/access tokens (#302)
1 parent 0eba423 commit bde0b2d

File tree

7 files changed

+165
-13
lines changed

7 files changed

+165
-13
lines changed

src/db/tokens/updateToken.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { prisma } from "../client";
2+
3+
interface UpdateTokenParams {
4+
id: string;
5+
label?: string;
6+
}
7+
8+
export const updateToken = async ({ id, label }: UpdateTokenParams) => {
9+
await prisma.tokens.update({
10+
where: {
11+
id,
12+
},
13+
data: {
14+
label,
15+
},
16+
});
17+
};

src/db/wallets/updateWalletDetails.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { prisma } from "../client";
2+
3+
interface UpdateWalletDetailsParams {
4+
address: string;
5+
label?: string;
6+
}
7+
8+
export const updateWalletDetails = async ({
9+
address,
10+
label,
11+
}: UpdateWalletDetailsParams) => {
12+
await prisma.walletDetails.update({
13+
where: {
14+
address: address.toLowerCase(),
15+
},
16+
data: {
17+
label,
18+
},
19+
});
20+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Static, Type } from "@sinclair/typebox";
2+
import { FastifyInstance } from "fastify";
3+
import { StatusCodes } from "http-status-codes";
4+
import { updateToken } from "../../../../db/tokens/updateToken";
5+
6+
const BodySchema = Type.Object({
7+
id: Type.String(),
8+
label: Type.Optional(Type.String()),
9+
});
10+
11+
const ReplySchema = Type.Object({
12+
result: Type.Object({
13+
success: Type.Boolean(),
14+
}),
15+
});
16+
17+
export async function updateAccessToken(fastify: FastifyInstance) {
18+
fastify.route<{
19+
Body: Static<typeof BodySchema>;
20+
Reply: Static<typeof ReplySchema>;
21+
}>({
22+
method: "POST",
23+
url: "/auth/access-tokens/update",
24+
schema: {
25+
summary: "Update an access token",
26+
description: "Update an access token",
27+
tags: ["Access Tokens"],
28+
operationId: "update",
29+
body: BodySchema,
30+
response: {
31+
[StatusCodes.OK]: ReplySchema,
32+
},
33+
},
34+
handler: async (req, res) => {
35+
const { id, label } = req.body;
36+
await updateToken({ id, label });
37+
38+
res.status(200).send({
39+
result: {
40+
success: true,
41+
},
42+
});
43+
},
44+
});
45+
}

src/server/routes/backend-wallet/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ responseSchema.example = {
2626
},
2727
};
2828

29-
export const createWallet = async (fastify: FastifyInstance) => {
29+
export const createBackendWallet = async (fastify: FastifyInstance) => {
3030
fastify.route<{
3131
Body: Static<typeof BodySchema>;
3232
Reply: Static<typeof responseSchema>;

src/server/routes/backend-wallet/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ResponseSchema.example = {
9191
},
9292
};
9393

94-
export const importWallet = async (fastify: FastifyInstance) => {
94+
export const importBackendWallet = async (fastify: FastifyInstance) => {
9595
fastify.route<{
9696
Reply: Static<typeof ResponseSchema>;
9797
Body: Static<typeof RequestBodySchema>;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Static, Type } from "@sinclair/typebox";
2+
import { FastifyInstance } from "fastify";
3+
import { StatusCodes } from "http-status-codes";
4+
import { updateWalletDetails } from "../../../db/wallets/updateWalletDetails";
5+
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
6+
7+
const BodySchema = Type.Object({
8+
walletAddress: Type.String(),
9+
label: Type.Optional(Type.String()),
10+
});
11+
12+
const responseSchema = Type.Object({
13+
result: Type.Object({
14+
walletAddress: Type.String(),
15+
status: Type.String(),
16+
}),
17+
});
18+
19+
responseSchema.example = {
20+
result: {
21+
walletAddress: "0x....",
22+
status: "success",
23+
},
24+
};
25+
26+
export const updateBackendWallet = async (fastify: FastifyInstance) => {
27+
fastify.route<{
28+
Body: Static<typeof BodySchema>;
29+
Reply: Static<typeof responseSchema>;
30+
}>({
31+
method: "POST",
32+
url: "/backend-wallet/update",
33+
schema: {
34+
summary: "Update backend wallet",
35+
description: "Update a backend wallet.",
36+
tags: ["Backend Wallet"],
37+
operationId: "update",
38+
body: BodySchema,
39+
response: {
40+
...standardResponseSchema,
41+
[StatusCodes.OK]: responseSchema,
42+
},
43+
},
44+
handler: async (req, reply) => {
45+
const { walletAddress, label } = req.body;
46+
47+
await updateWalletDetails({
48+
address: walletAddress,
49+
label,
50+
});
51+
52+
reply.status(StatusCodes.OK).send({
53+
result: {
54+
walletAddress,
55+
status: "success",
56+
},
57+
});
58+
},
59+
});
60+
};

src/server/routes/index.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,39 @@ import { erc721Routes } from "./contract/extensions/erc721";
1717
import { marketplaceV3Routes } from "./contract/extensions/marketplaceV3/index";
1818
import { prebuiltsRoutes } from "./deploy";
1919

20-
// Chain
20+
// Chains
2121
import { getChainData } from "./chain/get";
2222
import { getAllChainData } from "./chain/getAll";
2323

24-
// Contract Events
24+
// Contract events
2525
import { getAllEvents } from "./contract/events/getAllEvents";
2626
import { getEvents } from "./contract/events/getEvents";
2727

28-
// Contract Roles
28+
// Contract roles
2929
import { getRoles } from "./contract/roles/read/get";
3030
import { getAllRoles } from "./contract/roles/read/getAll";
3131
import { grantRole } from "./contract/roles/write/grant";
3232
import { revokeRole } from "./contract/roles/write/revoke";
3333

34-
// Contract Royalties
34+
// Contract royalties
3535
import { getDefaultRoyaltyInfo } from "./contract/royalties/read/getDefaultRoyaltyInfo";
3636
import { getTokenRoyaltyInfo } from "./contract/royalties/read/getTokenRoyaltyInfo";
3737
import { setDefaultRoyaltyInfo } from "./contract/royalties/write/setDefaultRoyaltyInfo";
3838
import { setTokenRoyaltyInfo } from "./contract/royalties/write/setTokenRoyaltyInfo";
3939

40-
// Contract Metadata
40+
// Contract metadata
4141
import { getABI } from "./contract/metadata/abi";
4242
import { extractEvents } from "./contract/metadata/events";
4343
import { extractFunctions } from "./contract/metadata/functions";
4444

4545
// Wallet
46-
import { createWallet } from "./backend-wallet/create";
46+
import { createBackendWallet } from "./backend-wallet/create";
4747
import { getAll } from "./backend-wallet/getAll";
4848
import { getBalance } from "./backend-wallet/getBalance";
49-
import { importWallet } from "./backend-wallet/import";
49+
import { importBackendWallet } from "./backend-wallet/import";
5050
import { sendTransaction } from "./backend-wallet/send";
5151
import { transfer } from "./backend-wallet/transfer";
52+
import { updateBackendWallet } from "./backend-wallet/update";
5253

5354
// Configuration
5455
import { getBackendWalletBalanceConfiguration } from "./configuration/backend-wallet-balance/get";
@@ -66,17 +67,24 @@ import { getWebhooksEventTypes } from "./webhooks/events";
6667
import { getAllWebhooksData } from "./webhooks/getAll";
6768
import { revokeWebhook } from "./webhooks/revoke";
6869

69-
// Accounts
70+
// Access tokens
7071
import { createAccessToken } from "./auth/access-tokens/create";
7172
import { getAllAccessTokens } from "./auth/access-tokens/getAll";
7273
import { revokeAccessToken } from "./auth/access-tokens/revoke";
74+
import { updateAccessToken } from "./auth/access-tokens/update";
75+
76+
// Admins
7377
import { getAllPermissions } from "./auth/permissions/getAll";
7478
import { grantPermissions } from "./auth/permissions/grant";
7579
import { revokePermissions } from "./auth/permissions/revoke";
7680
import { getAuthConfiguration } from "./configuration/auth/get";
7781
import { updateAuthConfiguration } from "./configuration/auth/update";
82+
83+
// Smart accounts
7884
import { accountRoutes } from "./contract/extensions/account";
7985
import { accountFactoryRoutes } from "./contract/extensions/accountFactory";
86+
87+
// Relayers
8088
import { relayTransaction } from "./relayer";
8189
import { createRelayer } from "./relayer/create";
8290
import { getAllRelayers } from "./relayer/getAll";
@@ -87,9 +95,10 @@ import { healthCheck } from "./health";
8795
import { home } from "./home";
8896

8997
export const withRoutes = async (fastify: FastifyInstance) => {
90-
// Wallet
91-
await fastify.register(createWallet);
92-
await fastify.register(importWallet);
98+
// Backend Wallets
99+
await fastify.register(createBackendWallet);
100+
await fastify.register(importBackendWallet);
101+
await fastify.register(updateBackendWallet);
93102
await fastify.register(getBalance);
94103
await fastify.register(getAll);
95104
await fastify.register(transfer);
@@ -122,6 +131,7 @@ export const withRoutes = async (fastify: FastifyInstance) => {
122131
await fastify.register(getAllAccessTokens);
123132
await fastify.register(createAccessToken);
124133
await fastify.register(revokeAccessToken);
134+
await fastify.register(updateAccessToken);
125135

126136
// Chains
127137
await fastify.register(getChainData);

0 commit comments

Comments
 (0)