From e0455d7b6ecb8a7b9f75d24ab8f8399307dfce62 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Fri, 20 Dec 2024 18:45:09 +0100 Subject: [PATCH] Namespace loading enhancement (#612) --- .../ui/src/components/modals/WalletConnectSigning.tsx | 8 +++++--- packages/ui/src/hooks/useWalletConnectNamespace.tsx | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/components/modals/WalletConnectSigning.tsx b/packages/ui/src/components/modals/WalletConnectSigning.tsx index 154c5bf1..cbbb36de 100644 --- a/packages/ui/src/components/modals/WalletConnectSigning.tsx +++ b/packages/ui/src/components/modals/WalletConnectSigning.tsx @@ -38,7 +38,7 @@ export interface SigningModalProps { const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModalProps) => { const { api, chainInfo } = useApi() - const { currentNamespace } = useGetWalletConnectNamespace() + const { currentNamespace, isLoading: isNamespaceLoading } = useGetWalletConnectNamespace() const [isSubmitting, setIsSubmitting] = useState(false) const { web3wallet } = useWalletConnect() const { @@ -84,13 +84,15 @@ const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModa }) useEffect(() => { + if (isNamespaceLoading) return + const requestedChainId = request.params.chainId if (requestedChainId !== currentNamespace) { setErrorMessage( - `Wrong selected network in Multix. Please reject, then select the correct network and resubmit the transaction. Request with namespace: ${requestedChainId}` + `Wrong selected network in Multix. Please reject, then select the correct network and resubmit the transaction. Current Namespace: ${currentNamespace}, Request with namespace: ${requestedChainId}` ) } - }, [currentNamespace, originAddress, request.params.chainId]) + }, [currentNamespace, isNamespaceLoading, originAddress, request.params.chainId]) const isCorrectMultiproxySelected = useMemo( () => diff --git a/packages/ui/src/hooks/useWalletConnectNamespace.tsx b/packages/ui/src/hooks/useWalletConnectNamespace.tsx index dc02166e..59fddc6b 100644 --- a/packages/ui/src/hooks/useWalletConnectNamespace.tsx +++ b/packages/ui/src/hooks/useWalletConnectNamespace.tsx @@ -4,6 +4,7 @@ import { useApi } from '../contexts/ApiContext' export const useGetWalletConnectNamespace = () => { const { client } = useApi() const [genesisHash, setGenesisHash] = useState('') + const [isLoading, setIsLoading] = useState(true) useEffect(() => { if (!client) return @@ -12,6 +13,7 @@ export const useGetWalletConnectNamespace = () => { .getChainSpecData() .then((data) => setGenesisHash(data.genesisHash)) .catch(console.error) + .finally(() => setIsLoading(false)) }, [client]) const genesisTruncated = useMemo(() => genesisHash.substring(2, 34), [genesisHash]) @@ -25,5 +27,5 @@ export const useGetWalletConnectNamespace = () => { [namespace] ) - return { currentNamespace: namespace, getAccountsWithNamespace } + return { currentNamespace: namespace, getAccountsWithNamespace, isLoading } }