import { useQuery } from '@tanstack/react-query'
import { OpenOceanService } from '../services/OpenOceanService.js'
import { useSettings } from '../stores/settings/useSettings.js'

const gasKey: any = {
  slow: 'standard',
  normal: 'instant',
  fast: 'fast',
}
export const useGasPrice = (chainName: string) => {
  const { gasPrice } = useSettings(['gasPrice'])
  const { data, isLoading } = useQuery({
    queryKey: ['gasPrice'],
    queryFn: () => OpenOceanService.getGasPrice(chainName.toLowerCase()),
  })
  const _gasPrice = data?.[gasKey[gasPrice || 'Normal']]
  return {
    gasPrice: _gasPrice && _gasPrice.maxFeePerGas,
    isLoading,
  }
}
