Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Create and implement a Stepper component. (#2246)
Browse files Browse the repository at this point in the history
* Fix duplicate CSS properties.

* Create and implement a Stepper component.

* Cleanup comment

* Further styling of active step text.

* Change button to use 'continue' text.

* Modify text + refactor stepper.

* Use a CSS var to store the default iconSize

* Use a CSS var to store the default iconSize

* Wording suggestions.

* Update src/custom/pages/Claim/InvestmentFlow/index.tsx

Co-authored-by: Leandro Boscariol <[email protected]>

* Fix code style issues with Prettier

* Revert key id to use index instead.

Co-authored-by: Leandro Boscariol <[email protected]>
Co-authored-by: Lint Action <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2022
1 parent 26e7540 commit 56fbeb1
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 168 deletions.
7 changes: 6 additions & 1 deletion src/custom/assets/cow-swap/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions src/custom/components/Stepper/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import styled from 'styled-components/macro'
import CheckCircle from 'assets/cow-swap/check.svg'
import { transparentize } from 'polished'

export const Wrapper = styled.div`
width: 100%;
display: flex;
flex-flow: row wrap;
margin: 12px 0 24px;
`

export const Step = styled.div<{
totalSteps: number
isActiveStep: boolean
completedStep: boolean
circleSize?: number
}>`
--circleSize: 42px;
display: flex;
flex-flow: column wrap;
align-items: center;
position: relative;
flex: 1 1 ${({ totalSteps }) => `calc(100% / ${totalSteps})`};
&::before,
&::after {
content: '';
position: absolute;
top: ${({ circleSize }) => (circleSize ? `calc(${circleSize / 2})px` : 'calc(var(--circleSize) / 2)')};
height: 1px;
border-top: 1px solid ${({ theme }) => theme.border2};
}
&::before {
left: 0;
right: 50%;
margin-right: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')};
}
&::after {
right: 0;
left: 50%;
margin-left: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')};
}
&:first-child::before,
&:last-child::after {
content: none;
display: none;
}
> span {
display: flex;
flex-flow: column wrap;
align-items: center;
justify-content: center;
width: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')};
height: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')};
margin: 0 auto 12px;
border-radius: ${({ circleSize }) => (circleSize ? `${circleSize}px` : 'var(--circleSize)')};
text-align: center;
line-height: 1;
font-size: 100%;
position: relative;
color: ${({ isActiveStep, completedStep, theme }) =>
completedStep ? theme.black : isActiveStep ? theme.black : transparentize(0.4, theme.text1)};
background: ${({ isActiveStep, completedStep, theme, circleSize }) =>
completedStep
? `url(${CheckCircle}) no-repeat center/${circleSize ? `${circleSize}px` : 'var(--circleSize)'}`
: isActiveStep
? theme.primary1
: theme.blueShade3};
> small {
font-size: inherit;
color: inherit;
display: ${({ completedStep }) => (completedStep ? 'none' : 'block')};
}
}
> b {
color: ${({ isActiveStep, completedStep, theme }) =>
completedStep ? theme.text1 : isActiveStep ? theme.text1 : transparentize(0.4, theme.text1)};
font-weight: ${({ isActiveStep, completedStep }) => (completedStep ? '300' : isActiveStep ? 'bold' : '300')};
}
> i {
font-style: normal;
color: ${({ isActiveStep, completedStep, theme }) =>
completedStep
? transparentize(0.2, theme.text1)
: isActiveStep
? transparentize(0.2, theme.text1)
: transparentize(0.4, theme.text1)};
font-size: 12px;
margin: 6px 0 0;
padding: 0 24px;
text-align: center;
}
`

interface StepperProps {
steps: {
title: string
subtitle?: string
}[]
activeStep: number
}

export function Stepper({ steps, activeStep }: StepperProps) {
return (
<Wrapper>
{steps.map(({ title, subtitle }, index) => {
const completedStep = activeStep > index
const isActiveStep = activeStep === index
return (
<Step key={index} totalSteps={steps.length} isActiveStep={isActiveStep} completedStep={completedStep}>
<span>
<small>{index + 1}</small>
</span>
<b>{title}</b>
<i>{subtitle}</i>
</Step>
)
})}
</Wrapper>
)
}
2 changes: 1 addition & 1 deletion src/custom/pages/Claim/FooterNavButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function FooterNavButtons({
<>
{investFlowStep === 0 ? (
<ButtonPrimary onClick={() => setInvestFlowStep(1)}>
<Trans>Approve tokens</Trans>
<Trans>Continue</Trans>
</ButtonPrimary>
) : investFlowStep === 1 ? (
<ButtonPrimary onClick={() => setInvestFlowStep(2)} disabled={hasError}>
Expand Down
70 changes: 53 additions & 17 deletions src/custom/pages/Claim/InvestmentFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
InvestContent,
InvestFlowValidation,
InvestSummaryTable,
StepIndicator,
Steps,
ClaimTable,
AccountClaimSummary,
} from 'pages/Claim/styled'
import { InvestSummaryRow } from 'pages/Claim/InvestmentFlow/InvestSummaryRow'
import { ClaimSummaryView } from 'pages/Claim/ClaimSummary'

import { Stepper } from 'components/Stepper'

import { ClaimType, useClaimState, useUserEnhancedClaimData, useClaimDispatchers } from 'state/claim/hooks'
import { ClaimStatus } from 'state/claim/actions'
import { InvestClaim } from 'state/claim/reducer'
Expand All @@ -25,6 +25,20 @@ import { useActiveWeb3React } from 'hooks/web3'
import InvestOption from './InvestOption'
import { ClaimCommonTypes, ClaimWithInvestmentData, EnhancedUserClaimData } from '../types'

const STEPS_DATA = [
{
title: 'Start',
},
{
title: 'Set allowances',
subtitle: 'Approve all tokens to be used for investment.',
},
{
title: 'Submit claim',
subtitle: 'Submit and confirm the transaction to claim vCOW.',
},
]

export type InvestOptionProps = {
claim: EnhancedUserClaimData
optionIndex: number
Expand Down Expand Up @@ -127,7 +141,7 @@ export default function InvestmentFlow({ hasClaims, isAirdropOnly, ...tokenAppro
if (
!activeClaimAccount || // no connected account
!hasClaims || // no claims
!isInvestFlowActive || // not on correct step (account change in mid step)
!isInvestFlowActive || // not on correct step (account change in mid-step)
claimStatus !== ClaimStatus.DEFAULT || // not in default claim state
isAirdropOnly // is only for airdrop
) {
Expand All @@ -136,19 +150,42 @@ export default function InvestmentFlow({ hasClaims, isAirdropOnly, ...tokenAppro

return (
<InvestFlow>
<StepIndicator>
<Steps step={investFlowStep}>
<li>Allowances: Approve all tokens to be used for investment.</li>
<li>Submit and confirm the transaction to claim vCOW</li>
</Steps>
<h1>
{investFlowStep === 0
? 'Claiming vCOW is a two step process'
: investFlowStep === 1
? 'Set allowance to Buy vCOW'
: 'Confirm transaction to claim all vCOW'}
</h1>
</StepIndicator>
<Stepper steps={STEPS_DATA} activeStep={investFlowStep} />

<h1>
{investFlowStep === 0
? 'Claim and invest'
: investFlowStep === 1
? 'Set allowance to Buy vCOW'
: 'Confirm transaction to claim all vCOW'}
</h1>

{investFlowStep === 0 && (
<p>
You have chosen to exercise one or more investment opportunities alongside claiming your airdrop. Exercising
your investment options will give you the chance to acquire vCOW tokens at at fixed price. This process
consists of two steps.
<br />
<br />
The first step allows you to define the investment amounts and set the required allowances for the tokens you
will use to invest with.
<br />
<br />
The last step executes all claiming opportunities on-chain. Additionally, it sends the tokens you will use to
invest with, to the smart contract. In return, the smart contract will send the vCOW tokens for the Airdrop
and your 4 years linear vesting of the investment amount will start.
<br />
<br />
For more details around the token, please read{' '}
<a href="https://cow.fi" target="_blank" rel="noreferrer">
the blog post
</a>
.<br /> For more details about the claiming process, please read the{' '}
<a href="https://cow.fi" target="_blank" rel="noreferrer">
step by step guide
</a>
</p>
)}

{/* Invest flow: Step 1 > Set allowances and investment amounts */}
{investFlowStep === 1 ? (
Expand All @@ -170,7 +207,6 @@ export default function InvestmentFlow({ hasClaims, isAirdropOnly, ...tokenAppro
<InvestFlowValidation>Approve all investment tokens before continuing</InvestFlowValidation>
</InvestContent>
) : null}

{/* Invest flow: Step 2 > Review summary */}
{investFlowStep === 2 ? (
<InvestContent>
Expand Down
Loading

0 comments on commit 56fbeb1

Please sign in to comment.