From cfaacabf9a800506a673c2f098ab572905dfe4a8 Mon Sep 17 00:00:00 2001 From: Alec Ananian <1013230+alecananian@users.noreply.github.com> Date: Fri, 17 May 2024 11:49:36 -0700 Subject: [PATCH 1/4] configure and run biome formatter --- apps/api/src/index.ts | 10 +- apps/api/src/routes/auth.ts | 248 +++++++++--------- apps/login/app/components/SpinnerIcon.tsx | 4 +- apps/login/app/entry.server.tsx | 2 - apps/login/app/hooks/useLogin.ts | 16 +- apps/login/app/routes/($slug)._index.tsx | 2 +- biome.json | 33 +++ examples/payments/src/App.tsx | 4 + package-lock.json | 156 +++++++++++ package.json | 1 + packages/core/src/api.ts | 10 +- packages/core/src/utils/harvesters.ts | 34 +-- packages/core/src/utils/login.ts | 4 +- packages/core/src/utils/payments.ts | 8 +- packages/core/src/utils/wagmi.ts | 8 +- .../src/components/PaymentsCartModal.tsx | 5 +- .../src/components/login/ConnectButton.tsx | 7 +- 17 files changed, 381 insertions(+), 171 deletions(-) create mode 100644 biome.json diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 6fb7a68e..884fca3e 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -58,15 +58,15 @@ const main = async () => { ? createConfig({ chains: SUPPORTED_CHAINS, transports: SUPPORTED_CHAINS.reduce( - (acc, chain) => ({ - ...acc, - [chain.id]: fallback([ + (acc, chain) => { + acc[chain.id] = fallback([ http( `https://${chain.id}.rpc.thirdweb.com/${env.THIRDWEB_CLIENT_ID}`, ), http(), - ]), - }), + ]); + return acc; + }, {} as Record, ), }) diff --git a/apps/api/src/routes/auth.ts b/apps/api/src/routes/auth.ts index f13e6fd4..aa5802df 100644 --- a/apps/api/src/routes/auth.ts +++ b/apps/api/src/routes/auth.ts @@ -54,143 +54,143 @@ export const authRoutes = }); reply.send(payload); }, - ), - app.post<{ Body: LoginBody; Reply: LoginReply | ErrorReply }>( - "/login", - { - schema: { - summary: "Log in", - description: "Log in with a signed payload", - body: loginBodySchema, - response: { - 200: loginReplySchema, - }, + ); + + app.post<{ Body: LoginBody; Reply: LoginReply | ErrorReply }>( + "/login", + { + schema: { + summary: "Log in", + description: "Log in with a signed payload", + body: loginBodySchema, + response: { + 200: loginReplySchema, }, }, - async (req, reply) => { - const verifiedPayload = await auth.verifyPayload(req.body); - if (!verifiedPayload.valid) { - return reply - .code(400) - .send({ error: `Login failed: ${verifiedPayload.error}` }); - } - - const smartAccountAddress = verifiedPayload.payload.address; - let user = await db.user.upsert({ - where: { - smartAccountAddress, - }, - update: { - lastLoginAt: new Date(), - }, - create: { - smartAccountAddress, - }, - select: { - id: true, - email: true, - treasureTag: true, - }, - }); + }, + async (req, reply) => { + const verifiedPayload = await auth.verifyPayload(req.body); + if (!verifiedPayload.valid) { + return reply + .code(400) + .send({ error: `Login failed: ${verifiedPayload.error}` }); + } - // User does not have an email address registered yet - if (!user.email) { - // Get admin wallet associated with this smart account address - const { - result: [adminAddress], - } = await engine.account.getAllAdmins( - verifiedPayload.payload.chain_id ?? - DEFAULT_TDK_CHAIN_ID.toString(), - smartAccountAddress, - ); + const smartAccountAddress = verifiedPayload.payload.address; + let user = await db.user.upsert({ + where: { + smartAccountAddress, + }, + update: { + lastLoginAt: new Date(), + }, + create: { + smartAccountAddress, + }, + select: { + id: true, + email: true, + treasureTag: true, + }, + }); - // Look up any possible associated email addresses (for embedded wallets) - const embeddedWalletUser = await fetchEmbeddedWalletUser( - adminAddress, - env.THIRDWEB_SECRET_KEY, - ); - if (embeddedWalletUser) { - const { email } = embeddedWalletUser; - let updateData: Prisma.UserUpdateInput = { email }; + // User does not have an email address registered yet + if (!user.email) { + // Get admin wallet associated with this smart account address + const { + result: [adminAddress], + } = await engine.account.getAllAdmins( + verifiedPayload.payload.chain_id ?? DEFAULT_TDK_CHAIN_ID.toString(), + smartAccountAddress, + ); - // Check if email was migrated from TreasureTag system, and delete existing record if so - const existingUser = await db.user.findUnique({ - where: { email }, - select: { id: true }, - }); - if (existingUser) { - updateData = { - ...updateData, - treasureTag: updateData.treasureTag, - }; - await db.user.delete({ where: { id: existingUser.id } }); - } + // Look up any possible associated email addresses (for embedded wallets) + const embeddedWalletUser = await fetchEmbeddedWalletUser( + adminAddress, + env.THIRDWEB_SECRET_KEY, + ); + if (embeddedWalletUser) { + const { email } = embeddedWalletUser; + let updateData: Prisma.UserUpdateInput = { email }; - // Set user's email address - user = await db.user.update({ - where: { - id: user.id, - }, - data: updateData, - select: { - id: true, - email: true, - treasureTag: true, - }, - }); + // Check if email was migrated from TreasureTag system, and delete existing record if so + const existingUser = await db.user.findUnique({ + where: { email }, + select: { id: true }, + }); + if (existingUser) { + updateData = { + ...updateData, + treasureTag: updateData.treasureTag, + }; + await db.user.delete({ where: { id: existingUser.id } }); } + + // Set user's email address + user = await db.user.update({ + where: { + id: user.id, + }, + data: updateData, + select: { + id: true, + email: true, + treasureTag: true, + }, + }); } + } - // Add user data to JWT payload's context - const authToken = await auth.generateJWT({ - payload: verifiedPayload.payload, - context: user, - }); - reply.send({ token: authToken }); - }, - ), - app.post<{ - Body: AuthenciateBody; - Reply: AuthenticateReply | ErrorReply; - }>( - "/auth/authenticate", - { - schema: { - summary: "Log in via third party", - description: - "Start login session with custom authentication method", - body: authenticateBodySchema, - response: { - 200: authenticateReplySchema, - }, + // Add user data to JWT payload's context + const authToken = await auth.generateJWT({ + payload: verifiedPayload.payload, + context: user, + }); + reply.send({ token: authToken }); + }, + ); + + app.post<{ + Body: AuthenciateBody; + Reply: AuthenticateReply | ErrorReply; + }>( + "/auth/authenticate", + { + schema: { + summary: "Log in via third party", + description: "Start login session with custom authentication method", + body: authenticateBodySchema, + response: { + 200: authenticateReplySchema, }, }, - async (req, reply) => { - const { projectId } = req; - let token: string | undefined; - if (projectId === "zeeverse") { - const { - body: { email, password }, - } = req; - token = ( - await logInWithZeeverse({ - apiUrl: env.ZEEVERSE_API_URL, - email, - password, - }) - ).item.access_token; - } + }, + async (req, reply) => { + const { projectId } = req; + let token: string | undefined; + if (projectId === "zeeverse") { + const { + body: { email, password }, + } = req; + token = ( + await logInWithZeeverse({ + apiUrl: env.ZEEVERSE_API_URL, + email, + password, + }) + ).item.access_token; + } - if (!token) { - return reply.code(401).send({ error: "Unauthorized" }); - } + if (!token) { + return reply.code(401).send({ error: "Unauthorized" }); + } - reply.send({ - projectId, - token, - }); - }, - ); + reply.send({ + projectId, + token, + }); + }, + ); app.post<{ Body: AuthVerifyBody; Reply: AuthVerifyReply | ErrorReply }>( "/auth/verify", diff --git a/apps/login/app/components/SpinnerIcon.tsx b/apps/login/app/components/SpinnerIcon.tsx index fa0e892b..f3f057a7 100644 --- a/apps/login/app/components/SpinnerIcon.tsx +++ b/apps/login/app/components/SpinnerIcon.tsx @@ -12,11 +12,11 @@ export const SpinnerIcon = ({ className }: { className?: string }) => ( r="10" stroke="currentColor" strokeWidth="4" - > + /> + /> ); diff --git a/apps/login/app/entry.server.tsx b/apps/login/app/entry.server.tsx index 3ea9c54f..ca63a506 100644 --- a/apps/login/app/entry.server.tsx +++ b/apps/login/app/entry.server.tsx @@ -63,7 +63,6 @@ function handleBotRequest( reject(error); }, onError(error: unknown) { - responseStatusCode = 500; // Log streaming rendering errors from inside the shell. Don't log // errors encountered during initial shell rendering since they'll // reject and get logged in handleDocumentRequest. @@ -113,7 +112,6 @@ function handleBrowserRequest( reject(error); }, onError(error: unknown) { - responseStatusCode = 500; // Log streaming rendering errors from inside the shell. Don't log // errors encountered during initial shell rendering since they'll // reject and get logged in handleDocumentRequest. diff --git a/apps/login/app/hooks/useLogin.ts b/apps/login/app/hooks/useLogin.ts index a4d8f755..6a3f3d29 100644 --- a/apps/login/app/hooks/useLogin.ts +++ b/apps/login/app/hooks/useLogin.ts @@ -185,7 +185,9 @@ export const useLogin = ({ ); return dispatch({ type: "ERROR", - error: `An error occurred while deploying your Treasure account: ${getErrorMessage(err)}`, + error: `An error occurred while deploying your Treasure account: ${getErrorMessage( + err, + )}`, status: "IDLE", }); } @@ -213,7 +215,9 @@ export const useLogin = ({ console.error("Error logging in smart account:", err); return dispatch({ type: "ERROR", - error: `An error occurred while authenticating your Treasure account: ${getErrorMessage(err)}`, + error: `An error occurred while authenticating your Treasure account: ${getErrorMessage( + err, + )}`, status: "IDLE", }); } @@ -252,7 +256,9 @@ export const useLogin = ({ console.error("Error creating new session key:", err); return dispatch({ type: "ERROR", - error: `An error occurred while starting your Treasure account session: ${getErrorMessage(err)}`, + error: `An error occurred while starting your Treasure account session: ${getErrorMessage( + err, + )}`, status: "IDLE", }); } @@ -298,7 +304,9 @@ export const useLogin = ({ console.error("Error finishing email login:", err); dispatch({ type: "ERROR", - error: `An error occurred while confirming your email: ${getErrorMessage(err)}`, + error: `An error occurred while confirming your email: ${getErrorMessage( + err, + )}`, }); } }, diff --git a/apps/login/app/routes/($slug)._index.tsx b/apps/login/app/routes/($slug)._index.tsx index 5137ad61..39ce75ab 100644 --- a/apps/login/app/routes/($slug)._index.tsx +++ b/apps/login/app/routes/($slug)._index.tsx @@ -149,7 +149,7 @@ export default function LoginPage() { ) : status === "CONFIRM_EMAIL" ? (
- +

We've sent you an email

diff --git a/biome.json b/biome.json new file mode 100644 index 00000000..6b386964 --- /dev/null +++ b/biome.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.7.3/schema.json", + "files": { + "ignore": [ + ".husky/**", + "build/**", + "cdk.out/**", + "dist/**", + "node_modules/", + ".dockerignore", + ".gitignore", + "package-lock.json" + ] + }, + "organizeImports": { + "enabled": true + }, + "formatter": { + "indentStyle": "space" + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "a11y": { + "noSvgWithoutTitle": "off" + }, + "style": { + "noNonNullAssertion": "warn" + } + } + } +} diff --git a/examples/payments/src/App.tsx b/examples/payments/src/App.tsx index d75483f7..0b496149 100644 --- a/examples/payments/src/App.tsx +++ b/examples/payments/src/App.tsx @@ -171,6 +171,7 @@ export const App = () => { {formatEther(paymentAmount)} {paymentToken}

@@ -228,6 +230,7 @@ const PaymentsCartModalContents = ({ {paymentTokens.map((token, i) => (