Skip to content

feat: (MMS-2106) supports copying block explorer link in bridge page #31498

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

Merged
merged 6 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 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: 3 additions & 0 deletions app/_locales/en_GB/messages.json

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

2 changes: 2 additions & 0 deletions ui/pages/bridge/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ exports[`Bridge renders the component with initial props 1`] = `
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--display-flex mm-box--gap-1 mm-box--color-text-alternative-soft"
style="cursor: default; text-decoration: none;"
/>
</div>
</div>
Expand Down Expand Up @@ -209,6 +210,7 @@ exports[`Bridge renders the component with initial props 1`] = `
</div>
<a
class="mm-box mm-text mm-text--body-md mm-box--display-flex mm-box--gap-1 mm-box--color-text-alternative-soft"
style="cursor: pointer; text-decoration: underline;"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ exports[`PrepareBridgePage should render the component, with initial state 1`] =
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--display-flex mm-box--gap-1 mm-box--color-text-alternative-soft"
style="cursor: default; text-decoration: none;"
/>
</div>
</div>
Expand Down Expand Up @@ -158,6 +159,7 @@ exports[`PrepareBridgePage should render the component, with initial state 1`] =
</div>
<a
class="mm-box mm-text mm-text--body-md mm-box--display-flex mm-box--gap-1 mm-box--color-text-alternative-soft"
style="cursor: pointer; text-decoration: underline;"
/>
</div>
</div>
Expand Down Expand Up @@ -281,6 +283,7 @@ exports[`PrepareBridgePage should render the component, with inputs set 1`] = `
</div>
<p
class="mm-box mm-text mm-text--body-md mm-box--display-flex mm-box--gap-1 mm-box--color-text-alternative-soft"
style="cursor: default; text-decoration: none;"
/>
</div>
</div>
Expand Down Expand Up @@ -349,6 +352,7 @@ exports[`PrepareBridgePage should render the component, with inputs set 1`] = `
</div>
<a
class="mm-box mm-text mm-text--body-md mm-box--display-flex mm-box--gap-1 mm-box--color-text-alternative-soft"
style="cursor: pointer; text-decoration: underline;"
/>
</div>
</div>
Expand Down
58 changes: 57 additions & 1 deletion ui/pages/bridge/prepare/bridge-input-group.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React, { useEffect, useRef } from 'react';
import { useSelector } from 'react-redux';
import { BigNumber } from 'bignumber.js';
import { isNativeAddress } from '@metamask/bridge-controller';
import {
formatChainIdToCaip,
isNativeAddress,
} from '@metamask/bridge-controller';
import type { BridgeToken } from '@metamask/bridge-controller';
import { getAccountLink } from '@metamask/etherscan-link';
import {
Text,
TextField,
Expand Down Expand Up @@ -35,6 +39,11 @@ import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard';
import { MINUTE } from '../../../../shared/constants/time';
import { getIntlLocale } from '../../../ducks/locale/locale';
import { useIsMultichainSwap } from '../hooks/useIsMultichainSwap';
import {
MULTICHAIN_NETWORK_BLOCK_EXPLORER_FORMAT_URLS_MAP,
MultichainNetworks,
} from '../../../../shared/constants/multichain/networks';
import { formatBlockExplorerAddressUrl } from '../../../../shared/lib/multichain/networks';
import { BridgeAssetPickerButton } from './components/bridge-asset-picker-button';

const sanitizeAmountInput = (textToSanitize: string) => {
Expand All @@ -60,6 +69,7 @@ export const BridgeInputGroup = ({
amountInFiat,
onMaxButtonClick,
isMultiselectEnabled,
onBlockExplorerClick,
buttonProps,
}: {
amountInFiat?: BigNumber;
Expand All @@ -71,6 +81,7 @@ export const BridgeInputGroup = ({
'testId' | 'autoFocus' | 'value' | 'readOnly' | 'disabled' | 'className'
>;
onMaxButtonClick?: (value: string) => void;
onBlockExplorerClick?: (token: BridgeToken) => void;
} & Pick<
React.ComponentProps<typeof AssetPicker>,
| 'networkProps'
Expand Down Expand Up @@ -110,6 +121,45 @@ export const BridgeInputGroup = ({

const isSwap = useIsMultichainSwap();

const handleAddressClick = () => {
if (token && selectedChainId) {
const caipChainId = formatChainIdToCaip(selectedChainId);
const isSolana = caipChainId === MultichainNetworks.SOLANA;

let blockExplorerUrl = '';
if (isSolana) {
const blockExplorerUrls =
MULTICHAIN_NETWORK_BLOCK_EXPLORER_FORMAT_URLS_MAP[caipChainId];
if (blockExplorerUrls) {
blockExplorerUrl = formatBlockExplorerAddressUrl(
blockExplorerUrls,
token.address.split(':').at(-1) ?? token.address,
);
}
} else {
const explorerUrl =
networkProps?.network?.blockExplorerUrls?.[
networkProps?.network?.defaultBlockExplorerUrlIndex ?? 0
];
if (explorerUrl) {
blockExplorerUrl = getAccountLink(
token.address,
selectedChainId,
{
blockExplorerUrl: explorerUrl,
},
undefined,
);
}
}

if (blockExplorerUrl) {
handleCopy(blockExplorerUrl);
onBlockExplorerClick?.(token);
}
}
};

return (
<Column paddingInline={6} gap={1}>
<Row gap={4}>
Expand Down Expand Up @@ -239,10 +289,16 @@ export const BridgeInputGroup = ({
}
onClick={() => {
if (isAmountReadOnly && token && selectedChainId) {
handleAddressClick();
} else if (token && selectedChainId) {
handleCopy(token.address);
}
}}
as={isAmountReadOnly ? 'a' : 'p'}
style={{
cursor: isAmountReadOnly ? 'pointer' : 'default',
textDecoration: isAmountReadOnly ? 'underline' : 'none',
}}
>
{isAmountReadOnly &&
token &&
Expand Down
Loading
Loading