11// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
22// SPDX-License-Identifier: Apache-2.0
33
4- import React , { FC , useMemo , useState } from 'react' ;
4+ import React , { FC , useEffect , useMemo , useState } from 'react' ;
55import { AiOutlineInfoCircle } from 'react-icons/ai' ;
6+ import { gql , useLazyQuery , useQuery } from '@apollo/client' ;
67import IPFSImage from '@components/IPFSImage' ;
78import { ApproveContract } from '@components/ModalApproveToken' ;
89import { NumberInput } from '@components/NumberInput' ;
@@ -15,6 +16,7 @@ import { useAddAllowance } from '@hooks/useAddAllowance';
1516import { useWaitTransactionhandled } from '@hooks/useWaitTransactionHandled' ;
1617import { Modal , openNotification , Spinner , Steps , Tag , Typography } from '@subql/components' ;
1718import { useGetDeploymentBoosterTotalAmountByDeploymentIdQuery } from '@subql/react-hooks' ;
19+ import { ProjectType } from '@subql/react-hooks/dist/graphql' ;
1820import { cidToBytes32 , parseError , TOKEN } from '@utils' ;
1921import { formatNumber , formatSQT } from '@utils/numberFormatters' ;
2022import { Button , Form , Radio , Tooltip } from 'antd' ;
@@ -28,6 +30,7 @@ import { useWeb3Store } from 'src/stores';
2830import styles from './index.module.less' ;
2931
3032interface IProps {
33+ projectType ?: ProjectType ;
3134 projectId ?: string ;
3235 deploymentId ?: string ;
3336 actionBtn ?: React . ReactNode ;
@@ -37,6 +40,7 @@ interface IProps {
3740}
3841
3942const DoBooster : FC < IProps > = ( {
43+ projectType,
4044 projectId,
4145 deploymentId,
4246 actionBtn,
@@ -63,6 +67,26 @@ const DoBooster: FC<IProps> = ({
6367 fetchPolicy : 'network-only' ,
6468 } ) ;
6569
70+ const [ getAverageBooster , averageBooster ] = useLazyQuery < {
71+ deploymentBoosterSummaries : {
72+ aggregates : {
73+ average : {
74+ totalAmount : string ;
75+ } ;
76+ } ;
77+ } ;
78+ } > ( gql `
79+ {
80+ deploymentBoosterSummaries(filter: { project: { type: { equalTo: ${ project . data ?. type } } } }) {
81+ aggregates {
82+ average {
83+ totalAmount
84+ }
85+ }
86+ }
87+ }
88+ ` ) ;
89+
6690 const [ open , setOpen ] = useState ( initialOpen ) ;
6791 const [ loading , setLoading ] = useState ( false ) ;
6892 const [ addOrRemove , setAddOrRemove ] = useState < 'add' | 'remove' > ( initAddOrRemove ) ;
@@ -141,6 +165,14 @@ const DoBooster: FC<IProps> = ({
141165 }
142166 } ;
143167
168+ useEffect ( ( ) => {
169+ if ( open && project . data ) {
170+ getAverageBooster ( ) ;
171+ }
172+ } , [ open , project . data ] ) ;
173+
174+ console . warn ( averageBooster . data ) ;
175+
144176 return (
145177 < div className = { styles . doBooster } >
146178 { actionBtn ? (
@@ -253,7 +285,7 @@ const DoBooster: FC<IProps> = ({
253285
254286 < div >
255287 < Form layout = "vertical" form = { form } >
256- < Typography > Boost amount</ Typography >
288+ < Typography > Boost amount </ Typography >
257289 < Form . Item
258290 style = { { marginBottom : 0 } }
259291 name = "boostVal"
@@ -291,6 +323,18 @@ const DoBooster: FC<IProps> = ({
291323 } }
292324 > </ NumberInput >
293325 </ Form . Item >
326+ { balance . result . data ?. eq ( 0 ) ? (
327+ < Typography . Link
328+ href = "https://subquery.network/doc/subquery_network/token/token.html#where-is-sqt-traded"
329+ type = "info"
330+ variant = "small"
331+ style = { { transform : 'translateY(-10px)' } }
332+ >
333+ Get SQT
334+ </ Typography . Link >
335+ ) : (
336+ ''
337+ ) }
294338 </ Form >
295339 < div className = "col-flex" style = { { gap : 8 , marginBottom : 24 } } >
296340 < div className = "flex" >
@@ -338,6 +382,36 @@ const DoBooster: FC<IProps> = ({
338382 { TOKEN }
339383 </ Typography >
340384 </ div >
385+
386+ < div className = "flex" >
387+ < Typography variant = "medium" type = "secondary" style = { { display : 'flex' , alignItems : 'center' } } >
388+ Average Booster
389+ < Tooltip title = "The total amount that you can freely boost to new projects." >
390+ < AiOutlineInfoCircle
391+ style = { { fontSize : 14 , marginLeft : 6 , color : 'var(--sq-gray500)' } }
392+ > </ AiOutlineInfoCircle >
393+ </ Tooltip >
394+ </ Typography >
395+ < span style = { { flex : 1 } } > </ span >
396+ < Typography variant = "medium" >
397+ { averageBooster . loading ? (
398+ < Spinner size = { 10 } > </ Spinner >
399+ ) : (
400+ < Tooltip
401+ title = { formatSQT (
402+ averageBooster . data ?. deploymentBoosterSummaries . aggregates . average . totalAmount || '0' ,
403+ { fixedNum : 18 } ,
404+ ) }
405+ >
406+ { formatSQT (
407+ averageBooster . data ?. deploymentBoosterSummaries . aggregates . average . totalAmount || '0' ,
408+ { fixedNum : 2 } ,
409+ ) }
410+ </ Tooltip >
411+ ) } { ' ' }
412+ { TOKEN }
413+ </ Typography >
414+ </ div >
341415 </ div >
342416 </ div >
343417 </ >
0 commit comments