Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 50% button #17

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/frontend/src/components/TokenInput/TokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IProps {
setAssetId?: (assetId: string) => void;

onMaxClick?: () => void;
on50Click?: () => void;
balance?: string;

disabled?: boolean;
Expand Down Expand Up @@ -64,6 +65,7 @@ const MaxButton = styled.div`
font-size: 13px;
line-height: 24px;
padding: 4px 16px;
margin-left: 8px;
border-radius: 4px;
cursor: pointer;
background: ${({ theme }) => theme.colors.button.secondaryBackground};
Expand Down Expand Up @@ -115,6 +117,17 @@ const TokenInput: React.FC<IProps> = (props) => {
placeholder="0.00"
readOnly={!props.setAmount}
/>
{props.on50Click && (
<MaxButton
onClick={() => {
if (props.disabled) return;
setFocused(true);
props.on50Click?.();
}}
>
50%
</MaxButton>
)}
{props.onMaxClick && (
<MaxButton
onClick={() => {
Expand Down
8 changes: 8 additions & 0 deletions apps/frontend/src/screens/Dashboard/ActionTab/InputCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,13 @@ const InputCard: React.FC<IProps> = () => {
}
};

const on50BtnClick = () => {
onMaxBtnClick();
if (dashboardStore.tokenAmount == null || dashboardStore.tokenAmount.eq(0))
return;
dashboardStore.setTokenAmount(dashboardStore.tokenAmount.div(2));
};

return (
<div>
<div {...getCollapseProps()}>
Expand All @@ -545,6 +552,7 @@ const InputCard: React.FC<IProps> = () => {
setAmount={dashboardStore.setTokenAmount}
assetId={dashboardStore.actionToken.assetId}
onMaxClick={() => onMaxBtnClick()}
on50Click={() => on50BtnClick()}
balance={tokenInputBalance()}
error={tokenInputError()}
/>
Expand Down