Skip to content

Commit

Permalink
fixed sonarcloud issues
Browse files Browse the repository at this point in the history
Signed-off-by: wadeking98 <[email protected]>
  • Loading branch information
wadeking98 committed Jul 29, 2024
1 parent 5bae6a0 commit 2edf41d
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions app/src/screens/PersonCredentialLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function PersonCredentialLoading() {
const timer = useRef<NodeJS.Timeout>()
const logger = useContainer().resolve(TOKENS.UTIL_LOGGER)
const receivedCredentialOffers = useCredentialByState(CredentialState.OfferReceived)
const { loading: attestationLoading } = useAttestation ? useAttestation() : { loading: false }
const { loading: attestationLoading } = useAttestation()
const { agent } = useAgent()
if (!agent) {
throw new Error('Unable to fetch agent from Credo')
Expand Down Expand Up @@ -80,36 +80,36 @@ export default function PersonCredentialLoading() {
},
})

useEffect(() => {
connectToIASAgent(agent, store, t)
.then((remoteAgentDetails: WellKnownAgentDetails) => {
setRemoteAgentDetails(remoteAgentDetails)
const connect = async () => {
try {
const remoteAgentDetails = await connectToIASAgent(agent, store, t)
setRemoteAgentDetails(remoteAgentDetails)
logger.error(`Connected to IAS agent, connectionId: ${remoteAgentDetails.connectionId}`)
} catch (err) {
logger.error(`Failed to connect to IAS agent, error: ${(err as BifoldError).message}`)
}
}

timer.current = setTimeout(() => {
if (!remoteAgentDetails || !remoteAgentDetails.connectionId) {
return
}
useEffect(() => {
connect()
}, [])

const proofRequest = receivedProofRequests.find(
(proof) => proof.connectionId === remoteAgentDetails.connectionId
)
useEffect(() => {
if (!remoteAgentDetails) {
return
}

if (!proofRequest) {
// No proof from our IAS Agent to respond to, do nothing.
logger.info(
`Waited ${attestationProofRequestWaitTimeout / 1000}sec on attestation proof request, continuing`
)
timer.current = setTimeout(() => {
const proofRequest = receivedProofRequests.find((proof) => proof.connectionId === remoteAgentDetails.connectionId)

setDidCompleteAttestationProofRequest(true)
}
}, attestationProofRequestWaitTimeout)
if (!proofRequest) {
// No proof from our IAS Agent to respond to, do nothing.
logger.info(`Waited ${attestationProofRequestWaitTimeout / 1000}sec on attestation proof request, continuing`)

logger.error(`Connected to IAS agent, connectionId: ${remoteAgentDetails?.connectionId}`)
})
.catch((error) => {
logger.error(`Failed to connect to IAS agent, error: ${error.message}`)
})
}, [])
setDidCompleteAttestationProofRequest(true)
}
}, attestationProofRequestWaitTimeout)
}, [remoteAgentDetails, receivedProofRequests])

// Use this function to accept the attestation proof request.
const acceptAttestationProofRequest = async (agent: BifoldAgent, proofRequest: ProofExchangeRecord) => {
Expand Down Expand Up @@ -212,17 +212,13 @@ export default function PersonCredentialLoading() {
.catch((error) => {
logger.error('Completed service card authentication with error, error: ', error.message)
})
}, [remoteAgentDetails, didCompleteAttestationProofRequest])
}, [remoteAgentDetails, didCompleteAttestationProofRequest, store.developer.environment.iasPortalUrl])

useEffect(() => {
if (!remoteAgentDetails || !remoteAgentDetails.connectionId) {
return
}

for (const credential of receivedCredentialOffers) {
if (
credential.state == CredentialState.OfferReceived &&
credential.connectionId === remoteAgentDetails.connectionId
credential.connectionId === remoteAgentDetails?.connectionId
) {
goToCredentialOffer(credential.id)
}
Expand Down

0 comments on commit 2edf41d

Please sign in to comment.