Skip to content

Commit

Permalink
feature: add delegation and undelegation flow (#846)
Browse files Browse the repository at this point in the history
* added delegation and undelegation flow

* fixed issue with sticky header in tabs

* added a new modal window with buttons on the home page

* added empty state UI for undelegation

* fixed deploys tab and deploys details page for staking

---------

Co-authored-by: ost-ptk <[email protected]>
Co-authored-by: Vynnyk Dmytro <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent 096fc63 commit b1e268a
Show file tree
Hide file tree
Showing 52 changed files with 3,066 additions and 157 deletions.
3 changes: 3 additions & 0 deletions src/apps/popup/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { NftDetailsPage } from '@popup/pages/nft-details';
import { WalletQrCodePage } from '@popup/pages/wallet-qr-code';
import { TransferNftPage } from '@popup/pages/transfer-nft';
import { ChangePasswordPage } from '@popup/pages/change-password';
import { StakesPage } from '@popup/pages/stakes';

export function AppRouter() {
const isLocked = useSelector(selectVaultIsLocked);
Expand Down Expand Up @@ -252,6 +253,8 @@ function AppRoutes() {
path={RouterPath.ChangePassword}
element={<ChangePasswordPage />}
/>
<Route path={RouterPath.Delegate} element={<StakesPage />} />
<Route path={RouterPath.Undelegate} element={<StakesPage />} />
</Routes>
);
}
29 changes: 20 additions & 9 deletions src/apps/popup/pages/activity-details/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ import {
} from '@libs/ui/utils/formatters';
import {
getBlockExplorerContractUrl,
TransferType,
TypeName
ActivityType,
ActivityTypeName,
AuctionManagerEntryPoint
} from '@src/constants';
import { selectApiConfigBasedOnActiveNetwork } from '@background/redux/settings/selectors';

interface ActivityDetailsPageContentProps {
fromAccount?: string;
toAccount?: string;
deployInfo?: ExtendedDeploy | null;
type?: TransferType | null;
type?: ActivityType | null;
amount?: string | null;
symbol?: string | null;
}
Expand Down Expand Up @@ -80,8 +81,11 @@ const AddressContainer = styled(FlexColumn)`
padding: 16px 12px 16px 0;
`;

const AmountContainer = styled(AlignedSpaceBetweenFlexRow)`
padding: 8px 16px 8px 0;
const AmountContainer = styled(AlignedSpaceBetweenFlexRow)<{
emptyAmount?: boolean;
}>`
padding: ${({ emptyAmount }) =>
emptyAmount ? '16px 16px 16px 0' : '8px 16px 8px 0'};
`;

const RowsContainer = styled(FlexColumn)<BorderBottomPseudoElementProps>`
Expand Down Expand Up @@ -117,7 +121,10 @@ export const ActivityDetailsPageContent = ({
[Erc20EventType.erc20_transfer_from]: t('Transfer from'),
[Erc20EventType.erc20_approve]: t('Approve of'),
[Erc20EventType.erc20_burn]: t('Burn of'),
[Erc20EventType.erc20_mint]: t('Mint of')
[Erc20EventType.erc20_mint]: t('Mint of'),
[AuctionManagerEntryPoint.delegate]: t('Delegate with'),
[AuctionManagerEntryPoint.undelegate]: t('Undelegate with'),
[AuctionManagerEntryPoint.redelegate]: t('Redelegate with')
};

const decimals = deployInfo.contractPackage?.metadata?.decimals;
Expand Down Expand Up @@ -173,7 +180,7 @@ export const ActivityDetailsPageContent = ({
<ContentContainer>
<ParagraphContainer top={SpacingSize.XL}>
<Typography type="header">
{type && <Trans t={t}>{TypeName[type]}</Trans>}
{type && <Trans t={t}>{ActivityTypeName[type]}</Trans>}
</Typography>
</ParagraphContainer>
<Tile>
Expand Down Expand Up @@ -285,7 +292,11 @@ export const ActivityDetailsPageContent = ({
}
/>
<Typography type="captionRegular">
<Trans t={t}>contract</Trans>
<Trans t={t}>
{deployInfo.contractPackage.contract_name === 'Auction'
? 'System Contract'
: 'contract'}
</Trans>
</Typography>
</AlignedFlexRow>
</RightAlignedFlexColumn>
Expand All @@ -295,7 +306,7 @@ export const ActivityDetailsPageContent = ({
</Typography>
)}
</ItemContainer>
<AmountContainer>
<AmountContainer emptyAmount={formattedTransferAmount === '-'}>
<Typography type="captionRegular" color="contentSecondary">
<Trans t={t}>Amount</Trans>
</Typography>
Expand Down
49 changes: 49 additions & 0 deletions src/apps/popup/pages/home/components/more-buttons-modal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { Trans, useTranslation } from 'react-i18next';
import styled from 'styled-components';

import { Button, Modal, SvgIcon, Typography } from '@libs/ui';
import { CenteredFlexColumn, SpacingSize } from '@libs/layout';

import { ModalButtons } from './modal-buttons';

const MoreButton = styled(CenteredFlexColumn)`
cursor: pointer;
padding: 0 16px;
`;

interface MoreButtonsModalProps {
handleBuyWithCSPR: () => void;
}

export const MoreButtonsModal = ({
handleBuyWithCSPR
}: MoreButtonsModalProps) => {
const { t } = useTranslation();

return (
<Modal
placement="bottom"
renderContent={() => (
<ModalButtons handleBuyWithCSPR={handleBuyWithCSPR} />
)}
children={() => (
<MoreButton gap={SpacingSize.Small}>
<Button circle>
<SvgIcon
src="assets/icons/more.svg"
color="contentOnFill"
style={{
transform: 'rotate(90deg)'
}}
/>
</Button>
<Typography type="captionMedium" color="contentAction">
<Trans t={t}>More</Trans>
</Typography>
</MoreButton>
)}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { Trans, useTranslation } from 'react-i18next';
import styled from 'styled-components';

import { NetworkSetting } from '@src/constants';
import { AlignedFlexRow, FlexColumn, SpacingSize } from '@libs/layout';
import { Button, SvgIcon, Typography } from '@libs/ui';
import { RouterPath, useTypedNavigate } from '@popup/router';
import { useCasperToken } from '@src/hooks';
import { selectActiveNetworkSetting } from '@background/redux/settings/selectors';

const ButtonContainer = styled(AlignedFlexRow)`
cursor: pointer;
padding: 14px 16px;
`;

interface ButtonsProps {
handleBuyWithCSPR: () => void;
}

export const ModalButtons = ({ handleBuyWithCSPR }: ButtonsProps) => {
const { t } = useTranslation();
const navigate = useTypedNavigate();
const casperToken = useCasperToken();

const network = useSelector(selectActiveNetworkSetting);

return (
<FlexColumn>
{network === NetworkSetting.Mainnet && (
<ButtonContainer gap={SpacingSize.Large} onClick={handleBuyWithCSPR}>
<Button circle>
<SvgIcon src="assets/icons/card.svg" color="contentOnFill" />
</Button>
<FlexColumn>
<Typography type="bodySemiBold">
<Trans t={t}>Buy</Trans>
</Typography>
<Typography type="captionRegular" color="contentSecondary">
<Trans t={t}>Buy CSPR with cash</Trans>
</Typography>
</FlexColumn>
</ButtonContainer>
)}
<ButtonContainer
gap={SpacingSize.Large}
onClick={() =>
navigate(
casperToken?.id
? RouterPath.Transfer.replace(
':tokenContractPackageHash',
casperToken.id
).replace(
':tokenContractHash',
casperToken.contractHash || 'null'
)
: RouterPath.TransferNoParams
)
}
>
<Button circle>
<SvgIcon src="assets/icons/transfer.svg" color="contentOnFill" />
</Button>
<FlexColumn>
<Typography type="bodySemiBold">
<Trans t={t}>Send</Trans>
</Typography>
<Typography type="captionRegular" color="contentSecondary">
<Trans t={t}>Send CSPR to any account</Trans>
</Typography>
</FlexColumn>
</ButtonContainer>
<ButtonContainer
gap={SpacingSize.Large}
onClick={() =>
navigate(RouterPath.Receive, {
state: { tokenData: casperToken }
})
}
>
<Button circle>
<SvgIcon src="assets/icons/receive.svg" color="contentOnFill" />
</Button>
<FlexColumn>
<Typography type="bodySemiBold">
<Trans t={t}>Receive</Trans>
</Typography>
<Typography type="captionRegular" color="contentSecondary">
<Trans t={t}>Receive CSPR</Trans>
</Typography>
</FlexColumn>
</ButtonContainer>
<ButtonContainer
gap={SpacingSize.Large}
onClick={() => navigate(RouterPath.Delegate)}
>
<Button circle>
<SvgIcon src="assets/icons/delegate.svg" color="contentOnFill" />
</Button>
<Typography type="bodySemiBold">
<Trans t={t}>Delegate</Trans>
</Typography>
</ButtonContainer>
<ButtonContainer
gap={SpacingSize.Large}
onClick={() => navigate(RouterPath.Undelegate)}
>
<Button circle>
<SvgIcon src="assets/icons/undelegate.svg" color="contentOnFill" />
</Button>
<Typography type="bodySemiBold">
<Trans t={t}>Undelegate</Trans>
</Typography>
</ButtonContainer>
</FlexColumn>
);
};
6 changes: 3 additions & 3 deletions src/apps/popup/pages/home/components/tokens-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { formatErc20TokenBalance } from './utils';
const TotalValueContainer = styled(SpaceBetweenFlexRow)`
padding: 12px 16px;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
border-top-left-radius: ${({ theme }) => theme.borderRadius.twelve}px;
border-top-right-radius: ${({ theme }) => theme.borderRadius.twelve}px;
background-color: ${({ theme }) => theme.color.backgroundPrimary};
`;

Expand Down Expand Up @@ -77,7 +77,7 @@ export const TokensList = () => {
/>
)}
marginLeftForItemSeparatorLine={56}
marginLeftForHeaderSeparatorLine={16}
marginLeftForHeaderSeparatorLine={0}
/>
);
};
56 changes: 21 additions & 35 deletions src/apps/popup/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
import { TokensList } from './components/tokens-list';
import { NftList } from './components/nft-list';
import { DeploysList } from './components/deploys-list';
import { MoreButtonsModal } from './components/more-buttons-modal';

const DividerLine = styled.hr`
margin: 16px 0;
Expand All @@ -65,11 +66,13 @@ const DividerLine = styled.hr`
`;

const ButtonsContainer = styled(CenteredFlexRow)`
margin-top: 28px;
margin-top: 16px;
`;

const ButtonContainer = styled(CenteredFlexColumn)`
cursor: pointer;
padding: 0 16px;
`;

export function HomePageContent() {
Expand Down Expand Up @@ -166,6 +169,22 @@ export function HomePageContent() {
</Typography>
</FlexColumn>
<ButtonsContainer gap={SpacingSize.XXXL}>
{network === NetworkSetting.Mainnet && (
<ButtonContainer
gap={SpacingSize.Small}
onClick={handleBuyWithCSPR}
>
<Button circle>
<SvgIcon
src="assets/icons/card.svg"
color="contentOnFill"
/>
</Button>
<Typography type="captionMedium" color="contentAction">
<Trans t={t}>Buy</Trans>
</Typography>
</ButtonContainer>
)}
<ButtonContainer
gap={SpacingSize.Small}
onClick={() =>
Expand All @@ -192,40 +211,7 @@ export function HomePageContent() {
<Trans t={t}>Send</Trans>
</Typography>
</ButtonContainer>
<ButtonContainer
gap={SpacingSize.Small}
onClick={() =>
navigate(RouterPath.Receive, {
state: { tokenData: casperToken }
})
}
>
<Button circle>
<SvgIcon
src="assets/icons/receive.svg"
color="contentOnFill"
/>
</Button>
<Typography type="captionMedium" color="contentAction">
<Trans t={t}>Receive</Trans>
</Typography>
</ButtonContainer>
{network === NetworkSetting.Mainnet && (
<ButtonContainer
gap={SpacingSize.Small}
onClick={handleBuyWithCSPR}
>
<Button circle>
<SvgIcon
src="assets/icons/card.svg"
color="contentOnFill"
/>
</Button>
<Typography type="captionMedium" color="contentAction">
<Trans t={t}>Buy</Trans>
</Typography>
</ButtonContainer>
)}
<MoreButtonsModal handleBuyWithCSPR={handleBuyWithCSPR} />
</ButtonsContainer>
</TileContainer>
</Tile>
Expand Down
Loading

0 comments on commit b1e268a

Please sign in to comment.