Skip to content

Commit

Permalink
feat: added Error for RequestProgress
Browse files Browse the repository at this point in the history
  • Loading branch information
Codetrauma committed Feb 17, 2025
1 parent 1c9f340 commit c088d30
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/entries/Background/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export enum RequestProgress {
SendingRequest,
ReadingTranscript,
FinalizingOutputs,
Error,
}

export function progressText(progress: RequestProgress): string {
Expand All @@ -183,6 +184,8 @@ export function progressText(progress: RequestProgress): string {
return 'Reading request transcript...';
case RequestProgress.FinalizingOutputs:
return 'Finalizing notarization outputs...';
case RequestProgress.Error:
return 'Notarization Failed';
}
}

Expand Down
45 changes: 24 additions & 21 deletions src/entries/Offscreen/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,32 +451,35 @@ async function createProver(options: {

const hostname = urlify(url)?.hostname || '';
const notary = NotaryServer.from(notaryUrl);
try {
updateRequestProgress(id, RequestProgress.CreatingProver);
const prover: TProver = await new Prover({
id,
serverDns: hostname,
maxSentData,
maxRecvData,
});

updateRequestProgress(id, RequestProgress.CreatingProver);
const prover: TProver = await new Prover({
id,
serverDns: hostname,
maxSentData,
maxRecvData,
});

updateRequestProgress(id, RequestProgress.GettingSession);
const sessionUrl = await notary.sessionUrl(maxSentData, maxRecvData);
updateRequestProgress(id, RequestProgress.GettingSession);
const sessionUrl = await notary.sessionUrl(maxSentData, maxRecvData);

updateRequestProgress(id, RequestProgress.SettingUpProver);
await prover.setup(sessionUrl);
updateRequestProgress(id, RequestProgress.SettingUpProver);
await prover.setup(sessionUrl);

updateRequestProgress(id, RequestProgress.SendingRequest);
await prover.sendRequest(websocketProxyUrl + `?token=${hostname}`, {
url,
method,
headers,
body,
});
updateRequestProgress(id, RequestProgress.SendingRequest);
await prover.sendRequest(websocketProxyUrl + `?token=${hostname}`, {
url,
method,
headers,
body,
});

return prover;
return prover;
} catch (error: any) {
updateRequestProgress(id, RequestProgress.Error);
throw error;
}
}

async function verifyProof(
proof: PresentationJSON,
): Promise<{ sent: string; recv: string }> {
Expand Down
14 changes: 8 additions & 6 deletions src/entries/SidePanel/SidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,14 @@ function StepContent(
<button className="button mt-2 w-fit flex flex-row flex-nowrap items-center gap-2 cursor-default">
<Icon className="animate-spin" fa="fa-solid fa-spinner" size={1} />
<span className="text-sm">
{notaryRequest?.progress
? `(${(
((notaryRequest.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(notaryRequest.progress)}`
: 'Pending...'}
{notaryRequest?.progress === 6
? 'Error: Notarization Failed'
: notaryRequest?.progress
? `(${(
((notaryRequest.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(notaryRequest.progress)}`
: 'Pending...'}
</span>
</button>
);
Expand Down
20 changes: 9 additions & 11 deletions src/pages/History/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React, { ReactElement, useState, useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { useNavigate } from 'react-router';
import {
useHistoryOrder,
useRequestHistory,
deleteRequestHistory,
} from '../../reducers/history';
import { useHistoryOrder, useRequestHistory } from '../../reducers/history';
import Icon from '../../components/Icon';
import NotarizeIcon from '../../assets/img/notarize.png';
import { getNotaryApi, getProxyApi } from '../../utils/storage';
Expand Down Expand Up @@ -110,12 +106,14 @@ export function OneRequestHistory(props: {
size={1}
/>
<span className="">
{request?.progress
? `(${(
((request.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(request.progress)}`
: 'Pending...'}
{request?.progress === 6
? 'Error: Notarization Failed'
: request?.progress
? `(${(
((request.progress + 1) / 6.06) *
100
).toFixed()}%) ${progressText(request.progress)}`
: 'Pending...'}
</span>
</div>
)}
Expand Down

0 comments on commit c088d30

Please sign in to comment.