Skip to content

Commit f4482e9

Browse files
authored
Merge branch 'develop' into dependabot/npm_and_yarn/develop/ledgerhq/hw-transport-webhid-6.30.0
2 parents 5429ad4 + 7bbc809 commit f4482e9

File tree

7 files changed

+49
-14
lines changed

7 files changed

+49
-14
lines changed

e2e-tests/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ export const NEW_VALIDATOR_FOR_SIGNATURE_REQUEST = {
9999
};
100100

101101
export const VALIDATOR_FOR_STAKE = {
102+
publicKey:
103+
'0106ca7c39cd272dbf21a86eeb3b36b7c26e2e9b94af64292419f7862936bca2ca',
104+
truncatedPublicKey: '0106...a2ca'
105+
};
106+
107+
export const VALIDATOR_FOR_UNDELEGATE = {
102108
publicKey:
103109
'01f340df2c32f25391e8f7924a99e93cab3a6f230ff7af1cacbfc070772cbebd94',
104110
truncatedPublicKey: '01f3...bd94'

e2e-tests/popup/stakes/redelagation.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
NEW_VALIDATOR_FOR_STAKE,
33
RPC_RESPONSE,
44
URLS,
5-
VALIDATOR_FOR_STAKE
5+
VALIDATOR_FOR_UNDELEGATE
66
} from '../../constants';
77
import { popup, popupExpect } from '../../fixtures';
88

@@ -28,11 +28,11 @@ popup.describe('Popup UI: Redelegation', () => {
2828

2929
await popupPage
3030
.getByPlaceholder('Validator public address', { exact: true })
31-
.fill(VALIDATOR_FOR_STAKE.publicKey);
31+
.fill(VALIDATOR_FOR_UNDELEGATE.publicKey);
3232

3333
await new Promise(r => setTimeout(r, 2000));
3434
await popupPage
35-
.getByText(VALIDATOR_FOR_STAKE.truncatedPublicKey, { exact: true })
35+
.getByText(VALIDATOR_FOR_UNDELEGATE.truncatedPublicKey, { exact: true })
3636
.click();
3737

3838
await popupPage.getByRole('button', { name: 'Next' }).click();
@@ -72,7 +72,7 @@ popup.describe('Popup UI: Redelegation', () => {
7272
).toBeDisabled();
7373

7474
await popupExpect(
75-
popupPage.getByText(VALIDATOR_FOR_STAKE.publicKey)
75+
popupPage.getByText(VALIDATOR_FOR_UNDELEGATE.publicKey)
7676
).toBeVisible();
7777

7878
await popupExpect(

e2e-tests/popup/stakes/undelegate.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RPC_RESPONSE, URLS, VALIDATOR_FOR_STAKE } from '../../constants';
1+
import { RPC_RESPONSE, URLS, VALIDATOR_FOR_UNDELEGATE } from '../../constants';
22
import { popup, popupExpect } from '../../fixtures';
33

44
popup.describe('Popup UI: Undelegation', () => {
@@ -22,7 +22,7 @@ popup.describe('Popup UI: Undelegation', () => {
2222
await new Promise(r => setTimeout(r, 2000));
2323

2424
await popupPage
25-
.getByText(VALIDATOR_FOR_STAKE.truncatedPublicKey, { exact: true })
25+
.getByText(VALIDATOR_FOR_UNDELEGATE.truncatedPublicKey, { exact: true })
2626
.click();
2727

2828
await popupPage.getByRole('button', { name: 'Next' }).click();
@@ -36,7 +36,7 @@ popup.describe('Popup UI: Undelegation', () => {
3636
await popupPage.getByRole('button', { name: 'Next' }).click();
3737

3838
await popupExpect(
39-
popupPage.getByText(VALIDATOR_FOR_STAKE.publicKey)
39+
popupPage.getByText(VALIDATOR_FOR_UNDELEGATE.publicKey)
4040
).toBeVisible();
4141

4242
// Scroll to the bottom

src/apps/popup/pages/add-contact/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { SuccessScreen } from '@popup/pages/add-contact/success-screen';
77
import { RouterPath, useTypedLocation, useTypedNavigate } from '@popup/router';
88

99
import { newContactAdded } from '@background/redux/contacts/actions';
10-
import { selectAllContactsNames } from '@background/redux/contacts/selectors';
10+
import {
11+
selectAllContactsNames,
12+
selectAllContactsPublicKeys
13+
} from '@background/redux/contacts/selectors';
1114
import { dispatchToMainStore } from '@background/redux/utils';
1215

1316
import {
@@ -28,12 +31,17 @@ export const AddContactPage = () => {
2831
const { state } = useTypedLocation();
2932

3033
const contactsNames = useSelector(selectAllContactsNames);
34+
const contactPublicKeys = useSelector(selectAllContactsPublicKeys);
3135

3236
const {
3337
register,
3438
handleSubmit,
3539
formState: { errors, isValid }
36-
} = useContactForm(contactsNames, state?.recipientPublicKey);
40+
} = useContactForm(
41+
contactsNames,
42+
contactPublicKeys,
43+
state?.recipientPublicKey
44+
);
3745

3846
const onSubmit = ({ name, publicKey }: ContactFromValues) => {
3947
const lastModified = new Date().toISOString();

src/apps/popup/pages/contact-details/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
} from '@background/redux/contacts/actions';
1818
import {
1919
selectAllContacts,
20-
selectAllContactsNames
20+
selectAllContactsNames,
21+
selectAllContactsPublicKeys
2122
} from '@background/redux/contacts/selectors';
2223
import { contactEditingPermissionChanged } from '@background/redux/session/actions';
2324
import { selectIsContactEditingAllowed } from '@background/redux/session/selectors';
@@ -48,6 +49,7 @@ export const ContactDetailsPage = () => {
4849
const { casperLiveUrl } = useSelector(selectApiConfigBasedOnActiveNetwork);
4950
const isContactEditingAllowed = useSelector(selectIsContactEditingAllowed);
5051
const contactsNames = useSelector(selectAllContactsNames);
52+
const contactPublicKeys = useSelector(selectAllContactsPublicKeys);
5153

5254
const handlePasswordConfirmed = useCallback(() => {
5355
dispatchToMainStore(contactEditingPermissionChanged());
@@ -66,7 +68,12 @@ export const ContactDetailsPage = () => {
6668
handleSubmit,
6769
getValues,
6870
formState: { errors, isValid }
69-
} = useContactForm(existingContactNames, contact?.publicKey!, contact?.name!);
71+
} = useContactForm(
72+
existingContactNames,
73+
contactPublicKeys,
74+
contact?.publicKey!,
75+
contact?.name!
76+
);
7077

7178
const isButtonDisabled = useMemo(
7279
() => calculateSubmitButtonDisabled({ isValid }),

src/libs/ui/forms/contact.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type ContactFromValues = {
1414

1515
export const useContactForm = (
1616
existingContactNames: string[],
17+
existingContactPublicKeys: string[],
1718
defaultPublicKey?: string,
1819
defaultName?: string
1920
) => {
@@ -22,7 +23,11 @@ export const useContactForm = (
2223
value =>
2324
value?.trim() != null && !existingContactNames.includes(value?.trim())
2425
),
25-
publicKey: useContactPublicKeyRule()
26+
publicKey: useContactPublicKeyRule(
27+
value =>
28+
value?.trim() != null &&
29+
!existingContactPublicKeys.includes(value?.trim())
30+
)
2631
});
2732

2833
const newContactFormOptions: UseFormProps<ContactFromValues> = {

src/libs/ui/forms/form-validation-rules.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,11 @@ export const useContactNameRule = (
602602
);
603603
};
604604

605-
export const useContactPublicKeyRule = () => {
605+
export const useContactPublicKeyRule = (
606+
isPublicKeyAlreadyInContactsCallback: (
607+
value: string | undefined
608+
) => Promise<boolean> | boolean
609+
) => {
606610
const { t } = useTranslation();
607611

608612
return Yup.string()
@@ -611,7 +615,12 @@ export const useContactPublicKeyRule = () => {
611615
name: 'contactPublicKey',
612616
test: value => (value ? isValidPublicKey(value) : false),
613617
message: t('Public address should be a valid public key')
614-
});
618+
})
619+
.test(
620+
'unique',
621+
t('You’ve already got a contact with this public key'),
622+
value => isPublicKeyAlreadyInContactsCallback(value)
623+
);
615624
};
616625

617626
export const useTorusSecretKeyRule = () => {

0 commit comments

Comments
 (0)