<commit_before>import { StakeyBounce } from "indicators";
import StakePools from "./LEGACY_StakePools/StakePoolsList";
import Tickets from "./LEGACY_Tickets";
import { useLegacyPurchasePage } from "./hooks";
import { EnableExternalRequestButton } from "buttons";
import { ExternalLink } from "shared";
import { EXTERNALREQUEST_STAKEPOOL_LISTING } from "main_dev/externalRequests";
import { FormattedMessage as T } from "react-intl";
import StakePoolsAddForm from "./LEGACY_AddForm";
import styles from "./PurchasePage.module.css";

const StakepoolListingDisabled = React.memo(() => (
  <div>
    <p>
      <T
        id="stake.enableStakePoolListing.description"
        m="VSP listing from external API endpoint is currently disabled. Please enable the access to this third party service or manually configure the VSP."
      />
    </p>
    <EnableExternalRequestButton
      requestType={EXTERNALREQUEST_STAKEPOOL_LISTING}>
      <T id="stake.enableStakePoolListing.button" m="Enable VSP Listing" />
    </EnableExternalRequestButton>
  </div>
));

const NoAvailableStakepools = React.memo(() => (
  <T
    id="stake.noAvailableStakepools"
    m="No VSP found. Check your internet connection or {link} to see if the VSP API is down."
    values={{
      link: (
        <ExternalLink
          href="https://api.decred.org/?c=gsd"
          className={styles.stakepoolLink}>
          <T id="stake.discoverStakeOoolsAPILink" m="this link" />
        </ExternalLink>
      )
    }}
  />
));

const PurchasePage = ({
  isShowingVsp,
  toggleShowVsp,
  toggleIsLegacy,
  ...props
}) => {
  const {
    onShowAddStakePool,
    toggleBackupModal,
    getNoAvailableStakepools,
    getStakepoolListingEnabled,
    getIsAdding,
    showModal,
    onRemoveStakePool,
    configuredStakePools,
    rescanRequest,
    selectedUnconfigured,
    unconfiguredStakePools,
    apiKey,
    isSavingStakePoolConfig,
    onChangeSelectedUnconfigured,
    onChangeApiKey,
    onSetStakePoolInfo,
    onCancelAddStakePool,
    hasFailedAttempt,
    addCustomStakePool,
    onEnableTicketAutoBuyer,
    onDisableTicketAutoBuyer,
    isTicketAutoBuyerEnabled,
    notMixedAccounts,
    getRunningIndicator,
    isPurchasingTickets
  } = useLegacyPurchasePage(toggleShowVsp);
  return getNoAvailableStakepools && !getStakepoolListingEnabled() ? (
    <StakepoolListingDisabled />
  ) : getNoAvailableStakepools ? (
    <NoAvailableStakepools />
  ) : isPurchasingTickets ? (
    <StakeyBounce center />
  ) : getIsAdding ? (
    <StakePoolsAddForm
      {...{
        selectedUnconfigured,
        unconfiguredStakePools,
        configuredStakePools,
        apiKey,
        isSavingStakePoolConfig,
        onChangeSelectedUnconfigured,
        onChangeApiKey,
        onSetStakePoolInfo,
        onCancelAddStakePool,
        hasFailedAttempt,
        toggleIsLegacy,
        addCustomStakePool
      }}
    />
  ) : isShowingVsp ? (
    <StakePools
      {...{
        configuredStakePools,
        onRemoveStakePool,
        showModal,
        toggleShowVsp,
        toggleBackupModal,
        onShowAddStakePool,
        rescanRequest,
        ...props<commit_msg>[tickets] Add legacy VSP toggle to empty state page. (#3408)<commit_after>import { FormattedMessage as T } from "react-intl";
import { Checkbox } from "pi-ui";
import { StakeyBounce } from "indicators";
import StakePools from "./LEGACY_StakePools/StakePoolsList";
import Tickets from "./LEGACY_Tickets";
import { useLegacyPurchasePage } from "./hooks";
import { EnableExternalRequestButton } from "buttons";
import { ExternalLink } from "shared";
import { EXTERNALREQUEST_STAKEPOOL_LISTING } from "main_dev/externalRequests";
import StakePoolsAddForm from "./LEGACY_AddForm";
import styles from "./PurchasePage.module.css";

const StakepoolListingDisabled = React.memo(() => (
  <div>
    <p>
      <T
        id="stake.enableStakePoolListing.description"
        m="VSP listing from external API endpoint is currently disabled. Please enable the access to this third party service or manually configure the VSP."
      />
    </p>
    <EnableExternalRequestButton
      requestType={EXTERNALREQUEST_STAKEPOOL_LISTING}>
      <T id="stake.enableStakePoolListing.button" m="Enable VSP Listing" />
    </EnableExternalRequestButton>
  </div>
));

const NoAvailableStakepools = React.memo(({ toggleIsLegacy }) => (
  <>
    <T
      id="stake.noAvailableStakepools"
      m="No VSP found. Check your internet connection or {link} to see if the VSP API is down."
      values={{
        link: (
          <ExternalLink
            href="https://api.decred.org/?c=gsd"
            className={styles.stakepoolLink}>
            <T id="stake.discoverStakeOoolsAPILink" m="this link" />
          </ExternalLink>
        )
      }}
    />
    <Checkbox
      className="margin-top-m"
      label={<T id="stake.isLegacy" m="Use Legacy VSP" />}
      id="box"
      checked={true}
      onChange={() => toggleIsLegacy(false)}
    />
  </>
));

const PurchasePage = ({
  isShowingVsp,
  toggleShowVsp,
  toggleIsLegacy,
  ...props
}) => {
  const {
    onShowAddStakePool,
    toggleBackupModal,
    getNoAvailableStakepools,
    getStakepoolListingEnabled,
    getIsAdding,
    showModal,
    onRemoveStakePool,
    configuredStakePools,
    rescanRequest,
    selectedUnconfigured,
    unconfiguredStakePools,
    apiKey,
    isSavingStakePoolConfig,
    onChangeSelectedUnconfigured,
    onChangeApiKey,
    onSetStakePoolInfo,
    onCancelAddStakePool,
    hasFailedAttempt,
    addCustomStakePool,
    onEnableTicketAutoBuyer,
    onDisableTicketAutoBuyer,
    isTicketAutoBuyerEnabled,
    notMixedAccounts,
    getRunningIndicator,
    isPurchasingTickets
  } = useLegacyPurchasePage(toggleShowVsp);
  return getNoAvailableStakepools && !getStakepoolListingEnabled() ? (
    <StakepoolListingDisabled />
  ) : getNoAvailableStakepools ? (
    <NoAvailableStakepools toggleIsLegacy={toggleIsLegacy} />
  ) : isPurchasingTickets ? (
    <StakeyBounce center />
  ) : getIsAdding ? (
    <StakePoolsAddForm
      {...{
        selectedUnconfigured,
        unconfiguredStakePools,
        configuredStakePools,
        apiKey,
        isSavingStakePoolConfig,
        onChangeSelectedUnconfigured,
        onChangeApiKey,
        onSetStakePoolInfo,
        onCancelAddStakePool,
        hasFailedAttempt,
        toggleIsLegacy,
        addCustomStakePool
      }}
    />
  ) : isShowingVsp ? (
    <StakePools
      {...{
        configuredStakePools,
        onRemoveStakePool,
        showModal,
        toggleShowVsp,
        toggleBackupModal,
        onShowAddStakePool,
        rescanRequest,
        ...props
{'fraction_non_alphanumeric': 0.09549549549549549, 'fraction_numerical': 0.0006006006006006006, 'mean_word_length': 3.074006116207951, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 46, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '379483', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2130, 'n_words': 385}