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: support multichain in blockexplorer and qr code #25526

Merged
merged 26 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0f6a897
fix: fix addresses in qr
montelaidev Jun 21, 2024
6a2bec9
feat: support multichain blockexplorer
montelaidev Jun 26, 2024
4d109ee
fix: update confirm remove account to support non evm accounts
montelaidev Jun 26, 2024
6bdfe81
fix: update util
montelaidev Jun 26, 2024
27afed2
fix: nickname popover test
montelaidev Jun 26, 2024
2b73a65
refactor: use InternalAccountPropType
montelaidev Jun 26, 2024
0fc049a
fix: test
montelaidev Jun 26, 2024
87a440d
fix: account link
montelaidev Jun 26, 2024
191a362
fix: update snapshot
montelaidev Jun 26, 2024
5b09f95
fix: test
montelaidev Jun 26, 2024
2165ef0
fix: checksum
montelaidev Jun 26, 2024
5280b97
fix: update getMultichainAccountLink to receive address instead of ac…
montelaidev Jun 27, 2024
6fa8eed
fix: lint
montelaidev Jun 27, 2024
6d9cf20
Merge branch 'develop' into fix/qr-and-blockexplore-for-multichain
montelaidev Jun 28, 2024
a129a3b
Apply suggestions from code review
montelaidev Jun 28, 2024
6fb9da4
fix: getMultichainBlockExplorerUrl and getMultichainAccountUrl being …
montelaidev Jun 28, 2024
f9a075b
fix: import
montelaidev Jun 28, 2024
848b52a
fix: add test
montelaidev Jun 28, 2024
d5e3768
Merge branch 'develop' into fix/qr-and-blockexplore-for-multichain
montelaidev Jul 1, 2024
befb7c9
Merge branch 'develop' into fix/qr-and-blockexplore-for-multichain
montelaidev Jul 2, 2024
431f190
Apply suggestions from code review
montelaidev Jul 2, 2024
292260e
fix: remove should
montelaidev Jul 2, 2024
aeb00ea
fix: use explorer url from config.
montelaidev Jul 2, 2024
41cd387
Update ui/helpers/utils/multichain/blockExplorer.ts
montelaidev Jul 2, 2024
47cd8ec
fix: casing
montelaidev Jul 2, 2024
0df3873
Merge branch 'develop' into fix/qr-and-blockexplore-for-multichain
montelaidev Jul 2, 2024
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
1 change: 1 addition & 0 deletions app/scripts/lib/accounts/BalancesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const mockBtcAccount = createMockInternalAccount({
name: 'Btc Account',
// @ts-expect-error - account type may be btc or eth, mock file is not typed
type: BtcAccountType.P2wpkh,
// @ts-expect-error - snap options is not typed and defaults to undefined
snapOptions: {
id: 'mock-btc-snap',
name: 'mock-btc-snap',
Expand Down
6 changes: 6 additions & 0 deletions shared/constants/multichain/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export enum MultichainNetworks {

export const BITCOIN_TOKEN_IMAGE_URL = './images/bitcoin-logo.svg';

export const MULTICHAIN_NETWORK_TO_EXPLORER_URL = {
montelaidev marked this conversation as resolved.
Show resolved Hide resolved
[MultichainNetworks.BITCOIN]: 'https://blockstream.info/address',
} as const;

export const MULTICHAIN_TOKEN_IMAGE_MAP = {
[MultichainNetworks.BITCOIN]: BITCOIN_TOKEN_IMAGE_URL,
} as const;
Expand All @@ -38,6 +42,8 @@ export const MULTICHAIN_PROVIDER_CONFIGS: Record<
type: 'rpc',
rpcPrefs: {
imageUrl: MULTICHAIN_TOKEN_IMAGE_MAP[MultichainNetworks.BITCOIN],
blockExplorerUrl:
MULTICHAIN_NETWORK_TO_EXPLORER_URL[MultichainNetworks.BITCOIN],
montelaidev marked this conversation as resolved.
Show resolved Hide resolved
},
isAddressCompatible: isBtcMainnetAddress,
},
Expand Down
30 changes: 30 additions & 0 deletions test/e2e/tests/dapp-interactions/block-explorer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ describe('Block Explorer', function () {
providerConfig: {
rpcPrefs: { blockExplorerUrl: 'https://etherscan.io/' },
},
networkConfigurations: {
networkConfigurationId: {
chainId: '0x539',
nickname: 'Localhost 8545',
rpcUrl: 'http://localhost:8545',
ticker: 'ETHasdfasdf',
montelaidev marked this conversation as resolved.
Show resolved Hide resolved
rpcPrefs: { blockExplorerUrl: 'https://etherscan.io/' },
},
},
selectedNetworkClientId: 'networkConfigurationId',
})
.build(),
ganacheOptions: defaultGanacheOptions,
Expand Down Expand Up @@ -58,6 +68,16 @@ describe('Block Explorer', function () {
providerConfig: {
rpcPrefs: { blockExplorerUrl: 'https://etherscan.io/' },
},
networkConfigurations: {
networkConfigurationId: {
chainId: '0x539',
nickname: 'Localhost 8545',
rpcUrl: 'http://localhost:8545',
ticker: 'ETHasdfasdf',
rpcPrefs: { blockExplorerUrl: 'https://etherscan.io/' },
},
},
selectedNetworkClientId: 'networkConfigurationId',
})
.withTokensControllerERC20()
.build(),
Expand Down Expand Up @@ -108,6 +128,16 @@ describe('Block Explorer', function () {
providerConfig: {
rpcPrefs: { blockExplorerUrl: 'https://etherscan.io/' },
},
networkConfigurations: {
networkConfigurationId: {
chainId: '0x539',
nickname: 'Localhost 8545',
rpcUrl: 'http://localhost:8545',
ticker: 'ETHasdfasdf',
rpcPrefs: { blockExplorerUrl: 'https://etherscan.io/' },
},
},
selectedNetworkClientId: 'networkConfigurationId',
})
.withTransactionControllerCompletedTransaction()
.build(),
Expand Down
2 changes: 1 addition & 1 deletion test/jest/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function createMockInternalAccount({
name,
type = EthAccountType.Eoa,
keyringType = KeyringTypes.hd,
snapOptions,
snapOptions = undefined,
} = {}) {
let methods;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports[`Confirm Remove Account should match snapshot 1`] = `
style="height: 32px; width: 32px; border-radius: 16px;"
>
<div
style="border-radius: 50px; overflow: hidden; padding: 0px; margin: 0px; width: 32px; height: 32px; display: inline-block; background: rgb(24, 151, 242);"
style="border-radius: 50px; overflow: hidden; padding: 0px; margin: 0px; width: 32px; height: 32px; display: inline-block; background: rgb(250, 58, 0);"
>
<svg
height="32"
Expand All @@ -45,25 +45,25 @@ exports[`Confirm Remove Account should match snapshot 1`] = `
y="0"
>
<rect
fill="#2362E1"
fill="#18CDF2"
height="32"
transform="translate(3.589330184792517 -5.334310623233522) rotate(458.4 16 16)"
transform="translate(-1.04839350379394 -3.3042840694604987) rotate(328.9 16 16)"
width="32"
x="0"
y="0"
/>
<rect
fill="#F94301"
fill="#035E56"
height="32"
transform="translate(-15.363459289650208 7.992351635486631) rotate(268.8 16 16)"
transform="translate(-18.298461708832043 10.5924618717486) rotate(176.2 16 16)"
width="32"
x="0"
y="0"
/>
<rect
fill="#FA7900"
fill="#F26602"
height="32"
transform="translate(-9.076254079301423 29.480015880683375) rotate(117.3 16 16)"
transform="translate(16.667842018223922 -14.205139722997082) rotate(468.9 16 16)"
width="32"
x="0"
y="0"
Expand Down Expand Up @@ -98,13 +98,14 @@ exports[`Confirm Remove Account should match snapshot 1`] = `
<span
class="account_value"
>
0x0...0
0x0D...E7bc
</span>
</div>
<div
class="confirm-remove-account__account__link"
>
<a
data-testid="explorer-link"
rel="noopener noreferrer"
target="_blank"
title="View account on Etherscan"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { getAccountLink } from '@metamask/etherscan-link';
import { isEvmAccountType } from '@metamask/keyring-api';
import { getMultichainAccountLink } from '../../../../helpers/utils/multichain/blockExplorer';
import Modal from '../../modal';
import { addressSummary, getURLHostName } from '../../../../helpers/utils/util';
import { normalizeSafeAddress } from '../../../../../app/scripts/lib/multichain/address';
import Identicon from '../../../ui/identicon';
import { MetaMetricsEventCategory } from '../../../../../shared/constants/metametrics';
import ZENDESK_URLS from '../../../../helpers/constants/zendesk-url';
import {
InternalAccountPropType,
MultichainNetworkProptype,
} from '../../../../selectors/multichain';

export default class ConfirmRemoveAccount extends Component {
static propTypes = {
hideModal: PropTypes.func.isRequired,
removeAccount: PropTypes.func.isRequired,
account: PropTypes.shape({
id: PropTypes.string.isRequired,
address: PropTypes.string.isRequired,
metadata: PropTypes.shape({
name: PropTypes.string.isRequired,
snap: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string,
enabled: PropTypes.bool,
}),
keyring: PropTypes.shape({
type: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
}).isRequired,
chainId: PropTypes.string.isRequired,
rpcPrefs: PropTypes.object.isRequired,
account: InternalAccountPropType.isRequired,
network: MultichainNetworkProptype.isRequired,
};

static contextTypes = {
Expand All @@ -47,7 +38,9 @@ export default class ConfirmRemoveAccount extends Component {

renderSelectedAccount() {
const { t } = this.context;
const { account, rpcPrefs, chainId } = this.props;
const { account, network } = this.props;
const normalizedAddress = normalizeSafeAddress(account.address);
montelaidev marked this conversation as resolved.
Show resolved Hide resolved

return (
<div className="confirm-remove-account__account">
<div className="confirm-remove-account__account__identicon">
Expand All @@ -64,16 +57,20 @@ export default class ConfirmRemoveAccount extends Component {
{t('publicAddress')}
</span>
<span className="account_value">
{addressSummary(account.address, 4, 4)}
{addressSummary(
normalizedAddress,
4,
4,
isEvmAccountType(account.type),
)}
</span>
</div>
<div className="confirm-remove-account__account__link">
<a
onClick={() => {
const accountLink = getAccountLink(
const accountLink = getMultichainAccountLink(
account.address,
chainId,
rpcPrefs,
network,
);
this.context.trackEvent({
category: MetaMetricsEventCategory.Accounts,
Expand All @@ -91,6 +88,7 @@ export default class ConfirmRemoveAccount extends Component {
target="_blank"
rel="noopener noreferrer"
title={t('etherscanView')}
data-testid="explorer-link"
>
<i
className="fa fa-share-square"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { connect } from 'react-redux';
import { compose } from 'redux';
import withModalProps from '../../../../helpers/higher-order-components/with-modal-props';
import {
getCurrentChainId,
getRpcPrefsForCurrentProvider,
} from '../../../../selectors';
import { removeAccount } from '../../../../store/actions';
import { getMultichainNetwork } from '../../../../selectors/multichain';
import ConfirmRemoveAccount from './confirm-remove-account.component';

const mapStateToProps = (state) => {
const mapStateToProps = (state, ownProps) => {
return {
chainId: getCurrentChainId(state),
rpcPrefs: getRpcPrefsForCurrentProvider(state),
network: getMultichainNetwork(state, ownProps.account),
};
};

Expand Down
Loading