Skip to content

Commit

Permalink
logRevoked
Browse files Browse the repository at this point in the history
  • Loading branch information
danicaMat committed Aug 30, 2022
1 parent 4cd6f1d commit 5d894a8
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 103 deletions.
199 changes: 109 additions & 90 deletions machines/revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createModel } from 'xstate/lib/model';
import { request } from '../shared/request';
import { VcIdType } from '../types/vc';
import i18n from '../i18n';
import { log } from 'xstate/lib/actions';
import { log, pure } from 'xstate/lib/actions';

const model = createModel(
{
Expand All @@ -31,110 +31,112 @@ const model = createModel(
}
);

export const revokeVidsMachine = model.createMachine(
export const revokeVidsMachine =
/** @xstate-layout N4IgpgJg5mDOIC5QCUwDcD2BrMA1AlhLAHSEA2YAxMgKK4DyA0jQPq4DCAyoqAA4ax8AF3wYAdjxAAPRACYAHAFZiARhUB2WQDZFABgCcO-boDMWgDQgAnohWyALLOK6X9k-J3zZirfYC+fpaomDgERKRiaACGZISUAJIAcgAKAKoAKiz06cmS-IIi4pIyCOq6TuomjvYqWlpe3iaWNgiKik4u5fK69vr2uipmAUHo2HiEJPiRMXEAIvGcALIL3Egg+cKiEmslZRVVDrX1so3Nclr6zi61pvLyKoY9wyDBY2EkUQDGn2C8ImJQXDxWaTCAUah0JisDirPgCTZFHaIEyydTEe6yEyaQzqXrtM4IeQmXRXcrqDz9dQPEzPV6hCbEL4-P5TQHAkgAJzAAEcAK5wf5QehCXiUCDiMAREKSunjcJM36CoEg4hcvkC1nC3gIKaYT5RQpiADaugAunl4Ybioh8dZbHtiHoevpFESlIp9DTAi9RvT5d9FazlZyefzYIKtZQwByORgOcReGQDQAzOMAW2IsvejIDLIBwdVoY1AK1OsiGH1hpN5rWGytSIQJix6LsWNkOLxsgJKLRnVMlXJdxq-m9WYZCrzbJBlHmSxWFoKW2tjdRLcx2K0uJdXbtCGMpN03Qe-X03VktN9co+uYjIviYl4vKECRSGSyOQXCO2oBKKkPaNdRQqXsRRBi0EwXQJep5EdFxURdTczB0C9pWzCdb14e9H2fWdlk4WF1ktJcGwUZQ1E0HQDCMUwLF3NQ+lJVFN3kXFvBQt4GTVMNBVlMUJSlMZM0vbMuOLKBZTLPUDS2atP3rH9bH-R0lGA0CzAgxQCRqS4nQ0F0-10SoRxGVDOKLcNWV46NY3jRMU3TITTPCUSLIBCTdQraTxFk2siMRBTSh3FpBhdWCeiAqkiSA4yfSckMQiDT4ZwWPCCLrYiAq8AlBgeYg6jKLF1DaB5ygCb0xAwCA4EkMdwnIMA5Iy6RbEMPKNGJSo2nuD17Gyh5lDqC59HUTwVBqL0TI4urpliCBiAwEVGv85rWipZx5GGxRiV8GjNN3BQALg8bMS0citHYv1JhmwhiAAIy+HAxAgJbvxWto0T6doTlkFwtBOFRuzaMK1G6TdqWGi6rylGZnt8xdlpKLaTGIT7vp+3Q-tkAH9pUZRdNOux9KxGLauvZklXZUgwQauGv2XH7LhMOwai+zcfvkXrd3sHQwsPal7C8WpFEhtCbyDSmXIwl7l00btud5twLj-Op5BF8cxfzdlpYbAXspYhW9iG3w1f9cnNTvB8n21gKBbROpHEAhn20UTngp+lRiCx7nN1uAxMRNkN1Vc8TL2tlaiTRQZtBMCKBe+gkXZJJ1tB6ECBf0FQA8LBL80+MPf3bGC7lRDHT1TptuzuMLDhRMwzoD-O5Fd2wYOuVF-raXx7HUMq-CAA */
model.createMachine(
{
tsTypes: {} as import('./revoke.typegen').Typegen0,
id: 'RevokeVids',
context: model.initialContext,
initial: 'acceptingVIDs',
states: {
idle: {
on: {
REVOKE_VCS: {
actions: ['setTransactionId', 'clearOtp'],
target: 'acceptingOtpInput',
},
context: model.initialContext,
tsTypes: {} as import('./revoke.typegen').Typegen0,
id: 'RevokeVids',
initial: 'acceptingVIDs',
states: {
idle: {
on: {
REVOKE_VCS: {
actions: ['setTransactionId', 'clearOtp'],
target: 'acceptingOtpInput',
},
},
invalid: {
states: {
otp: {},
backend: {},
},
invalid: {
states: {
otp: {},
backend: {},
},
on: {
INPUT_OTP: {
actions: 'setOtp',
target: 'requestingRevoke',
},
on: {
INPUT_OTP: {
actions: 'setOtp',
target: 'requestingRevoke',
},
DISMISS: {
target: 'idle',
},
DISMISS: {
target: 'idle',
},
},
acceptingVIDs: {
entry: ['setTransactionId', 'clearOtp'],
initial: 'idle',
states: {
idle: {
on: {
REVOKE_VCS: {
actions: ['setVIDs'],
target: '#RevokeVids.acceptingOtpInput',
},
},
},
requestingOtp: {
invoke: {
src: 'requestOtp',
onDone: [
{
actions: [log('accepting OTP')],
target: '#RevokeVids.acceptingOtpInput',
},
],
onError: [
{
actions: [log('error OTP'), 'setIdBackendError'],
target: '#RevokeVids.invalid.backend',
},
],
},
acceptingVIDs: {
entry: ['setTransactionId', 'clearOtp'],
initial: 'idle',
states: {
idle: {
on: {
REVOKE_VCS: {
actions: 'setVIDs',
target: '#RevokeVids.acceptingOtpInput',
},
},
},
on: {
DISMISS: {
target: 'idle',
requestingOtp: {
invoke: {
src: 'requestOtp',
onDone: [
{
actions: log('accepting OTP'),
target: '#RevokeVids.acceptingOtpInput',
},
],
onError: [
{
actions: [log('error OTP'), 'setIdBackendError'],
target: '#RevokeVids.invalid.backend',
},
],
},
},
},
acceptingOtpInput: {
entry: 'clearOtp',
on: {
INPUT_OTP: {
actions: 'setOtp',
target: 'requestingRevoke',
},
DISMISS: {
target: 'idle',
},
on: {
DISMISS: {
target: 'idle',
},
},
requestingRevoke: {
invoke: {
src: 'requestRevoke',
onDone: [
{
target: 'revokingVc',
},
],
onError: [
{
actions: 'setOtpError',
target: 'acceptingOtpInput',
},
],
},
acceptingOtpInput: {
entry: 'clearOtp',
on: {
INPUT_OTP: {
actions: 'setOtp',
target: 'requestingRevoke',
},
DISMISS: {
target: 'idle',
},
},
revokingVc: {
entry: ['logRevoked'],
on: {
DISMISS: {
target: 'idle',
},
requestingRevoke: {
invoke: {
src: 'requestRevoke',
onDone: [
{
target: 'revokingVc',
},
],
onError: [
{
actions: [log('error on Revoking'), 'setOtpError'],
target: 'acceptingOtpInput',
},
],
},
},
revokingVc: {
entry: 'logRevoked',
on: {
DISMISS: {
target: 'idle',
},
},
},
},
},
{
actions: {
setOtp: model.assign({
Expand Down Expand Up @@ -184,9 +186,24 @@ export const revokeVidsMachine = model.createMachine(

clearOtp: assign({ otp: '' }),

logRevoked: (_context) => {
_context.VIDs.forEach((vc) => {
send(
// logRevoked: pure((context) =>
// context.VIDs.map((vc) =>
// send(
// ActivityLogEvents.LOG_ACTIVITY({
// _vcKey: vc,
// action: 'revoked',
// timestamp: Date.now(),
// deviceName: '',
// vcLabel: vc.split(':')[2],
// }),
// { to: () => context.serviceRefs.activityLog }
// )
// )
// ),

logRevoked: pure(
(context) => context.VIDs.map(
(vc) => send(
() =>
ActivityLogEvents.LOG_ACTIVITY({
_vcKey: vc,
Expand All @@ -198,9 +215,10 @@ export const revokeVidsMachine = model.createMachine(
{
to: (_context) => _context.serviceRefs.activityLog,
}
);
});
},
)
)
),

},

services: {
Expand All @@ -215,6 +233,7 @@ export const revokeVidsMachine = model.createMachine(
},

requestRevoke: async (context) => {
console.log('context.otp', context.otp)
try {
return await Promise.all(
context.VIDs.map((vid: string) => {
Expand Down
9 changes: 4 additions & 5 deletions machines/vcItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ export const vcItemMachine =
},
},
requestingOtp: {
entry: 'setTransactionId',
invoke: {
src: 'requestOtp',
onDone: [
Expand All @@ -255,7 +254,7 @@ export const vcItemMachine =
},
},
acceptingOtpInput: {
entry: 'clearOtp',
entry: ['clearOtp', 'setTransactionId'],
on: {
INPUT_OTP: [
{
Expand All @@ -264,7 +263,7 @@ export const vcItemMachine =
target: 'requestingLock',
},
{
actions: [log('setting OTP'), 'setOtp'],
actions: [log('setting OTP'), 'setTransactionId', 'setOtp'],
cond: 'notRequestingLock',
target: 'requestingRevoke',
},
Expand Down Expand Up @@ -305,13 +304,13 @@ export const vcItemMachine =
src: 'requestRevoke',
onDone: [
{
actions: ['setRevoke'],
actions: [log('doneRevoking'), 'setRevoke'],
target: 'revokingVc',
},
],
onError: [
{
actions: 'setOtpError',
actions: [log('OTP error'), 'setOtpError'],
target: 'acceptingOtpInput',
},
],
Expand Down
7 changes: 6 additions & 1 deletion machines/vcItem.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ export interface Typegen0 {
| 'error.platform.vc-item.requestingRevoke:invocation[0]';
setRevoke: 'done.invoke.vc-item.requestingRevoke:invocation[0]';
setTag: 'SAVE_TAG';
setTransactionId: 'LOCK_VC' | 'UNLOCK_VC';
setTransactionId:
| 'INPUT_OTP'
| 'REVOKE_VC'
| 'done.invoke.vc-item.requestingOtp:invocation[0]'
| 'error.platform.vc-item.requestingLock:invocation[0]'
| 'error.platform.vc-item.requestingRevoke:invocation[0]';
storeContext:
| 'CREDENTIAL_DOWNLOADED'
| 'done.invoke.vc-item.requestingRevoke:invocation[0]'
Expand Down
13 changes: 10 additions & 3 deletions screens/Home/ViewVcModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { VcDetails } from '../../components/VcDetails';
import { MessageOverlay } from '../../components/MessageOverlay';
import { ToastItem } from '../../components/ui/ToastItem';
import { Passcode } from '../../components/Passcode';
//import { OtpVerificationModal } from './MyVcs/OtpVerificationModal';
import { OtpVerificationModal } from './MyVcs/OtpVerificationModal';
import { OIDcAuthenticationModal } from '../../components/OIDcAuth';
import { useViewVcModal, ViewVcModalProps } from './ViewVcModalController';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -59,10 +59,17 @@ export const ViewVcModal: React.FC<ViewVcModalProps> = (props) => {
onDismiss={controller.DISMISS}
onVerify={() => {
console.log('onVerify')
controller.revokeVc('1111')
controller.revokeVc('111111')
}}
error={controller.otpError}
/>
/>

{/* <OtpVerificationModal
isVisible={controller.isAcceptingOtpInput}
onDismiss={controller.DISMISS}
onInputDone={controller.INPUT_OTP}
error={controller.otpError}
/> */}

<MessageOverlay
isVisible={controller.isRequestingOtp}
Expand Down
7 changes: 5 additions & 2 deletions screens/Profile/Revoke.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@ export const Revoke: React.FC<RevokeScreenProps> = (props) => {
<OIDcAuthenticationModal
isVisible={controller.isAuthenticating}
onDismiss={() => controller.setAuthenticating(false)}
onVerify={() => controller.setIsViewing(true)}
onVerify={() => {
controller.setAuthenticating(false)
controller.setIsViewing(true)
}}
/>
<OIDcAuthenticationModal
isVisible={controller.isAcceptingOtpInput}
onDismiss={controller.DISMISS}
onVerify={() => {
controller.revokeVc('1111')
controller.revokeVc('111111')
}}
/>
<Overlay
Expand Down
1 change: 1 addition & 0 deletions screens/Profile/RevokeController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function useRevoke() {

useEffect(() => {
if (isRevokingVc) {
setSelectedVidKeys([])
showToast(t('revokeSuccessful'));
revokeService.send(RevokeVidsEvents.DISMISS());
}
Expand Down
4 changes: 2 additions & 2 deletions shared/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export async function request(
path: `/${string}`,
body?: Record<string, unknown>
) {
console.log('----->HOST', HOST)
console.log('----->body', body)
console.log('HOST',HOST + path );
console.log('BODY', body)
const response = await fetch(HOST + path, {
method,
headers: {
Expand Down

0 comments on commit 5d894a8

Please sign in to comment.