diff --git a/src/components/domains/BuyDomainButtons.tsx b/src/components/domains/BuyDomainButtons.tsx index b21327264..51d570ff9 100644 --- a/src/components/domains/BuyDomainButtons.tsx +++ b/src/components/domains/BuyDomainButtons.tsx @@ -51,8 +51,7 @@ export const BuyByDotTxButton = ({ close, price, }: BuyByDotTxButtonProps) => { - const { recipient, purchaser, setIsFetchNewDomains, setProcessingDomains } = - useManageDomainContext() + const { recipient, purchaser, setDomainToFetch, setProcessingDomains } = useManageDomainContext() const sellerConfig = useSelectSellerConfig() const dispatch = useAppDispatch() const myAddress = useMyAddress() @@ -115,7 +114,7 @@ export const BuyByDotTxButton = ({ } const onSuccess = async () => { - setIsFetchNewDomains(true) + setDomainToFetch(domainName) setProcessingDomains({ [domainName]: true }) close() diff --git a/src/components/domains/index.tsx b/src/components/domains/index.tsx index a09000279..1473394ee 100644 --- a/src/components/domains/index.tsx +++ b/src/components/domains/index.tsx @@ -32,7 +32,7 @@ const DomainMarketSection = ({ promoCode }: DomainServerProps) => { const myAddress = useMyAddress() const { domains } = useMyDomains() const { api, isApiReady, subsocial } = useSubstrate() - useFetchNewDomains(domain?.id) + useFetchNewDomains() const onSearchDomain = async (domain?: string) => { if (!domain) return diff --git a/src/components/domains/manage/ManageDomainProvider.tsx b/src/components/domains/manage/ManageDomainProvider.tsx index b8520f71c..b37f9b4fb 100644 --- a/src/components/domains/manage/ManageDomainProvider.tsx +++ b/src/components/domains/manage/ManageDomainProvider.tsx @@ -17,8 +17,8 @@ type ManageDomainProviderState = { setRecipient: (recipient: string) => void purchaser: string setPurchaser: (recipient: string) => void - isFetchNewDomains: boolean - setIsFetchNewDomains: (isFetchNewDomains: boolean) => void + domainToFetch?: string + setDomainToFetch: (domainToFetch?: string) => void processingDomains: Record setProcessingDomains: (processingDomains: Record) => void } @@ -36,15 +36,15 @@ export const ManageDomainProvider: React.FC<{ promoCode?: string }> = ({ childre const [domainSellerKind, setVariant] = useState('SUB') const [recipient, setRecipient] = useState(myAddress || '') const [purchaser, setPurchaser] = useState(myAddress || '') - const [isFetchNewDomains, setIsFetchNewDomains] = useState(false) + const [domainToFetch, setDomainToFetch] = useState() const [processingDomains, setProcessingDomains] = useState>({}) useEffect(() => { - if(!myAddress) return + if (!myAddress) return setRecipient(myAddress) setPurchaser(myAddress) - }, [ myAddress]) + }, [myAddress]) const router = useRouter() const [activePromoCode, setActivePromoCode] = useState(promoCode) @@ -78,8 +78,8 @@ export const ManageDomainProvider: React.FC<{ promoCode?: string }> = ({ childre clearPromoCode, purchaser, setPurchaser, - isFetchNewDomains, - setIsFetchNewDomains, + domainToFetch, + setDomainToFetch, processingDomains, setProcessingDomains: (newData: Record) => setProcessingDomains({ ...processingDomains, ...newData }), diff --git a/src/components/domains/utils.tsx b/src/components/domains/utils.tsx index e6bd1cc7d..42155ba36 100644 --- a/src/components/domains/utils.tsx +++ b/src/components/domains/utils.tsx @@ -132,17 +132,16 @@ const waitMessage = controlledMessage({ icon: , }) -export const useFetchNewDomains = (domainName?: string) => { +export const useFetchNewDomains = () => { const myAddress = useMyAddress() - const { setIsFetchNewDomains, isFetchNewDomains, openManageModal, setProcessingDomains } = + const { setDomainToFetch, domainToFetch, openManageModal, setProcessingDomains } = useManageDomainContext() const upsertDomains = useCreateUpsertDomains() const removePendingOrder = useCreateRemovePendingOrders() useSubsocialEffect( ({ substrate }) => { - setIsFetchNewDomains(false) - if (!myAddress || !isFetchNewDomains || !domainName) return + if (!myAddress || !domainToFetch || !domainToFetch) return let unsub: any @@ -150,20 +149,21 @@ export const useFetchNewDomains = (domainName?: string) => { const api = await (await substrate.api).isReady waitMessage.open() - unsub = await api.query.domains.registeredDomains(domainName, data => { + unsub = await api.query.domains.registeredDomains(domainToFetch, data => { const domain = data.unwrapOr(undefined) if (domain) { const domainEntity = { - id: domainName, + id: domainToFetch, ...(domain as unknown as DomainStruct), } - upsertDomains({ domain: domainEntity, address: myAddress, domainName }) - removePendingOrder({ domainName }) - setProcessingDomains({ [domainName]: false }) + setDomainToFetch(undefined) + upsertDomains({ domain: domainEntity, address: myAddress, domainName: domainToFetch }) + removePendingOrder({ domainName: domainToFetch }) + setProcessingDomains({ [domainToFetch]: false }) waitMessage.close() - openManageModal('success', domainName) + openManageModal('success', domainToFetch) } }) } @@ -172,7 +172,7 @@ export const useFetchNewDomains = (domainName?: string) => { return () => unsub && unsub() }, - [isFetchNewDomains, myAddress], + [domainToFetch, myAddress], ) }