-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9e9c89
commit 1a5535c
Showing
5 changed files
with
214 additions
and
29 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,132 @@ | ||
import Expand from 'components/Expand'; | ||
import QuestionHelper from 'components/QuestionHelper'; | ||
import Row, { RowBetween } from 'components/Row'; | ||
import { BodySmall } from 'components/Text'; | ||
import { AppContext } from 'contexts'; | ||
import React, { useContext, useEffect, useState } from 'react' | ||
import { Box, styled, Switch, SwitchProps, Typography, useTheme } from 'soroswap-ui'; | ||
|
||
|
||
export const CustomSwitch = styled((props: SwitchProps) => ( | ||
<Switch sx={{ my: 1 }} focusVisibleClassName=".Mui-focusVisible" disableRipple {...props} /> | ||
))(({ theme }) => ({ | ||
width: 42, | ||
height: 26, | ||
padding: 0, | ||
alignContent: 'center', | ||
alignItems: 'center', | ||
'& .MuiSwitch-switchBase': { | ||
padding: 0, | ||
margin: 3, | ||
'&.Mui-checked': { | ||
transform: 'translateX(16px)', | ||
color: '#8866DD', | ||
'& .MuiSwitch-thumb:before': { | ||
backgroundColor: '#8866DD', | ||
borderRadius: 32, | ||
}, | ||
'& + .MuiSwitch-track': { | ||
backgroundColor: theme.palette.background.paper, | ||
opacity: 1, | ||
border: 0, | ||
}, | ||
}, | ||
}, | ||
'& .MuiSwitch-thumb': { | ||
backgroundColor: 'rgba(136, 102, 221, 0.25)', | ||
width: 20, | ||
height: 20, | ||
'&:before': { | ||
content: "''", | ||
position: 'absolute', | ||
width: '100%', | ||
height: '100%', | ||
left: 0, | ||
top: 0, | ||
backgroundRepeat: 'no-repeat', | ||
backgroundPosition: 'center', | ||
}, | ||
}, | ||
'& .MuiSwitch-track': { | ||
borderRadius: 32, | ||
backgroundColor: theme.palette.background.paper, | ||
opacity: 1, | ||
}, | ||
})); | ||
|
||
const Option = styled(Row, { | ||
shouldForwardProp: (prop) => prop !== 'isActive', | ||
}) <{ isActive: boolean }>` | ||
width: auto; | ||
cursor: pointer; | ||
padding: 6px 12px; | ||
text-align: center; | ||
gap: 4px; | ||
border-radius: 12px; | ||
background: ${({ isActive, theme }) => | ||
isActive ? theme.palette.customBackground.module : 'transparent'}; | ||
pointer-events: ${({ isActive }) => isActive && 'none'}; | ||
`; | ||
|
||
const firstLetterUppercase = (string: string) => { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
const ProtocolsSettings = () => { | ||
const theme = useTheme(); | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
const { Settings } = useContext(AppContext); | ||
const { protocolsStatus, setProtocolsStatus } = Settings; | ||
|
||
const switchProtocolValue = (key: string) => { | ||
const newProtocolsStatus = protocolsStatus.map((protocol) => { | ||
if (protocol.key === key) { | ||
return { | ||
key: protocol.key, | ||
value: !protocol.value, | ||
}; | ||
} | ||
return protocol; | ||
}); | ||
setProtocolsStatus(newProtocolsStatus); | ||
} | ||
|
||
return ( | ||
|
||
<Expand | ||
testId="protocols-settings" | ||
isOpen={isOpen} | ||
onToggle={() => setIsOpen(!isOpen)} | ||
header={ | ||
<Row width="auto"> | ||
<Typography color={theme.palette.secondary.main}>Protocols</Typography> | ||
<QuestionHelper | ||
text={ | ||
<div> | ||
The protocols Soroswap.finance will use to calculate the most efficient path for your transaction. | ||
</div> | ||
} | ||
/> | ||
</Row> | ||
} | ||
button={<></>} | ||
> | ||
<RowBetween gap="md" width={'100%'}> | ||
<Box sx={{ ml: 2 }} width={'100%'} > | ||
{protocolsStatus.map((option, index) => { | ||
return ( | ||
<Row key={index} gap="4px" justify='space-between' align='center'> | ||
<BodySmall fontWeight={100} color={theme.palette.secondary.main} >{firstLetterUppercase(option.key)}</BodySmall> | ||
<CustomSwitch checked={option.value} onClick={() => { switchProtocolValue(option.key) }} color="secondary" /> | ||
</Row> | ||
) | ||
})} | ||
{ } | ||
</Box> | ||
</RowBetween> | ||
|
||
</Expand> | ||
|
||
) | ||
} | ||
|
||
export default ProtocolsSettings |
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