diff --git a/nym-wallet/src/hooks/useCheckOwnership.ts b/nym-wallet/src/hooks/useCheckOwnership.ts index 1e68660cd6..911e3997e2 100644 --- a/nym-wallet/src/hooks/useCheckOwnership.ts +++ b/nym-wallet/src/hooks/useCheckOwnership.ts @@ -1,45 +1,52 @@ import { useCallback, useContext, useEffect, useState } from 'react' import { ClientContext } from '../context/main' -import { checkGatewayOwnership, checkMixnodeOwnership } from '../requests' -import { EnumNodeType, TNodeOwnership } from '../types' +import { checkGatewayOwnership, checkMixnodeOwnership, getPledgeInfo } from '../requests' +import { EnumNodeType, TNodeOwnership, PledgeData } from '../types' const initial = { hasOwnership: false, nodeType: undefined, + vestingPledge: undefined, } export const useCheckOwnership = () => { const { clientDetails } = useContext(ClientContext) + const [ownership, setOwnership] = useState(initial) - const [isLoading, setIsLoading] = useState(false) + const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState() const checkOwnership = useCallback(async () => { const status = {} as TNodeOwnership - setIsLoading(true) - try { - const ownsMixnode = await checkMixnodeOwnership() - const ownsGateway = await checkGatewayOwnership() - + const [ownsMixnode, ownsGateway] = await Promise.all([checkMixnodeOwnership(), checkGatewayOwnership()]) if (ownsMixnode) { status.hasOwnership = true status.nodeType = EnumNodeType.mixnode + status.vestingPledge = await getPledgeInfo({ + address: clientDetails?.client_address!, + type: EnumNodeType.mixnode, + }) } if (ownsGateway) { status.hasOwnership = true status.nodeType = EnumNodeType.gateway + status.vestingPledge = await getPledgeInfo({ + address: clientDetails?.client_address!, + type: EnumNodeType.gateway, + }) } setOwnership(status) } catch (e) { setError(e as string) - setIsLoading(false) setOwnership(initial) + } finally { + setIsLoading(false) } - }, []) + }, [clientDetails]) useEffect(() => { checkOwnership()