Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Double attributes displayed for a single schema during OOB and connection verification. #869

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/commonComponents/CustomCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { setToLocalStorage } from '../api/Auth';
import { storageKeys } from '../config/CommonConstant';
import type { ICustomCheckboxProps, ISchemaData } from './interface';

const CustomCheckbox: React.FC<ICustomCheckboxProps> = ({ showCheckbox, isVerificationUsingEmail, onChange, schemaData }) => {
const CustomCheckbox: React.FC<ICustomCheckboxProps> = ({ showCheckbox, isSelectedSchema, isVerificationUsingEmail, onChange, schemaData }) => {
const [checked, setChecked] = useState<boolean>(false);
const handleCheckboxChange = async () => {
const newChecked = !checked;
setChecked(newChecked);
onChange(newChecked, schemaData);
};
useEffect(() => {
setChecked(isSelectedSchema);
}, [isSelectedSchema]);

return (
<>
Expand Down
5 changes: 5 additions & 0 deletions src/commonComponents/SchemaCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const SchemaCard = (props: ISchemaCardProps) => {
orgDidDetails();
}, []);

const isSelected = props.selectedSchemas?.some(
(selectedSchema) => selectedSchema.schemaId === props.schemaId || selectedSchema.schemaLedgerId === props.schemaId
);

const attributes = props.limitedAttributes !== false ? props?.attributes?.slice(0, 3) : props?.attributes

const AttributesList: React.FC<{ attributes: IAttribute[], limitedAttributes?: boolean }> = ({ attributes, limitedAttributes }) => {
Expand Down Expand Up @@ -193,6 +197,7 @@ const SchemaData = {

{props.showCheckbox && (
<CustomCheckbox
isSelectedSchema={isSelected}
onChange={handleCheckboxChange}
showCheckbox={props.showCheckbox}
schemaData={{ schemaId: props.schemaId, schemaName: props.schemaName, attributes: props.attributes }}
Expand Down
4 changes: 4 additions & 0 deletions src/commonComponents/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ISchema } from "../components/Verification/interface";

export interface IProps {
openModal: boolean;
closeModal: (flag: boolean) => void;
Expand All @@ -24,6 +26,7 @@ export interface ISchemaData {
}

export interface ICustomCheckboxProps {
isSelectedSchema: boolean;
showCheckbox: boolean;
isVerificationUsingEmail?: boolean;
onChange: (checked: boolean, schemaData?: ISchemaData) => void;
Expand All @@ -33,6 +36,7 @@ export interface ICustomCheckboxProps {
export interface ISchemaCardProps {
className?: string;
schemaName: string;
selectedSchemas:ISchema[];
version: string;
schemaId: string;
issuerDid: string;
Expand Down
8 changes: 3 additions & 5 deletions src/components/Resources/Schema/ViewSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ const ViewSchemas = ({ schemaId }: { schemaId: string }) => {
const fetchData = async () => {
const organizationId = await getFromLocalStorage(storageKeys.ORG_ID);
setOrgId(String(organizationId));
const id = encodeURIComponent(schemaId);
if (id) {
await getSchemaDetails(id, String(organizationId));
await getCredentialDefinitionList(id, String(organizationId));
}
await getSchemaDetails(schemaId, String(organizationId));
await getCredentialDefinitionList(schemaId, String(organizationId));

};

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/components/Verification/VerificationSchemasList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ const [schemasList, setSchemasList] = useState([]);
schemasList.map((element) => (
<div className="px-0 sm:px-2" key={element['schemaLedgerId']}>
<SchemaCard
selectedSchemas={selectedSchemas}
schemaName={element['name']}
version={element['version']}
schemaId={element['schemaLedgerId']}
Expand Down
1 change: 1 addition & 0 deletions src/components/Verification/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export interface ISchemaData {
}

export interface ISchema {
schemaLedgerId?: string;
schemaId: string;
attributes: IAttributesDetails[];
issuerId: string;
Expand Down
Loading