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

feat: new you have (Portfolio) for Extension mode #1655

Merged
merged 33 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
479df64
style: work in progress
Nick-1979 Nov 14, 2024
03f3c2c
style: add available
Nick-1979 Nov 14, 2024
be11d21
feat: add withDecimal
Nick-1979 Nov 14, 2024
8b6309c
style: adjust logo
Nick-1979 Nov 14, 2024
c33e855
style: adjust stuff
Nick-1979 Nov 14, 2024
c2eaa3c
chore: remove unused
Nick-1979 Nov 15, 2024
1735b0d
style: adjust space
Nick-1979 Nov 15, 2024
16549ba
chore: adjust height
Nick-1979 Nov 15, 2024
3dad7ca
Merge branch 'main' into newYouHave
Nick-1979 Nov 15, 2024
dfb792f
style: adjust currency dialog
Nick-1979 Nov 16, 2024
b444aa5
style: move starts center
Nick-1979 Nov 16, 2024
81f0147
chore: add tooltip
Nick-1979 Nov 16, 2024
ebc8e45
refactor: adjust spacing
Nick-1979 Nov 16, 2024
9ed7ed6
style: increase font size
Nick-1979 Nov 16, 2024
28e609d
refactor: remove theme as props
Nick-1979 Nov 16, 2024
a4a2adf
refactor: remove unused
Nick-1979 Nov 16, 2024
3f98446
style: adjust starts placement
Nick-1979 Nov 16, 2024
e6117b0
docs: update news
Nick-1979 Nov 16, 2024
811769a
docs: update translations
Nick-1979 Nov 16, 2024
4a1f321
style: adjust portfolio bg effect
Nick-1979 Nov 16, 2024
3d738a7
style: adjust font sizes
Nick-1979 Nov 16, 2024
ed9d845
style: adjust fontSizes
Nick-1979 Nov 16, 2024
f061cf6
refactor: minor styling and refactor in menu transitions (#1657)
AMIRKHANEF Nov 16, 2024
e16eb2a
style: adjust light mode color
Nick-1979 Nov 16, 2024
6ffc4e5
style: add new green color
Nick-1979 Nov 16, 2024
ec5f133
style: reduce font size (#1658)
AMIRKHANEF Nov 16, 2024
be34cbc
style: adjust spacings
Nick-1979 Nov 16, 2024
537d208
fix: badge text color
Nick-1979 Nov 16, 2024
1499c25
fix: signal indicator border issue
Nick-1979 Nov 16, 2024
b48da3d
chore: minor adjustments
Nick-1979 Nov 16, 2024
f017e4b
chore: remove unused
Nick-1979 Nov 16, 2024
24100db
style: adjust titles
Nick-1979 Nov 16, 2024
05c88fc
style: make extension profile tabs smoother
Nick-1979 Nov 16, 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
4 changes: 2 additions & 2 deletions packages/extension-polkagate/src/components/AccountIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ function AccountIcons ({ address, identiconTheme, isSubId, judgements, prefix }:
}, [address]);

return (
<Grid container direction='column' sx={{ ml: '8px', width: '17%' }}>
<Grid container direction='column' sx={{ m: '7px 0px 0px 8px', width: '17%' }}>
<Grid item m='auto' width='fit-content'>
<Identicon
iconTheme={identiconTheme}
isSubId={isSubId}
judgement={judgements}
prefix={prefix}
size={40}
size={35}
value={formatted || address}
/>
</Grid>
Expand Down
24 changes: 14 additions & 10 deletions packages/extension-polkagate/src/components/FormatPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ export function nFormatter (num: number, decimalPoint: number) {
const DECIMAL_POINTS_FOR_CRYPTO_AS_CURRENCY = 4;
const SMALL_DECIMALS_FONT_SIZE_REDUCTION = 20;

const DecimalPart = ({ value, withCountUp }: { value: string | number, withCountUp: boolean | undefined }) => (
withCountUp
? <CountUp
duration={1}
end={Number(getDecimal(value))}
prefix={'.'}
/>
: <>{`.${getDecimal(value)}`}</>
);

function FormatPrice ({ amount, commify, decimalPoint = 2, decimals, fontSize, fontWeight, height, lineHeight = 1, mt = '0px', num, price, sign, skeletonHeight = 15, textAlign = 'left', textColor, width = '90px', withCountUp, withSmallDecimal }: Props): React.ReactElement<Props> {
const currency = useCurrency();
const theme = useTheme();
Expand Down Expand Up @@ -135,16 +145,10 @@ function FormatPrice ({ amount, commify, decimalPoint = 2, decimals, fontSize, f
lineHeight={lineHeight}
sx={{ color: theme.palette.secondary.contrastText }}
>
{withCountUp
? <CountUp
duration={1}
end={Number(getDecimal(total))}
prefix={'.'}
/>
: <>
{`.${getDecimal(total)}`}
</>
}
<DecimalPart
value={total}
withCountUp={withCountUp}
/>
</Typography>
}
</Stack>
Expand Down
6 changes: 3 additions & 3 deletions packages/extension-polkagate/src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { noop } from '../util/utils';
interface Props {
disabled?: boolean;
icon?: string;
iconComponent?: JSX.Element;
iconComponent?: React.JSX.Element;
text: string;
children?: React.ReactElement<Props>;
onClick?: MouseEventHandler<HTMLDivElement>;
Expand All @@ -35,8 +35,8 @@ export default function MenuItem ({ children, disabled = false, fontSize, icon,

return (
<>
<Grid alignItems='center' color={disabled ? '#4B4B4B' : 'inherit'} container item justifyContent='space-between' my='4px' onClick={disabled ? noop : onClick} pl={pl} py={py} sx={{ cursor: disabled ? '' : 'pointer', ...(withHoverEffect ? hoverEffectStyles : {}) }} textAlign='left' xs={12}>
<Grid alignItems='center' container item xs sx={{ flexWrap: 'nowrap' }}>
<Grid alignItems='center' color={disabled ? '#4B4B4B' : 'inherit'} container item justifyContent='space-between' my='4px' onClick={disabled ? noop : onClick} pl={pl} py={py} sx={{ cursor: disabled ? 'default' : 'pointer', ...(withHoverEffect ? hoverEffectStyles : {}) }} textAlign='left' xs={12}>
<Grid alignItems='center' container item sx={{ flexWrap: 'nowrap' }} xs>
<Grid alignItems='center' container item xs={1}>
{iconComponent ??
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function RemoteNodeSelector ({ address, genesisHash }: Props): Re
<>
{endpoint &&
<Select
_mt='10px'
_mt='3px'
defaultValue={undefined}
label={t('Remote node')}
onChange={onChangeEndpoint}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AccountContext, ActionContext, Warning } from '../../components';
import { useAccountAssets, useBalances, useCurrency, useFullscreen, useInfo, usePrices, useTokenPrice, useTranslation } from '../../hooks';
import { getValue } from '../../popup/account/util';
import HistoryModal from '../../popup/history/modal/HistoryModal';
import { AccountLabel } from '../../popup/home/AccountLabel';
import AccountLabel from '../../popup/home/AccountLabel';
import ReceiveModal from '../../popup/receive/ReceiveModal';
import { ASSET_HUBS, GOVERNANCE_CHAINS, STAKING_CHAINS } from '../../util/constants';
import getParentNameSuri from '../../util/getParentNameSuri';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import React, { useContext, useMemo, useState } from 'react';
import { AccountContext } from '../../../components';
import { useAccountAssets, useChain } from '../../../hooks';
import QuickActionFullScreen from '../../../partials/QuickActionFullScreen';
import { AccountLabel } from '../../../popup/home/AccountLabel';
import AccountLabel from '../../../popup/home/AccountLabel';
import getParentNameSuri from '../../../util/getParentNameSuri';
import AccountInformationForHome from './AccountInformationForHome';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ export interface CurrencyItemType {
sign: string;
}

export default function Currency (): React.ReactElement {
interface Props {
color?: string;
dialogLeft?: number;
fontSize?: string;
height?: string;
minWidth?: string;
}

function Currency ({ color, fontSize = '22px', height, minWidth, dialogLeft=260 }: Props): React.ReactElement {
// export default function Currency ({ color, fontSize = '22px' }: Props): React.ReactElement {
const theme = useTheme();

const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
const [currencyToShow, setCurrencyToShow] = useState<CurrencyItemType | undefined>();

const textColor = useMemo(() => theme.palette.mode === 'dark' ? theme.palette.text.primary : theme.palette.text.secondary, [theme.palette.mode, theme.palette.text.primary, theme.palette.text.secondary]);
const textColor = useMemo(() => color || (theme.palette.mode === 'dark' ? theme.palette.text.primary : theme.palette.text.secondary), [color, theme]);

useLayoutEffect(() => {
if (currencyToShow) {
Expand All @@ -46,9 +55,17 @@ export default function Currency (): React.ReactElement {

return (
<>
<Grid alignItems='center' component='button' container direction='column' item justifyContent='center' onClick={onCurrencyClick} sx={{ ...HEADER_COMPONENT_STYLE, zIndex: anchorEl && theme.zIndex.modal + 1 }}>
<Grid
alignItems='center' component='button' container direction='column' item justifyContent='center' onClick={onCurrencyClick}
sx={{
...HEADER_COMPONENT_STYLE,
height: height || HEADER_COMPONENT_STYLE?.height,
minWidth: minWidth || HEADER_COMPONENT_STYLE?.minWidth,
zIndex: anchorEl && theme.zIndex.modal + 1
}}
>
<Infotip2 text={currencyToShow?.currency}>
<Typography color={textColor} fontSize='22px' fontWeight={500}>
<Typography color={textColor} fontSize={ fontSize } fontWeight={500}>
{currencyToShow?.sign || '$'}
</Typography>
</Infotip2>
Expand All @@ -62,7 +79,7 @@ export default function Currency (): React.ReactElement {
boxShadow: theme.palette.mode === 'dark'
? '0px 4px 4px rgba(255, 255, 255, 0.25)'
: '0px 0px 25px 0px rgba(0, 0, 0, 0.50)',
left: anchorEl?.getBoundingClientRect().right - 260,
left: anchorEl?.getBoundingClientRect().right - dialogLeft,
position: 'absolute',
top: anchorEl?.getBoundingClientRect().bottom - 30
Nick-1979 marked this conversation as resolved.
Show resolved Hide resolved
}
Expand All @@ -89,3 +106,5 @@ export default function Currency (): React.ReactElement {
</>
);
}

export default React.memo(Currency);
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ const InputBox = ({ addToNewProfile, editName, newName }: InputBoxProps) => {
};

interface AddProfileProps {
address: string | undefined
address: string | undefined;
showName: boolean | undefined;
setShowName: React.Dispatch<React.SetStateAction<boolean | undefined>>;
handleClose: () => void
handleClose: () => void;
closeParentMenu: () => void
extensionMode: boolean;
}

const AddMenu = ({ address, handleClose, setShowName, showName }: AddProfileProps) => {
const AddMenu = ({ address, closeParentMenu, extensionMode, handleClose, setShowName, showName }: AddProfileProps) => {
const theme = useTheme();
const { t } = useTranslation();
const { userDefinedProfiles } = useProfiles();
Expand Down Expand Up @@ -103,18 +105,20 @@ const AddMenu = ({ address, handleClose, setShowName, showName }: AddProfileProp
updateMeta(String(address), metaData)
.then(() => {
handleClose();
closeParentMenu();
}).catch(console.error);
}, [account, address, handleClose]);
}, [account, address, closeParentMenu, handleClose]);

return (
<Grid alignItems='flex-start' container display='block' item sx={{ borderRadius: '10px', minWidth: '300px', p: '10px' }}>
<Grid alignItems='flex-start' container display='block' item sx={{ borderRadius: '10px', minWidth: '300px', p: extensionMode ? '5px' : '10px' }}>
{showName
? <InputBox
addToNewProfile={addToNewProfile}
editName={editName}
newName={newName}
/>
: <MenuItem
fontSize={extensionMode ? '16px' : undefined}
iconComponent={
<VaadinIcon icon='vaadin:plus' style={{ color: theme.palette.text.primary, height: '20px' }} />
}
Expand All @@ -123,10 +127,11 @@ const AddMenu = ({ address, handleClose, setShowName, showName }: AddProfileProp
withHoverEffect
/>
}
<Divider sx={{ bgcolor: 'divider', height: '1px', my: '6px' }} />
<Divider sx={{ bgcolor: 'divider', height: '1px', my: extensionMode ? '3px' : '6px' }} />
{userDefinedProfiles.length > 0
? userDefinedProfiles.map((profile) => (
<MenuItem
fontSize={extensionMode ? '16px' : undefined}
iconComponent={
<VaadinIcon icon='vaadin:folder-open-o' style={{ color: theme.palette.text.primary, height: '20px' }} />
}
Expand All @@ -139,6 +144,7 @@ const AddMenu = ({ address, handleClose, setShowName, showName }: AddProfileProp
))
: <MenuItem
disabled
fontSize={extensionMode ? '16px' : undefined}
iconComponent={
<VaadinIcon icon='vaadin:minus' style={{ color: `${theme.palette.text.disabled}`, height: '20px' }} />
}
Expand All @@ -153,18 +159,20 @@ const AddMenu = ({ address, handleClose, setShowName, showName }: AddProfileProp
interface RemoveProfileProps {
profileNames: string[] | undefined;
onRemove: (profile: string) => void;
extensionMode: boolean;
}

const RemoveMenu = ({ onRemove, profileNames }: RemoveProfileProps) => {
const RemoveMenu = ({ extensionMode, onRemove, profileNames }: RemoveProfileProps) => {
const theme = useTheme();
const { t } = useTranslation();

return (
<Grid alignItems='flex-start' container display='block' item sx={{ borderRadius: '10px', minWidth: '300px', p: '10px' }}>
<Grid alignItems='flex-start' container display='block' item sx={{ borderRadius: '10px', minWidth: '300px', p: extensionMode ? '5px' : '10px' }}>
{profileNames?.map((profileName) => (
// eslint-disable-next-line react/jsx-no-bind
<Grid component='button' container item key={profileName} onClick={() => onRemove(profileName)} sx={{ '> div div:last-child p': { maxWidth: '220px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, bgcolor: 'transparent', border: 'none', color: theme.palette.text.primary, height: 'fit-content', p: 0, width: 'inherit' }}>
<MenuItem
fontSize={extensionMode ? '16px' : undefined}
iconComponent={
<VaadinIcon icon='vaadin:folder-remove' style={{ color: theme.palette.text.primary, height: '20px' }} />
}
Expand Down Expand Up @@ -206,8 +214,7 @@ function ProfileMenu ({ address, closeParentMenu }: Props): React.ReactElement<P
const handleClose = useCallback(() => {
setAnchorEl(null);
setShowName(false);
closeParentMenu();
}, [closeParentMenu]);
}, []);

const onAddClick = useCallback((event: React.MouseEvent<HTMLButtonElement | HTMLDivElement>) => {
setAnchorEl(event.currentTarget);
Expand Down Expand Up @@ -240,14 +247,18 @@ function ProfileMenu ({ address, closeParentMenu }: Props): React.ReactElement<P

if (isLastAccountWithTheProfile && currentProfile === profileToBeRemoved) {
setStorage('profile', PROFILE_TAGS.ALL)
.then(handleClose)
.then(() => {
handleClose();
closeParentMenu();
})
.catch(console.error);
} else {
handleClose();
closeParentMenu();
}
})
.catch(console.error);
}, [profileNames, accounts, address, currentProfile, handleClose]);
}, [address, profileNames, accounts, currentProfile, handleClose, closeParentMenu]);

const open = Boolean(anchorEl);
const id = open ? 'simple-popover 2' : undefined;
Expand All @@ -256,6 +267,7 @@ function ProfileMenu ({ address, closeParentMenu }: Props): React.ReactElement<P
<>
<Grid aria-describedby={id} component='button' container item onClick={onAddClick} sx={{ bgcolor: 'transparent', border: 'none', color: theme.palette.text.primary, height: 'fit-content', p: 0, width: 'inherit' }}>
<MenuItem
fontSize={isExtensionMode ? '16px' : undefined}
iconComponent={
<VaadinIcon icon='vaadin:folder-add' style={{ color: `${theme.palette.text.primary}`, height: '20px' }} />
}
Expand Down Expand Up @@ -284,6 +296,7 @@ function ProfileMenu ({ address, closeParentMenu }: Props): React.ReactElement<P
{isExtensionMode && profileNames && profileNames.length > 0 &&
<Grid aria-describedby={id} component='button' container item onClick={onRemoveMenuClick} sx={{ bgcolor: 'transparent', border: 'none', color: theme.palette.text.primary, height: 'fit-content', p: 0, width: 'inherit' }}>
<MenuItem
fontSize='16px'
iconComponent={
<VaadinIcon icon='vaadin:folder-remove' style={{ color: theme.palette.text.primary, height: '20px' }} />
}
Expand All @@ -293,7 +306,6 @@ function ProfileMenu ({ address, closeParentMenu }: Props): React.ReactElement<P
/>
</Grid>
}
{isExtensionMode && <Divider sx={{ bgcolor: 'divider', height: '1px', my: '6px', width: '100%' }} />}
<Popover
PaperProps={{
sx: {
Expand Down Expand Up @@ -322,12 +334,15 @@ function ProfileMenu ({ address, closeParentMenu }: Props): React.ReactElement<P
{status === STATUS.SHOW_ADD &&
<AddMenu
address={address}
closeParentMenu={closeParentMenu}
extensionMode={isExtensionMode}
handleClose={handleClose}
setShowName={setShowName}
showName={showName}
/>}
{status === STATUS.SHOW_REMOVE &&
<RemoveMenu
extensionMode={isExtensionMode}
onRemove={onRemove}
profileNames={profileNames}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function TotalBalancePieChart ({ setGroupedAssets }: Props): React.ReactElement
withCountUp
withSmallDecimal
/>
<Typography sx={{ color: !youHave.change ? 'secondary.contrastText' : youHave.change > 0 ? 'success.main' : 'warning.main', fontSize: '16px', fontWeight: 500 }}>
<Typography sx={{ color: !youHave.change ? 'secondary.contrastText' : youHave.change > 0 ? 'success.contrastText' : 'warning.main', fontSize: '16px', fontWeight: 500 }}>
<CountUp
decimals={countDecimalPlaces(portfolioChange) || PORTFOLIO_CHANGE_DECIMAL}
duration={1}
Expand Down
14 changes: 9 additions & 5 deletions packages/extension-polkagate/src/hooks/useYouHave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { amountToHuman } from '../util/utils';
import { usePrices } from '.';

export interface YouHaveType {
available: number;
change: number;
date: number;
portfolio: number;
Expand Down Expand Up @@ -45,8 +46,9 @@ export default function useYouHave (): YouHaveType | undefined | null {
return undefined;
}

let totalPrice = 0;
let totalBeforeChange = 0;
let portfolio = 0;
let available = 0;
let change = 0;
const balances = accountsAssets.balances;
const date = Math.min(accountsAssets.timeStamp, pricesInCurrencies.date);

Expand All @@ -56,14 +58,16 @@ export default function useYouHave (): YouHaveType | undefined | null {
const tokenValue = pricesInCurrencies.prices[asset.priceId]?.value ?? 0;
const tokenPriceChange = pricesInCurrencies.prices[asset.priceId]?.change ?? 0;
const currentAssetPrice = calcPrice(tokenValue, asset.totalBalance, asset.decimal);
const currentAvailableAssetPrice = calcPrice(tokenValue, asset.availableBalance, asset.decimal);

totalPrice += currentAssetPrice;
totalBeforeChange += calcChange(tokenValue, Number(asset.totalBalance) / (10 ** asset.decimal), tokenPriceChange);
portfolio += currentAssetPrice;
available += currentAvailableAssetPrice;
change += calcChange(tokenValue, Number(asset.totalBalance) / (10 ** asset.decimal), tokenPriceChange);
});
});
});

return { change: totalBeforeChange, date, portfolio: totalPrice } as unknown as YouHaveType;
return { available, change, date, portfolio } as unknown as YouHaveType;
}, [accountsAssets, pricesInCurrencies]);

return youHave;
Expand Down
Loading
Loading