This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MaximumSlippage: create comp 1. dumb for now * Tooltip size prop * text * moved MaximumSlippage to own file 1. minor css changes * const: slippage map and default slip * PriceSlippage reducer & actions * Price: move MaximumSlippage state inside 1. MaximumSlippage remains dumb 2. added slippage label next to price title for clarity * MaximumSlippage: passed state setters / CSS 1. passed custom slippage setters from parent containers 2. css fixes * const: fixed exports + added new const 1. BigNumber ONE & ONE_HUNDRED exports * usePriceEstimation: added slippage price calc * just use index as key * css for dark mode * remove slippage from app because :( * commented in useful code for if we reinstantiate * move price checking function to utils/price * usePriceEstimation: removed price slippage code 1. also removed reducer code for slippage
- Loading branch information
Showing
9 changed files
with
276 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
|
||
import { MEDIA, SLIPPAGE_MAP } from 'const' | ||
import { PriceSlippageState } from 'reducers-actions/priceSlippage' | ||
|
||
const Wrapper = styled.div` | ||
font-size: 1.6rem; | ||
width: 100%; | ||
> strong { | ||
display: flex; | ||
align-items: center; | ||
text-transform: capitalize; | ||
color: var(--color-text-primary); | ||
width: 100%; | ||
margin: 0 0 1rem; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-size: 1.5rem; | ||
@media ${MEDIA.mobile} { | ||
font-size: 1.3rem; | ||
} | ||
} | ||
> div { | ||
display: flex; | ||
flex-flow: row wrap; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
margin: 1rem auto 0.2rem; | ||
height: 4.4rem; | ||
width: 100%; | ||
> button { | ||
border-radius: 3rem; | ||
> small { | ||
font-size: x-small; | ||
margin-left: 0.4rem; | ||
} | ||
} | ||
> button, | ||
> label > input { | ||
display: flex; | ||
flex: 1; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
background: var(--color-background-input); | ||
color: var(--color-text-primary); | ||
font-size: inherit; | ||
font-weight: normal; | ||
height: 100%; | ||
padding: 0.65rem 1.5rem; | ||
&:not(:last-child) { | ||
margin-right: 1rem; | ||
} | ||
white-space: nowrap; | ||
&.selected, | ||
&.selected ~ small, | ||
&:hover:not(input), | ||
&:focus, | ||
&:focus ~ small { | ||
color: var(--color-text-button-hover); | ||
} | ||
&:hover:not(input):not(.selected), | ||
&:focus { | ||
background-color: var(--color-background-button-hover); | ||
} | ||
&.selected { | ||
background: var(--color-text-active); | ||
} | ||
transition: all 0.2s ease-in-out; | ||
} | ||
> label { | ||
position: relative; | ||
flex: 1.6; | ||
height: 100%; | ||
> small { | ||
position: absolute; | ||
right: 2rem; | ||
top: 0; | ||
bottom: 0; | ||
margin: auto; | ||
display: flex; | ||
align-items: center; | ||
opacity: 0.75; | ||
color: var(--color-text-primary); | ||
letter-spacing: -0.05rem; | ||
text-align: right; | ||
font-weight: var(--font-weight-bold); | ||
@media ${MEDIA.mobile} { | ||
font-size: 1rem; | ||
letter-spacing: 0.03rem; | ||
} | ||
} | ||
> input { | ||
border-radius: var(--border-radius-top); | ||
margin: 0; | ||
padding-right: 3.4rem; | ||
width: 100%; | ||
&::placeholder { | ||
opacity: 0.6; | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
interface MaximumSlippageProps { | ||
priceSlippage: PriceSlippageState | ||
setNewSlippage: (customSlippage: string | React.ChangeEvent<HTMLInputElement>) => void | ||
} | ||
|
||
const slippagePercentages = Array.from(SLIPPAGE_MAP.keys()) | ||
|
||
const checkCustomPriceSlippage = (slippagePercentage: string): boolean => | ||
!!slippagePercentage && !SLIPPAGE_MAP.has(slippagePercentage) | ||
|
||
const MaximumSlippage: React.FC<MaximumSlippageProps> = ({ setNewSlippage, priceSlippage }) => { | ||
return ( | ||
<Wrapper> | ||
<strong>Limit additional price slippage</strong> | ||
<div> | ||
{slippagePercentages.map((slippage, index) => ( | ||
<button | ||
key={index} | ||
type="button" | ||
onClick={(): void => setNewSlippage(slippage)} | ||
className={slippage === priceSlippage ? 'selected' : ''} | ||
> | ||
{slippage}%{SLIPPAGE_MAP.get(slippage) && <small>(suggested)</small>} | ||
</button> | ||
))} | ||
<label> | ||
<input | ||
type="number" | ||
step="0.1" | ||
placeholder="Custom" | ||
value={priceSlippage} | ||
className={checkCustomPriceSlippage(priceSlippage) ? 'selected' : ''} | ||
onChange={(e): void => setNewSlippage(e.target.value)} | ||
/> | ||
<small>%</small> | ||
</label> | ||
</div> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
/* | ||
// PRICE SLIPPAGE | ||
const dispatchNewSlippage = (payload: string): void => dispatch(setPriceSlippage(payload)) | ||
// to add in Price component to show current selected slippage | ||
{priceSlippage && ( | ||
<FormMessage className="warning"> | ||
<small>{priceSlippage}% slippage</small> | ||
</FormMessage> | ||
)} | ||
*/ | ||
|
||
export default MaximumSlippage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Actions, ActionCreator, ReducerCreator } from 'reducers-actions' | ||
import { DEFAULT_SUGGESTED_SLIPPAGE } from 'const' | ||
|
||
const ActionsList = ['SET_PRICE_SLIPPAGE'] as const | ||
|
||
type PriceSlippageActions = typeof ActionsList[number] | ||
type PriceSlippagePayload = string | ||
|
||
type PriceSlippageState = PriceSlippagePayload | ||
|
||
const setPriceSlippage: ActionCreator<PriceSlippageActions, PriceSlippagePayload> = payload => ({ | ||
type: ActionsList[0], | ||
payload, | ||
}) | ||
|
||
const PRICE_SLIPPAGE_INITIAL_STATE = DEFAULT_SUGGESTED_SLIPPAGE | ||
|
||
const reducer: ReducerCreator<PriceSlippageState, Actions<PriceSlippageActions, PriceSlippagePayload>> = ( | ||
state, | ||
action, | ||
) => { | ||
switch (action.type) { | ||
case ActionsList[0]: | ||
return action.payload | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export { setPriceSlippage, reducer, PriceSlippageState, PRICE_SLIPPAGE_INITIAL_STATE } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters