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

Use name component in signature requests #20831

Merged
merged 24 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b2113da
Add name and combo components
matthewwalsh0 Sep 8, 2023
a339366
Revert bad merge changes
matthewwalsh0 Sep 8, 2023
482f703
Use released name controller
matthewwalsh0 Sep 8, 2023
8dae5db
Update snapshots
matthewwalsh0 Sep 8, 2023
c754e18
Update Lavamoat policies
matthewwalsh0 Sep 8, 2023
dd4f2a5
Fix linting
matthewwalsh0 Sep 8, 2023
caf7a5f
Use name component in signature data
matthewwalsh0 Sep 11, 2023
5633a35
Add E2E test
matthewwalsh0 Sep 12, 2023
8c22ca7
Update proposed names in name component
matthewwalsh0 Sep 13, 2023
3c18c96
Merge branch 'feat/name-component' into feat/signature-names-flask
matthewwalsh0 Sep 13, 2023
3f4e045
Mock name provider requests in E2E test
matthewwalsh0 Sep 13, 2023
daf6902
Fix unit tests
matthewwalsh0 Sep 13, 2023
1a7c7ff
Merge branch 'feat/name-component' into feat/signature-names-flask
matthewwalsh0 Sep 13, 2023
c255458
Fix unit tests
matthewwalsh0 Sep 13, 2023
70a9c48
Move form combo field to UI directory
matthewwalsh0 Sep 13, 2023
c5fdaca
Add E2E test for V3 signatures
matthewwalsh0 Sep 13, 2023
e57454b
Merge branch 'feat/name-component' into feat/signature-names-flask
matthewwalsh0 Sep 13, 2023
f192a3c
Revert unnecessary change
matthewwalsh0 Sep 13, 2023
cbe4188
Fix CSS import
matthewwalsh0 Sep 13, 2023
6534103
Merge branch 'feat/name-component' into feat/signature-names-flask
matthewwalsh0 Sep 13, 2023
e6a95b0
Merge branch 'develop' into feat/signature-names-flask
matthewwalsh0 Sep 18, 2023
5d70f93
Merge branch 'develop' into feat/signature-names-flask
matthewwalsh0 Sep 18, 2023
c93917c
Use property rather than custom style
matthewwalsh0 Sep 18, 2023
4f56098
Merge branch 'develop' into feat/signature-names-flask
matthewwalsh0 Sep 19, 2023
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
45 changes: 44 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ import {
} from '@metamask/controller-utils';
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';

///: BEGIN:ONLY_INCLUDE_IN(petnames)
import {
NameController,
ENSNameProvider,
EtherscanNameProvider,
TokenNameProvider,
LensNameProvider,
} from '@metamask/name-controller';
///: END:ONLY_INCLUDE_IN

///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils';
///: END:ONLY_INCLUDE_IN
Expand Down Expand Up @@ -1511,6 +1521,27 @@ export default class MetamaskController extends EventEmitter {
initState.SmartTransactionsController,
);

///: BEGIN:ONLY_INCLUDE_IN(petnames)
this.nameController = new NameController({
getChainId: () => this.networkController.state.providerConfig.chainId,
messenger: this.controllerMessenger.getRestricted({
name: 'NameController',
allowedActions: [],
}),
providers: [
new ENSNameProvider({
reverseLookup: this.ensController.reverseResolveAddress.bind(
this.ensController,
),
}),
new EtherscanNameProvider({}),
new TokenNameProvider({}),
new LensNameProvider(),
],
state: initState.NameController,
});
///: END:ONLY_INCLUDE_IN

this.txController.on('newSwapApproval', (txMeta) => {
this.swapsController.setApproveTxId(txMeta.id);
});
Expand Down Expand Up @@ -1716,6 +1747,9 @@ export default class MetamaskController extends EventEmitter {
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
PPOMController: this.ppomController,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(petnames)
NameController: this.nameController,
///: END:ONLY_INCLUDE_IN
...resetOnRestartStore,
});

Expand Down Expand Up @@ -1751,13 +1785,15 @@ export default class MetamaskController extends EventEmitter {
///: BEGIN:ONLY_INCLUDE_IN(desktop)
DesktopController: this.desktopController.store,
///: END:ONLY_INCLUDE_IN

///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
CustodyController: this.custodyController.store,
InstitutionalFeaturesController:
this.institutionalFeaturesController.store,
MmiConfigurationController: this.mmiConfigurationController.store,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(petnames)
NameController: this.nameController,
///: END:ONLY_INCLUDE_IN
...resetOnRestartStore,
},
controllerMessenger: this.controllerMessenger,
Expand Down Expand Up @@ -2854,6 +2890,13 @@ export default class MetamaskController extends EventEmitter {

// E2E testing
throwTestError: this.throwTestError.bind(this),

///: BEGIN:ONLY_INCLUDE_IN(petnames)
updateProposedNames: this.nameController.updateProposedNames.bind(
this.nameController,
),
setName: this.nameController.setName.bind(this.nameController),
///: END:ONLY_INCLUDE_IN
};
}

Expand Down
2 changes: 2 additions & 0 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ buildTypes:
- build-flask
- keyring-snaps
- blockaid
- petnames
env:
- INFURA_FLASK_PROJECT_ID
- SEGMENT_FLASK_WRITE_KEY
Expand Down Expand Up @@ -125,6 +126,7 @@ features:
env:
- BLOCKAID_FILE_CDN: static.metafi.codefi.network/api/v1/confirmations/ppom
- BLOCKAID_PUBLIC_KEY: 066ad3e8af5583385e312c156d238055215d5f25247c1e91055afa756cb98a88
petnames:

###
# Build Type code extensions. Things like different support links, warning pages, banners
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,20 @@ class FixtureBuilder {
});
}

withNameController(data) {
merge(
this.fixture.data.NameController
? this.fixture.data.NameController
: (this.fixture.data.NameController = {}),
data,
);
return this;
}

withNoNames() {
return this.withNameController({ names: {} });
}

build() {
this.fixture.meta = {
version: 74,
Expand Down
54 changes: 54 additions & 0 deletions test/e2e/mock-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,61 @@ async function setupMocking(server, testSpecificMock, { chainId }) {
};
});

await mockLensNameProvider(server);
await mockTokenNameProvider(server, chainId);

return mockedEndpoint;
}

async function mockLensNameProvider(server) {
const handlesByAddress = {
'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826': 'test.lens',
'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB': 'test2.lens',
'0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC': 'test3.lens',
};

await server.forPost('https://api.lens.dev').thenCallback((request) => {
const address = request.body?.json?.variables?.address;
const handle = handlesByAddress[address];

return {
statusCode: 200,
json: {
data: {
profiles: {
items: [
{
handle,
},
],
},
},
},
};
});
}

async function mockTokenNameProvider(server) {
const namesByAddress = {
'0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF': 'Test Token',
'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57': 'Test Token 2',
};

for (const address of Object.keys(namesByAddress)) {
const name = namesByAddress[address];

await server
.forGet(/https:\/\/token-api\.metaswap\.codefi\.network\/token\/.*/gu)
.withQuery({ address })
.thenCallback(() => {
return {
statusCode: 200,
json: {
name,
},
};
});
}
}

module.exports = { setupMocking };
1 change: 1 addition & 0 deletions test/e2e/run-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ async function main() {
'test-snap-rpc.spec.js',
'test-snap-lifecycle.spec.js',
'ppom-toggle-settings.spec.js',
'petnames.spec.js',
];
testPaths = testPaths.filter((p) =>
filteredTests.every((filteredTest) => !p.endsWith(filteredTest)),
Expand Down
Loading