Skip to content

Commit de22411

Browse files
committed
feat: tip to entries
1 parent b062ea2 commit de22411

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

src/hono.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,6 +2297,22 @@ declare const transactions: drizzle_orm_pg_core.PgTableWithColumns<{
22972297
baseColumn: never;
22982298
generated: undefined;
22992299
}, {}, {}>;
2300+
toEntryId: drizzle_orm_pg_core.PgColumn<{
2301+
name: "to_entry_id";
2302+
tableName: "transactions";
2303+
dataType: "string";
2304+
columnType: "PgText";
2305+
data: string;
2306+
driverParam: string;
2307+
notNull: false;
2308+
hasDefault: false;
2309+
isPrimaryKey: false;
2310+
isAutoincrement: false;
2311+
hasRuntimeDefault: false;
2312+
enumValues: [string, ...string[]];
2313+
baseColumn: never;
2314+
generated: undefined;
2315+
}, {}, {}>;
23002316
powerToken: drizzle_orm_pg_core.PgColumn<{
23012317
name: "power_token";
23022318
tableName: "transactions";
@@ -2354,6 +2370,7 @@ declare const transactionsOpenAPISchema: zod.ZodObject<{
23542370
fromUserId: zod.ZodNullable<zod.ZodString>;
23552371
toUserId: zod.ZodNullable<zod.ZodString>;
23562372
toFeedId: zod.ZodNullable<zod.ZodString>;
2373+
toEntryId: zod.ZodNullable<zod.ZodString>;
23572374
powerToken: zod.ZodString;
23582375
createdAt: zod.ZodString;
23592376
comment: zod.ZodNullable<zod.ZodString>;
@@ -2364,6 +2381,7 @@ declare const transactionsOpenAPISchema: zod.ZodObject<{
23642381
fromUserId: string | null;
23652382
toUserId: string | null;
23662383
toFeedId: string | null;
2384+
toEntryId: string | null;
23672385
powerToken: string;
23682386
comment: string | null;
23692387
}, {
@@ -2373,6 +2391,7 @@ declare const transactionsOpenAPISchema: zod.ZodObject<{
23732391
fromUserId: string | null;
23742392
toUserId: string | null;
23752393
toFeedId: string | null;
2394+
toEntryId: string | null;
23762395
powerToken: string;
23772396
comment: string | null;
23782397
}>;
@@ -2535,9 +2554,8 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
25352554
$post: {
25362555
input: {
25372556
json: {
2538-
amount: string;
2539-
userId?: string | undefined;
2540-
feedId?: string | undefined;
2557+
entryId: string;
2558+
amount: "1000000000000000000" | "2000000000000000000";
25412559
};
25422560
};
25432561
output: {
@@ -2572,6 +2590,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
25722590
fromUserId: string | null;
25732591
toUserId: string | null;
25742592
toFeedId: string | null;
2593+
toEntryId: string | null;
25752594
powerToken: string;
25762595
comment: string | null;
25772596
fromUser: {

src/renderer/src/hooks/biz/useEntryActions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const useEntryActions = ({
141141
const openTipModal = useTipModal({
142142
userId: populatedEntry?.feeds.ownerUserId ?? undefined,
143143
feedId: populatedEntry?.feeds.id ?? undefined,
144+
entryId: populatedEntry?.entries.id ?? undefined,
144145
})
145146

146147
const collect = useCollect(populatedEntry)

src/renderer/src/modules/wallet/hooks.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ import { TipModalContent } from "./tip-modal"
77
export const useTipModal = ({
88
userId,
99
feedId,
10+
entryId,
1011
}: {
1112
userId?: string
1213
feedId?: string
14+
entryId?: string
1315
}) => {
1416
const { present } = useModalStack()
1517

1618
return useCallback(() => {
17-
if (!userId && !feedId) {
19+
if (!feedId || !entryId) {
1820
// this should not happen unless there is a bug in the code
19-
toast.error("Invalid user id or feed id")
21+
toast.error("Invalid feed id or entry id")
2022
return
2123
}
2224
window.posthog?.capture("tip_modal_opened", { feedId })
2325
present({
2426
title: "Tip Power",
25-
content: () => createElement(TipModalContent, { userId, feedId }),
27+
content: () => createElement(TipModalContent, { userId, feedId, entryId }),
2628
})
27-
}, [present, userId, feedId])
29+
}, [present, userId, feedId, entryId])
2830
}

src/renderer/src/modules/wallet/tip-modal.tsx

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import { nextFrame } from "@renderer/lib/dom"
1010
import {
1111
useWallet,
1212
useWalletTipMutation,
13-
useWalletTransactions,
1413
} from "@renderer/queries/wallet"
15-
import { from, toNumber } from "dnum"
14+
import { from } from "dnum"
1615
import type { FC } from "react"
1716
import { useState } from "react"
1817

@@ -36,7 +35,8 @@ const Loading = () => (
3635

3736
export const TipModalContent: FC<{
3837
userId?: string
39-
feedId?: string
38+
feedId: string
39+
entryId: string
4040
}> = (props) => {
4141
const myWallet = useMyWallet()
4242

@@ -47,31 +47,19 @@ export const TipModalContent: FC<{
4747
}
4848
const TipModalContent_: FC<{
4949
userId?: string
50-
feedId?: string
51-
}> = ({ userId, feedId }) => {
50+
feedId: string
51+
entryId: string
52+
}> = ({ userId, feedId, entryId }) => {
5253
const myWallet = useMyWallet()
5354
const myWalletData = myWallet.data?.[0]
5455

5556
const dPowerBigInt = BigInt(myWalletData?.dailyPowerToken ?? 0)
5657
const cPowerBigInt = BigInt(myWalletData?.cashablePowerToken ?? 0)
5758
const balanceBigInt = cPowerBigInt + dPowerBigInt
58-
const balanceNumber = toNumber(from(balanceBigInt, 18), {
59-
digits: 2,
60-
trailingZeros: true,
61-
})
62-
63-
const transactionsQuery = useWalletTransactions({
64-
toUserId: userId,
65-
toFeedId: feedId,
66-
})
6759

6860
const tipMutation = useWalletTipMutation()
6961

70-
const [amount, setAmount] = useState(
71-
DEFAULT_RECOMMENDED_TIP > balanceNumber ?
72-
balanceNumber :
73-
DEFAULT_RECOMMENDED_TIP,
74-
)
62+
const [amount, setAmount] = useState<1 | 2>(DEFAULT_RECOMMENDED_TIP)
7563

7664
const amountBigInt = from(amount, 18)[0]
7765

@@ -86,7 +74,7 @@ const TipModalContent_: FC<{
8674
feedId,
8775
})
8876

89-
if (transactionsQuery.isPending || myWallet.isPending) {
77+
if (myWallet.isPending) {
9078
return <Loading />
9179
}
9280

@@ -176,7 +164,7 @@ const TipModalContent_: FC<{
176164

177165
<RadioGroup
178166
value={amount.toString()}
179-
onValueChange={(value) => setAmount(Number(value))}
167+
onValueChange={(value) => setAmount(Number(value) as 1 | 2)}
180168
>
181169
<div className="grid grid-cols-2 gap-2">
182170
<RadioCard
@@ -213,9 +201,8 @@ const TipModalContent_: FC<{
213201
onClick={() => {
214202
if (tipMutation.isPending) return
215203
tipMutation.mutate({
216-
userId,
217-
feedId,
218-
amount: amountBigInt.toString(),
204+
entryId,
205+
amount: amountBigInt.toString() as "1000000000000000000" | "2000000000000000000",
219206
})
220207
}}
221208
variant={tipMutation.isSuccess ? "outline" : "primary"}

0 commit comments

Comments
 (0)