Skip to content

chore: adds solana banner to carousel #32000

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 14 commits into from
Apr 23, 2025
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changes in account modal to switch to smart account type ([#31899](https://github.com/MetaMask/metamask-extension/pull/31899))
- Support for Solana Devnet ([#31702](https://github.com/MetaMask/metamask-extension/pull/31702))
- [Beta] Create Solana account automatically on wallet creation or SRP import [#32038](https://github.com/MetaMask/metamask-extension/pull/32038)
- Adds the Solana banner/slide to the existing home carousel ([#32000](https://github.com/MetaMask/metamask-extension/pull/32000))
- Support for Solana on Firefox ([#32104](https://github.com/MetaMask/metamask-extension/pull/32104))
- Update CAIP-294 wallet announcement event to include `targets` property and new `caip-348` target object ([#32070](https://github.com/MetaMask/metamask-extension/pull/32070))
- Replace `caip-x` with `caip-348` in Multichain API over externally_connectable ([#32070](https://github.com/MetaMask/metamask-extension/pull/32070))
Expand Down
6 changes: 6 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.

6 changes: 6 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.

11 changes: 11 additions & 0 deletions app/images/slide-solana-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import { useDispatch, useSelector } from 'react-redux';
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
import { isEqual } from 'lodash';
///: END:ONLY_INCLUDE_IF
import { removeSlide } from '../../../store/actions';
import {
removeSlide,
///: BEGIN:ONLY_INCLUDE_IF(solana)
setSelectedAccount,
///: END:ONLY_INCLUDE_IF
} from '../../../store/actions';
import { Carousel } from '..';
import {
getAppIsLoading,
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
getSwapsDefaultToken,
///: END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(solana)
hasCreatedSolanaAccount,
///: END:ONLY_INCLUDE_IF
} from '../../../selectors';
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
import useBridging from '../../../hooks/bridge/useBridging';
Expand All @@ -20,7 +28,16 @@ import {
MetaMetricsEventCategory,
} from '../../../../shared/constants/metametrics';
import type { CarouselSlide } from '../../../../shared/constants/app-state';
import { useCarouselManagement } from '../../../hooks/useCarouselManagement';
import {
useCarouselManagement,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
} from '../../../hooks/useCarouselManagement';
///: BEGIN:ONLY_INCLUDE_IF(solana)
import { CreateSolanaAccountModal } from '../create-solana-account-modal';
import { getLastSelectedSolanaAccount } from '../../../selectors/multichain';
///: END:ONLY_INCLUDE_IF
import {
AccountOverviewTabsProps,
AccountOverviewTabs,
Expand All @@ -39,6 +56,13 @@ export const AccountOverviewLayout = ({
const trackEvent = useContext(MetaMetricsContext);
const [hasRendered, setHasRendered] = useState(false);

///: BEGIN:ONLY_INCLUDE_IF(solana)
const [showCreateSolanaAccountModal, setShowCreateSolanaAccountModal] =
useState(false);
const hasSolanaAccount = useSelector(hasCreatedSolanaAccount);
const selectedSolanaAccount = useSelector(getLastSelectedSolanaAccount);
///: END:ONLY_INCLUDE_IF

///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
const defaultSwapsToken = useSelector(getSwapsDefaultToken, isEqual);
///: END:ONLY_INCLUDE_IF
Expand All @@ -60,6 +84,16 @@ export const AccountOverviewLayout = ({
}
///: END:ONLY_INCLUDE_IF

///: BEGIN:ONLY_INCLUDE_IF(solana)
if (id === SOLANA_SLIDE.id) {
if (hasSolanaAccount && selectedSolanaAccount) {
dispatch(setSelectedAccount(selectedSolanaAccount.address));
} else {
setShowCreateSolanaAccountModal(true);
}
}
///: END:ONLY_INCLUDE_IF

trackEvent({
event: MetaMetricsEventName.BannerSelect,
category: MetaMetricsEventCategory.Banner,
Expand Down Expand Up @@ -108,6 +142,15 @@ export const AccountOverviewLayout = ({
onRenderSlides={handleRenderSlides}
/>
<AccountOverviewTabs {...tabsProps}></AccountOverviewTabs>
{
///: BEGIN:ONLY_INCLUDE_IF(solana)
showCreateSolanaAccountModal && (
<CreateSolanaAccountModal
onClose={() => setShowCreateSolanaAccountModal(false)}
/>
)
///: END:ONLY_INCLUDE_IF
}
</>
);
};
17 changes: 16 additions & 1 deletion ui/components/multichain/carousel/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import { getSweepstakesCampaignActive } from '../../../hooks/useCarouselManagement';
import {
getSweepstakesCampaignActive,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
} from '../../../hooks/useCarouselManagement';
import type { CarouselProps } from './carousel.types';
import { BANNER_STYLES, MAX_SLIDES } from './constants';
import {
Expand Down Expand Up @@ -43,6 +48,16 @@ export const Carousel = React.forwardRef(
const visibleSlides = slides
.filter((slide) => !slide.dismissed || slide.undismissable)
.sort((a, b) => {
///: BEGIN:ONLY_INCLUDE_IF(solana)
// prioritize Solana slide
if (a.id === SOLANA_SLIDE.id) {
return -1;
}
if (b.id === SOLANA_SLIDE.id) {
return 1;
}
///: END:ONLY_INCLUDE_IF

const isSweepstakesActive = getSweepstakesCampaignActive(
new Date(new Date().toISOString()),
);
Expand Down
9 changes: 9 additions & 0 deletions ui/hooks/useCarouselManagement/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ export const REMOTE_MODE_SLIDE = {
href: '/home.html#remote',
};

///: BEGIN:ONLY_INCLUDE_IF(solana)
export const SOLANA_SLIDE = {
id: 'solana',
title: 'slideSolanaTitle',
description: 'slideSolanaDescription',
image: './images/slide-solana-icon.svg',
};
///: END:ONLY_INCLUDE_IF

export const SWEEPSTAKES_SLIDE = {
id: 'sweepStake',
title: 'slideSweepStakeTitle',
Expand Down
25 changes: 25 additions & 0 deletions ui/hooks/useCarouselManagement/useCarouselManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ZERO_BALANCE,
REMOTE_MODE_SLIDE,
MULTI_SRP_SLIDE,
SOLANA_SLIDE,
} from './constants';

const SLIDES_ZERO_FUNDS_REMOTE_OFF_SWEEPSTAKES_OFF = [
Expand All @@ -29,6 +30,9 @@ const SLIDES_ZERO_FUNDS_REMOTE_OFF_SWEEPSTAKES_OFF = [
CARD_SLIDE,
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

const SLIDES_POSITIVE_FUNDS_REMOTE_OFF_SWEEPSTAKES_OFF = [
Expand All @@ -39,6 +43,9 @@ const SLIDES_POSITIVE_FUNDS_REMOTE_OFF_SWEEPSTAKES_OFF = [
{ ...FUND_SLIDE, undismissable: false },
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

const SLIDES_ZERO_FUNDS_REMOTE_ON_SWEEPSTAKES_OFF = [
Expand All @@ -50,6 +57,9 @@ const SLIDES_ZERO_FUNDS_REMOTE_ON_SWEEPSTAKES_OFF = [
CARD_SLIDE,
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

const SLIDES_POSITIVE_FUNDS_REMOTE_ON_SWEEPSTAKES_OFF = [
Expand All @@ -61,6 +71,9 @@ const SLIDES_POSITIVE_FUNDS_REMOTE_ON_SWEEPSTAKES_OFF = [
{ ...FUND_SLIDE, undismissable: false },
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

const SLIDES_ZERO_FUNDS_REMOTE_OFF_SWEEPSTAKES_ON = [
Expand All @@ -72,6 +85,9 @@ const SLIDES_ZERO_FUNDS_REMOTE_OFF_SWEEPSTAKES_ON = [
CARD_SLIDE,
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

const SLIDES_POSITIVE_FUNDS_REMOTE_OFF_SWEEPSTAKES_ON = [
Expand All @@ -83,6 +99,9 @@ const SLIDES_POSITIVE_FUNDS_REMOTE_OFF_SWEEPSTAKES_ON = [
{ ...FUND_SLIDE, undismissable: false },
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

const SLIDES_ZERO_FUNDS_REMOTE_ON_SWEEPSTAKES_ON = [
Expand All @@ -95,6 +114,9 @@ const SLIDES_ZERO_FUNDS_REMOTE_ON_SWEEPSTAKES_ON = [
CARD_SLIDE,
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

const SLIDES_POSITIVE_FUNDS_REMOTE_ON_SWEEPSTAKES_ON = [
Expand All @@ -107,6 +129,9 @@ const SLIDES_POSITIVE_FUNDS_REMOTE_ON_SWEEPSTAKES_ON = [
{ ...FUND_SLIDE, undismissable: false },
CASH_SLIDE,
MULTI_SRP_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
];

jest.mock('react-redux', () => ({
Expand Down
8 changes: 7 additions & 1 deletion ui/hooks/useCarouselManagement/useCarouselManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import {
CARD_SLIDE,
CASH_SLIDE,
REMOTE_MODE_SLIDE,
SWEEPSTAKES_SLIDE,
SWEEPSTAKES_START,
SWEEPSTAKES_END,
ZERO_BALANCE,
MULTI_SRP_SLIDE,
SWEEPSTAKES_SLIDE,
///: BEGIN:ONLY_INCLUDE_IF(solana)
SOLANA_SLIDE,
///: END:ONLY_INCLUDE_IF
} from './constants';

type UseSlideManagementProps = {
Expand Down Expand Up @@ -57,6 +60,9 @@ export const useCarouselManagement = ({
defaultSlides.push(CARD_SLIDE);
defaultSlides.push(CASH_SLIDE);
defaultSlides.push(MULTI_SRP_SLIDE);
///: BEGIN:ONLY_INCLUDE_IF(solana)
defaultSlides.push(SOLANA_SLIDE);
///: END:ONLY_INCLUDE_IF

defaultSlides.splice(hasZeroBalance ? 0 : 2, 0, fundSlide);

Expand Down
Loading