mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* use smaller SVG for publishing test, siwtch to Buffer encoding/decoding * shorter NFT name & symbol * fix: fix small test svg * feat: first draft random wave svg generation * refactor: utilize join to remove unecessary ',' separator * feature: add gas cost estimation for nft artwork * refacotr: allow fillColor as array and adjust opacity * refactor: adjust random wave generation * refactor: change nft help text * refactor: trying tooltip for nft image info * feat: add custom algorithm to generate svg waves * fix: use text colors for nft form field svgs * refactor: code cleanup nft utils * refactor: improve readability * refactor: improve comment * refactor: (re)move comments, cleanup * refactor: remove console log * refactor: adjust default svg wave values & remove logging * refactor: tweak default SvgWave prop values * fix: svg preview with disconnected wallet * feat: show artwork gas fee estimation in user preferred currency * refactor: extract gas fee estimation logic to new component * cleanup: remove oceanWaves, remove d3 * icon visual weight tweak Co-authored-by: Luca Milanese <luca.milanese90@gmail.com> Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import React, { ReactElement, useEffect, useState } from 'react'
|
|
import { usePrices } from '@context/Prices'
|
|
import { useWeb3 } from '@context/Web3'
|
|
import useNftFactory from '@hooks/contracts/useNftFactory'
|
|
import { NftFactory } from '@oceanprotocol/lib'
|
|
import Conversion from '@shared/Price/Conversion'
|
|
import { generateNftCreateData, NftMetadata } from '@utils/nft'
|
|
|
|
const getEstGasFee = async (
|
|
address: string,
|
|
nftFactory: NftFactory,
|
|
nftMetadata: NftMetadata,
|
|
ethToOceanConversionRate: number
|
|
): Promise<string> => {
|
|
if (!address || !nftFactory || !nftMetadata || !ethToOceanConversionRate)
|
|
return
|
|
|
|
const { web3 } = nftFactory
|
|
const nft = generateNftCreateData(nftMetadata)
|
|
|
|
const gasPrice = await web3.eth.getGasPrice()
|
|
const gasLimit = await nftFactory?.estGasCreateNFT(address, nft)
|
|
const gasFeeEth = web3.utils.fromWei(
|
|
(+gasPrice * +gasLimit).toString(),
|
|
'ether'
|
|
)
|
|
const gasFeeOcean = (+gasFeeEth / +ethToOceanConversionRate).toString()
|
|
return gasFeeOcean
|
|
}
|
|
|
|
export default function TxFee({
|
|
nftMetadata
|
|
}: {
|
|
nftMetadata: NftMetadata
|
|
}): ReactElement {
|
|
const { accountId } = useWeb3()
|
|
const { prices } = usePrices()
|
|
const nftFactory = useNftFactory()
|
|
const [gasFee, setGasFee] = useState('')
|
|
|
|
useEffect(() => {
|
|
const calculateGasFee = async () =>
|
|
setGasFee(
|
|
await getEstGasFee(
|
|
accountId,
|
|
nftFactory,
|
|
nftMetadata,
|
|
(prices as any)?.eth
|
|
)
|
|
)
|
|
calculateGasFee()
|
|
}, [accountId, nftFactory, nftMetadata, prices])
|
|
|
|
return gasFee ? (
|
|
<p>
|
|
Gas fee estimation for this artwork
|
|
<Conversion price={gasFee} />
|
|
</p>
|
|
) : accountId ? (
|
|
<p>
|
|
An error occurred while estimating the gas fee for this artwork, please
|
|
try again.
|
|
</p>
|
|
) : (
|
|
<p>Please connect your wallet to get a gas fee estimate for this artwork</p>
|
|
)
|
|
}
|