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

fix: allow ramps dev environment on Flask #25659

Merged
merged 4 commits into from
Jul 4, 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
60 changes: 36 additions & 24 deletions app/scripts/lib/snap-keyring/keyring-snaps-permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import {
keyringSnapPermissionsBuilder,
} from './keyring-snaps-permissions';

const PORTFOLIO_ORIGINS: string[] = [
'https://portfolio.metamask.io',
'https://dev.portfolio.metamask.io',
'https://ramps-dev.portfolio.metamask.io',
];

describe('keyringSnapPermissionsBuilder', () => {
const mockController = new SubjectMetadataController({
subjectCacheLimit: 100,
Expand All @@ -26,32 +32,38 @@ describe('keyringSnapPermissionsBuilder', () => {
});

describe('Portfolio origin', () => {
it('returns the methods Portfolio can call', () => {
const permissions = keyringSnapPermissionsBuilder(
mockController,
'https://portfolio.metamask.io',
);
expect(permissions()).toStrictEqual([
KeyringRpcMethod.ListAccounts,
KeyringRpcMethod.GetAccount,
KeyringRpcMethod.GetAccountBalances,
KeyringRpcMethod.SubmitRequest,
]);
});
// @ts-expect-error This is missing from the Mocha type definitions
it.each(PORTFOLIO_ORIGINS)(
'returns the methods that can be called by %s',
(origin: string) => {
const permissions = keyringSnapPermissionsBuilder(
mockController,
origin,
);
expect(permissions()).toStrictEqual([
KeyringRpcMethod.ListAccounts,
KeyringRpcMethod.GetAccount,
KeyringRpcMethod.GetAccountBalances,
KeyringRpcMethod.SubmitRequest,
]);
},
);

it('cannot create an account', () => {
const permissions = keyringSnapPermissionsBuilder(
mockController,
'https://portfolio.metamask.io',
);
expect(permissions()).not.toContain(KeyringRpcMethod.CreateAccount);
});
// @ts-expect-error This is missing from the Mocha type definitions
it.each(PORTFOLIO_ORIGINS)(
'%s cannot create an account',
(origin: string) => {
const permissions = keyringSnapPermissionsBuilder(
mockController,
origin,
);
expect(permissions()).not.toContain(KeyringRpcMethod.CreateAccount);
},
);

it('can submit a request', () => {
const permissions = keyringSnapPermissionsBuilder(
mockController,
'https://portfolio.metamask.io',
);
// @ts-expect-error This is missing from the Mocha type definitions
it.each(PORTFOLIO_ORIGINS)('%s can submit a request', (origin: string) => {
const permissions = keyringSnapPermissionsBuilder(mockController, origin);
expect(permissions()).toContain(KeyringRpcMethod.SubmitRequest);
});
});
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import {
import { KeyringRpcMethod } from '@metamask/keyring-api';

/**
* The origin of the Portfolio dapp.
* The origins of the Portfolio dapp.
*/
const PORTFOLIO_ORIGIN = 'https://portfolio.metamask.io';
const PORTFOLIO_ORIGINS: string[] = [
'https://portfolio.metamask.io',
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
'https://dev.portfolio.metamask.io',
'https://ramps-dev.portfolio.metamask.io',
///: END:ONLY_INCLUDE_IF
];

/**
* List of keyring methods MetaMask can call.
Expand Down Expand Up @@ -94,7 +100,7 @@ export function keyringSnapPermissionsBuilder(
return METAMASK_ALLOWED_METHODS;
}

if (origin === PORTFOLIO_ORIGIN) {
if (PORTFOLIO_ORIGINS.includes(origin)) {
return PORTFOLIO_ALLOWED_METHODS;
}

Expand Down