diff --git a/src/components/domains/BuyDomainButtons.tsx b/src/components/domains/BuyDomainButtons.tsx index 1bccaa5d3..18b20c41d 100644 --- a/src/components/domains/BuyDomainButtons.tsx +++ b/src/components/domains/BuyDomainButtons.tsx @@ -51,7 +51,7 @@ export const BuyByDotTxButton = ({ close, price, }: BuyByDotTxButtonProps) => { - const { recipient, purchaser, setDomainToFetch, setProcessingDomains } = useManageDomainContext() + const { recipient, purchaser, setDomainToFetch, setProcessingDomain } = useManageDomainContext() const sellerConfig = useSelectSellerConfig() const dispatch = useAppDispatch() const myAddress = useMyAddress() @@ -115,7 +115,7 @@ export const BuyByDotTxButton = ({ const onSuccess = async () => { setDomainToFetch(domainName) - setProcessingDomains({ [domainName]: true }) + setProcessingDomain(true) close() } @@ -152,7 +152,7 @@ export const BuyByDotTxButton = ({ }) if (preventTx) { - setProcessingDomains({ [domainName]: false }) + setProcessingDomain(false) } else { await updatePendingOrder({ domain: domainName, @@ -218,7 +218,7 @@ export const BuyDomainSection = ({ price, }: BuyDomainSectionProps) => { const reloadMyDomains = useCreateReloadMyDomains() - const { openManageModal, setProcessingDomains, recipient } = useManageDomainContext() + const { openManageModal, setProcessingDomain, recipient } = useManageDomainContext() const { api, isApiReady } = useSubstrate() const reloadPendingOrders = useCreateReloadPendingOrders() const { purchaser } = useManageDomainContext() @@ -241,7 +241,7 @@ export const BuyDomainSection = ({ reloadMyDomains() - setProcessingDomains({ [domainName]: false }) + setProcessingDomain(false) await pendingOrderAction({ action: deletePendingOrder, @@ -260,7 +260,7 @@ export const BuyDomainSection = ({ log.error('Failed:', jsonErr) errorInfo && showErrorMessage(jsonErr) - setProcessingDomains({ [domainName]: false }) + setProcessingDomain(false) } const onClick = async () => { @@ -268,7 +268,7 @@ export const BuyDomainSection = ({ const { sellerApiAuthTokenManager } = sellerConfig - setProcessingDomains({ [domainName]: true }) + setProcessingDomain(true) if (pendingOrder) { await pendingOrderAction({ @@ -296,7 +296,7 @@ export const BuyDomainSection = ({ }) if (preventTx) { - setProcessingDomains({ [domainName]: false }) + setProcessingDomain(false) } else { await updatePendingOrder({ domain: domainName, diff --git a/src/components/domains/manage/ManageDomainProvider.tsx b/src/components/domains/manage/ManageDomainProvider.tsx index b37f9b4fb..37fc065fa 100644 --- a/src/components/domains/manage/ManageDomainProvider.tsx +++ b/src/components/domains/manage/ManageDomainProvider.tsx @@ -19,8 +19,8 @@ type ManageDomainProviderState = { setPurchaser: (recipient: string) => void domainToFetch?: string setDomainToFetch: (domainToFetch?: string) => void - processingDomains: Record - setProcessingDomains: (processingDomains: Record) => void + processingDomain: boolean + setProcessingDomain: (processingDomain: boolean) => void } export type DomainSellerKind = 'SUB' | 'DOT' @@ -37,7 +37,7 @@ export const ManageDomainProvider: React.FC<{ promoCode?: string }> = ({ childre const [recipient, setRecipient] = useState(myAddress || '') const [purchaser, setPurchaser] = useState(myAddress || '') const [domainToFetch, setDomainToFetch] = useState() - const [processingDomains, setProcessingDomains] = useState>({}) + const [processingDomain, setProcessingDomain] = useState(false) useEffect(() => { if (!myAddress) return @@ -80,9 +80,8 @@ export const ManageDomainProvider: React.FC<{ promoCode?: string }> = ({ childre setPurchaser, domainToFetch, setDomainToFetch, - processingDomains, - setProcessingDomains: (newData: Record) => - setProcessingDomains({ ...processingDomains, ...newData }), + processingDomain, + setProcessingDomain: (processingDomain: boolean) => setProcessingDomain(processingDomain), } return ( diff --git a/src/components/domains/pendingOrders/index.tsx b/src/components/domains/pendingOrders/index.tsx index e6bf0b09e..9a8a90f90 100644 --- a/src/components/domains/pendingOrders/index.tsx +++ b/src/components/domains/pendingOrders/index.tsx @@ -1,7 +1,6 @@ import { InfoCircleOutlined } from '@ant-design/icons' import { isEmptyArray, SubDate } from '@subsocial/utils' -import { Space, Tag, Tooltip } from 'antd' -import clsx from 'clsx' +import { Space, Tooltip } from 'antd' import dayjs from 'dayjs' import { useEffect, useMemo, useState } from 'react' import { useMyAddress } from 'src/components/auth/MyAccountsContext' @@ -13,7 +12,7 @@ import { import { PendingDomainEntity } from 'src/rtk/features/domainPendingOrders/pendingOrdersSlice' import { useSelectSellerConfig } from 'src/rtk/features/sellerConfig/sellerConfigHooks' import { MutedDiv } from '../../utils/MutedText' -import { DomainSellerKind, useManageDomainContext } from '../manage/ManageDomainProvider' +import { DomainSellerKind } from '../manage/ManageDomainProvider' import RegisterDomainButton from '../registerDomainModal/RegisterDomainModal' import { getTime, useGetDomainPrice } from '../utils' import styles from './Index.module.sass' @@ -31,8 +30,6 @@ const PendingDomain = ({ pendingDomain, time }: PendingDomainProps) => { const myAddress = useMyAddress() const { price: domainPrice, loading: loadingPrice } = useGetDomainPrice(pendingDomain.id) - const { processingDomains } = useManageDomainContext() - const { id, timestamp, destination, purchaseInterrupted, signer } = pendingDomain const { dmnRegPendingOrderExpTime } = sellerConfig || {} @@ -46,13 +43,7 @@ const PendingDomain = ({ pendingDomain, time }: PendingDomainProps) => { return SubDate.formatDate(expiresAtValue) }, [time]) - const isDomainProcessing = processingDomains[pendingDomain.id] - - const registerButton = isDomainProcessing ? ( - - Processing - - ) : ( + const registerButton = ( !!purchaseTxStarted) + const isSomePurchaseInerrupted = pendingOrders.some( + ({ purchaseInterrupted }) => !!purchaseInterrupted, + ) useEffect(() => { - if (purchaseTxStarted && !purchaseInterrupted) { + if (isSomePurchaseTxStarted && !isSomePurchaseInerrupted) { setDomainToFetch(domainName) } - }, [purchaseTxStarted]) + }, [isSomePurchaseTxStarted]) const [open, setOpen] = useState(false) const { decimal, symbol } = useGetDecimalAndSymbol(sellerChain) @@ -201,11 +207,7 @@ const RegisterDomainButton = ({ const chainProps = isSub ? {} : { decimals: decimal, currency: symbol } const disableRegisterButton = - processingDomains[domainName] || - loadingPrice || - price === '0' || - !myAddress || - purchaseTxStarted + processingDomain || loadingPrice || price === '0' || !myAddress || isSomePurchaseTxStarted const priceValue = withPrice && (
{price ? : <>-}
diff --git a/src/components/domains/utils.tsx b/src/components/domains/utils.tsx index f9184764d..24d3b176e 100644 --- a/src/components/domains/utils.tsx +++ b/src/components/domains/utils.tsx @@ -134,7 +134,7 @@ const waitMessage = controlledMessage({ export const useFetchNewDomains = () => { const myAddress = useMyAddress() - const { setDomainToFetch, domainToFetch, openManageModal, setProcessingDomains } = + const { setDomainToFetch, domainToFetch, openManageModal, setProcessingDomain } = useManageDomainContext() const upsertDomains = useCreateUpsertDomains() const removePendingOrder = useCreateRemovePendingOrders() @@ -160,7 +160,7 @@ export const useFetchNewDomains = () => { setDomainToFetch(undefined) removePendingOrder({ domainName: domainToFetch }) - setProcessingDomains({ [domainToFetch]: false }) + setProcessingDomain(false) upsertDomains({ domain: domainEntity, address: myAddress, domainName: domainToFetch }) waitMessage.close() openManageModal('success', domainToFetch)