import { Button, Collapse, Input, Row, Tooltip, Typography } from 'antd' import TextArea from 'antd/lib/input/TextArea' import BigNumber from 'bignumber.js' import { ethers } from 'ethers' import { Sdk } from 'etherspot' import { useState } from 'react' import { useOffsetCarbonExecutor } from '../../hooks/Etherspot/offsetCarbonExecutor' import { useBeneficiaryInfo, useSetBeneficiaryInfo, } from '../../providers/ToSectionCarbonOffsetProvider' import { ChainId, CoinKey, ExtendedRouteOptional, findDefaultToken } from '../../types' import LoadingIndicator from '../LoadingIndicator' import { MinimalEtherspotStep } from '../SwappingEtherspot/StepRenderers/MinimalStepRenderers/MinimalEtherspotStep' const { Panel } = Collapse const TOKEN_POLYGON_USDC = findDefaultToken(CoinKey.USDC, ChainId.POL) interface Props { etherSpotSDK: Sdk residualRoute: ExtendedRouteOptional etherspotWalletBalance: BigNumber setResidualRoute: Function setEtherspotWalletBalance: Function } export const ResidualRouteCarbonOffsetModal = ({ etherSpotSDK, residualRoute, etherspotWalletBalance, setEtherspotWalletBalance, setResidualRoute, }: Props) => { const [isSwapping, setIsSwapping] = useState(false) const { etherspotStepExecution, executeEtherspotStep, resetEtherspotExecution, handlePotentialEtherSpotError, finalizeEtherSpotExecution, } = useOffsetCarbonExecutor() // chains const setBeneficiaryInfo = useSetBeneficiaryInfo() const beneficiaryInfo = useBeneficiaryInfo() const stakeResidualFunds = async () => { setIsSwapping(true) try { finalizeEtherSpotExecution( await executeEtherspotStep( etherSpotSDK!, residualRoute!.gasStep!, residualRoute!.stakingStep!, ethers.utils .parseUnits(etherspotWalletBalance?.toString()!, TOKEN_POLYGON_USDC.decimals) .toString(), ), residualRoute!.stakingStep!.estimate.toAmountMin, ) } catch (e) { // eslint-disable-next-line no-console console.warn(e) setIsSwapping(false) handlePotentialEtherSpotError(e, residualRoute!) } } return ( <> You still have {etherspotWalletBalance.toFixed(2)} USDC in your smart contract based wallet, do you want to swap and offset carbon using the Toucan Protocol: Base Carbon Tonne (BCT)?
{MinimalEtherspotStep({ etherspotStepExecution, stakingStep: residualRoute?.stakingStep, isSwapping: isSwapping, index: 0, previousStepInfo: { amount: etherspotWalletBalance.shiftedBy(TOKEN_POLYGON_USDC.decimals).toString(), token: TOKEN_POLYGON_USDC, }, })}
setBeneficiaryInfo({ ...beneficiaryInfo, beneficiaryName: event.currentTarget.value, }) } style={{ color: 'rgba(0, 0, 0, 0.85)', fontWeight: '400' }} /> setBeneficiaryInfo({ ...beneficiaryInfo, beneficiaryAddress: event.currentTarget.value, }) } style={{ color: 'rgba(0, 0, 0, 0.85)', fontWeight: '400' }} />