Skip to content

Commit 5ad619d

Browse files
committed
clean up
1 parent d89556a commit 5ad619d

File tree

8 files changed

+76
-68
lines changed

8 files changed

+76
-68
lines changed

packages/browser-wallet/src/background/identity-issuance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createIdentityRequest, IdentityRequestInput } from '@concordium/web-sdk';
1+
import { createIdentityRequest } from '@concordium/web-sdk';
22
import { IdentityIssuanceBackgroundResponse } from '@shared/utils/identity-helpers';
33
import { ExtensionMessageHandler, InternalMessageType } from '@messaging';
44
import { BackgroundResponseStatus, IdentityIssuanceRequestPayload } from '@shared/utils/types';

packages/browser-wallet/src/popup/popupX/pages/IdIssuance/ExternalFlow.tsx

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback, useEffect } from 'react';
2-
import { Location, Navigate, useLocation, useNavigate } from 'react-router-dom';
2+
import { Location, useLocation, useNavigate } from 'react-router-dom';
33
import { useTranslation } from 'react-i18next';
4-
import { useAtom } from 'jotai';
4+
import { useSetAtom } from 'jotai';
55

66
import { InternalMessageType } from '@messaging';
77
import { absoluteRoutes } from '@popup/popupX/constants/routes';
@@ -20,9 +20,9 @@ import { IdIssuanceFailedLocationState } from './Failed';
2020
import { IdIssuanceExternalFlowLocationState } from './util';
2121

2222
export default function IdIssuanceExternalFlow() {
23-
const { state, pathname } = useLocation() as Location & { state: IdIssuanceExternalFlowLocationState | undefined };
23+
const { state } = useLocation() as Location & { state: IdIssuanceExternalFlowLocationState };
2424
const { t } = useTranslation('x', { keyPrefix: 'idIssuance.externalFlow' });
25-
const [pendingIdentity, updatePendingIdentity] = useAtom(pendingIdentityAtom);
25+
const updatePendingIdentity = useSetAtom(pendingIdentityAtom);
2626
const nav = useNavigate();
2727

2828
const handleError = useCallback(
@@ -36,7 +36,6 @@ export default function IdIssuanceExternalFlow() {
3636
const seedPhrase = useDecryptedSeedPhrase((e) => handleError(e.message));
3737

3838
const start = useCallback(async () => {
39-
if (state === undefined) throw new Error('Location state not available');
4039
if (seedPhrase === undefined) throw new Error('Seed phrase not available');
4140

4241
updatePendingIdentity(state.pendingIdentity);
@@ -61,34 +60,24 @@ export default function IdIssuanceExternalFlow() {
6160
logError('Failed to issue identity due to internal error');
6261
handleError('Internal error, please try again.');
6362
} else {
64-
nav(pathname, { state: undefined, replace: true }); // This ensures that when we navigate back, we don't try again automatically.
63+
nav(absoluteRoutes.settings.identities.path, { replace: true });
6564
}
6665
}, [state, seedPhrase, handleError]);
6766

6867
useEffect(() => {
69-
if (state !== undefined && seedPhrase !== undefined) {
68+
if (state !== null && seedPhrase !== undefined) {
7069
start();
7170
}
7271
}, [start]);
7372

74-
if (state === undefined) {
75-
return <Navigate to={absoluteRoutes.settings.identities.create.path} />;
76-
}
77-
7873
return (
7974
<Page>
8075
<Page.Top />
81-
{pendingIdentity === undefined ? (
82-
<Text.Capture className="text-center">{t('description')}</Text.Capture>
83-
) : (
84-
<Text.Capture className="text-center">{t('descriptionOngoing')}</Text.Capture>
85-
)}
76+
<Text.Capture className="text-center">{t('description')}</Text.Capture>
8677
<LoaderInline className="m-t-50 margin-center" />
87-
{pendingIdentity !== undefined && (
88-
<Page.Footer>
89-
<Button.Main label={t('buttonReset')} />
90-
</Page.Footer>
91-
)}
78+
<Page.Footer>
79+
<Button.Main label={t('buttonReset')} />
80+
</Page.Footer>
9281
</Page>
9382
);
9483
}

packages/browser-wallet/src/popup/popupX/pages/IdIssuance/Failed.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ export type IdIssuanceFailedLocationState = { message: string; backState?: IdIss
1313

1414
export default function IdIssuanceFailed() {
1515
const { t } = useTranslation('x', { keyPrefix: 'idIssuance.failed' });
16-
const { state } = useLocation() as Location & { state: IdIssuanceFailedLocationState | undefined };
16+
const { state } = useLocation() as Location & { state: IdIssuanceFailedLocationState };
1717
const nav = useNavigate();
1818

1919
const handleRetry = useCallback(() => {
20-
if (state?.backState !== undefined) {
20+
if (state.backState !== undefined) {
2121
nav(absoluteRoutes.settings.identities.create.externalFlow.path, { state: state.backState, replace: true });
2222
} else {
2323
nav(absoluteRoutes.settings.identities.create.path, { replace: true });
2424
}
25-
}, [state?.backState]);
26-
27-
if (state === undefined) throw new Error('Must specify "state.message" for route');
25+
}, [state.backState]);
2826

2927
return (
3028
<Page>
Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
1+
import { useAtom, useAtomValue } from 'jotai';
22
import React, { useCallback, useEffect, useState } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import { useNavigate } from 'react-router-dom';
@@ -11,26 +11,28 @@ import IdentityProviderIcon from '@popup/shared/IdentityProviderIcon';
1111
import { getIdentityProviders } from '@popup/shared/utils/wallet-proxy';
1212
import { identitiesAtom, identityProvidersAtom, pendingIdentityAtom } from '@popup/store/identity';
1313
import { grpcClientAtom, networkConfigurationAtom } from '@popup/store/settings';
14-
import { CreationStatus, IdentityProvider } from '@shared/storage/types';
15-
import { getGlobal, getNet } from '@shared/utils/network-helpers';
16-
import { IdIssuanceExternalFlowLocationState } from './ExternalFlow';
14+
import { CreationStatus, IdentityProvider, SessionPendingIdentity } from '@shared/storage/types';
15+
import { getGlobal } from '@shared/utils/network-helpers';
16+
import { logErrorMessage } from '@shared/utils/log-helpers';
17+
18+
import { IdIssuanceExternalFlowLocationState } from './util';
1719

1820
export default function IdIssuance() {
1921
const { t } = useTranslation('x', { keyPrefix: 'idIssuance.idIssuer' });
2022
const [providers, setProviders] = useAtom(identityProvidersAtom);
2123
const network = useAtomValue(networkConfigurationAtom);
2224
const identities = useAtomValue(identitiesAtom);
23-
const updatePendingIdentity = useSetAtom(pendingIdentityAtom);
2425
const client = useAtomValue(grpcClientAtom);
2526
const nav = useNavigate();
2627
const [buttonDisabled, setButtonDisabled] = useState(false);
28+
const [pendingIdentity, setPendingIdentity] = useAtom(pendingIdentityAtom);
2729

2830
useEffect(() => {
2931
// TODO: only load once per session?
3032
getIdentityProviders()
3133
.then(setProviders)
3234
// eslint-disable-next-line no-console
33-
.catch(() => console.error('Unable to update identity provider list')); // TODO: log error
35+
.catch(() => logErrorMessage('Unable to update identity provider list'));
3436
}, []);
3537

3638
const startIssuance = useCallback(
@@ -49,24 +51,20 @@ export default function IdIssuance() {
4951
0
5052
);
5153

52-
updatePendingIdentity({
54+
const identity: SessionPendingIdentity = {
5355
identity: {
5456
status: CreationStatus.Pending,
5557
index: identityIndex,
5658
name: `Identity ${identities.length + 1}`,
5759
providerIndex,
5860
},
5961
network,
60-
});
62+
};
6163

6264
const issuanceParams: IdIssuanceExternalFlowLocationState = {
63-
globalContext: global,
64-
ipInfo: provider.ipInfo,
65-
arsInfos: provider.arsInfos,
66-
net: getNet(network),
67-
identityIndex,
68-
arThreshold: Math.min(Object.keys(provider.arsInfos).length - 1, 255),
69-
baseUrl: provider.metadata.issuanceStart,
65+
global,
66+
provider,
67+
pendingIdentity: identity,
7068
};
7169
nav(absoluteRoutes.settings.identities.create.externalFlow.path, { state: issuanceParams });
7270
} catch {
@@ -79,20 +77,31 @@ export default function IdIssuance() {
7977
return (
8078
<Page>
8179
<Page.Top heading={t('title')} />
82-
<Text.Capture>{t('description')}</Text.Capture>
83-
<div className="m-t-20">
84-
{providers.map((p) => (
85-
<Button.Base
86-
className="id-issuance__issuer-btn"
87-
key={p.ipInfo.ipDescription.url}
88-
disabled={buttonDisabled}
89-
onClick={() => startIssuance(p)}
90-
>
91-
<IdentityProviderIcon provider={p} />
92-
<span>{p.metadata.display ?? p.ipInfo.ipDescription.name}</span>
93-
</Button.Base>
94-
))}
95-
</div>
80+
{pendingIdentity !== undefined ? (
81+
<Text.Capture>{t('descriptionOngoing')}</Text.Capture>
82+
) : (
83+
<Text.Capture>{t('description')}</Text.Capture>
84+
)}
85+
{pendingIdentity === undefined && (
86+
<div className="m-t-20">
87+
{providers.map((p) => (
88+
<Button.Base
89+
className="id-issuance__issuer-btn"
90+
key={p.ipInfo.ipDescription.url}
91+
disabled={buttonDisabled}
92+
onClick={() => startIssuance(p)}
93+
>
94+
<IdentityProviderIcon provider={p} />
95+
<span>{p.metadata.display ?? p.ipInfo.ipDescription.name}</span>
96+
</Button.Base>
97+
))}
98+
</div>
99+
)}
100+
{pendingIdentity !== undefined && (
101+
<Page.Footer>
102+
<Button.Main label={t('buttonReset')} onClick={() => setPendingIdentity(undefined)} />
103+
</Page.Footer>
104+
)}
96105
</Page>
97106
);
98107
}

packages/browser-wallet/src/popup/popupX/pages/IdIssuance/Submitted.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
import React, { useContext, useEffect } from 'react';
1+
import React from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { useAtomValue } from 'jotai';
4-
import { noOp } from 'wallet-common-helpers';
54

65
import Button from '@popup/popupX/shared/Button';
76
import { ConfirmedIdCard, RejectedIdCard, PendingIdCard } from '@popup/popupX/shared/IdCard';
87
import Page from '@popup/popupX/shared/Page';
98
import Text from '@popup/popupX/shared/Text';
109
import { identitiesAtomWithLoading } from '@popup/store/identity';
1110
import { CreationStatus } from '@shared/storage/types';
12-
import { fullscreenPromptContext } from '@popup/popupX/page-layouts/FullscreenPromptLayout';
1311
import { absoluteRoutes } from '@popup/popupX/constants/routes';
12+
import { isSpawnedWindow } from '@popup/shared/window-helpers';
13+
import { useNavigate } from 'react-router-dom';
1414

1515
export default function IdIssuanceSubmitted() {
1616
const { t } = useTranslation('x', { keyPrefix: 'idIssuance.submitted' });
1717
const { loading, value: identities } = useAtomValue(identitiesAtomWithLoading);
18-
const { setReturnLocation, withClose } = useContext(fullscreenPromptContext);
18+
const nav = useNavigate();
1919

20-
useEffect(() => {
21-
setReturnLocation(absoluteRoutes.settings.identities.path);
22-
}, [setReturnLocation]);
20+
const handleDone = () => {
21+
if (isSpawnedWindow) {
22+
window.close();
23+
} else {
24+
nav(absoluteRoutes.settings.identities.path, { replace: true });
25+
}
26+
};
2327

2428
if (loading) {
2529
return null;
@@ -37,7 +41,7 @@ export default function IdIssuanceSubmitted() {
3741
{identity.status === CreationStatus.Confirmed && <ConfirmedIdCard identity={identity} />}
3842
</div>
3943
<Page.Footer>
40-
<Button.Main className="m-t-20" label={t('buttonContinue')} onClick={withClose(noOp)} />
44+
<Button.Main className="m-t-20" label={t('buttonContinue')} onClick={handleDone} />
4145
</Page.Footer>
4246
</Page>
4347
);

packages/browser-wallet/src/popup/popupX/pages/IdIssuance/i18n/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const en = {
33
title: 'Request an identity',
44
description:
55
'The ID Documents (e.g. Passport pictures) that are used for the ID verification, are held exclusively by our trusted, third-party identity providers in their own off-chain records.\n\nChoose one of the identity providers below to request a Concordium Identity and create an account.',
6+
descriptionOngoing:
7+
'An identity issuance process is ongoing in the browser. Please follow the steps to complete the process for the identity provider.\n\nIf you wish to abort the flow, or try again, press "Reset" below.',
68
buttonContinue: 'Request Identity',
9+
buttonReset: 'Reset',
710
},
811
externalFlow: {
912
description:

packages/browser-wallet/src/popup/popupX/pages/MainPage/MainPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function MainPage({ credential }: MainPageProps) {
221221
case CreationStatus.Rejected:
222222
return <>Account Creation was rejected</>;
223223
default:
224-
throw new Error(`Unexpected status for credential: ${credential.status}`);
224+
throw new Error(`Unexpected status for credential`);
225225
}
226226
}
227227

packages/browser-wallet/src/popup/popupX/pages/prompts/EndIdentityIssuance.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ import { absoluteRoutes } from '@popup/popupX/constants/routes';
55
import { IdentityIssuanceBackgroundResponse } from '@shared/utils/identity-helpers';
66
import { BackgroundResponseStatus } from '@shared/utils/types';
77
import { useTranslation } from 'react-i18next';
8+
import { WalletEvent } from '@messaging';
89

910
export default function EndIdentityIssuance() {
10-
const { state } = useLocation() as Location & { state: IdentityIssuanceBackgroundResponse };
11+
const {
12+
state: { payload },
13+
} = useLocation() as Location & {
14+
state: WalletEvent & { payload: IdentityIssuanceBackgroundResponse };
15+
};
1116
const { t } = useTranslation('x', { keyPrefix: 'idIssuance.aborted' });
1217

13-
switch (state.status) {
18+
switch (payload.status) {
1419
case BackgroundResponseStatus.Success:
1520
return <Navigate to={absoluteRoutes.settings.identities.create.submitted.path} replace />;
1621
case BackgroundResponseStatus.Error:
1722
return (
1823
<Navigate
1924
to={absoluteRoutes.settings.identities.create.failed.path}
2025
replace
21-
state={{ message: state.reason }}
26+
state={{ message: payload.reason }}
2227
/>
2328
);
2429
case BackgroundResponseStatus.Aborted:

0 commit comments

Comments
 (0)