-
Notifications
You must be signed in to change notification settings - Fork 4
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
9f5fe24
commit 9564273
Showing
6 changed files
with
173 additions
and
14 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,78 @@ | ||
import React, { useMemo } from "react" | ||
import { | ||
Button, | ||
Flex, | ||
HStack, | ||
Icon, | ||
InputGroup, | ||
InputRightElement, | ||
NumberInput, | ||
NumberInputField, | ||
Text, | ||
Tooltip, | ||
useColorModeValue, | ||
} from "@chakra-ui/react" | ||
import { TokenBalance } from "../TokenBalance" | ||
import { Currency } from "../../types" | ||
import { fixedPointNumberToString } from "../../utils" | ||
import { Alert } from "../../static/icons" | ||
import { USD } from "../../constants" | ||
|
||
export default function TokenBalanceInput({ | ||
amount, | ||
usdAmount, | ||
currency, | ||
tokenBalance, | ||
placeholder, | ||
onChange, | ||
}: { | ||
amount?: string | ||
usdAmount?: string | ||
currency: Currency | ||
tokenBalance: string | number | ||
placeholder?: string | ||
onChange: (value: string) => void | ||
}) { | ||
// TODO: Set the correct color | ||
const colorInfo = useColorModeValue("grey.200", "grey.200") | ||
|
||
const tokenBalanceAmount = useMemo( | ||
() => | ||
fixedPointNumberToString(BigInt(tokenBalance || 0), currency.decimals), | ||
[currency.decimals, tokenBalance], | ||
) | ||
|
||
return ( | ||
<Flex direction="column" gap={2}> | ||
<Flex justifyContent="space-between"> | ||
<Text>Amount</Text> | ||
<HStack> | ||
<Text>Balance</Text> | ||
<TokenBalance tokenBalance={tokenBalance} currency={currency} /> | ||
</HStack> | ||
</Flex> | ||
<InputGroup> | ||
<NumberInput | ||
w="100%" | ||
min={0} | ||
value={amount} | ||
onChange={(valueString) => onChange(valueString)} | ||
> | ||
<NumberInputField placeholder={placeholder} /> | ||
</NumberInput> | ||
<InputRightElement width="5rem"> | ||
<Button h="1.75rem" onClick={() => onChange(tokenBalanceAmount)}> | ||
Max | ||
</Button> | ||
</InputRightElement> | ||
</InputGroup> | ||
<HStack> | ||
{/* TODO: Add correct text for tooltip */} | ||
<Tooltip label="Template"> | ||
<Icon as={Alert} color={colorInfo} /> | ||
</Tooltip> | ||
<Text color={colorInfo}>{`${usdAmount} ${USD.symbol}`}</Text> | ||
</HStack> | ||
</Flex> | ||
) | ||
} |
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,31 @@ | ||
import React from "react" | ||
import { createIcon } from "@chakra-ui/react" | ||
|
||
export const Alert = createIcon({ | ||
displayName: "Alert", | ||
viewBox: "0 0 16 16", | ||
path: ( | ||
<svg | ||
width="16" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g clipPath="url(#clip0_3178_2454)"> | ||
<path | ||
d="M7.99967 5.33325V7.99992M7.99967 10.6666H8.00634M14.6663 7.99992C14.6663 11.6818 11.6816 14.6666 7.99967 14.6666C4.31778 14.6666 1.33301 11.6818 1.33301 7.99992C1.33301 4.31802 4.31778 1.33325 7.99967 1.33325C11.6816 1.33325 14.6663 4.31802 14.6663 7.99992Z" | ||
stroke="#675E60" | ||
strokeWidth="1.5" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_3178_2454"> | ||
<rect width="16" height="16" fill="currentColor" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
), | ||
}) |
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