Skip to content
Draft
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
2 changes: 2 additions & 0 deletions packages/bitcoin-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Never display an opaque request origin: the PSBT-signing and send confirmations now show a hostname (or `MetaMask`) and hide the row otherwise, instead of printing the raw origin, which for remote transports is a connection id
- Stop labelling the literal `wallet-connect` origin as "WalletConnect"; the clients now pass a per-session channel id instead
- **BREAKING** Bump `@metamask/keyring-api` from `^23.7.0` to `^24.1.0` ([#214](https://github.com/MetaMask/internal-snaps/pull/214))
- **BREAKING** Bump `@metamask/keyring-snap-sdk` from `^9.2.1` to `^10.0.0` ([#214](https://github.com/MetaMask/internal-snaps/pull/214))
- **BREAKING** Bump `@metamask/snaps-sdk` from `^11.2.0` to `^12.0.1` ([#214](https://github.com/MetaMask/internal-snaps/pull/214))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
displayCaip10,
displayExchangeAmount,
displayNetwork,
displayOrigin,
translate,
} from '../format';

Expand Down Expand Up @@ -144,7 +145,7 @@ export const SignPsbtConfirmationView: SnapComponent<
<SnapText fontWeight="medium" color="alternative">
{t('confirmation.requestOrigin')}
</SnapText>
<SnapText>{origin ?? 'MetaMask'}</SnapText>
<SnapText>{displayOrigin(origin ?? 'metamask')}</SnapText>
</Box>
<Box>{null}</Box>
<Box alignment="space-between" direction="horizontal">
Expand Down
9 changes: 4 additions & 5 deletions packages/bitcoin-wallet-snap/src/infra/jsx/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ describe('displayOrigin', () => {
expect(displayOrigin('metamask')).toBe('MetaMask');
});

it('returns the known label for the "wallet-connect" origin', () => {
expect(displayOrigin('wallet-connect')).toBe('WalletConnect');
it('matches the internal origin case-insensitively', () => {
expect(displayOrigin('MetaMask')).toBe('MetaMask');
});

it('matches known origins case-insensitively', () => {
expect(displayOrigin('MetaMask')).toBe('MetaMask');
expect(displayOrigin('Wallet-Connect')).toBe('WalletConnect');
it('returns an empty string for the legacy "wallet-connect" origin', () => {
expect(displayOrigin('wallet-connect')).toBe('');
});

it('returns the hostname for a valid https URL', () => {
Expand Down
40 changes: 17 additions & 23 deletions packages/bitcoin-wallet-snap/src/infra/jsx/format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Network } from '@metamask/bitcoindevkit';
import { Amount, BdkErrorCode } from '@metamask/bitcoindevkit';
import { resolveOrigin } from '@metamask/snap-networks-utils';
import type { CaipAccountId } from '@metamask/snaps-sdk';

import type { CurrencyRate, CurrencyUnit, Messages } from '../../entities';
Expand Down Expand Up @@ -69,30 +70,23 @@ export const errorCodeToLabel = (code: number): string => {
};

/**
* Known origins mapped to their human-readable labels. Keys are lowercased so
* lookups can be performed case-insensitively against the raw origin.
* Formats a request origin for display.
*
* Returns an empty string when the origin is not displayable: remote
* transports (WalletConnect, SDK) pass an opaque connection id, which is
* meaningless to the user, so the caller hides the origin row instead of
* showing it.
*
* ponytail: the self-reported URL that rides along such requests in
* `originMetadata` is not plumbed into the confirmations yet (Bitcoin has no
* remote-transport support to exercise it). Pass it to `resolveOrigin` and
* render its `isSelfReported` flag when that support lands.
*
* @param origin - The origin of the request, as received by the snap.
* @returns The hostname, a label for known origins, or an empty string.
*/
const KNOWN_ORIGIN_LABELS: Record<string, string> = {
metamask: 'MetaMask',
'wallet-connect': 'WalletConnect',
};

export const displayOrigin = (origin: string): string => {
const knownLabel = KNOWN_ORIGIN_LABELS[origin.toLowerCase()];
if (knownLabel) {
return knownLabel;
}

try {
const url = new URL(origin);
return url.protocol === 'http:' || url.protocol === 'https:'
? url.hostname
: '';
} catch {
console.log('[format] - displayOrigin - failed to parse origin', origin);
return '';
}
};
export const displayOrigin = (origin: string): string =>
resolveOrigin(origin).displayOrigin ?? '';

export const displayCaip10 = (
network: Network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
displayExchangeAmount,
displayExplorerUrl,
displayNetwork,
displayOrigin,
isValidSnapLinkProtocol,
translate,
} from '../format';
Expand Down Expand Up @@ -103,7 +104,7 @@ export const UnifiedSendFormView: SnapComponent<UnifiedSendFormViewProps> = ({
<SnapText fontWeight="medium" color="alternative">
{t('confirmation.requestOrigin')}
</SnapText>
<SnapText>{origin ?? 'MetaMask'}</SnapText>
<SnapText>{displayOrigin(origin ?? 'metamask')}</SnapText>
</Box>
<Box>{null}</Box>
<Box alignment="space-between" direction="horizontal">
Expand Down
Loading