Skip to content

Commit

Permalink
feat: 10x token (#354)
Browse files Browse the repository at this point in the history
* feat: 10x token

* feat: power withdraw modal

* feat: update token text
  • Loading branch information
DIYgod authored Sep 13, 2024
1 parent 77419ac commit 9088aea
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 66 deletions.
34 changes: 31 additions & 3 deletions src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4362,7 +4362,7 @@ declare const _routes: hono_hono_base.HonoBase<
input: {
json: {
entryId: string
amount: "1000000000000000000" | "2000000000000000000"
amount: string
}
}
output: {
Expand Down Expand Up @@ -4465,7 +4465,7 @@ declare const _routes: hono_hono_base.HonoBase<
status: 200
}
}
"/wallets/transactions/withdrawable": {
"/wallets/transactions/feed-withdrawable": {
$get: {
input: {
query: {
Expand All @@ -4484,7 +4484,7 @@ declare const _routes: hono_hono_base.HonoBase<
status: 200
}
}
"/wallets/transactions/withdraw": {
"/wallets/transactions/feed-withdraw": {
$post: {
input: {
json: {
Expand All @@ -4501,6 +4501,24 @@ declare const _routes: hono_hono_base.HonoBase<
status: 200
}
}
"/wallets/transactions/withdraw": {
$post: {
input: {
json: {
address: string
amount: string
}
}
output: {
code: 0
data: {
transactionHash: string
}
}
outputFormat: "json" | "text"
status: 200
}
}
"/wallets/transactions/claim-check": {
$get: {
input: {}
Expand Down Expand Up @@ -4544,6 +4562,16 @@ declare const _routes: hono_hono_base.HonoBase<
status: 200
}
}
"/wallets/refresh": {
$post: {
input: {}
output: {
code: 0
}
outputFormat: "json" | "text"
status: 200
}
}
} & {
"/subscriptions": {
$get: {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/src/constants/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ export const QUERY_PERSIST_KEY = getStorageNS("REACT_QUERY_OFFLINE_CACHE")
export const ROUTE_FEED_PENDING = "all"
export const ROUTE_ENTRY_PENDING = "pending"
export const ROUTE_FEED_IN_FOLDER = "folder-"

export const DAILY_CLAIM_AMOUNT = "20"
export const INVITATION_PRICE = "100"
1 change: 0 additions & 1 deletion src/renderer/src/modules/feed-column/list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import * as HoverCard from "@radix-ui/react-hover-card"
import { useUISettingKey } from "@renderer/atoms/settings/ui"
import { ScrollArea } from "@renderer/components/ui/scroll-area"
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/modules/panel/cmdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const SearchResultCount: FC<{
const searchInstance = React.useContext(SearchCmdKContext)
const hasKeyword = useSearchStore((s) => !!s.keyword)
const searchType = useSearchStore((s) => s.searchType)
// eslint-disable-next-line react-compiler/react-compiler
const recordCountPromise = useMemo(async () => {
let count = 0
const counts = await searchInstance?.then((s) => s.counts)
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/src/modules/settings/tabs/invitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TooltipPortal,
TooltipTrigger,
} from "@renderer/components/ui/tooltip"
import { INVITATION_PRICE } from "@renderer/constants"
import { useAuthQuery } from "@renderer/hooks/common"
import { apiClient } from "@renderer/lib/api-fetch"
import { toastFetchError } from "@renderer/lib/error-parser"
Expand All @@ -42,8 +43,8 @@ export const SettingInvitations = () => {
use.
</p>
<p className="flex items-center">
<span>You can spend 10 </span>
<i className="i-mgc-power ml-1 mr-0.5 text-base text-accent" />
<span>You can spend {INVITATION_PRICE} </span>
<i className="i-mgc-power mx-0.5 text-base text-accent" />
<span> Power to generate an invitation code for your friends.</span>
</p>
</div>
Expand Down Expand Up @@ -153,7 +154,7 @@ const ConfirmModalContent = ({ dismiss }: { dismiss: () => void }) => {
return (
<>
<div className="flex items-center">
<span>Generating an invitation code will cost you 10 </span>
<span>Generating an invitation code will cost you {INVITATION_PRICE} </span>
<i className="i-mgc-power mx-1 text-base text-accent" />
<span>Power. Do you want to continue?</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TooltipTrigger } from "@radix-ui/react-tooltip"
import { Button } from "@renderer/components/ui/button"
import { Tooltip, TooltipContent } from "@renderer/components/ui/tooltip"
import { DAILY_CLAIM_AMOUNT } from "@renderer/constants"
import { useClaimCheck, useClaimWalletDailyRewardMutation } from "@renderer/queries/wallet"

export const ClaimDailyReward = () => {
Expand All @@ -22,7 +23,9 @@ export const ClaimDailyReward = () => {
</Button>
</TooltipTrigger>
<TooltipContent>
{canClaim ? "Claim your 2 Daily Power now!" : `You have already claimed today.`}
{canClaim
? `Claim your ${DAILY_CLAIM_AMOUNT} Daily Power now!`
: `You have already claimed today.`}
</TooltipContent>
</Tooltip>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useWhoami } from "@renderer/atoms/user"
import { Button } from "@renderer/components/ui/button"
import { CopyButton } from "@renderer/components/ui/code-highlighter"
import { LoadingWithIcon } from "@renderer/components/ui/loading"
import {
Expand All @@ -7,9 +8,13 @@ import {
TooltipPortal,
TooltipTrigger,
} from "@renderer/components/ui/tooltip"
import { DAILY_CLAIM_AMOUNT } from "@renderer/constants"
import { apiClient } from "@renderer/lib/api-fetch"
import { cn } from "@renderer/lib/utils"
import { SettingSectionTitle } from "@renderer/modules/settings/section"
import { Balance } from "@renderer/modules/wallet/balance"
import { useWallet } from "@renderer/queries/wallet"
import { useWallet, wallet as walletActions } from "@renderer/queries/wallet"
import { useMutation } from "@tanstack/react-query"

import { ClaimDailyReward } from "./claim-daily-reward"
import { CreateWallet } from "./create-wallet"
Expand All @@ -20,6 +25,15 @@ export const MyWalletSection = () => {
const wallet = useWallet({ userId: user?.id })
const myWallet = wallet.data?.[0]

const refreshMutation = useMutation({
mutationFn: async () => {
await apiClient.wallets.refresh.$post()
},
onSuccess: () => {
walletActions.get().invalidate()
},
})

if (wallet.isPending) {
return (
<div className="center absolute inset-0 flex">
Expand Down Expand Up @@ -51,7 +65,10 @@ export const MyWalletSection = () => {
</a>
.
</p>
<p>You can claim 2 free Power daily, which can be used to tip RSS entries on Follow.</p>
<p>
You can claim {DAILY_CLAIM_AMOUNT} free Power daily, which can be used to tip RSS
entries on Follow.
</p>
</div>
<SettingSectionTitle margin="compact" title="Your Address" />
<div className="flex items-center gap-2 text-sm">
Expand All @@ -66,9 +83,23 @@ export const MyWalletSection = () => {
</div>
<SettingSectionTitle title="Your Balance" margin="compact" />
<div className="mb-2 flex items-end justify-between">
<Balance className="text-xl font-bold text-accent">
{BigInt(myWallet.dailyPowerToken || 0n) + BigInt(myWallet.cashablePowerToken || 0n)}
</Balance>
<div className="flex items-center gap-1">
<Balance className="text-xl font-bold text-accent">
{BigInt(myWallet.dailyPowerToken || 0n) + BigInt(myWallet.cashablePowerToken || 0n)}
</Balance>
<Button
variant="ghost"
onClick={() => refreshMutation.mutate()}
disabled={refreshMutation.isPending}
>
<i
className={cn(
"i-mgc-refresh-2-cute-re",
refreshMutation.isPending && "animate-spin",
)}
/>
</Button>
</div>
<div className="flex gap-2">
<WithdrawButton />
<ClaimDailyReward />
Expand All @@ -77,35 +108,18 @@ export const MyWalletSection = () => {
<Tooltip>
<TooltipTrigger className="block">
<div className="flex flex-row items-center gap-x-2 text-xs text-zinc-600 dark:text-neutral-400">
<span className="flex w-[120px] items-center gap-1 text-left">
Daily Power
<i className="i-mingcute-question-line" />
</span>
<Balance>{myWallet.dailyPowerToken}</Balance>
</div>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent align="start" className="z-[999]">
<p>1. Daily Power can only be used for tipping others.</p>
<p>2. You can claim 2 free Daily Power daily.</p>
</TooltipContent>
</TooltipPortal>
</Tooltip>
<Tooltip>
<TooltipTrigger className="block">
<div className="flex flex-row items-center gap-x-2 text-xs text-zinc-600 dark:text-neutral-400">
<span className="flex w-[120px] items-center gap-1 text-left">
Cashable Power <i className="i-mingcute-question-line" />
<span className="flex items-center gap-1 text-left">
Withdrawable <i className="i-mingcute-question-line" />
</span>

<Balance>{myWallet.cashablePowerToken}</Balance>
</div>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent align="start" className="z-[999]">
<p>1. Cashable Power can be withdrawn to your wallet for trading.</p>
<p>
2. Cashable Power is the Power you have recharged and the tips you have received.
Withdrawable Power includes both the tips you've received and the Power you've
recharged.
</p>
</TooltipContent>
</TooltipPortal>
Expand Down
Loading

0 comments on commit 9088aea

Please sign in to comment.