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

chore: add support us modal #1620

Merged
merged 12 commits into from
Nov 2, 2024
6 changes: 5 additions & 1 deletion packages/extension-polkagate/src/components/TwoButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface Props {
onPrimaryClick: React.MouseEventHandler<HTMLButtonElement>;
secondaryBtnText?: string;
onSecondaryClick: React.MouseEventHandler<HTMLButtonElement>;
primaryBtnStartIcon?: React.JSX.Element;
secondaryBtnStartIcon?: React.JSX.Element;
mt?: string;
ml?: string;
disabled?: boolean;
Expand All @@ -25,7 +27,7 @@ interface Props {
}
// TODO: can replace ButtonWithCancel later

export default function TwoButtons ({ disabled = false, isBusy = false, ml = '6%', mt, onPrimaryClick, onSecondaryClick, primaryBtnText, secondaryBtnText, variant = 'outlined', width = '88%' }: Props): React.ReactElement<Props> {
export default function TwoButtons ({ disabled = false, isBusy = false, ml = '6%', mt, onPrimaryClick, onSecondaryClick, primaryBtnStartIcon, primaryBtnText, secondaryBtnStartIcon, secondaryBtnText, variant = 'outlined', width = '88%' }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const theme = useTheme();

Expand All @@ -35,6 +37,7 @@ export default function TwoButtons ({ disabled = false, isBusy = false, ml = '6%
<Button
disabled={isBusy}
onClick={onSecondaryClick}
startIcon={secondaryBtnStartIcon}
sx={{
borderColor: 'secondary.main',
color: variant === 'text' ? 'secondary.main' : 'text.primary',
Expand All @@ -59,6 +62,7 @@ export default function TwoButtons ({ disabled = false, isBusy = false, ml = '6%
: <Button
disabled={disabled}
onClick={onPrimaryClick}
startIcon={primaryBtnStartIcon}
sx={{
borderColor: 'secondary.main',
borderRadius: '5px',
Expand Down
121 changes: 121 additions & 0 deletions packages/extension-polkagate/src/fullscreen/governance/SupportUs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable react/jsx-max-props-per-line */

import { faHandshakeAngle } from '@fortawesome/free-solid-svg-icons';
import ThumbUpIcon from '@mui/icons-material/ThumbUp';
import WatchLaterIcon from '@mui/icons-material/WatchLater';
import { Box, Grid, Typography } from '@mui/material';
import React, { useCallback, useContext, useEffect, useState } from 'react';

import { BN, BN_ZERO } from '@polkadot/util';

import { AccountsAssetsContext, TwoButtons } from '../../components';
import { getStorage, setStorage } from '../../components/Loading';
import { useTranslation } from '../../hooks';
import { tieAccount } from '../../messaging';
import { POLKADOT_GENESIS_HASH } from '../../util/constants';
import { openOrFocusTab } from '../accountDetails/components/CommonTasks';
import SimpleModalTitle from '../partials/SimpleModalTitle';
import { DraggableModal } from './components/DraggableModal';

const PROPOSAL_NO = 1264;
const SHOW_INTERVAL = 10 * 1000; // ms
const STORAGE_LABEL = `polkaGateVoteReminderLastShown_${PROPOSAL_NO}`;
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

export default function SupportUs (): React.ReactElement {
const { t } = useTranslation();
const { accountsAssets } = useContext(AccountsAssetsContext);

const [open, setOpen] = useState<boolean>(true);
const [maxPowerAddress, setAddress] = useState<string>();
const [timeToShow, setTimeToShow] = useState<boolean>();

useEffect(() => {
getStorage(STORAGE_LABEL).then((maybeDate) => {
(!maybeDate || Date.now() - (maybeDate as unknown as number) > SHOW_INTERVAL) && setTimeToShow(true);
}).catch(console.error);
}, [accountsAssets]);
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
if (!accountsAssets) {
return;
}

const balances = accountsAssets.balances;
let addressWithMaxVotingPower: string | undefined;
let max = BN_ZERO;

Object.keys(balances).forEach((address) => {
const maybeAsset = balances[address]?.[POLKADOT_GENESIS_HASH];

if (!maybeAsset) {
return;
}

const votingBalance = maybeAsset[0].votingBalance ? new BN(maybeAsset[0].votingBalance) : BN_ZERO;

max = votingBalance.gt(max) ? votingBalance : max;
addressWithMaxVotingPower = address;
});
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

addressWithMaxVotingPower && tieAccount(addressWithMaxVotingPower, POLKADOT_GENESIS_HASH).finally(() => {
setAddress(addressWithMaxVotingPower);
}).catch(console.error);
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved
}, [accountsAssets]);

const handleClose = useCallback(() => {
setOpen(false);
}, []);

const handleOnVote = useCallback(() => {
maxPowerAddress && openOrFocusTab(`/governance/${maxPowerAddress}/referenda/${PROPOSAL_NO}`);
}, [maxPowerAddress]);
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

const handleMaybeLater = useCallback(() => {
setStorage(STORAGE_LABEL, Date.now()).catch(console.error);
setOpen(false);
}, []);
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
{maxPowerAddress && timeToShow &&
<DraggableModal onClose={handleClose} open={open}>
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved
<>
<SimpleModalTitle
icon={faHandshakeAngle}
onClose={handleClose}
title={t('Support PolkaGate!')}
/>
<Grid item sx={{ bgcolor: 'background.paper', border: 1, borderColor: 'divider', borderRadius: '5px', mt: 5, p: '10px' }}>
<Typography fontSize='14px' lineHeight='25px' textAlign='left'>
{t('We’re seeking retroactive funding to sustain and expand PolkaGate’s impact! Your vote can empower us to continue delivering valuable improvements and innovations. Voting won’t spend your tokens—they’ll just be temporarily locked based on your chosen conviction level.')}
</Typography>
</Grid>
<Box
alt='Description of the image'
component='img'
src='/images/supportUs.webp'
sx={{
width: '60%',
height: 'auto',
borderRadius: 1
}}
/>
<TwoButtons
ml='0'
onPrimaryClick={handleOnVote}
onSecondaryClick={handleMaybeLater}
primaryBtnStartIcon={<ThumbUpIcon />}
primaryBtnText={t('Vote to Support Us')}
secondaryBtnStartIcon={<WatchLaterIcon />}
secondaryBtnText={t('Maybe Later')}
width='88%'
/>
</>
</DraggableModal>
}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AccountContext, ActionContext } from '../../components';
import { useAccountsOrder, useAlerts, useFullscreen, useProfileAccounts, useTranslation } from '../../hooks';
import { AddNewAccountButton } from '../../partials';
import FullScreenHeader from '../governance/FullScreenHeader';
import SupportUs from '../governance/SupportUs';
import HeaderComponents from './components/HeaderComponents';
import DraggableAccountsList from './partials/DraggableAccountList';
import HomeMenu from './partials/HomeMenu';
Expand Down Expand Up @@ -89,6 +90,7 @@ function HomePageFullScreen (): React.ReactElement {
</Grid>
</Grid>
</Grid>
<SupportUs />
</Grid>
);
}
Expand Down
Binary file added packages/extension/public/images/supportUs.webp
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/extension/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1411,5 +1411,6 @@
"Not recoverable": "",
"No proxy": "",
"Switch Theme": "",
"Account Icon": ""
"Account Icon": "",
"Support PolkaGate!": ""
}
Loading