Skip to content

Commit

Permalink
Merge pull request #829 from magiclabs/cancel-event-for-recovery-flow
Browse files Browse the repository at this point in the history
fix: cancel event for recovery factor
  • Loading branch information
sukhrobbekodilov authored Oct 24, 2024
2 parents 6793fa8 + 3f5b59b commit 94bc319
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/@magic-sdk/provider/src/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export class UserModule extends BaseModule {
handle.on(RecoveryFactorEventEmit.StartEditPhoneNumber, () => {
this.createIntermediaryEvent(RecoveryFactorEventEmit.StartEditPhoneNumber, requestPayload.id as string)();
});
handle.on(RecoveryFactorEventEmit.Cancel, () => {
this.createIntermediaryEvent(RecoveryFactorEventEmit.Cancel, requestPayload.id as string)();
});
handle.on(RecencyCheckEventEmit.VerifyEmailOtp, (otp: string) => {
this.createIntermediaryEvent(RecencyCheckEventEmit.VerifyEmailOtp, requestPayload.id as string)(otp);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jest.mock('@magic-sdk/types', () => ({
RecoveryFactorEventEmit: {
SendNewPhoneNumber: 'send-new-phone-number',
SendOtpCode: 'send-otp-code',
Cancel: 'cancel',
StartEditPhoneNumber: 'start-edit-phone-number',
},
}));
Expand Down Expand Up @@ -151,6 +152,25 @@ test('ShowSettings should call createIntermediaryEvent with StartEditPhoneNumber

expect(createIntermediaryEventFn).toHaveBeenCalled();
});
test('ShowSettings should call createIntermediaryEvent with Cancel', () => {
const magic = createMagicSDK();
const mockOn = jest.fn();
const mockHandle = { on: mockOn };

magic.user.request = jest.fn().mockReturnValue(mockHandle);

const config = { page: DeepLinkPage.Recovery, showUI: false };
magic.user.showSettings(config);

const createIntermediaryEventFn = jest.fn();
magic.user.createIntermediaryEvent = jest.fn(() => createIntermediaryEventFn);

const startEditPhoneNumberListener = mockOn.mock.calls.find((call) => call[0] === 'cancel')[1];

startEditPhoneNumberListener();

expect(createIntermediaryEventFn).toHaveBeenCalled();
});

test('ShowSettings should attach event listener for StartEditPhoneNumber event', () => {
const magic = createMagicSDK();
Expand Down
2 changes: 2 additions & 0 deletions packages/@magic-sdk/types/src/modules/user-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum RecoveryFactorEventOnReceived {
export enum RecoveryFactorEventEmit {
SendNewPhoneNumber = 'send-new-phone-number',
SendOtpCode = 'send-otp-code',
Cancel = 'cancel',
StartEditPhoneNumber = 'start-edit-phone-number',
}

Expand All @@ -58,6 +59,7 @@ export type RecoveryFactorEventHandlers = {
[RecoveryFactorEventEmit.SendNewPhoneNumber]: (phone_number: string) => void;
[RecoveryFactorEventEmit.SendOtpCode]: (otp: string) => void;
[RecoveryFactorEventEmit.StartEditPhoneNumber]: () => void;
[RecoveryFactorEventEmit.Cancel]: () => void;

// Event sent
[RecoveryFactorEventOnReceived.EnterNewPhoneNumber]: () => void;
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ __metadata:
"@babel/plugin-proposal-optional-chaining": ^7.9.0
"@babel/runtime": ^7.9.6
"@magic-ext/oauth": ^22.14.0
magic-sdk: ^28.14.0
magic-sdk: ^28.15.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -12780,7 +12780,7 @@ fsevents@^2.3.2:
languageName: unknown
linkType: soft

"magic-sdk@^28.14.0, magic-sdk@workspace:packages/magic-sdk":
"magic-sdk@^28.15.0, magic-sdk@workspace:packages/magic-sdk":
version: 0.0.0-use.local
resolution: "magic-sdk@workspace:packages/magic-sdk"
dependencies:
Expand Down

0 comments on commit 94bc319

Please sign in to comment.