11import { LiquidityPool } from '@interlay/interbtc-api' ;
22import Big from 'big.js' ;
3- import { useEffect , useRef , useState } from 'react' ;
3+ import { useEffect , useState } from 'react' ;
44import { useTranslation } from 'react-i18next' ;
55
66import { formatUSD } from '@/common/utils/utils' ;
7- import { Card , CTA , Dl , DlGroup , Flex , Modal , ModalBody , ModalFooter , ModalHeader } from '@/component-library' ;
8- import {
9- AuthCTA ,
10- TransactionDetails ,
11- TransactionDetailsDd ,
12- TransactionDetailsDt ,
13- TransactionDetailsGroup ,
14- TransactionFeeDetails
15- } from '@/components' ;
7+ import { Card , Dl , DlGroup } from '@/component-library' ;
168import { AccountPoolsData } from '@/hooks/api/amm/use-get-account-pools' ;
179import { useGetPrices } from '@/hooks/api/use-get-prices' ;
1810import { Transaction , useTransaction } from '@/hooks/transaction' ;
19- import { isTransactionFormDisabled } from '@/hooks/transaction/utils/form' ;
2011import {
2112 ClaimRewardsPoolFormData ,
2213 claimRewardsPoolSchema ,
@@ -26,7 +17,6 @@ import {
2617import { calculateAccountLiquidityUSD , calculateTotalLiquidityUSD } from '@/utils/helpers/pool' ;
2718
2819import { StyledDd , StyledDt } from './PoolsInsights.style' ;
29- import { calculateClaimableFarmingRewardUSD } from './utils' ;
3020
3121type PoolsInsightsProps = {
3222 pools : LiquidityPool [ ] ;
@@ -38,7 +28,6 @@ const PoolsInsights = ({ pools, accountPoolsData, refetch }: PoolsInsightsProps)
3828 const { t } = useTranslation ( ) ;
3929 const prices = useGetPrices ( ) ;
4030 const [ isOpen , setOpen ] = useState ( false ) ;
41- const overlappingModalRef = useRef < HTMLDivElement > ( null ) ;
4231
4332 const transaction = useTransaction ( Transaction . AMM_CLAIM_REWARDS , {
4433 onSuccess : refetch ,
@@ -72,8 +61,6 @@ const PoolsInsights = ({ pools, accountPoolsData, refetch }: PoolsInsightsProps)
7261 // eslint-disable-next-line react-hooks/exhaustive-deps
7362 } , [ isOpen ] ) ;
7463
75- const handleCloseModal = ( ) => setOpen ( false ) ;
76-
7764 const accountPositions = accountPoolsData ?. positions ;
7865
7966 const supplyAmountUSD = accountPositions ?. reduce ( ( acc , curr ) => {
@@ -97,75 +84,21 @@ const PoolsInsights = ({ pools, accountPoolsData, refetch }: PoolsInsightsProps)
9784
9885 const totalLiquidityUSD = formatUSD ( totalLiquidity ?. toNumber ( ) || 0 , { compact : true } ) ;
9986
100- const totalClaimableRewardUSD = calculateClaimableFarmingRewardUSD ( accountPoolsData ?. claimableRewards , prices ) ;
101- const totalClaimableRewardUSDLabel = formatUSD ( totalClaimableRewardUSD , { compact : true } ) ;
102-
103- const handleClickClaimRewards = ( ) => setOpen ( true ) ;
104-
105- const hasClaimableRewards = totalClaimableRewardUSD > 0 ;
106-
107- const isBtnDisabled = isTransactionFormDisabled ( form , transaction . fee ) ;
108-
10987 return (
110- < >
111- < Dl wrap direction = 'row' >
112- < Card flex = '1' >
113- < DlGroup direction = 'column' alignItems = 'flex-start' gap = 'spacing1' >
114- < StyledDt color = 'primary' > { t ( 'supply_balance' ) } </ StyledDt >
115- < StyledDd color = 'secondary' > { supplyBalanceLabel } </ StyledDd >
116- </ DlGroup >
117- </ Card >
118- < Card flex = '1' >
119- < DlGroup direction = 'column' alignItems = 'flex-start' gap = 'spacing1' >
120- < StyledDt color = 'primary' > { t ( 'total_liquidity' ) } </ StyledDt >
121- < StyledDd color = 'secondary' > { totalLiquidityUSD } </ StyledDd >
122- </ DlGroup >
123- </ Card >
124- < Card direction = 'row' flex = '1' gap = 'spacing2' alignItems = 'center' justifyContent = 'space-between' >
125- < DlGroup direction = 'column' alignItems = 'flex-start' gap = 'spacing1' >
126- < StyledDt color = 'primary' > { t ( 'rewards' ) } </ StyledDt >
127- < StyledDd color = 'secondary' > { totalClaimableRewardUSDLabel } </ StyledDd >
128- </ DlGroup >
129- { hasClaimableRewards && (
130- < CTA onPress = { handleClickClaimRewards } loading = { transaction . isLoading } >
131- Claim
132- </ CTA >
133- ) }
134- </ Card >
135- </ Dl >
136- < Modal
137- isOpen = { isOpen }
138- onClose = { handleCloseModal }
139- // does not close overlapped modal when overlapping modal is closed
140- shouldCloseOnInteractOutside = { ( el ) => ! overlappingModalRef . current ?. contains ( el ) }
141- >
142- < ModalHeader > Claim Rewards</ ModalHeader >
143- < ModalBody >
144- < TransactionDetails >
145- < TransactionDetailsGroup >
146- < TransactionDetailsDt > Amount</ TransactionDetailsDt >
147- < TransactionDetailsDd > { totalClaimableRewardUSDLabel } </ TransactionDetailsDd >
148- </ TransactionDetailsGroup >
149- </ TransactionDetails >
150- </ ModalBody >
151- < ModalFooter >
152- < form onSubmit = { form . handleSubmit } >
153- < Flex direction = 'column' gap = 'spacing4' >
154- < TransactionFeeDetails
155- fee = { transaction . fee }
156- selectProps = { {
157- ...form . getSelectFieldProps ( POOL_CLAIM_REWARDS_FEE_TOKEN_FIELD ) ,
158- modalRef : overlappingModalRef
159- } }
160- />
161- < AuthCTA type = 'submit' size = 'large' disabled = { isBtnDisabled } >
162- { t ( 'claim_rewards' ) }
163- </ AuthCTA >
164- </ Flex >
165- </ form >
166- </ ModalFooter >
167- </ Modal >
168- </ >
88+ < Dl wrap direction = 'row' >
89+ < Card flex = '1' >
90+ < DlGroup direction = 'column' alignItems = 'flex-start' gap = 'spacing1' >
91+ < StyledDt color = 'primary' > { t ( 'supply_balance' ) } </ StyledDt >
92+ < StyledDd color = 'secondary' > { supplyBalanceLabel } </ StyledDd >
93+ </ DlGroup >
94+ </ Card >
95+ < Card flex = '1' >
96+ < DlGroup direction = 'column' alignItems = 'flex-start' gap = 'spacing1' >
97+ < StyledDt color = 'primary' > { t ( 'total_liquidity' ) } </ StyledDt >
98+ < StyledDd color = 'secondary' > { totalLiquidityUSD } </ StyledDd >
99+ </ DlGroup >
100+ </ Card >
101+ </ Dl >
169102 ) ;
170103} ;
171104
0 commit comments