Skip to content

Commit

Permalink
fix: hide data as fallback when not available
Browse files Browse the repository at this point in the history
  • Loading branch information
wellitongervickas committed Dec 9, 2023
1 parent 2373891 commit a536768
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export const BridgeButton = ({
register('bridgeFees')
})

console.log(!isERC721Approved || !isERC20Approved)

return (
<>
{!isConnected ? (
Expand All @@ -117,7 +119,9 @@ export const BridgeButton = ({
)}
</ul>
<Button
type={isERC721Approved ? 'submit' : 'button'}
type={
!isERC721Approved || !isERC20Approved ? 'button' : 'submit'
}
className='w-full'
size='lg'
onClick={
Expand All @@ -132,6 +136,8 @@ export const BridgeButton = ({
disabled ||
loading ||
isLoading ||
!erc721AddressField.length ||
!erc721TokenIdField ||
isERC721Loading ||
isERC20Loading
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,60 @@ export type UseBridgeFeesProps = {
ERC721TokenId: bigint
}

type GetPayloadProps = {
config?: Chain
targetEvmChainIdSettings?: EvmChainSettings
receiver?: string
originEvmChainId?: bigint
ERC721Address?: string
ERC721TokenId?: bigint
name?: string
symbol?: string
tokenURI?: string
}

const getPayload = ({
config,
targetEvmChainIdSettings,
receiver,
originEvmChainId,
ERC721Address,
ERC721TokenId,
name,
symbol,
tokenURI
}: GetPayloadProps) => {
const receiverFallback = ethers.isAddress(receiver)
? receiver
: ethers.ZeroAddress

const evmChainId = originEvmChainId || config?.id || 0n
const ERC721AddressFallback = ethers.isAddress(ERC721Address)
? ERC721Address
: ethers.ZeroAddress
const ERC721TokenIdFallback = ERC721TokenId || 0n

return {
toChain: targetEvmChainIdSettings?.nonEvmChainId,
receiver: targetEvmChainIdSettings?.adapter,
gasLimit: targetEvmChainIdSettings?.gasLimit,
data: coderUtils.abiCoder.encode(
['address', 'bytes', 'bytes'],
[
receiverFallback,
coderUtils.abiCoder.encode(
['uint256', 'address', 'uint256'],
[evmChainId, ERC721AddressFallback, ERC721TokenIdFallback]
),
coderUtils.abiCoder.encode(
['string', 'string', 'string'],
[name, symbol, tokenURI]
)
]
)
}
}

export const useBridgeFees = ({
destinationChain,
ERC721Address,
Expand Down Expand Up @@ -79,30 +133,6 @@ export const useBridgeFees = ({
const wrappedToken =
getWERC721ByOriginERC721AddressResult.data as ERC721Wrapped

const payload = {
toChain: targetEvmChainIdSettings?.nonEvmChainId,
receiver: targetEvmChainIdSettings?.adapter,
gasLimit: targetEvmChainIdSettings?.gasLimit,
data: coderUtils.abiCoder.encode(
['address', 'bytes', 'bytes'],
[
walletAddress || ethers.ZeroAddress,
coderUtils.abiCoder.encode(
['uint256', 'address', 'uint256'],
[
wrappedToken?.evmChainId || config.id || 0n,
ERC721Address || ethers.ZeroAddress,
ERC721TokenId || 0n
]
),
coderUtils.abiCoder.encode(
['string', 'string', 'string'],
[name, symbol, tokenURI]
)
]
)
}

const getFeeResult = useContractRead({
address: targetEvmChainIdSettings?.adapter as `0x${string}`,
abi: BASE_ADAPTER_ABI,
Expand All @@ -114,7 +144,19 @@ export const useBridgeFees = ({
ethers.isAddress(targetEvmChainIdSettings?.adapter) &&
targetEvmChainIdSettings?.isEnabled,
functionName: 'getFee',
args: [payload]
args: [
getPayload({
config,
targetEvmChainIdSettings,
receiver: walletAddress as string,
originEvmChainId: wrappedToken?.evmChainId,
ERC721Address,
ERC721TokenId,
name,
symbol,
tokenURI
})
]
})

return {
Expand Down

0 comments on commit a536768

Please sign in to comment.