Skip to content

Commit

Permalink
fix: range slider decimals issue
Browse files Browse the repository at this point in the history
  • Loading branch information
naturexie committed Jan 17, 2025
1 parent 8286d01 commit ff42926
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
16 changes: 4 additions & 12 deletions components/Modal/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ import RangeSlider from "./RangeSlider";
import TokenBox from "./TokenBox";
import { isMemeCategory } from "../../redux/categorySelectors";

export default function Controls({
amount,
available,
action,
tokenId,
asset,
totalAvailable,
available$,
}) {
export default function Controls({ amount, available, action, asset, totalAvailable, available$ }) {
const dispatch = useAppDispatch();
const isMeme = useAppSelector(isMemeCategory);
const handleInputChange = (e) => {
Expand All @@ -31,22 +23,22 @@ export default function Controls({
dispatch(updateAmount({ isMax: false, amount: value }));
}
};

const handleSliderChange = (percent) => {
const p = percent < 1 ? 0 : percent > 99 ? 100 : percent;
const value = new Decimal(available).mul(p).div(100).toFixed();
const decimalLength = value?.split(".")?.[1]?.length || 0;
if (isMeme) {
dispatch(
updateAmountMEME({
isMax: p === 100,
amount: new Decimal(value || 0).toFixed(),
amount: new Decimal(value || 0).toFixed(Math.min(decimalLength, asset.decimals)),
}),
);
} else {
dispatch(
updateAmount({
isMax: p === 100,
amount: new Decimal(value || 0).toFixed(),
amount: new Decimal(value || 0).toFixed(Math.min(decimalLength, asset.decimals)),
}),
);
}
Expand Down
1 change: 0 additions & 1 deletion components/Modal/RangeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export default function RangeSlider(props: any) {
function changeValue(v: string, isClickValue?: boolean) {
let matchedValue;
const numValue = Number(v);
// const toPercent = (100 / splitList.length) * numValue;
if (isClickValue) {
matchedValue = numValue;
if (isMonth) {
Expand Down
1 change: 0 additions & 1 deletion components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ const Modal = () => {
amount={amount}
available={isBtcSupply ? btcAvailableBalance : available}
action={action}
tokenId={tokenId}
asset={asset}
totalAvailable={isBtcSupply ? btcAvailableBalance : available}
available$={available$}
Expand Down

0 comments on commit ff42926

Please sign in to comment.