Skip to content

Commit ef595c0

Browse files
committed
small change
1 parent e99196a commit ef595c0

7 files changed

Lines changed: 20 additions & 25 deletions

File tree

packages/client/src/EIP1193Provider.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('EIP1193Provider', () => {
2323
beforeEach(() => {
2424
mockWallet = Wallets.CoinbaseSmartWallet;
2525
mockClient = {
26+
handshake: jest.fn(),
2627
request: jest.fn(),
2728
reset: jest.fn(),
2829
} as unknown as jest.Mocked<MWPClient>;

packages/client/src/MWPClient.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { WebBasedWalletCommunicator } from 'src/components/communicator/webBased/Communicator';
22

3-
import { Communicator, CommunicatorInterface } from './components/communicator';
3+
import { CommunicatorInterface, getCommunicator } from './components/communicator';
44
import { KeyManager } from './components/key/KeyManager';
55
import { MWPClient } from './MWPClient';
66
import {
@@ -68,7 +68,7 @@ describe('MWPClient', () => {
6868
};
6969

7070
WebBasedWalletCommunicator.communicators.clear();
71-
mockCommunicator = Communicator.getInstance(mockWallet);
71+
mockCommunicator = getCommunicator(mockWallet);
7272
jest
7373
.spyOn(mockCommunicator, 'postRequestAndWaitForResponse')
7474
.mockResolvedValue(mockSuccessResponse);

packages/client/src/MWPClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const ACCOUNTS_KEY = 'accounts';
1616
const ACTIVE_CHAIN_STORAGE_KEY = 'activeChain';
1717
const AVAILABLE_CHAINS_STORAGE_KEY = 'availableChains';
1818
const WALLET_CAPABILITIES_STORAGE_KEY = 'walletCapabilities';
19-
import { Communicator, CommunicatorInterface } from './components/communicator';
19+
import { CommunicatorInterface, getCommunicator } from './components/communicator';
2020
import { LIB_VERSION } from './version';
2121
import {
2222
appendMWPResponsePath,
@@ -57,7 +57,7 @@ export class MWPClient {
5757
this.keyManager = new KeyManager({ wallet: this.wallet });
5858
this.storage = new ScopedAsyncStorage(this.wallet.name, 'MWPClient');
5959

60-
this.communicator = Communicator.getInstance(this.wallet);
60+
this.communicator = getCommunicator(this.wallet);
6161

6262
// default values
6363
this.accounts = [];

packages/client/src/components/communicator/Communicator.test.ts renamed to packages/client/src/components/communicator/getCommunicator.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Communicator } from './Communicator';
1+
import { getCommunicator } from './getCommunicator';
22
import { WebBasedWalletCommunicator } from './webBased/Communicator';
33
import { Wallet } from ':core/wallet';
44

@@ -25,7 +25,7 @@ describe('Communicator', () => {
2525
};
2626
(WebBasedWalletCommunicator.getInstance as jest.Mock).mockReturnValue(mockCommunicator);
2727

28-
const result = Communicator.getInstance(mockWebBasedWallet);
28+
const result = getCommunicator(mockWebBasedWallet);
2929

3030
expect(WebBasedWalletCommunicator.getInstance).toHaveBeenCalledWith('test-scheme://');
3131
expect(result).toBe(mockCommunicator);
@@ -34,9 +34,7 @@ describe('Communicator', () => {
3434
test('getInstance throws error for native wallet', () => {
3535
const mockNativeWallet: Wallet = { type: 'native', scheme: 'native-scheme://' } as Wallet;
3636

37-
expect(() => Communicator.getInstance(mockNativeWallet)).toThrow(
38-
'Native wallet not supported yet'
39-
);
37+
expect(() => getCommunicator(mockNativeWallet)).toThrow('Native wallet not supported yet');
4038
});
4139

4240
test('getInstance throws error for unsupported wallet type', () => {
@@ -45,8 +43,6 @@ describe('Communicator', () => {
4543
scheme: 'unsupported-scheme://',
4644
} as Wallet;
4745

48-
expect(() => Communicator.getInstance(mockUnsupportedWallet)).toThrow(
49-
'Unsupported wallet type'
50-
);
46+
expect(() => getCommunicator(mockUnsupportedWallet)).toThrow('Unsupported wallet type');
5147
});
5248
});

packages/client/src/components/communicator/Communicator.ts renamed to packages/client/src/components/communicator/getCommunicator.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ export interface CommunicatorInterface {
77
handleResponse: (responseUrl: string) => boolean;
88
}
99

10-
export class Communicator {
11-
static getInstance(wallet: Wallet): CommunicatorInterface {
12-
const { type, scheme } = wallet;
10+
export function getCommunicator(wallet: Wallet): CommunicatorInterface {
11+
const { type, scheme } = wallet;
1312

14-
if (type === 'webBased') {
15-
return WebBasedWalletCommunicator.getInstance(scheme);
16-
}
17-
18-
if (type === 'native') {
19-
throw new Error('Native wallet not supported yet');
20-
}
13+
if (type === 'webBased') {
14+
return WebBasedWalletCommunicator.getInstance(scheme);
15+
}
2116

22-
throw new Error('Unsupported wallet type');
17+
if (type === 'native') {
18+
throw new Error('Native wallet not supported yet');
2319
}
20+
21+
throw new Error('Unsupported wallet type');
2422
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './Communicator';
1+
export * from './getCommunicator';
22
export * from './handleResponse';

packages/client/src/components/communicator/webBased/Communicator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as WebBrowser from 'expo-web-browser';
22

3-
import { CommunicatorInterface } from '../Communicator';
3+
import { CommunicatorInterface } from '../getCommunicator';
44
import { HashedContent } from './types';
55
import { standardErrors } from ':core/error';
66
import { MessageID, RPCRequestMessage, RPCResponseMessage } from ':core/message';

0 commit comments

Comments
 (0)