Skip to content

Commit

Permalink
refactor(request): extract xChain checking on pay view
Browse files Browse the repository at this point in the history
  • Loading branch information
jjramirezn committed Oct 4, 2024
1 parent 8ffef14 commit 5487afc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/components/Request/Pay/Views/Initial.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const InitialView = ({
selectedTokenData,
setSelectedChainID,
setSelectedTokenAddress,
isXChain,
setIsXChain,
} = useContext(context.tokenSelectorContext)
const [errorState, setErrorState] = useState<{
Expand Down Expand Up @@ -69,10 +70,7 @@ export const InitialView = ({
const estimateTxFee = async () => {

setLinkState(RequestStatus.LOADING)
if (
selectedTokenData!.chainId === requestLinkData.chainId
&& utils.areTokenAddressesEqual(selectedTokenData!.tokenAddress, requestLinkData.tokenAddress)
) {
if (!isXChain) {
setErrorState({ showError: false, errorMessage: '' })
setIsFeeEstimationError(false)
setLinkState(RequestStatus.CLAIM)
Expand Down Expand Up @@ -144,10 +142,7 @@ export const InitialView = ({
try {
setErrorState({ showError: false, errorMessage: '' })
if (!unsignedTx) return
if (
selectedTokenData!.chainId === requestLinkData.chainId
&& utils.areTokenAddressesEqual(selectedTokenData!.tokenAddress, requestLinkData.tokenAddress)
){
if (!isXChain){
await checkUserHasEnoughBalance({ tokenValue: requestLinkData.tokenAmount })
if (selectedTokenData?.chainId !== String(currentChain?.id)) {
await switchNetwork(selectedTokenData!.chainId)
Expand Down Expand Up @@ -328,12 +323,10 @@ export const InitialView = ({
<label className="font-bold">Network cost</label>
</div>
<label className="flex flex-row items-center justify-center gap-1 text-center text-sm font-normal leading-4">
{requestLinkData.chainId === selectedTokenData?.chainId &&
requestLinkData.tokenAddress === selectedTokenData?.tokenAddress
{!isXChain
? `$${utils.formatTokenAmount(estimatedGasCost, 3) ?? 0}`
: `$${txFee}`}
{requestLinkData.chainId === selectedTokenData?.chainId &&
requestLinkData.tokenAddress === selectedTokenData?.tokenAddress ? (
{!isXChain ? (
<MoreInfo
text={
estimatedGasCost && estimatedGasCost > 0
Expand Down

0 comments on commit 5487afc

Please sign in to comment.