Skip to content

CAIP-2 Chain ID#19991

Closed
jiexi wants to merge 70 commits intodevelopfrom
jl/mmp-901/caip-2
Closed

CAIP-2 Chain ID#19991
jiexi wants to merge 70 commits intodevelopfrom
jl/mmp-901/caip-2

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Jul 12, 2023

Explanation

As part of the push for multichain, we want to move away from Eth specific references to chainId. We achieve this by replacing our usage of hex/dec chain IDs with CAIP-2 (chain agnostic, human readable) chain IDs.

  • Use CaipChainId type for internal chain representation where appropriate
  • Rename chainId to caipChainId

See: MetaMask/utils#116
See: MetaMask/core#1489
See: MetaMask/smart-transactions-controller#184

Screenshots/Screencaps

None. These change should should be minimally apparent to the end user. Users will continue to use and be shown hex/dec chainIds denoting an Ethereum based chain. The only caveat is for the Network Form:

  • Currently displays chainId as hex when triggered from jsonrpc, and as decimal or hex from the wallet ui itself
  • This behavior will change for the wallet ui, where we can only show decimal XOR hex after being saved, not both. I’ve made changes to have it show decimal.
  • The reason for this is that the user input hex/dec chainId gets converted into caipChainId which is decimal formatted. When we display this back to the user, we have no idea what their originally formatted input was

Manual Testing Steps

These changes can be tested by using the wallet as you normally would. Everything should function exactly the same except for the caveat with Network Form explained above.

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@jiexi jiexi requested a review from a team as a code owner July 12, 2023 23:50
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@jiexi jiexi requested a review from a team as a code owner July 20, 2023 00:00
@jiexi jiexi changed the title Jl/mmp 901/caip 2 CAIP-2 Aug 15, 2023
@jiexi jiexi changed the title CAIP-2 CAIP-2 Chain ID Aug 15, 2023
@jiexi jiexi marked this pull request as ready for review August 16, 2023 16:27
},
},
accountTokens: {
accountTokens: { // this state is stale
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see this referenced anywhere

'0x9d0ba4ddac06032527b140912ec808ab9451b788': {},
},
accountHiddenTokens: {
accountHiddenTokens: { // this state is stale
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see this referenced anywhere

'NetworkController:stateChange',
),
onTokenListStateChange: (tokenListState) =>
console.log('onTokenListStateChange', tokenListState), // this is missing
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now a required field by the TokensController.
It's used like this in mobile: https://github.com/MetaMask/metamask-mobile/blob/2326d8707aeb01480d765bc417553b0517ab8411/app/core/Engine.ts#L299

/** The transaction status property is not considered sensitive and is now included in the non-anonymous event */
let properties = {
chain_id: chainId,
chain_id: caipChainId, // what to do here?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably have left a comment elsewhere, but are we okay with using CAIP chain ID values for the chain_id metrics property?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix dependencies once core is merged

* dapp may specify any caipChainId.
*/
export type ChainId = (typeof CHAIN_IDS)[keyof typeof CHAIN_IDS];
// export type ChainId = (typeof CAIP_CHAIN_IDS)[keyof typeof CAIP_CHAIN_IDS];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any need to keep a type that includes all built caip chain IDs around? I'm thinking no

build() {
this.fixture.meta = {
version: 74,
version: 91,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this okay for us to bump? It's not clear to me what version this fixture has been left at. It's definitely not 74

category: 'inpage_provider',
locale: 'en',
chain_id: '0x539',
chain_id: 'eip155:1337', // same
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we okay with chain_id metrics being changed to caip chain id?

category: 'inpage_provider',
locale: 'en',
chain_id: '0x539',
chain_id: 'eip155:1337', // what should this be?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we okay with chain_id metrics being changed to caip chain id?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this spec seems partially broken for firefox on my local machine. can revert and recheck on CI later

export default {
title: 'Components/App/AddNetwork',
argTypes: {
// this component doesn't take props. what are these?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this just stale code?


const { address: from } = useSelector(getSelectedAccount);
const network = hexToDecimal(useSelector(getCurrentChainId));
const network = toEthChainIdInt(useSelector(getCurrentCaipChainId)); // is this named wrong?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

address,
error,
chainId,
caipChainId, // this isn't even used in the slice?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file confuses me a little

// await screen.findByText(
// 'URLs require the appropriate HTTP/HTTPS prefix.',
// ),
// ).toBeInTheDocument();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to revert this and test in CI later. I believe nock is giving me grief locally

@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Aug 28, 2023

Postponed. Not sure if/when will be picked back up.

@jiexi jiexi closed this Aug 28, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2023
@HowardBraham HowardBraham deleted the jl/mmp-901/caip-2 branch January 19, 2026 19:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant