Skip to content

Commit f99b9f4

Browse files
committed
Only show valid IDs during account creation and text when none are valid
1 parent af41e86 commit f99b9f4

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

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

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import Page from '@popup/popupX/shared/Page';
33
import Text from '@popup/popupX/shared/Text';
44
import { useTranslation } from 'react-i18next';
@@ -10,9 +10,31 @@ import Button from '@popup/popupX/shared/Button';
1010
import { generatePath, useNavigate } from 'react-router-dom';
1111
import { absoluteRoutes } from '@popup/popupX/constants/routes';
1212

13+
/**
14+
* Get the valid identities, which is Identities that are confirmed by the ID provider and are not
15+
* expired.
16+
* This is not recomputed by change of current time, meaning the returned identities might become
17+
* expired over time.
18+
*/
19+
function useValidIdentities(): ConfirmedIdentity[] {
20+
const identities = useAtomValue(identitiesAtom);
21+
return useMemo(() => {
22+
const now = new Date();
23+
return identities.flatMap((id) => {
24+
if (id.status !== CreationStatus.Confirmed) {
25+
return [];
26+
}
27+
const validToDate = new Date(id.idObject.value.attributeList.validTo);
28+
if (validToDate < now) {
29+
return [];
30+
}
31+
return [id];
32+
});
33+
}, [identities]);
34+
}
35+
1336
export default function CreateAccount() {
1437
const { t } = useTranslation('x', { keyPrefix: 'createAccount' });
15-
const identities = useAtomValue(identitiesAtom);
1638
const nav = useNavigate();
1739
const navToCreateAccountConfirm = (identity: ConfirmedIdentity) => () =>
1840
nav(
@@ -21,35 +43,28 @@ export default function CreateAccount() {
2143
identityIndex: identity.index.toString(),
2244
})
2345
);
46+
const validIdentities = useValidIdentities();
47+
2448
return (
2549
<Page className="create-account-x">
2650
<Page.Top heading={t('selectIdentity')} />
2751
<Page.Main>
2852
<Text.MainRegular>{t('selectIdentityDescription')}</Text.MainRegular>
29-
{identities.map((id) => {
30-
switch (id.status) {
31-
case CreationStatus.Confirmed:
32-
return (
33-
<Button.Base
34-
className="id-card-button"
35-
key={`${id.providerIndex}:${id.index}`}
36-
onClick={navToCreateAccountConfirm(id)}
37-
>
38-
<ConfirmedIdCard
39-
identity={id}
40-
shownAttributes={['idDocType', 'idDocNo']}
41-
hideAccounts
42-
/>
43-
</Button.Base>
44-
);
45-
case CreationStatus.Pending:
46-
return null;
47-
case CreationStatus.Rejected:
48-
return null;
49-
default:
50-
return null;
51-
}
52-
})}
53+
{validIdentities.length === 0 ? (
54+
<p className="m-t-40">
55+
<Text.Capture>{t('noValidIdentities')}</Text.Capture>
56+
</p>
57+
) : (
58+
validIdentities.map((id) => (
59+
<Button.Base
60+
className="id-card-button"
61+
key={`${id.providerIndex}:${id.index}`}
62+
onClick={navToCreateAccountConfirm(id)}
63+
>
64+
<ConfirmedIdCard identity={id} shownAttributes={['idDocType', 'idDocNo']} hideAccounts />
65+
</Button.Base>
66+
))
67+
)}
5368
</Page.Main>
5469
</Page>
5570
);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const t = {
22
selectIdentity: 'Select an identity',
3+
noValidIdentities:
4+
'There are currently no confirmed and non-expired identities. Please issue a new identity first.',
35
selectIdentityDescription: `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. This means your ID data will not be share on-chain.
46
57
Which identity do you want to use to create the account?`,

0 commit comments

Comments
 (0)