@@ -2,7 +2,9 @@ import { useRouter } from 'next/router'
22import { ReactNode , useMemo , useState } from 'react'
33import { twMerge } from 'tailwind-merge'
44
5+ import useAppAdvancedSettings from '@/application/common/useAppAdvancedSettings'
56import useAppSettings from '@/application/common/useAppSettings'
7+ import useConnection from '@/application/connection/useConnection'
68import txCreateAndInitNewPool from '@/application/createPool/txCreateAndInitNewPool'
79import { updateCreatePoolInfo } from '@/application/createPool/updateCreatePoolInfo'
810import useCreatePool from '@/application/createPool/useCreatePool'
@@ -23,14 +25,16 @@ import Link from '@/components/Link'
2325import PageLayout from '@/components/PageLayout'
2426import Row from '@/components/Row'
2527import SetpIndicator from '@/components/SetpIndicator'
28+ import Tooltip from '@/components/Tooltip'
2629import copyToClipboard from '@/functions/dom/copyToClipboard'
2730import { toTokenAmount } from '@/functions/format/toTokenAmount'
2831import { isMeaningfulNumber , lte } from '@/functions/numberish/compare'
2932import { div } from '@/functions/numberish/operations'
3033import { toString } from '@/functions/numberish/toString'
34+ import useAsyncMemo from '@/hooks/useAsyncMemo'
3135import useToggle from '@/hooks/useToggle'
36+ import { Liquidity , struct , u64 } from '@raydium-io/raydium-sdk'
3237import { getMaxBalanceBNIfNotATA } from '../../application/token/getMaxBalanceIfNotATA'
33- import Tooltip from '@/components/Tooltip'
3438
3539/**
3640 * @see https://uiwjs.github.io/#/components/date-input
@@ -125,6 +129,7 @@ function PanelContent({ close }: { close(): void }) {
125129 const haveEnoughCoinQuote = quoteAmount && quoteTokenBalance && lte ( quoteAmount , quoteTokenBalance )
126130
127131 const [ priceReverse , { toggle } ] = useToggle ( )
132+ const solCost = useCreatePoolSOLCost ( )
128133
129134 const step2Content = (
130135 < >
@@ -180,8 +185,8 @@ function PanelContent({ close }: { close(): void }) {
180185 onDateChange = { ( selectedDate ) => useCreatePool . setState ( { startTime : selectedDate } ) }
181186 showTime = { { format : 'HH:mm:ss' } }
182187 />
183- { /* <Row className="text-xs font-medium text-[#D6CC56] bg-[#D6CC5620] py-3 px-4 rounded-xl mb-5">
184- A creation fee of X.XX SOL is required for new pools
188+ < Row className = "text-xs font-medium text-[#D6CC56] bg-[#D6CC5620] py-3 px-4 rounded-xl mb-5" >
189+ A creation fee of { solCost ?? '--' } SOL is required for new pools
185190 < Tooltip >
186191 < Icon iconClassName = "ml-1" size = "sm" heroIconName = "information-circle" />
187192 < Tooltip . Panel >
@@ -191,7 +196,7 @@ function PanelContent({ close }: { close(): void }) {
191196 </ div >
192197 </ Tooltip . Panel >
193198 </ Tooltip >
194- </Row> */ }
199+ </ Row >
195200
196201 < Button
197202 className = "frosted-glass-teal w-full"
@@ -440,3 +445,27 @@ function UserCreatedPoolsExhibitionPanel() {
440445 </ div >
441446 )
442447}
448+
449+ /**
450+ * async hook
451+ * used in sol cost alert
452+ * @author Rudy
453+ */
454+ function useCreatePoolSOLCost ( ) : number | undefined {
455+ const programIds = useAppAdvancedSettings ( ( s ) => s . programIds )
456+ const connection = useConnection ( ( s ) => s . connection )
457+ const cost = useAsyncMemo ( async ( ) => {
458+ const data = (
459+ await connection ?. getAccountInfo ( Liquidity . getAssociatedConfigId ( { programId : programIds . AmmV4 } ) , {
460+ dataSlice : { offset : 536 , length : 8 }
461+ } )
462+ ) ?. data
463+ return data
464+ ? struct ( [ u64 ( 'fee' ) ] )
465+ . decode ( data )
466+ . fee . toNumber ( ) /
467+ 10 ** 9
468+ : undefined
469+ } , [ connection , programIds . AmmV4 ] )
470+ return cost
471+ }
0 commit comments