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

feat: add MetaMask Flask provider support for EIP-6963 #1192

Merged
merged 1 commit into from
Jan 10, 2025
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
2 changes: 1 addition & 1 deletion packages/sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const METAMASK_DEEPLINK_BASE = 'metamask://connect';

export const METAMASK_EIP_6369_PROVIDER_INFO = {
NAME: 'MetaMask',
RDNS: 'io.metamask',
RDNS: ['io.metamask', 'io.metamask.flask'],
};

export const UUID_V4_REGEX =
Expand Down
31 changes: 30 additions & 1 deletion packages/sdk/src/utils/eip6963RequestProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('eip6963RequestProvider', () => {
);
});

it('should resolve with valid provider', async () => {
it('should resolve with valid provider for MetaMask Main', async () => {
const mockProvider: SDKProvider = {} as SDKProvider;
const mockInfo: EIP6963ProviderInfo = {
uuid: 'a1d2c588-106f-4d05-958d-5e7d6c57c822',
Expand Down Expand Up @@ -60,4 +60,33 @@ describe('eip6963RequestProvider', () => {

expect(requestProviderPromise).toBe(mockProvider);
});

it('should resolve with valid provider for MetaMask Flask', async () => {
const mockProvider: SDKProvider = {} as SDKProvider;
const mockInfo: EIP6963ProviderInfo = {
uuid: 'a1d2c588-106f-4d05-958d-5e7d6c57c822',
name: 'MetaMask Flask',
icon: 'icon-path',
rdns: 'io.metamask.flask',
};
const mockEventDetail: EIP6963ProviderDetail = {
info: mockInfo,
provider: mockProvider,
};

(window.addEventListener as jest.Mock).mockImplementationOnce(
(eventName, callback) => {
if (eventName === EIP6963EventNames.Announce) {
callback({
type: EIP6963EventNames.Announce,
detail: mockEventDetail,
});
}
},
);

const requestProviderPromise = await eip6963RequestProvider();

expect(requestProviderPromise).toBe(mockProvider);
});
});
2 changes: 1 addition & 1 deletion packages/sdk/src/utils/eip6963RequestProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function eip6963RequestProvider(): Promise<MetaMaskInpageProvider> {
const isValid =
UUID_V4_REGEX.test(uuid) &&
(name as string).startsWith(METAMASK_EIP_6369_PROVIDER_INFO.NAME) &&
rdns === METAMASK_EIP_6369_PROVIDER_INFO.RDNS;
METAMASK_EIP_6369_PROVIDER_INFO.RDNS.includes(rdns);

if (isValid) {
clearTimeout(timeoutId);
Expand Down
Loading