Skip to content

Commit

Permalink
refactor api standardization and bug fixes
Browse files Browse the repository at this point in the history
Signed-off-by: karan <[email protected]>
  • Loading branch information
16-karan committed Sep 21, 2023
1 parent 736efbd commit a04de65
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 26 deletions.
9 changes: 6 additions & 3 deletions src/api/issuance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { getHeaderConfigs } from '../config/GetHeaderConfigs';
import { axiosGet, axiosPost } from '../services/apiRequests';
import { getFromLocalStorage } from './Auth';

export const getIssuedCredentials = async (schemaId: string) => {
export const getIssuedCredentials = async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.getIssuedCredentials}`;

const axiosPayload = {
url,
Expand All @@ -22,6 +22,7 @@ export const getIssuedCredentials = async (schemaId: string) => {
};

export const getCredentialDefinitions = async (schemaId: string) => {

const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;

Expand All @@ -41,7 +42,9 @@ export const getCredentialDefinitions = async (schemaId: string) => {

export const issueCredential = async (data: object) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.issueCredential}`; const payload = data;
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.issueCredential}`;
const payload = data;

const axiosPayload = {
url,
payload,
Expand Down
8 changes: 5 additions & 3 deletions src/api/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const verifyCredential = async (payload: any) => {
export const getVerificationCredential = async (state: IssueCredential) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Issuance.getIssuedCredentials}?orgId=${orgId}&state=${state}`;

const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand All @@ -40,7 +39,8 @@ export const getVerificationCredential = async (state: IssueCredential) => {

export const getVerificationList = async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.getAllRequestList}`
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.verifyCredential}`

const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand Down Expand Up @@ -88,7 +88,9 @@ export const getProofAttributes=async (proofId:string)=>{
}

export const getCredentialDefinitionsForVerification = async (schemaId: string) => {
const url = `${apiRoutes.schema.getCredDefBySchemaId}?schemaId=${schemaId}`;
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;

const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand Down
7 changes: 4 additions & 3 deletions src/components/AlertComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Alert } from 'flowbite-react';
import { pathRoutes } from '../../config/pathRoutes';

export const AlertComponent = ({ message, type, viewButton, onAlertClose }: { message: string | null, type: string, viewButton?: boolean, onAlertClose: () => void }) => {
export const AlertComponent = ({ message, type, viewButton, onAlertClose, goToInvite }: { message: string | null, type: string, viewButton?: boolean,goToInvite?:boolean, onAlertClose: () => void }) => {


return message !== null ? <Alert
Expand All @@ -16,12 +17,12 @@ export const AlertComponent = ({ message, type, viewButton, onAlertClose }: { me
{
viewButton
&& <p className='md:w-32 lg:w-48 text-base text-primary-700 text-right'>
View more...
{goToInvite ? <a href={pathRoutes.users.invitations}>View more... </a> :"View more..." }
</p>
}

</span>

</Alert>
: <></>
}
}
1 change: 1 addition & 0 deletions src/components/Issuance/CredDefSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const CredDefSelection = () => {
const getCredDefs = async (schemaId: string) => {
setLoading(true)
const response = await getCredentialDefinitions(schemaId);

const { data } = response as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
Expand Down
7 changes: 4 additions & 3 deletions src/components/Issuance/IssuedCrdentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const CredentialList = () => {

const getIssuedCredDefs = async () => {
setLoading(true);
const response = await getIssuedCredentials(
IssueCredential.credentialIssued,
);
const response = await getIssuedCredentials();

const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {

const credentialList = data?.data?.map(
(issuedCredential: IssuedCredential) => {
const schemaName = issuedCredential.metadata['_anoncreds/credential']
Expand All @@ -51,6 +51,7 @@ const CredentialList = () => {
.slice(2)
.join(':')
: 'Not available';

return {
data: [
{
Expand Down
2 changes: 0 additions & 2 deletions src/components/Resources/Schema/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import React from 'react';
const [orgId, setOrgId] = useState<number>(0);
const [orgDid, setOrgDid] = useState<string>('');
const [createloader, setCreateLoader] = useState<boolean>(false);

useEffect(() => {
const fetchData = async () => {
const organizationId = await getFromLocalStorage(
Expand Down Expand Up @@ -540,7 +539,6 @@ import React from 'react';
No, cancel
</button>
<Button
data-modal-hide="popup-modal"
type="submit"
isProcessing={createloader}
disabled={createloader}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Resources/Schema/SchemasList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
message={'No Schemas'}
description={'Get started by creating a new Schema'}
buttonContent={'Create'}
svgComponent={<svg className='pr-2' xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 24 24">
svgComponent={<svg className='pr-2 mr-1' xmlns="http://www.w3.org/2000/svg" width="24" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>}
onClick={() => {
Expand All @@ -234,4 +234,4 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
}


export default SchemaList
export default SchemaList
13 changes: 8 additions & 5 deletions src/components/User/UserDashBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ const UserDashBoard = () => {
getUserRecentActivity()
}, [])

const redirectToInvitations = () => {
window.location.href = pathRoutes.users.invitations
}
// const redirectToInvitations = () => {
// window.location.href = pathRoutes.users.invitations
// }

const goToOrgDashboard = async (orgId: number, roles: string[]) => {
await setToLocalStorage(storageKeys.ORG_ID, orgId.toString());
Expand All @@ -124,11 +124,14 @@ const UserDashBoard = () => {

return (
<div className="px-4 pt-6">
<div className="cursor-pointer" onClick={redirectToInvitations}>
{/* <div className="cursor-pointer" onClick={redirectToInvitations}> */}
<div className="cursor-pointer">

<AlertComponent
message={message ? message : error}
type={message ? 'warning' : 'failure'}
viewButton={viewButton}
goToInvite={true}
onAlertClose={() => {
setMessage(null)
setError(null)
Expand Down Expand Up @@ -293,4 +296,4 @@ const UserDashBoard = () => {

)
}
export default UserDashBoard;
export default UserDashBoard;
3 changes: 2 additions & 1 deletion src/components/Verification/CredDefSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const CredDefSelection = () => {
//Fetch credential definitions against schemaId
const getCredDefs = async (schemaId: string) => {
setLoading(true)
const response = await getCredentialDefinitionsForVerification(schemaId);
const response = await getCredentialDefinitionsForVerification(schemaId,31);

const { data } = response as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Verification/Verification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const VerificationCred = () => {

const attributes = await selectedUsersData.map(user => ({
attributeName: user.name,
credDefId: credDefId,
...(credDefId ? { credDefId } : {}),
schemaId: schemaId
}));
const verifyCredentialPayload: VerifyCredentialPayload = {
Expand Down
1 change: 1 addition & 0 deletions src/components/Verification/VerificationCredentialList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const VerificationCredentialList = () => {
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {

const credentialList = data?.data?.map((requestProof: RequestProof) => {
return {
data: [
Expand Down
5 changes: 3 additions & 2 deletions src/components/organization/OrganizationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const OrganizationDetails = ({ orgData }: { orgData: Organisation | null }) => {

setLoading(true)
const response = await createConnection(orgData?.name as string);

const { data } = response as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {

setConnectionData(data?.data)

Expand Down Expand Up @@ -210,4 +211,4 @@ const OrganizationDetails = ({ orgData }: { orgData: Organisation | null }) => {

}

export default OrganizationDetails
export default OrganizationDetails
2 changes: 1 addition & 1 deletion src/components/organization/OrganizationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const OrganizationsList = () => {
buttonContent={'Create Organization'}
onClick={createOrganizationModel}
feature={Features.CRETAE_ORG}
svgComponent={<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 24 24">
svgComponent={<svg className='pr-2 mr-1' xmlns="http://www.w3.org/2000/svg" width="24" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>} />)
}
Expand Down

0 comments on commit a04de65

Please sign in to comment.