11"use client" ;
22
3- import { useQuery } from "@tanstack/react-query" ;
43import { ArrowRightIcon } from "lucide-react" ;
54import { toast } from "sonner" ;
6- import type { ThirdwebContract } from "thirdweb" ;
5+ import { type ThirdwebClient , type ThirdwebContract , toTokens } from "thirdweb" ;
76import { claimReward } from "thirdweb/assets" ;
87import { useSendAndConfirmTransaction } from "thirdweb/react" ;
98import { WalletAddress } from "@/components/blocks/wallet-address" ;
@@ -12,21 +11,28 @@ import { Spinner } from "@/components/ui/Spinner/Spinner";
1211import { parseError } from "@/utils/errorParser" ;
1312import { tryCatch } from "@/utils/try-catch" ;
1413import type { getValidReward } from "../utils/rewards" ;
15- import { getUnclaimedFees } from "../utils/unclaimed-fees" ;
1614
1715export function ClaimRewardsPage ( props : {
1816 assetContractClient : ThirdwebContract ;
1917 entrypointContractClient : ThirdwebContract ;
2018 reward : NonNullable < Awaited < ReturnType < typeof getValidReward > > > ;
21- rewardLockerContractClient : ThirdwebContract ;
22- v3PositionManagerContractClient : ThirdwebContract ;
19+ unclaimedFees : {
20+ token0 : {
21+ address : string ;
22+ amount : bigint ;
23+ } ;
24+ token1 : {
25+ address : string ;
26+ amount : bigint ;
27+ } ;
28+ } ;
2329} ) {
2430 const sendAndConfirmTransaction = useSendAndConfirmTransaction ( ) ;
2531
2632 async function handleClaim ( ) {
2733 const claimRewardsTx = claimReward ( {
2834 asset : props . assetContractClient . address ,
29- contract : props . rewardLockerContractClient ,
35+ contract : props . entrypointContractClient ,
3036 } ) ;
3137
3238 const claimRewardsResult = await tryCatch (
@@ -42,71 +48,66 @@ export function ClaimRewardsPage(props: {
4248 }
4349 }
4450
45- const unclaimedFeesQuery = useQuery ( {
46- queryKey : [
47- "get-unclaimed-fees" ,
48- {
49- positionManager : props . v3PositionManagerContractClient . address ,
50- reward : {
51- tokenId : props . reward . tokenId . toString ( ) ,
52- recipient : props . reward . recipient ,
53- } ,
54- } ,
55- ] ,
56- queryFn : async ( ) =>
57- getUnclaimedFees ( {
58- positionManager : props . v3PositionManagerContractClient ,
59- reward : {
60- tokenId : props . reward . tokenId ,
61- recipient : props . reward . recipient ,
62- } ,
63- } ) ,
51+ console . log ( {
52+ props,
6453 } ) ;
6554
66- // TODO: add proper UI
55+ return (
56+ < ClaimRewardsPageUI
57+ unclaimedFees = { props . unclaimedFees }
58+ recipient = { props . reward . recipient }
59+ referrer = { props . reward . referrer }
60+ handleClaim = { handleClaim }
61+ isClaimPending = { sendAndConfirmTransaction . isPending }
62+ client = { props . assetContractClient . client }
63+ />
64+ ) ;
65+ }
6766
67+ export function ClaimRewardsPageUI ( props : {
68+ unclaimedFees : {
69+ token0 : {
70+ address : string ;
71+ amount : bigint ;
72+ } ;
73+ token1 : {
74+ address : string ;
75+ amount : bigint ;
76+ } ;
77+ } ;
78+ recipient : string ;
79+ referrer : string ;
80+ handleClaim : ( ) => void ;
81+ isClaimPending : boolean ;
82+ client : ThirdwebClient ;
83+ } ) {
6884 return (
6985 < div >
7086 < h2 className = "font-semibold text-2xl tracking-tight mb-3" >
7187 Claim Rewards
7288 </ h2 >
7389
7490 < div className = "mb-4" >
75- { unclaimedFeesQuery . isPending && (
76- < div className = "flex items-center gap-2" >
77- < Spinner className = "size-4" />
78- Loading unclaimed fees
79- </ div >
80- ) }
81- { unclaimedFeesQuery . error && (
82- < div className = "text-red-500" >
83- Failed to load unclaimed fees { parseError ( unclaimedFeesQuery . error ) }
84- </ div >
85- ) }
86-
87- { unclaimedFeesQuery . data && (
88- < div className = "flex flex-col gap-2" >
89- < p >
90- Amount0: { unclaimedFeesQuery . data . token0 . amount } { " " }
91- { unclaimedFeesQuery . data . token0 . address }
92- </ p >
93- < p >
94- Amount1: { unclaimedFeesQuery . data . token1 . amount } { " " }
95- { unclaimedFeesQuery . data . token1 . address }
96- </ p >
97- </ div >
98- ) }
99-
91+ < div className = "flex flex-col gap-2" >
92+ < p >
93+ Amount0: { toTokens ( props . unclaimedFees . token0 . amount , 18 ) } { " " }
94+ { props . unclaimedFees . token0 . address }
95+ </ p >
96+ < p >
97+ Amount1: { toTokens ( props . unclaimedFees . token1 . amount , 18 ) } { " " }
98+ { props . unclaimedFees . token1 . address }
99+ </ p >
100+ </ div >
100101 < p > Recipient</ p >
101- < WalletAddress
102- address = { props . reward . recipient }
103- client = { props . assetContractClient . client }
104- />
102+ < WalletAddress address = { props . recipient } client = { props . client } />
103+
104+ < p > Referrer </ p >
105+ < WalletAddress address = { props . referrer } client = { props . client } />
105106 </ div >
106107
107- < Button onClick = { handleClaim } className = "gap-2" >
108+ < Button onClick = { props . handleClaim } className = "gap-2" >
108109 Claim Rewards
109- { sendAndConfirmTransaction . isPending ? (
110+ { props . isClaimPending ? (
110111 < Spinner className = "size-4" />
111112 ) : (
112113 < ArrowRightIcon className = "size-4" />
0 commit comments