Bid Form Component

The BidForm component provides the user interface for creating and managing bids:

// src/features/dAppHub/EpochStakeAuction/Bid/bid-form.tsx
// Main component for the stake auction bidding interface
export const BidForm = ({
  bidId,
  currentScreen = "bid",
}: {
  bidId: string | undefined;
  currentScreen?: "bid" | "adjustBid";
}) => {
  // Component implementation details
  const dispatch = useAppDispatch();
  const stakeAuctionBidResponse = useAppSelector(selectStakeAuctionBidResponse);
  const cancelStakeAuctionBidResponse = useAppSelector(selectCancelStakeAuctionBidResponse)

  // State management for form inputs
  const [orderType, setOrderType] = useState<OrderType>("market");
  const [limitOrderType, setLimitOrderType] = useState<LimitOrderType>("partialFill");
  const [currencyChoice, setCurrencyChoice] = useState<CurrencyChoice>("ada");

  // Market order state
  const [marketOrderState, setMarketOrderState] = useState<MarketOrderState>({
    totalReservesLovelace: Big(0),
    stakedReservesLovelace: Big(0),
    timeIntervalIndex: Big(0),
    minBidLovelace: initialMinBidLovelace,
    maxBidLovelace: initialMaxBidLovelace,
    minBidApy: initialMinBidApy,
    maxBidApy: initialMaxBidApy,
    minBidRequestedStakeLovelace: initialMinBidRequestedStakeLovelace,
    maxBidRequestedStakeLovelace: initialMaxBidRequestedStakeLovelace,
    bidLovelace: initialBidLovelace,
    bidApy: initialBidApy,
    bidRequestedStakeLovelace: initialBidRequestedStakeLovelace,
  });

  // Handler for bid submission
  const handleBidNow = () => {
    if (bidApy === undefined || bidLovelace.lte(0)) {
      return;
    }

    let bidType: BidType | undefined = undefined
    if (orderType === "market") {
      bidType = "BidTypePartial"
    } else {
      if (limitOrderType === "fillOrKill") {
        bidType = "BidTypeFull"
      } else {
        bidType = "BidTypePartial"
      }
    }
    if (bidType === undefined) {
      return;
    }

    let bidValue: GYValueOut | undefined = undefined
    const bidAmountRounded = bidLovelace.round(0, Big.roundDown)
    if (currencyChoice === "ada") {
      bidValue = {
        lovelace: BigInt(bidAmountRounded.toString())
      }
    } else {
      bidValue = {
        lovelace: 1500000n,
        [`${oadaNetwork.oadaPolicyId}.${oadaNetwork.oadaTokenName}`]: BigInt(bidAmountRounded.sub(1500000).toString())
      }
    }

    if (bidValue === undefined) {
      return;
    }

    dispatch(stakeAuctionBid({
      bidType,
      bidApy,
      bidValue,
      stakeAddressBech32: stakeAddress
    })).then(() => dispatch(getOadaFrontendInfo))
  }

  // Handler for bid cancellation
  const handleCancel = () => bidId && dispatch(cancelStakeAuctionBid({bidId}))

  // Component render logic
  return (
    // JSX implementation
  );
};

Last updated