feat: tip to entries
This commit is contained in:
+22
-3
@@ -2297,6 +2297,22 @@ declare const transactions: drizzle_orm_pg_core.PgTableWithColumns<{
|
||||
baseColumn: never;
|
||||
generated: undefined;
|
||||
}, {}, {}>;
|
||||
toEntryId: drizzle_orm_pg_core.PgColumn<{
|
||||
name: "to_entry_id";
|
||||
tableName: "transactions";
|
||||
dataType: "string";
|
||||
columnType: "PgText";
|
||||
data: string;
|
||||
driverParam: string;
|
||||
notNull: false;
|
||||
hasDefault: false;
|
||||
isPrimaryKey: false;
|
||||
isAutoincrement: false;
|
||||
hasRuntimeDefault: false;
|
||||
enumValues: [string, ...string[]];
|
||||
baseColumn: never;
|
||||
generated: undefined;
|
||||
}, {}, {}>;
|
||||
powerToken: drizzle_orm_pg_core.PgColumn<{
|
||||
name: "power_token";
|
||||
tableName: "transactions";
|
||||
@@ -2354,6 +2370,7 @@ declare const transactionsOpenAPISchema: zod.ZodObject<{
|
||||
fromUserId: zod.ZodNullable<zod.ZodString>;
|
||||
toUserId: zod.ZodNullable<zod.ZodString>;
|
||||
toFeedId: zod.ZodNullable<zod.ZodString>;
|
||||
toEntryId: zod.ZodNullable<zod.ZodString>;
|
||||
powerToken: zod.ZodString;
|
||||
createdAt: zod.ZodString;
|
||||
comment: zod.ZodNullable<zod.ZodString>;
|
||||
@@ -2364,6 +2381,7 @@ declare const transactionsOpenAPISchema: zod.ZodObject<{
|
||||
fromUserId: string | null;
|
||||
toUserId: string | null;
|
||||
toFeedId: string | null;
|
||||
toEntryId: string | null;
|
||||
powerToken: string;
|
||||
comment: string | null;
|
||||
}, {
|
||||
@@ -2373,6 +2391,7 @@ declare const transactionsOpenAPISchema: zod.ZodObject<{
|
||||
fromUserId: string | null;
|
||||
toUserId: string | null;
|
||||
toFeedId: string | null;
|
||||
toEntryId: string | null;
|
||||
powerToken: string;
|
||||
comment: string | null;
|
||||
}>;
|
||||
@@ -2535,9 +2554,8 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
||||
$post: {
|
||||
input: {
|
||||
json: {
|
||||
amount: string;
|
||||
userId?: string | undefined;
|
||||
feedId?: string | undefined;
|
||||
entryId: string;
|
||||
amount: "1000000000000000000" | "2000000000000000000";
|
||||
};
|
||||
};
|
||||
output: {
|
||||
@@ -2572,6 +2590,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
||||
fromUserId: string | null;
|
||||
toUserId: string | null;
|
||||
toFeedId: string | null;
|
||||
toEntryId: string | null;
|
||||
powerToken: string;
|
||||
comment: string | null;
|
||||
fromUser: {
|
||||
|
||||
@@ -141,6 +141,7 @@ export const useEntryActions = ({
|
||||
const openTipModal = useTipModal({
|
||||
userId: populatedEntry?.feeds.ownerUserId ?? undefined,
|
||||
feedId: populatedEntry?.feeds.id ?? undefined,
|
||||
entryId: populatedEntry?.entries.id ?? undefined,
|
||||
})
|
||||
|
||||
const collect = useCollect(populatedEntry)
|
||||
|
||||
@@ -7,22 +7,24 @@ import { TipModalContent } from "./tip-modal"
|
||||
export const useTipModal = ({
|
||||
userId,
|
||||
feedId,
|
||||
entryId,
|
||||
}: {
|
||||
userId?: string
|
||||
feedId?: string
|
||||
entryId?: string
|
||||
}) => {
|
||||
const { present } = useModalStack()
|
||||
|
||||
return useCallback(() => {
|
||||
if (!userId && !feedId) {
|
||||
if (!feedId || !entryId) {
|
||||
// this should not happen unless there is a bug in the code
|
||||
toast.error("Invalid user id or feed id")
|
||||
toast.error("Invalid feed id or entry id")
|
||||
return
|
||||
}
|
||||
window.posthog?.capture("tip_modal_opened", { feedId })
|
||||
present({
|
||||
title: "Tip Power",
|
||||
content: () => createElement(TipModalContent, { userId, feedId }),
|
||||
content: () => createElement(TipModalContent, { userId, feedId, entryId }),
|
||||
})
|
||||
}, [present, userId, feedId])
|
||||
}, [present, userId, feedId, entryId])
|
||||
}
|
||||
|
||||
@@ -10,9 +10,8 @@ import { nextFrame } from "@renderer/lib/dom"
|
||||
import {
|
||||
useWallet,
|
||||
useWalletTipMutation,
|
||||
useWalletTransactions,
|
||||
} from "@renderer/queries/wallet"
|
||||
import { from, toNumber } from "dnum"
|
||||
import { from } from "dnum"
|
||||
import type { FC } from "react"
|
||||
import { useState } from "react"
|
||||
|
||||
@@ -36,7 +35,8 @@ const Loading = () => (
|
||||
|
||||
export const TipModalContent: FC<{
|
||||
userId?: string
|
||||
feedId?: string
|
||||
feedId: string
|
||||
entryId: string
|
||||
}> = (props) => {
|
||||
const myWallet = useMyWallet()
|
||||
|
||||
@@ -47,31 +47,19 @@ export const TipModalContent: FC<{
|
||||
}
|
||||
const TipModalContent_: FC<{
|
||||
userId?: string
|
||||
feedId?: string
|
||||
}> = ({ userId, feedId }) => {
|
||||
feedId: string
|
||||
entryId: string
|
||||
}> = ({ userId, feedId, entryId }) => {
|
||||
const myWallet = useMyWallet()
|
||||
const myWalletData = myWallet.data?.[0]
|
||||
|
||||
const dPowerBigInt = BigInt(myWalletData?.dailyPowerToken ?? 0)
|
||||
const cPowerBigInt = BigInt(myWalletData?.cashablePowerToken ?? 0)
|
||||
const balanceBigInt = cPowerBigInt + dPowerBigInt
|
||||
const balanceNumber = toNumber(from(balanceBigInt, 18), {
|
||||
digits: 2,
|
||||
trailingZeros: true,
|
||||
})
|
||||
|
||||
const transactionsQuery = useWalletTransactions({
|
||||
toUserId: userId,
|
||||
toFeedId: feedId,
|
||||
})
|
||||
|
||||
const tipMutation = useWalletTipMutation()
|
||||
|
||||
const [amount, setAmount] = useState(
|
||||
DEFAULT_RECOMMENDED_TIP > balanceNumber ?
|
||||
balanceNumber :
|
||||
DEFAULT_RECOMMENDED_TIP,
|
||||
)
|
||||
const [amount, setAmount] = useState<1 | 2>(DEFAULT_RECOMMENDED_TIP)
|
||||
|
||||
const amountBigInt = from(amount, 18)[0]
|
||||
|
||||
@@ -86,7 +74,7 @@ const TipModalContent_: FC<{
|
||||
feedId,
|
||||
})
|
||||
|
||||
if (transactionsQuery.isPending || myWallet.isPending) {
|
||||
if (myWallet.isPending) {
|
||||
return <Loading />
|
||||
}
|
||||
|
||||
@@ -176,7 +164,7 @@ const TipModalContent_: FC<{
|
||||
|
||||
<RadioGroup
|
||||
value={amount.toString()}
|
||||
onValueChange={(value) => setAmount(Number(value))}
|
||||
onValueChange={(value) => setAmount(Number(value) as 1 | 2)}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<RadioCard
|
||||
@@ -213,9 +201,8 @@ const TipModalContent_: FC<{
|
||||
onClick={() => {
|
||||
if (tipMutation.isPending) return
|
||||
tipMutation.mutate({
|
||||
userId,
|
||||
feedId,
|
||||
amount: amountBigInt.toString(),
|
||||
entryId,
|
||||
amount: amountBigInt.toString() as "1000000000000000000" | "2000000000000000000",
|
||||
})
|
||||
}}
|
||||
variant={tipMutation.isSuccess ? "outline" : "primary"}
|
||||
|
||||
Reference in New Issue
Block a user