Skip to content

Commit

Permalink
feat(redux): delete credentialRecord and proofRecord (#421)
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht authored Aug 10, 2021
1 parent f0cf209 commit 9fa6c6d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const connectionsSlice = createSlice({
.addCase(ConnectionThunks.acceptInvitation.fulfilled, (state) => {
state.invitation.isLoading = false
})
// deleteConnection
.addCase(ConnectionThunks.deleteConnection.fulfilled, (state, action) => {
const connectionId = action.payload.id
const index = state.connections.records.findIndex((connectionRecord) => connectionRecord.id === connectionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const ConnectionThunks = {
),

/**
* Deletes a connectionRecord in the connectionRepository
* Deletes a connectionRecord in the connectionRepository.
*/
deleteConnection: createAsyncAgentThunk('connections/deleteConnection', async (connectionId: string, thunksApi) => {
const connectionRepository = thunksApi.extra.agent.injectionContainer.resolve(ConnectionRepository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ const credentialsSlice = createSlice({
.addCase(CredentialsThunks.acceptCredential.rejected, (state, action) => {
state.error = action.error
})
// deleteCredential
.addCase(CredentialsThunks.deletCredential.fulfilled, (state, action) => {
const credentialId = action.payload.id
const index = state.credentials.records.findIndex((record) => record.id == credentialId)
state.credentials.records.splice(index, 1)
})
},
})

Expand Down
12 changes: 12 additions & 0 deletions packages/redux-store/src/slices/credentials/credentialsThunks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ClassMethodParameters } from '../../utils'
import type { CredentialsModule } from '@aries-framework/core'

import { CredentialRepository } from '@aries-framework/core'

import { createAsyncAgentThunk } from '../../utils'

/**
Expand Down Expand Up @@ -121,6 +123,16 @@ const CredentialsThunks = {
acceptCredential: createAsyncAgentThunk('credentials/acceptCredential', async (credentialId: string, thunkApi) => {
return thunkApi.extra.agent.credentials.acceptCredential(credentialId)
}),

/**
* Deletes a credentialRecord in the credential repository.
*/
deletCredential: createAsyncAgentThunk('credentials/deleteCredential', async (credentialId: string, thunkApi) => {
const credentialRepository = thunkApi.extra.agent.injectionContainer.resolve(CredentialRepository)
const credentialRecord = await credentialRepository.getById(credentialId)
await credentialRepository.delete(credentialRecord)
return credentialRecord
}),
}

export { CredentialsThunks }
6 changes: 6 additions & 0 deletions packages/redux-store/src/slices/proofs/proofsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ const proofsSlice = createSlice({
.addCase(ProofsThunks.autoSelectCredentialsForProofRequest.rejected, (state, action) => {
state.error = action.error
})
// deleteProof
.addCase(ProofsThunks.deletCredential.fulfilled, (state, action) => {
const proofId = action.payload.id
const index = state.proofs.records.findIndex((record) => record.id == proofId)
state.proofs.records.splice(index, 1)
})
},
})

Expand Down
11 changes: 11 additions & 0 deletions packages/redux-store/src/slices/proofs/proofsThunks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ClassMethodParameters } from '../../utils'
import type { RequestedCredentials, ProofsModule, RetrievedCredentials } from '@aries-framework/core'

import { ProofRepository } from '@aries-framework/core'

import { createAsyncAgentThunk } from '../../utils'

/**
Expand Down Expand Up @@ -142,6 +144,15 @@ const ProofsThunks = {
return thunkApi.extra.agent.proofs.autoSelectCredentialsForProofRequest(retrievedCredentials)
}
),
/**
* Deletes a proofRecord in the proof repository.
*/
deletCredential: createAsyncAgentThunk('proofs/deleteProof', async (proofId: string, thunkApi) => {
const proofRepository = thunkApi.extra.agent.injectionContainer.resolve(ProofRepository)
const proofRecord = await proofRepository.getById(proofId)
await proofRepository.delete(proofRecord)
return proofRecord
}),
}

export { ProofsThunks }

0 comments on commit 9fa6c6d

Please sign in to comment.