Skip to content

Commit

Permalink
fix: Disable preload for magic init
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmuscat committed Jul 19, 2024
1 parent 1d1dea2 commit c800c4f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/passport/sdk/src/Passport.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('Passport', () => {
(Magic as jest.Mock).mockImplementation(() => ({
openid: { loginWithOIDC: mockLoginWithOidc },
rpcProvider: { request: mockMagicRequest },
preload: jest.fn(),
}));
});

Expand Down
9 changes: 2 additions & 7 deletions packages/passport/sdk/src/magicAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MagicAdapter from './magicAdapter';
import { PassportConfiguration } from './config';
import { PassportError, PassportErrorType } from './errors/passportError';

const loginWithOIDCMock:jest.MockedFunction<(args: LoginWithOpenIdParams) => Promise<void>> = jest.fn();
const loginWithOIDCMock: jest.MockedFunction<(args: LoginWithOpenIdParams) => Promise<void>> = jest.fn();

const rpcProvider = {};

Expand All @@ -23,7 +23,6 @@ describe('MagicWallet', () => {
magicProviderId: providerId,
} as PassportConfiguration;
const idToken = 'e30=.e30=.e30=';
const preload = jest.fn();

beforeEach(() => {
jest.resetAllMocks();
Expand All @@ -35,7 +34,6 @@ describe('MagicWallet', () => {
logout: logoutMock,
},
rpcProvider,
preload,
}));
});

Expand All @@ -56,7 +54,6 @@ describe('MagicWallet', () => {
});
it('starts initialising the magicClient', () => {
jest.spyOn(window.document, 'readyState', 'get').mockReturnValue('complete');
preload.mockResolvedValue(Promise.resolve());
const magicAdapter = new MagicAdapter(config);
// @ts-ignore
expect(magicAdapter.lazyMagicClient).toBeDefined();
Expand All @@ -83,13 +80,13 @@ describe('MagicWallet', () => {

describe('login', () => {
it('should call loginWithOIDC and initialise the provider with the correct arguments', async () => {
preload.mockResolvedValue(Promise.resolve());
const magicAdapter = new MagicAdapter(config);
const magicProvider = await magicAdapter.login(idToken);

expect(Magic).toHaveBeenCalledWith(apiKey, {
network: 'mainnet',
extensions: [new OpenIdExtension()],
deferPreload: true,
});

expect(loginWithOIDCMock).toHaveBeenCalledWith({
Expand All @@ -101,7 +98,6 @@ describe('MagicWallet', () => {
});

it('should throw a PassportError when an error is thrown', async () => {
preload.mockResolvedValue(Promise.resolve());
const magicAdapter = new MagicAdapter(config);

loginWithOIDCMock.mockImplementation(() => {
Expand All @@ -121,7 +117,6 @@ describe('MagicWallet', () => {

describe('logout', () => {
it('calls the logout function', async () => {
preload.mockResolvedValue(Promise.resolve());
const magicAdapter = new MagicAdapter(config);
await magicAdapter.login(idToken);
await magicAdapter.logout();
Expand Down
2 changes: 1 addition & 1 deletion packages/passport/sdk/src/magicAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default class MagicAdapter {
const client = new Magic(this.config.magicPublishableApiKey, {
extensions: [new OpenIdExtension()],
network: MAINNET, // We always connect to mainnet to ensure addresses are the same across envs
deferPreload: true,
});
client.preload();
return client;
});
}
Expand Down

0 comments on commit c800c4f

Please sign in to comment.