forked from burrowfdn/burrow-cash
-
Notifications
You must be signed in to change notification settings - Fork 6
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
b8d9fda
commit aacb61a
Showing
6 changed files
with
444 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useEffect, useState, createContext } from "react"; | ||
import { Modal as MUIModal, Typography, Box, Stack, useTheme } from "@mui/material"; | ||
import { useAppSelector, useAppDispatch } from "../../../redux/hooks"; | ||
import { hideModal, updateAmount, updatePosition } from "../../../redux/appSlice"; | ||
import { getModalStatus, getAssetData, getSelectedValues } from "../../../redux/appSelectors"; | ||
import { Wrapper } from "../../../components/Modal/style"; | ||
import { DEFAULT_POSITION, lpTokenPrefix } from "../../../utils/config"; | ||
|
||
export const ModalContext = createContext(null) as any; | ||
const ConfirmMobile = () => { | ||
const dispatch = useAppDispatch(); | ||
const handleClose = () => dispatch(hideModal()); | ||
const theme = useTheme(); | ||
const [selectedCollateralType, setSelectedCollateralType] = useState(DEFAULT_POSITION); | ||
|
||
return ( | ||
<MUIModal open onClose={handleClose}> | ||
<Wrapper | ||
sx={{ | ||
"& *::-webkit-scrollbar": { | ||
backgroundColor: theme.custom.scrollbarBg, | ||
}, | ||
}} | ||
> | ||
<ModalContext.Provider | ||
value={{ | ||
position: selectedCollateralType, | ||
}} | ||
> | ||
<Box sx={{ p: ["20px", "20px"] }}>弹窗内容</Box> | ||
</ModalContext.Provider> | ||
</Wrapper> | ||
</MUIModal> | ||
); | ||
}; | ||
|
||
export default ConfirmMobile; |
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,72 @@ | ||
import React, { useRef, useState, useEffect } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
const RangeSlider = ({ defaultValue, action }) => { | ||
const allowedValues = [1, 1.25, 1.5, 1.75, 2]; | ||
const [value, setValue] = useState(defaultValue); | ||
const [splitList, setSplitList] = useState(allowedValues); | ||
const [matchValue, setMatchValue] = useState(value); | ||
const valueRef = useRef<HTMLInputElement>(null); | ||
const [selectedItem, setSelectedItem] = useState(defaultValue); | ||
|
||
useEffect(() => { | ||
if (valueRef.current) { | ||
const nearestValue = allowedValues.reduce((prev, curr) => { | ||
return Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev; | ||
}); | ||
const percentage = | ||
((nearestValue - splitList[0]) / (splitList[splitList.length - 1] - splitList[0])) * 100; | ||
valueRef.current.style.backgroundSize = `${percentage}% 100%`; | ||
setMatchValue(nearestValue); | ||
} | ||
}, [value, splitList, allowedValues]); | ||
|
||
function changeValue(v) { | ||
const numValue = Number(v); | ||
const nearestValue = allowedValues.reduce((prev, curr) => { | ||
return Math.abs(curr - numValue) < Math.abs(prev - numValue) ? curr : prev; | ||
}); | ||
setValue(nearestValue); | ||
setSelectedItem(nearestValue); | ||
} | ||
const actionShowRedColor = action === "Long"; | ||
return ( | ||
<div className="mt-5 pb-5 border-b border-dark-700 -mx-4 px-4"> | ||
<div className="mb-3.5 text-sm text-gray-300">Leverage: {matchValue}X</div> | ||
<div className="relative flex flex-col z-10"> | ||
<input | ||
ref={valueRef} | ||
onChange={(e) => changeValue(e.target.value)} | ||
value={value} | ||
type="range" | ||
className={`w-full cursor-pointer ${actionShowRedColor ? "" : "redInput"}`} | ||
style={{ backgroundSize: "100% 100%" }} | ||
min={splitList[0]} | ||
max={splitList[splitList.length - 1]} | ||
step="any" | ||
/> | ||
</div> | ||
<div className={twMerge("flex justify-between items-center mt-2")}> | ||
{splitList.map((p) => ( | ||
<div | ||
key={p} | ||
className="flex flex-col items-center cursor-pointer" | ||
onClick={() => changeValue(p)} | ||
> | ||
<span | ||
className={twMerge( | ||
`flex items-center justify-center text-xs text-gray-400 w-11 py-0.5 border border-transparent hover:border-v3LiquidityRemoveBarColor | ||
rounded-lg`, | ||
p === selectedItem && "bg-black bg-opacity-20", | ||
)} | ||
> | ||
{p}X | ||
</span> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RangeSlider; |
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
Oops, something went wrong.