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(btc): fix jazzicons generations #27662

Merged
merged 6 commits into from
Oct 10, 2024
Merged

fix(btc): fix jazzicons generations #27662

merged 6 commits into from
Oct 10, 2024

Conversation

ccharly
Copy link
Contributor

@ccharly ccharly commented Oct 7, 2024

Description

The jazzicons were all the same for mainnet/testnet accounts. It was probably due to the fact that the namespace being used was eip155 for all addresses, but Bitcoin addresses have a different format.

Here's the technical details:

  1. The current "icon factory" being in used is the ethereum one:
  1. The default constructor used for the ethereum factory uses the jsNumberForAddress which is ethereum-specific (or more like, "hex-specific" here):

To fix this, we check for the current address used for the jazzicon and change the namespace based on this.

Ideally, we would want to use the InternalAccount object directly, but that would require quite a lot of changes, so for now we keep this simple.

Open in GitHub Codespaces

Related issues

N/A

Manual testing steps

  1. yarn start:flask
  2. Settings > Experimental > "Enable Bitcoin support"
  3. Create a Bitcoin mainnet account
  4. Create a Bitcoin testnet account
  5. Check that both jazzicons are different for those 2 Bitcoin accounts
  6. Remove your Bitcoin accounts
  7. Re-create them
  8. Re-check that jazzicons are the same than step 5
  9. "Hard"-restart your extension
  10. Re-check that jazzicons are the same than step 5

Screenshots/Recordings

Before

Screenshot 2024-10-07 at 16 17 35

After

Screenshot 2024-10-07 at 16 18 57

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

github-actions bot commented Oct 7, 2024

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.

@metamaskbot
Copy link
Collaborator

Builds ready [b3563ec]
Page Load Metrics (1827 ± 69 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16052212181613364
domContentLoaded15982101178311756
load16062227182714469
domInteractive2684562110
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 17 Bytes (0.00%)
  • ui: -105 Bytes (-0.00%)
  • common: 347 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [bef6290]
Page Load Metrics (2035 ± 89 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31525981873546262
domContentLoaded16832401200017182
load17512482203518589
domInteractive289248178
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 17 Bytes (0.00%)
  • ui: -105 Bytes (-0.00%)
  • common: 347 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [239ca2f]
Page Load Metrics (1973 ± 72 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint22622061731602289
domContentLoaded16582182194814469
load16662196197315072
domInteractive30134542412
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 240 Bytes (0.00%)

@ccharly ccharly force-pushed the fix/btc-jazzicons branch 2 times, most recently from 1a982ee to 5cd471e Compare October 8, 2024 15:35
@ccharly ccharly marked this pull request as ready for review October 8, 2024 17:12
@ccharly ccharly requested review from a team as code owners October 8, 2024 17:12
@ccharly ccharly self-assigned this Oct 8, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [acf55ff]
Page Load Metrics (1942 ± 128 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint38225701850427205
domContentLoaded156425111915269129
load158625211942266128
domInteractive187953199
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 240 Bytes (0.00%)

gantunesr
gantunesr previously approved these changes Oct 8, 2024
montelaidev
montelaidev previously approved these changes Oct 8, 2024
Copy link
Member

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

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

suggestions to make it a little more ready for extensibility. wdyt?

@@ -14,6 +18,21 @@ import {
AvatarAccountProps,
} from './avatar-account.types';

// TODO: This might not scale well with our new multichain initiative since it would require
Copy link
Member

Choose a reason for hiding this comment

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

you can make it a little more ready for extensibility with an approach like that. wdyt?

type ChainType = 'btc' | 'eth';

function getChainType(address: string): ChainType | undefined {
  if (isBtcMainnetAddress(address) || isBtcTestnetAddress(address)) {
    return 'btc';
  }
  // Default to 'eth' for other cases, can be extended as needed
  return 'eth';
}

function getJazziconNamespace(address: string): string | undefined {
  const chainType = getChainType(address);

  switch (chainType) {
    case 'btc':
      return 'bip122';
    case 'eth':
      return undefined; // Falls back to default Jazzicon behavior
    default:
      return undefined;
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea, lemme address this now!

@ccharly ccharly dismissed stale reviews from montelaidev and gantunesr via 52aae8f October 9, 2024 09:29
@ccharly ccharly requested a review from a team as a code owner October 9, 2024 09:29
andreahaku
andreahaku previously approved these changes Oct 9, 2024
Copy link
Member

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

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

LGTM

@metamaskbot
Copy link
Collaborator

Builds ready [4622980]
Page Load Metrics (1714 ± 90 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15082314171117785
domContentLoaded14992183168915776
load15062344171418890
domInteractive248044199
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 507 Bytes (0.01%)

/**
* Multi-chain family type.
*/
export enum MultichainType {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if MultichainType is the right name here, something like Namespace or Caip2Namespace would make more sense. However, we should pay attention to not reuse a type already used in @metamask/utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially wanted to use the one coming from @metamask/utils but we have no Bip122 yet 😅

I can try to update this too, I started a PR some days ago here:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm now using KnownCaipNamespace for this type instead!

Copy link

socket-security bot commented Oct 9, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/utils@9.3.0 None 0 706 kB metamaskbot

🚮 Removed packages: npm/@metamask/utils@9.2.1

View full report↗︎

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

Hey @ccharly, this is working great! I had one question about the logic for the getCaipNamespaceFromAddress but otherwise LGTM!

  • Pulled branch and checked locally ✅
  • Ensured jazzicons remain the same after hard reset ✅
Screenshot 2024-10-09 at 10 51 50 AM Screenshot 2024-10-09 at 10 56 53 AM

Also are we aware that the Bitcoin account creation modals aren't the same as the ethereum ones? Seems like a bug

bitcoin.accounts.mov

Comment on lines 19 to 32
import { KnownCaipNamespace } from '@metamask/utils';

function getJazziconNamespace(address: string): string | undefined {
const namespace = getCaipNamespaceFromAddress(address);

switch (namespace) {
case KnownCaipNamespace.Bip122:
return namespace;
case KnownCaipNamespace.Eip155:
return undefined; // Falls back to default Jazzicon behavior
default:
return undefined;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Why is getJazziconNamespace defined in the AvatarAccount component instead of within the Jazzicon component itself?

This function appears to be specific to Jazzicon behavior and isn't used for Blockies. It seems like it might be more appropriate to encapsulate this logic within the Jazzicon component for better separation of concerns and to keep the AvatarAccount component more generic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, you are 100% right, this makes more sense to move it there. I'm changing that!

@ccharly
Copy link
Contributor Author

ccharly commented Oct 9, 2024

@georgewrmarshall

Also are we aware that the Bitcoin account creation modals aren't the same as the ethereum ones? Seems like a bug

So yes, they look different indeed and that's not a bug! 😄 The Bitcoin accounts are backed by a Snap, and we recently introduced a new modal when creating Snap accounts and this one is in full screen (which seems to be a restriction for now when using the confirmation system).

We would like to have a very similar modal in the future yes, but for now, we live with this one!

Copy link

sonarcloud bot commented Oct 9, 2024

@georgewrmarshall
Copy link
Contributor

Thanks for the clarification @ccharly that makes sense!

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

Excellent work! LGTM! 🚀

  • Checked locally after code changes to Jazzicon

@metamaskbot
Copy link
Collaborator

Builds ready [0d565f3]
Page Load Metrics (1843 ± 100 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31525871710503242
domContentLoaded15742462180918087
load157925991843208100
domInteractive2581522110
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 1.21 KiB (0.02%)

Copy link
Member

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

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

LGTM

@ccharly ccharly added this pull request to the merge queue Oct 10, 2024
Merged via the queue into develop with commit 04ba878 Oct 10, 2024
78 checks passed
@ccharly ccharly deleted the fix/btc-jazzicons branch October 10, 2024 13:32
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2024
@metamaskbot metamaskbot added the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 10, 2024
@gauthierpetetin gauthierpetetin added release-12.6.0 Issue or pull request that will be included in release 12.6.0 and removed release-12.7.0 Issue or pull request that will be included in release 12.7.0 labels Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.6.0 Issue or pull request that will be included in release 12.6.0 team-accounts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants