Skip to content

Commit

Permalink
Merge branch 'develop' into MMS-1564-swaps-token-verification-info
Browse files Browse the repository at this point in the history
  • Loading branch information
bfullam authored Oct 10, 2024
2 parents 5b410dc + 7d7f017 commit 8523b5b
Show file tree
Hide file tree
Showing 53 changed files with 1,419 additions and 308 deletions.
3 changes: 0 additions & 3 deletions app/_locales/de/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/el/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/en_GB/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/es/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/fr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/hi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/id/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ja/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ko/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/pt/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ru/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/tl/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/tr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/vi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/zh_CN/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
"@metamask/snaps-utils": "^8.1.1",
"@metamask/transaction-controller": "^37.2.0",
"@metamask/user-operation-controller": "^13.0.0",
"@metamask/utils": "^9.1.0",
"@metamask/utils": "^9.3.0",
"@ngraveio/bc-ur": "^1.1.12",
"@noble/hashes": "^1.3.3",
"@popperjs/core": "^2.4.0",
Expand Down
105 changes: 73 additions & 32 deletions shared/lib/multichain.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isBtcMainnetAddress, isBtcTestnetAddress } from './multichain';
import { KnownCaipNamespace } from '@metamask/utils';
import {
getCaipNamespaceFromAddress,
isBtcMainnetAddress,
isBtcTestnetAddress,
} from './multichain';

const BTC_MAINNET_ADDRESSES = [
// P2WPKH
Expand All @@ -20,35 +25,71 @@ const SOL_ADDRESSES = [
];

describe('multichain', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(BTC_MAINNET_ADDRESSES)(
'returns true if address is compatible with BTC mainnet: %s',
(address: string) => {
expect(isBtcMainnetAddress(address)).toBe(true);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each([...BTC_TESTNET_ADDRESSES, ...ETH_ADDRESSES, ...SOL_ADDRESSES])(
'returns false if address is not compatible with BTC mainnet: %s',
(address: string) => {
expect(isBtcMainnetAddress(address)).toBe(false);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(BTC_TESTNET_ADDRESSES)(
'returns true if address is compatible with BTC testnet: %s',
(address: string) => {
expect(isBtcTestnetAddress(address)).toBe(true);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each([...BTC_MAINNET_ADDRESSES, ...ETH_ADDRESSES, ...SOL_ADDRESSES])(
'returns false if address is compatible with BTC testnet: %s',
(address: string) => {
expect(isBtcTestnetAddress(address)).toBe(false);
},
);
describe('isBtcMainnetAddress', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(BTC_MAINNET_ADDRESSES)(
'returns true if address is compatible with BTC mainnet: %s',
(address: string) => {
expect(isBtcMainnetAddress(address)).toBe(true);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each([...BTC_TESTNET_ADDRESSES, ...ETH_ADDRESSES, ...SOL_ADDRESSES])(
'returns false if address is not compatible with BTC mainnet: %s',
(address: string) => {
expect(isBtcMainnetAddress(address)).toBe(false);
},
);
});

describe('isBtcTestnetAddress', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(BTC_TESTNET_ADDRESSES)(
'returns true if address is compatible with BTC testnet: %s',
(address: string) => {
expect(isBtcTestnetAddress(address)).toBe(true);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each([...BTC_MAINNET_ADDRESSES, ...ETH_ADDRESSES, ...SOL_ADDRESSES])(
'returns false if address is compatible with BTC testnet: %s',
(address: string) => {
expect(isBtcTestnetAddress(address)).toBe(false);
},
);
});

describe('getChainTypeFromAddress', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each([...BTC_MAINNET_ADDRESSES, ...BTC_TESTNET_ADDRESSES])(
'returns ChainType.Bitcoin for bitcoin address: %s',
(address: string) => {
expect(getCaipNamespaceFromAddress(address)).toBe(
KnownCaipNamespace.Bip122,
);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(ETH_ADDRESSES)(
'returns ChainType.Ethereum for ethereum address: %s',
(address: string) => {
expect(getCaipNamespaceFromAddress(address)).toBe(
KnownCaipNamespace.Eip155,
);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(SOL_ADDRESSES)(
'returns ChainType.Ethereum for non-supported address: %s',
(address: string) => {
expect(getCaipNamespaceFromAddress(address)).toBe(
KnownCaipNamespace.Eip155,
);
},
);
});
});
15 changes: 15 additions & 0 deletions shared/lib/multichain.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CaipNamespace, KnownCaipNamespace } from '@metamask/utils';
import { validate, Network } from 'bitcoin-address-validation';

/**
Expand Down Expand Up @@ -26,3 +27,17 @@ export function isBtcMainnetAddress(address: string): boolean {
export function isBtcTestnetAddress(address: string): boolean {
return validate(address, Network.testnet);
}

/**
* Returns the associated chain's type for the given address.
*
* @param address - The address to check.
* @returns The chain's type for that address.
*/
export function getCaipNamespaceFromAddress(address: string): CaipNamespace {
if (isBtcMainnetAddress(address) || isBtcTestnetAddress(address)) {
return KnownCaipNamespace.Bip122;
}
// Defaults to "Ethereum" for all other cases for now.
return KnownCaipNamespace.Eip155;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ async function mintNft(driver: Driver) {
async function displayAlertForInsufficientBalance(driver: Driver) {
await driver.waitForSelector({
css: '[data-testid="alert-modal__selected-alert"]',
text: 'You do not have enough ETH in your account to pay for transaction fees.',
text: 'You do not have enough ETH in your account to pay for network fees.',
});
}
4 changes: 2 additions & 2 deletions test/e2e/tests/multichain/asset-picker-send.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ describe('AssetPickerSendFlow @no-mmi', function () {
)
).getText();

assert.equal(tokenListValue, '25 ETH');
assert.equal(tokenListValue, '$250,000.00');

const tokenListSecondaryValue = await (
await driver.findElement(
'[data-testid="multichain-token-list-item-secondary-value"]',
)
).getText();

assert.equal(tokenListSecondaryValue, '$250,000.00');
assert.equal(tokenListSecondaryValue, '25 ETH');

// Search for CHZ
const searchInputField = await driver.waitForSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ const SnapAuthorshipHeader = ({
display={Display.Flex}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
style={{ overflow: 'hidden' }}
>
<SnapIcon snapId={snapId} avatarSize={IconSize.Sm} />
<Text
color={TextColor.textDefault}
variant={TextVariant.bodyMdMedium}
marginLeft={2}
title={snapName}
ellipsis
>
{snapName}
Expand Down
Loading

0 comments on commit 8523b5b

Please sign in to comment.