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

feat: added configuration options to K-menu #109

Merged
merged 28 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5ddaeb4
feat: added configuration options to K-menu
jimezesinachi Sep 23, 2022
225a621
feat: added logic for invitation method switch from K-menu
jimezesinachi Sep 26, 2022
967a190
test: updated tests
jimezesinachi Sep 26, 2022
9ac5fba
test: removed theme logic from setInvitationMethod
jimezesinachi Sep 26, 2022
02dc014
Merge pull request #1 from animo/main
jimezesinachi Sep 26, 2022
7fcf676
fix: fixed use of React hooks incorectly
jimezesinachi Sep 27, 2022
6b2b73d
Merge branch 'feat/add-configuration-screen' of https://github.com/ra…
jimezesinachi Sep 27, 2022
c701866
fix: fixed issue with ConfigurationState use
jimezesinachi Sep 27, 2022
8417fc9
Update client/src/utils/KBar.tsx
jimezesinachi Sep 28, 2022
14cc304
Update client/src/slices/configuration/configurationSlice.ts
jimezesinachi Sep 28, 2022
1840c07
fix: renamed Bcovrin menu object and setLegacyInvitation method
jimezesinachi Sep 28, 2022
29b4a91
fix: actions menu and ConfigurationSlice
jimezesinachi Sep 28, 2022
d3c5d3e
fix: added state logic for credential protocol version switch
jimezesinachi Sep 28, 2022
18234fc
feat: moved ConfigurationSlice logic into ConnectionSlice and added r…
jimezesinachi Sep 29, 2022
cc61008
test: added oob invitation test and removed demo reset call in onboar…
jimezesinachi Oct 3, 2022
14dc22c
Update cypress/e2e/legacy_invitation_usecase_page.cy.ts
jimezesinachi Oct 4, 2022
61dd6a3
separated stage logic into demo/RESET and demo/resetState and removed…
jimezesinachi Oct 4, 2022
7b47a77
Merge branch 'feat/add-configuration-screen' of https://github.com/ra…
jimezesinachi Oct 4, 2022
cd92196
Update client/src/slices/credentials/credentialsSlice.ts
jimezesinachi Oct 4, 2022
b095c64
Update client/src/slices/onboarding/onboardingSlice.ts
jimezesinachi Oct 4, 2022
af7cd9b
Update client/src/store/configureStore.tsx
jimezesinachi Oct 4, 2022
5b685ef
fixed slice reducer logic for demo/resetState and removed commented i…
jimezesinachi Oct 4, 2022
3ecda9b
test: added issue credential protocol version tests
jimezesinachi Oct 5, 2022
4fc5c9a
test: switched issue credential protocol version tests from oob to le…
jimezesinachi Oct 5, 2022
3b5fa91
test: renamed issue credential test assertions and set wait times to …
jimezesinachi Oct 6, 2022
ae67c8a
Update client/src/utils/KBar.tsx
jimezesinachi Oct 6, 2022
f4e3b3b
Update client/src/utils/KBar.tsx
jimezesinachi Oct 6, 2022
41a34c4
Update client/src/utils/KBar.tsx
jimezesinachi Oct 6, 2022
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
10 changes: 9 additions & 1 deletion client/src/api/ConnectionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import type { AxiosResponse } from 'axios'

import { apiCall } from './BaseUrl'

export const createInvitation = (agentName?: string, agentImageUrl?: string): Promise<AxiosResponse> => {
export const createOobInvitation = (agentName?: string, agentImageUrl?: string): Promise<AxiosResponse> => {
return apiCall.post('/oob/create-invitation', {
autoAcceptConnection: true,
label: agentName,
imageUrl: agentImageUrl,
})
}

export const createLegacyInvitation = (agentName?: string, agentImageUrl?: string): Promise<AxiosResponse> => {
return apiCall.post('/oob/create-legacy-invitation', {
autoAcceptConnection: true,
label: agentName,
Expand Down
8 changes: 6 additions & 2 deletions client/src/api/CredentialApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import type { AxiosResponse } from 'axios'

import { apiCall } from './BaseUrl'

export const issueCredential = async (connectionId: string, data: CredentialData): Promise<AxiosResponse> => {
export const issueCredential = async (
connectionId: string,
data: CredentialData,
protocolVersion: 'v1' | 'v2'
): Promise<AxiosResponse> => {
return apiCall.post(`/credentials/offer-credential`, {
protocolVersion: 'v1',
protocolVersion: protocolVersion,
connectionId: connectionId,
credentialFormats: {
indy: {
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/landing/components/MainSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const MainSection: React.FC = () => {
</div>
<div className="flex flex-row justify-start text-base sxl:text-lg font-normal mt-6">
<motion.button
data-cy="try-demo-button"
variants={fadeDelay}
whileHover={buttonHover}
className="bg-animo-black dark:bg-animo-white text-animo-white dark:text-animo-black py-3 px-5 rounded-lg font-semibold shadow-sm dark:shadow-none select-none "
Expand Down
1 change: 0 additions & 1 deletion client/src/pages/onboarding/OnboardingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const OnboardingPage: React.FC = () => {
dispatch(fetchAllUseCasesByCharId(currentCharacter.id))
navigate('/dashboard')
} else {
dispatch({ type: 'demo/RESET' })
jimezesinachi marked this conversation as resolved.
Show resolved Hide resolved
jimezesinachi marked this conversation as resolved.
Show resolved Hide resolved
dispatch(fetchWallets())
dispatch(fetchAllCharacters())
setMounted(true)
Expand Down
8 changes: 6 additions & 2 deletions client/src/pages/onboarding/steps/AcceptCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ export const AcceptCredential: React.FC<Props> = ({ content, connectionId, crede
(x) => x.state === 'credential-issued' || x.state === 'done'
)

let { protocolVersion } = useCredentials()
useEffect(() => {
if (credentials.length === 0) {
currentCharacter.starterCredentials.forEach((item) => {
dispatch(issueCredential({ connectionId: connectionId, cred: item }))
dispatch(issueCredential({ connectionId: connectionId, cred: item, protocolVersion }))
trackEvent('credential-issued')
})
setCredentialsIssued(true)
Expand Down Expand Up @@ -97,6 +98,8 @@ export const AcceptCredential: React.FC<Props> = ({ content, connectionId, crede
dispatch({ type: 'demo/RESET' })
}

protocolVersion = useCredentials().protocolVersion

const sendNewCredentials = () => {
credentials.forEach((cred) => {
if (cred.state !== 'credential-issued' && cred.state !== 'done') {
Expand All @@ -110,7 +113,8 @@ export const AcceptCredential: React.FC<Props> = ({ content, connectionId, crede
)
})

if (newCredential) dispatch(issueCredential({ connectionId: connectionId, cred: newCredential }))
if (newCredential)
dispatch(issueCredential({ connectionId: connectionId, cred: newCredential, protocolVersion }))
}
})
closeFailedRequestModal()
Expand Down
4 changes: 3 additions & 1 deletion client/src/pages/onboarding/steps/SetupConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Loader } from '../../../components/Loader'
import { QRCode } from '../../../components/QRCode'
import { useAppDispatch } from '../../../hooks/hooks'
import { useInterval } from '../../../hooks/useInterval'
import { useConnection } from '../../../slices/connection/connectionSelectors'
import {
createInvitation,
fetchConnectionById,
Expand All @@ -36,9 +37,10 @@ export const SetupConnection: React.FC<Props> = ({
}) => {
const dispatch = useAppDispatch()
const isCompleted = connectionState === 'response-sent' || connectionState === 'completed'
const { useLegacyInvitations } = useConnection()

useEffect(() => {
if (!isCompleted) dispatch(createInvitation())
if (!isCompleted) dispatch(createInvitation({ useLegacyInvitations }))
}, [])

useEffect(() => {
Expand Down
6 changes: 5 additions & 1 deletion client/src/pages/useCase/steps/StepConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { fade, fadeX } from '../../../FramerAnimations'
import { QRCode } from '../../../components/QRCode'
import { useAppDispatch } from '../../../hooks/hooks'
import { useInterval } from '../../../hooks/useInterval'
import { useConnection } from '../../../slices/connection/connectionSelectors'
import {
createInvitation,
fetchConnectionById,
Expand All @@ -27,9 +28,12 @@ export const StepConnection: React.FC<Props> = ({ step, connection, entity }) =>
const dispatch = useAppDispatch()
const { id, state, invitationUrl, outOfBandId } = connection
const isCompleted = state === 'response-sent' || state === 'completed'
const { useLegacyInvitations } = useConnection()

useEffect(() => {
if (!isCompleted) dispatch(createInvitation(entity))
if (!isCompleted) {
dispatch(createInvitation({ entity, useLegacyInvitations }))
}
}, [])

useInterval(
Expand Down
10 changes: 8 additions & 2 deletions client/src/pages/useCase/steps/StepCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ActionCTA } from '../../../components/ActionCTA'
import { Loader } from '../../../components/Loader'
import { useAppDispatch } from '../../../hooks/hooks'
import { useInterval } from '../../../hooks/useInterval'
import { useCredentials } from '../../../slices/credentials/credentialsSelectors'
import {
deleteCredentialById,
fetchCredentialsByConId,
Expand Down Expand Up @@ -42,6 +43,8 @@ export const StepCredential: React.FC<Props> = ({ step, connectionId, issueCrede
)
const [issuedCredData, setIssuedCredData] = useState<CredentialData[]>([])

let { protocolVersion } = useCredentials()

const issueCreds = () => {
// get attributes from proof
let attributes: Attribute[] = []
Expand All @@ -60,7 +63,7 @@ export const StepCredential: React.FC<Props> = ({ step, connectionId, issueCrede

// issue credentials
credentialData.forEach((item) => {
dispatch(issueCredential({ connectionId: connectionId, cred: item }))
dispatch(issueCredential({ connectionId: connectionId, cred: item, protocolVersion }))
trackEvent('credential-issued')
})
}
Expand All @@ -76,6 +79,8 @@ export const StepCredential: React.FC<Props> = ({ step, connectionId, issueCrede
!credentialsAccepted ? 1000 : null
)

protocolVersion = useCredentials().protocolVersion
jimezesinachi marked this conversation as resolved.
Show resolved Hide resolved

const sendNewCredentials = () => {
credentials.forEach((cred) => {
if (cred.state !== 'credential-issued' && cred.state !== 'done') {
Expand All @@ -88,7 +93,8 @@ export const StepCredential: React.FC<Props> = ({ step, connectionId, issueCrede
credClass.metadata.get<CredReqMetadata>('_internal/indyCredential')?.credentialDefinitionId
)
})
if (newCredential) dispatch(issueCredential({ connectionId: connectionId, cred: newCredential }))
if (newCredential)
dispatch(issueCredential({ connectionId: connectionId, cred: newCredential, protocolVersion }))
}
})
closeFailedRequestModal()
Expand Down
7 changes: 6 additions & 1 deletion client/src/slices/connection/connectionSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ConnectionState {
invitationUrl?: string
outOfBandId?: string
isLoading: boolean
useLegacyInvitations: boolean
}

const initialState: ConnectionState = {
Expand All @@ -16,6 +17,7 @@ const initialState: ConnectionState = {
invitationUrl: undefined,
outOfBandId: undefined,
isLoading: false,
useLegacyInvitations: true,
}

const connectionSlice = createSlice({
Expand All @@ -28,6 +30,9 @@ const connectionSlice = createSlice({
state.invitationUrl = undefined
state.isLoading = false
},
setUseLegacyInvitations: (state, action) => {
state.useLegacyInvitations = action.payload
},
},
extraReducers: (builder) => {
builder
Expand Down Expand Up @@ -65,6 +70,6 @@ const connectionSlice = createSlice({
},
})

export const { clearConnection } = connectionSlice.actions
export const { clearConnection, setUseLegacyInvitations } = connectionSlice.actions

export default connectionSlice.reducer
18 changes: 13 additions & 5 deletions client/src/slices/connection/connectionThunks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Entity } from '../../slices/types'
import type { CreateInvitationProps } from '../../slices/types'

import { createAsyncThunk } from '@reduxjs/toolkit'

Expand All @@ -14,7 +14,15 @@ export const fetchConnectionByOutOfBandId = createAsyncThunk('connection/fetchBy
return response.data
})

export const createInvitation = createAsyncThunk('connection/createInvitation', async (entity?: Entity) => {
const response = await Api.createInvitation(entity?.name, entity?.imageUrl)
return response.data
})
export const createInvitation = createAsyncThunk(
'connection/createInvitation',
async (createInvitationOptions?: CreateInvitationProps) => {
const entity = createInvitationOptions?.entity

const response = createInvitationOptions?.useLegacyInvitations
? await Api.createLegacyInvitation(entity?.name, entity?.imageUrl)
: await Api.createOobInvitation(entity?.name, entity?.imageUrl)

return response.data
}
)
7 changes: 6 additions & 1 deletion client/src/slices/credentials/credentialsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface CredentialState {
issuedCredentials: CredentialExchangeRecord[]
isLoading: boolean
isIssueCredentialLoading: boolean
protocolVersion: 'v1' | 'v2'
error: SerializedError | undefined
}

Expand All @@ -23,6 +24,7 @@ const initialState: CredentialState = {
issuedCredentials: [],
isLoading: true,
isIssueCredentialLoading: true,
protocolVersion: 'v1',
error: undefined,
}

Expand All @@ -36,6 +38,9 @@ const credentialSlice = createSlice({
)
state.credentials = []
},
setProtocolVersion: (state, action) => {
state.protocolVersion = action.payload
},
},
extraReducers: (builder) => {
builder
Expand Down Expand Up @@ -90,6 +95,6 @@ const credentialSlice = createSlice({
},
})

export const { clearCredentials } = credentialSlice.actions
export const { clearCredentials, setProtocolVersion } = credentialSlice.actions

export default credentialSlice.reducer
4 changes: 2 additions & 2 deletions client/src/slices/credentials/credentialsThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const fetchCredentialsByConId = createAsyncThunk('credentials/fetchAllByC

export const issueCredential = createAsyncThunk(
'credentials/issueCredential',
async (data: { connectionId: string; cred: CredentialData }) => {
const response = await Api.issueCredential(data.connectionId, data.cred)
async (data: { connectionId: string; cred: CredentialData; protocolVersion: 'v1' | 'v2' }) => {
const response = await Api.issueCredential(data.connectionId, data.cred, data.protocolVersion)
return response.data
}
)
Expand Down
5 changes: 5 additions & 0 deletions client/src/slices/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export interface Entity {
imageUrl?: string
}

export interface CreateInvitationProps {
entity?: Entity
useLegacyInvitations?: boolean
}

export interface Colors {
primary: string
secondary: string
Expand Down
2 changes: 1 addition & 1 deletion client/src/store/configureStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import rootReducer from '../slices/index'
export const persistConfig = {
key: 'redux-store-root',
storage,
whitelist: ['preferences', 'characters', 'onboarding', 'credentials', 'connection'],
whitelist: ['preferences', 'configuration', 'characters', 'onboarding', 'credentials', 'connection'],
jimezesinachi marked this conversation as resolved.
Show resolved Hide resolved
version: 4,
}

Expand Down
Loading