File tree Expand file tree Collapse file tree 7 files changed +49
-14
lines changed
Expand file tree Collapse file tree 7 files changed +49
-14
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,12 @@ export const NEW_VALIDATOR_FOR_SIGNATURE_REQUEST = {
9999} ;
100100
101101export 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'
Original file line number Diff line number Diff line change 22 NEW_VALIDATOR_FOR_STAKE ,
33 RPC_RESPONSE ,
44 URLS ,
5- VALIDATOR_FOR_STAKE
5+ VALIDATOR_FOR_UNDELEGATE
66} from '../../constants' ;
77import { 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 (
Original file line number Diff line number Diff line change 1- import { RPC_RESPONSE , URLS , VALIDATOR_FOR_STAKE } from '../../constants' ;
1+ import { RPC_RESPONSE , URLS , VALIDATOR_FOR_UNDELEGATE } from '../../constants' ;
22import { popup , popupExpect } from '../../fixtures' ;
33
44popup . 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
Original file line number Diff line number Diff line change @@ -7,7 +7,10 @@ import { SuccessScreen } from '@popup/pages/add-contact/success-screen';
77import { RouterPath , useTypedLocation , useTypedNavigate } from '@popup/router' ;
88
99import { 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' ;
1114import { dispatchToMainStore } from '@background/redux/utils' ;
1215
1316import {
@@ -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 ( ) ;
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ import {
1717} from '@background/redux/contacts/actions' ;
1818import {
1919 selectAllContacts ,
20- selectAllContactsNames
20+ selectAllContactsNames ,
21+ selectAllContactsPublicKeys
2122} from '@background/redux/contacts/selectors' ;
2223import { contactEditingPermissionChanged } from '@background/redux/session/actions' ;
2324import { 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 } ) ,
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export type ContactFromValues = {
1414
1515export 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 > = {
Original file line number Diff line number Diff 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
617626export const useTorusSecretKeyRule = ( ) => {
You can’t perform that action at this time.
0 commit comments