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(mosip#280): serviceRefs wrongly included in vc data #272

Merged
merged 2 commits into from
Dec 16, 2022
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
7 changes: 6 additions & 1 deletion components/SingleVcItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ export const SingleVcItem: React.FC<VcItemProps> = (props) => {
const { appService } = useContext(GlobalContext);
const { t } = useTranslation('VcDetails');

const machine = useRef(createVcItemMachine(appService, props.vcKey));
const machine = useRef(
createVcItemMachine(
appService.getSnapshot().context.serviceRefs,
props.vcKey
)
);

const service = useInterpret(machine.current);
const context = useSelector(service, selectContext);
Expand Down
8 changes: 6 additions & 2 deletions components/VcItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ const getDetails = (arg1, arg2, verifiableCredential) => {
export const VcItem: React.FC<VcItemProps> = (props) => {
const { appService } = useContext(GlobalContext);
const { t } = useTranslation('VcDetails');

const machine = useRef(createVcItemMachine(appService, props.vcKey));
const machine = useRef(
createVcItemMachine(
appService.getSnapshot().context.serviceRefs,
props.vcKey
)
);

const service = useInterpret(machine.current, { devTools: __DEV__ });
const context = useSelector(service, selectContext);
Expand Down
4 changes: 2 additions & 2 deletions ios/MOSIPResidentApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MOSIPResidentApp/MOSIPResidentApp.entitlements;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 9L83VVTX8B;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand Down Expand Up @@ -335,7 +335,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MOSIPResidentApp/MOSIPResidentApp.entitlements;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 9L83VVTX8B;
INFOPLIST_FILE = MOSIPResidentApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
Expand Down
52 changes: 24 additions & 28 deletions machines/vcItem.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import {
AnyInterpreter,
assign,
ErrorPlatformEvent,
EventFrom,
send,
StateFrom,
} from 'xstate';
import { assign, ErrorPlatformEvent, EventFrom, send, StateFrom } from 'xstate';
import { createModel } from 'xstate/lib/model';
import { MY_VCS_STORE_KEY, VC_ITEM_STORE_KEY } from '../shared/constants';
import { AppServices } from '../shared/GlobalContext';
import { CredentialDownloadResponse, request } from '../shared/request';
import {
VC,
Expand All @@ -22,7 +16,7 @@ import { log } from 'xstate/lib/actions';

const model = createModel(
{
appService: {} as AnyInterpreter, // `InterpreterFrom<typeof appMachine>` does not work for some reason
serviceRefs: {} as AppServices,
id: '',
idType: '' as VcIdType,
tag: '',
Expand Down Expand Up @@ -356,10 +350,12 @@ export const vcItemMachine =
actions: {
updateVc: send(
(context) => {
const { appService, ...vc } = context;
const { serviceRefs, ...vc } = context;
return { type: 'VC_DOWNLOADED', vc };
},
{ to: (context) => context.appService.children.get('vc') }
{
to: (context) => context.serviceRefs.vc,
}
),

requestVcContext: send(
Expand All @@ -368,24 +364,24 @@ export const vcItemMachine =
vcKey: VC_ITEM_STORE_KEY(context),
}),
{
to: (context) => context.appService.children.get('vc'),
to: (context) => context.serviceRefs.vc,
}
),

requestStoredContext: send(
(context) => StoreEvents.GET(VC_ITEM_STORE_KEY(context)),
{
to: (context) => context.appService.children.get('store'),
to: (context) => context.serviceRefs.store,
}
),

storeContext: send(
(context) => {
const { appService, ...data } = context;
const { serviceRefs, ...data } = context;
return StoreEvents.SET(VC_ITEM_STORE_KEY(context), data);
},
{
to: (context) => context.appService.children.get('store'),
to: (context) => context.serviceRefs.store,
}
),

Expand All @@ -395,19 +391,19 @@ export const vcItemMachine =

storeTag: send(
(context) => {
const { appService, ...data } = context;
const { serviceRefs, ...data } = context;
return StoreEvents.SET(VC_ITEM_STORE_KEY(context), data);
},
{ to: (context) => context.appService.children.get('store') }
{ to: (context) => context.serviceRefs.store }
),

setCredential: model.assign((_, event) => {
setCredential: model.assign((context, event) => {
switch (event.type) {
case 'STORE_RESPONSE':
return event.response;
return { ...context, ...event.response };
case 'GET_VC_RESPONSE':
case 'CREDENTIAL_DOWNLOADED':
return event.vc;
return { ...context, ...event.vc };
}
}),

Expand All @@ -421,7 +417,7 @@ export const vcItemMachine =
vcLabel: event.vc.tag || event.vc.id,
}),
{
to: (context) => context.appService.children.get('activityLog'),
to: (context) => context.serviceRefs.activityLog,
}
),

Expand All @@ -435,7 +431,7 @@ export const vcItemMachine =
vcLabel: context.tag || context.id,
}),
{
to: (context) => context.appService.children.get('activityLog'),
to: (context) => context.serviceRefs.activityLog,
}
),

Expand All @@ -447,7 +443,7 @@ export const vcItemMachine =
);
},
{
to: (context) => context.appService.children.get('store'),
to: (context) => context.serviceRefs.store,
}
),

Expand Down Expand Up @@ -486,10 +482,10 @@ export const vcItemMachine =

storeLock: send(
(context) => {
const { appService, ...data } = context;
const { serviceRefs, ...data } = context;
return StoreEvents.SET(VC_ITEM_STORE_KEY(context), data);
},
{ to: (context) => context.appService.children.get('store') }
{ to: (context) => context.serviceRefs.store }
),
},

Expand Down Expand Up @@ -628,13 +624,13 @@ export const vcItemMachine =
);

export const createVcItemMachine = (
appService: AnyInterpreter,
serviceRefs: AppServices,
vcKey: string
) => {
const [, idType, id, requestId] = vcKey.split(':');
return vcItemMachine.withContext({
...vcItemMachine.context,
appService,
serviceRefs,
id,
idType: idType as VcIdType,
requestId,
Expand All @@ -644,7 +640,7 @@ export const createVcItemMachine = (
type State = StateFrom<typeof vcItemMachine>;

export function selectVc(state: State) {
const { appService, ...data } = state.context;
const { serviceRefs, ...data } = state.context;
return data;
}

Expand Down
7 changes: 2 additions & 5 deletions screens/Scan/SendVcScreenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { selectVcLabel } from '../../machines/settings';
import { selectShareableVcs } from '../../machines/vc';
import { vcItemMachine } from '../../machines/vcItem';
import { GlobalContext } from '../../shared/GlobalContext';
import { VC } from '../../types/vc';

export function useSendVcScreen() {
const { appService } = useContext(GlobalContext);
Expand All @@ -49,7 +48,6 @@ export function useSendVcScreen() {
}

const [selectedIndex, setSelectedIndex] = useState<number>(null);
const SELECT_VC = (vc: VC) => scanService.send(ScanEvents.SELECT_VC(vc));

return {
selectedIndex,
Expand All @@ -58,8 +56,8 @@ export function useSendVcScreen() {
SELECT_VC_ITEM:
(index: number) => (vcRef: ActorRefFrom<typeof vcItemMachine>) => {
setSelectedIndex(index);
const vcData = vcRef.getSnapshot().context;
SELECT_VC(vcData);
const { serviceRefs, ...vcData } = vcRef.getSnapshot().context;
scanService.send(ScanEvents.SELECT_VC(vcData));
},

status,
Expand All @@ -80,7 +78,6 @@ export function useSendVcScreen() {
isCancelling: useSelector(scanService, selectIsCancelling),

CANCEL,
SELECT_VC,
ACCEPT_REQUEST: () => scanService.send(ScanEvents.ACCEPT_REQUEST()),
VERIFY_AND_ACCEPT_REQUEST: () =>
scanService.send(ScanEvents.VERIFY_AND_ACCEPT_REQUEST()),
Expand Down