From 48d5fbecd2edf4a6aa92a51c3bbbca83c95dabbe Mon Sep 17 00:00:00 2001 From: ttang Date: Wed, 3 Apr 2024 12:31:04 +0800 Subject: [PATCH] feat: haidilao imgv2 --- src/haidilao/check.tsx | 4 +- src/haidilao/images/index.tsx | 201 ++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+), 2 deletions(-) diff --git a/src/haidilao/check.tsx b/src/haidilao/check.tsx index 3f217e9..080ef2a 100644 --- a/src/haidilao/check.tsx +++ b/src/haidilao/check.tsx @@ -30,7 +30,7 @@ export async function check(c: FrameContext) { } return c.res({ action: "/", - image: `/haidilao/images/check/${fid}/image.png`, + image: `/haidilao/images/check/${fid}/imagev2.png`, intents: [ , Share diff --git a/src/haidilao/images/index.tsx b/src/haidilao/images/index.tsx index 48a2533..7e99ecc 100644 --- a/src/haidilao/images/index.tsx +++ b/src/haidilao/images/index.tsx @@ -242,4 +242,205 @@ images.hono.get("/check/:fid/image.png", async (ctx) => { }); }); +images.hono.get("/check/:fid/imagev2.png", async (ctx) => { + const fid = ctx.req.param("fid"); + if (fid === "0") { + const errorImg = ( +
+ {fid} +
+ ); + return new ImageResponse(errorImg, { + format: "png", + headers: { + "Cache-Control": "public, max-age=3600", + }, + }); + } + const { ethAddress } = (await getAddressFromFid(Number(fid))) as { + ethAddress: `0x${string}`; + }; + if (!ethAddress) { + const errorImg = ( +
+ There is no wallet address associated with this account. +
+ ); + return new ImageResponse(errorImg, { + format: "png", + headers: { + "Cache-Control": "public, max-age=3600", + }, + }); + } + const [user, degenSold] = await Promise.all([ + getUserDataByFid(Number(fid)), + fetchSoldDegen({ address: ethAddress }), + ]); + const degenPriceData = await fetchDegenPrice(); + const degenPrice = degenPriceData.pair.priceUsd; + + const transfers = degenSold.result.transfers; + // console.log(transfers); + + let amount = 0; + for (let i = 0; i < transfers.length; i++) { + amount += transfers[i].value; + } + const total = amount * Number(degenPrice || 0); + // console.log({ amount }); + const image = ( +
+
+
+ {user.display} + {`@${user.username}:`} +
+
+ I sold {amount.toLocaleString().split(".")[0]} $degen for $ + {total.toLocaleString().split(".")[0]}, if i held them today i can + have... +
+
+ +
+
+ +
+ +
+
+ {(total / 50).toLocaleString()} +
+
time haidilao hot pot!!!!!
+
+
+
+ ); + return new ImageResponse(image, { + format: "png", + headers: { + "Cache-Control": "public, max-age=3600", + }, + width: 800, + height: 480, + fonts: [ + { + data: upheavttFont, + name: "upheaval", + }, + ], + }); +}); + export default images;