import React from "react"; import { Modal, Text, VStack, HStack, Button, Center, Divider } from "native-base"; import { BigNumber, utils } from "ethers"; interface BridgeSuccessModalProps { open: boolean; onClose: () => void; data: { bridgeProvider: string; sourceChain: string; targetChain: string; amount: string; protocolFeePercent?: number; networkFee?: BigNumber; txHash?: string; }; onTrackTransaction: () => void; } export const BridgeSuccessModal = ({ open, onClose, data, onTrackTransaction }: BridgeSuccessModalProps) => { const { bridgeProvider, sourceChain, targetChain, amount, protocolFeePercent = 0, networkFee = BigNumber.from(0) } = data; const amountBN = BigNumber.from(amount || "0"); const amountFormatted = utils.formatEther(amountBN); const protocolFeeBN = amountBN.mul(Math.floor(protocolFeePercent * 10000)).div(10000); const protocolFeeFormatted = utils.formatEther(protocolFeeBN); const networkFeeFormatted = utils.formatEther(networkFee); const totalFeesBN = protocolFeeBN.add(networkFee); const totalFeesFormatted = utils.formatEther(totalFeesBN); const receiveAmountBN = amountBN.sub(totalFeesBN); const receiveFormatted = utils.formatEther(receiveAmountBN.lt(0) ? 0 : receiveAmountBN); return (
Transaction Submitted! Your bridging transaction via {capitalize(bridgeProvider)} is being processed. You Have Bridged G$ {capitalize(sourceChain)} {formatCurrency(amountFormatted)} You Will Receive (Est.) G$ {capitalize(targetChain)} {formatCurrency(receiveFormatted)} Total Fees G$ {formatCurrency(totalFeesFormatted)} Bridge Fee ({(protocolFeePercent * 100).toFixed(2)}%) {formatCurrency(protocolFeeFormatted)} G$ Network Fee {formatCurrency(networkFeeFormatted)} G$ The transaction may take a few minutes to complete. You can close this window.
); }; const formatCurrency = (val: string) => { return Number(val).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }; const capitalize = (s: string) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : "");