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

Warn developers of Coming Deprecation of Universal Wallet API Keys #716

Merged
merged 4 commits into from
Feb 26, 2024
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
6 changes: 5 additions & 1 deletion packages/@magic-sdk/provider/src/core/sdk-exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ export function createDeprecationWarning(options: {
}) {
const { method, removalVersions, useInstead } = options;

const preventDisruptionLanguage = 'to prevent disruption of the wallet service';

const removalVersion = removalVersions[SDKEnvironment.sdkName];
const useInsteadSuffix = useInstead ? ` Use \`${useInstead}\` instead.` : '';
const useInsteadSuffix = useInstead
? ` Use \`${useInstead}\` instead ${useInstead.includes('Dedicated Wallet') ? preventDisruptionLanguage : ''}.`
: '';
const message = `\`${method}\` will be removed from \`${SDKEnvironment.sdkName}\` in version \`${removalVersion}\`.${useInsteadSuffix}`;

return new MagicSDKWarning(SDKWarningCode.DeprecationNotice, message);
Expand Down
19 changes: 18 additions & 1 deletion packages/@magic-sdk/provider/src/core/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createPromise } from '../util/promise-tools';
import { getItem, setItem } from '../util/storage';
import { createJwt } from '../util/web-crypto';
import { SDKEnvironment } from './sdk-environment';
import { createModalNotReadyError } from './sdk-exceptions';
import { createDeprecationWarning, createModalNotReadyError } from './sdk-exceptions';
import {
clearDeviceShares,
encryptAndPersistDeviceShare,
Expand All @@ -34,6 +34,13 @@ interface StandardizedMagicRequest {
deviceShare?: string;
}

export const UniversalWalletRemovalVersions = {
'magic-sdk': 'v23.0.0',
'@magic-sdk/react-native': 'v14.0.0',
'@magic-sdk/react-native-bare': 'v24.0.0',
'@magic-sdk/react-native-expo': 'v24.0.0',
};

/**
* Get the originating payload from a batch request using the specified `id`.
*/
Expand Down Expand Up @@ -259,5 +266,15 @@ export abstract class ViewController {
this.on(MagicIncomingWindowMessage.MAGIC_SHOW_OVERLAY, () => {
this.showOverlay();
});

this.on(MagicIncomingWindowMessage.MAGIC_SEND_PRODUCT_TYPE, (event: MagicMessageEvent) => {
if (event.data.response.result.product_type === 'connect') {
createDeprecationWarning({
method: 'Usage of Universal Wallet API Keys',
removalVersions: UniversalWalletRemovalVersions,
useInstead: 'Dedicated Wallet API Key',
}).log();
}
});
}
}
1 change: 1 addition & 0 deletions packages/@magic-sdk/provider/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const MSG_TYPES = (parameters = ENCODED_QUERY_PARAMS) => ({
MAGIC_HIDE_OVERLAY: `MAGIC_HIDE_OVERLAY-${parameters}`,
MAGIC_HANDLE_REQUEST: `MAGIC_HANDLE_REQUEST-${parameters}`,
MAGIC_HANDLE_EVENT: `MAGIC_HANDLE_EVENT-${parameters}`,
MAGIC_SEND_PRODUCT_TYPE: `MAGIC_SEND_PRODUCT_TYPE-${parameters}`,
});
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ test('Creates a `DEPRECATION_NOTICE` warning with `useInstead` suffix', async ()
warningAssertions(
warning,
'DEPRECATION_NOTICE',
'`test()` will be removed from `magic-sdk` in version `v999`. Use `test2()` instead.',
'`test()` will be removed from `magic-sdk` in version `v999`. Use `test2()` instead .',
);
});

test('Creates a `DEPRECATION_NOTICE` warning with `useInstead` containing "Dedicated Wallet" suffix', async () => {
mockSDKEnvironmentConstant({ sdkName: 'magic-sdk' });

const { createDeprecationWarning } = require('../../../../src/core/sdk-exceptions');
const warning = createDeprecationWarning({
method: 'test()',
removalVersions: {
'magic-sdk': 'v999',
'@magic-sdk/react-native-bare': 'v888',
'@magic-sdk/react-native-expo': 'v777',
},
useInstead: 'Dedicated Wallet',
});

warningAssertions(
warning,
'DEPRECATION_NOTICE',
'`test()` will be removed from `magic-sdk` in version `v999`. Use `Dedicated Wallet` instead to prevent disruption of the wallet service.',
);
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import browserEnv from '@ikscodes/browser-env';
import { createViewController } from '../../../factories';
import { MSG_TYPES } from '../../../constants';
import { createDeprecationWarning } from '../../../../src/core/sdk-exceptions';
import { UniversalWalletRemovalVersions } from '../../../../src/core/view-controller';

beforeEach(() => {
browserEnv();
});

jest.mock('../../../../src/core/sdk-exceptions', () => ({
...jest.requireActual('../../../../src/core/sdk-exceptions'),
createDeprecationWarning: jest.fn(),
}));

test('Receive MAGIC_HIDE_OVERLAY, call `hideOverlay`', (done) => {
const overlay = createViewController('');
const hideOverlayStub = jest.fn();
Expand All @@ -31,3 +38,32 @@ test('Receive MAGIC_SHOW_OVERLAY, call `showOverlay`', (done) => {
done();
}, 0);
});

test('Receive MAGIC_SEND_PRODUCT_TYPE with product_type "connect", call `createDeprecationWarning`', (done) => {
const overlay = createViewController('');

// Cast the imported function to its mocked version
const mockCreateDeprecationWarning = createDeprecationWarning as jest.Mock;

// Mock the return value
mockCreateDeprecationWarning.mockReturnValue({
log: jest.fn(),
});

window.postMessage(
{
msgType: MSG_TYPES().MAGIC_SEND_PRODUCT_TYPE,
response: { result: { product_type: 'connect' } },
},
'*',
);

setTimeout(() => {
expect(mockCreateDeprecationWarning).toBeCalledWith({
method: 'Usage of Universal Wallet API Keys',
removalVersions: UniversalWalletRemovalVersions,
useInstead: 'Dedicated Wallet API Key',
});
done();
}, 0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ beforeEach(() => {
/**
* We start with 3 listeners whenever a `ViewController` is created.
*/
const baselineListeners = 3;
const baselineListeners = 4;

test('Adds the event listener callback to the internal state', () => {
const viewController = createViewController();
Expand Down
1 change: 1 addition & 0 deletions packages/@magic-sdk/types/src/core/json-rpc-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface JsonRpcResponsePayload<ResultType = any> {
id: string | number | null;
result?: ResultType | null;
error?: JsonRpcError | null;
product_type?: 'magic' | 'connect';
}

export interface UserInfo {
Expand Down
1 change: 1 addition & 0 deletions packages/@magic-sdk/types/src/core/message-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum MagicIncomingWindowMessage {
MAGIC_HIDE_OVERLAY = 'MAGIC_HIDE_OVERLAY',
MAGIC_HANDLE_EVENT = 'MAGIC_HANDLE_EVENT',
MAGIC_MG_BOX_SEND_RECEIPT = 'MAGIC_MG_BOX_SEND_RECEIPT',
MAGIC_SEND_PRODUCT_TYPE = 'MAGIC_SEND_PRODUCT_TYPE',
}

export enum MagicOutgoingWindowMessage {
Expand Down
Loading