Skip to content

fix: handle non-url origins - #140

Merged
0xEdouardEth merged 2 commits into
mainfrom
fix/validate-origin-url
Jun 30, 2026
Merged

fix: handle non-url origins#140
0xEdouardEth merged 2 commits into
mainfrom
fix/validate-origin-url

Conversation

@0xEdouardEth

Copy link
Copy Markdown
Collaborator

Explanation

This PR updates the Stellar Snap confirmation origin helpers to handle non-URL origins such as the stable wallet-connect origin used by MetaMask Mobile WalletConnect multichain requests.

Valid HTTP(S) URL origins continue to be displayed as hostnames. Known non-URL origins are displayed with friendly labels, currently MetaMask and WalletConnect. Unknown invalid origins, including WalletConnect channel IDs, now format to an empty string so confirmation UI can avoid showing meaningless identifiers.

Tests were added for known origins, URL origins, non-http URLs, WalletConnect channel IDs, invalid origin strings, and the existing confirmation utility behavior.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
    • N/A - no package changelog update needed for this internal behavior fix.
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them
    • N/A - this does not introduce a breaking API change.

Validation

ENVIRONMENT=test LOG_LEVEL=error ... yarn workspace @metamask/stellar-wallet-snap jest packages/snap/src/ui/confirmation/utils.test.ts --runInBand --coverage=false

Result: 1 test suite passed, 23 tests passed.

yarn eslint packages/snap/src/ui/confirmation/utils.ts packages/snap/src/ui/confirmation/utils.test.ts

Result: passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the confirmation UI origin formatting helpers so non-URL origins (e.g., MetaMask internal origin and WalletConnect) display friendly labels, while invalid/non-HTTP(S) values format to an empty string to allow the UI to hide the origin row.

Changes:

  • Added a known-origins label map and updated formatOrigin to return friendly labels, HTTP(S) hostnames, or '' for other inputs.
  • Added an HTTP(S)-protocol guard (isHttpOrHttpsUrl) to prevent displaying hostnames for non-HTTP(S) URL schemes.
  • Expanded unit tests for formatOrigin to cover known origins, URL origins, non-HTTP URLs, invalid strings, and channel-id-like values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/snap/src/ui/confirmation/utils.ts Implements new origin formatting rules (known labels, HTTP(S) hostname extraction, empty string for unsupported/invalid origins).
packages/snap/src/ui/confirmation/utils.test.ts Adds coverage for the updated formatOrigin behavior across expected origin input variants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@stanleyyconsensys stanleyyconsensys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, 2 min comments, not a blocker

);
});

describe('formatOrigin', () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit:

lets use it.each , to min the duplicate
wdyt?

e.g

it.each([
    {
       testcase: '"Unknown" for an undefined origin',
        input: undefined,
        expected: 'Unknown'
     },
    ...
])('returns %s', ({
   input,
   expected
}) => {
    expect(formatOrigin(input)).toStrictEqual(expected);
})

});

it('returns "Unknown" for an empty origin', () => {
expect(formatOrigin('')).toBe('Unknown');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
expect(formatOrigin('')).toBe('Unknown');
expect(formatOrigin('')).toStrictEqual('Unknown');

@0xEdouardEth
0xEdouardEth merged commit 990b34d into main Jun 30, 2026
10 checks passed
@0xEdouardEth
0xEdouardEth deleted the fix/validate-origin-url branch June 30, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants