-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat(web)/desktop-navbar-and-responsiveness
- Loading branch information
Showing
9 changed files
with
145 additions
and
44 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 |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
"repartitions", | ||
"solhint", | ||
"typechain", | ||
"uncommify", | ||
"Unslashed", | ||
"viem", | ||
"wagmi" | ||
|
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,57 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
import { Field } from "@kleros/ui-components-library"; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
height: fit-content; | ||
`; | ||
|
||
const StyledField = styled(Field)` | ||
width: 100%; | ||
height: fit-content; | ||
`; | ||
|
||
interface INumberInputField { | ||
placeholder?: string; | ||
message?: string; | ||
value?: string; | ||
onChange?: (value: string) => void; | ||
formatter?: (value: string) => string; | ||
} | ||
|
||
export const NumberInputField: React.FC<INumberInputField> = ({ placeholder, message, value, onChange, formatter }) => { | ||
const [isEditing, setIsEditing] = useState(false); | ||
|
||
const toggleEditing = () => { | ||
setIsEditing(!isEditing); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
{isEditing ? ( | ||
<StyledField | ||
type="number" | ||
value={value} | ||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => { | ||
onChange?.(event.target.value); | ||
}} | ||
placeholder={placeholder} | ||
message={message} | ||
variant="info" | ||
onBlur={toggleEditing} | ||
/> | ||
) : ( | ||
<StyledField | ||
type="text" | ||
value={formatter ? formatter(value ?? "0") : value} | ||
placeholder={placeholder} | ||
message={message} | ||
variant="info" | ||
onFocus={toggleEditing} | ||
readOnly | ||
/> | ||
)} | ||
</Container> | ||
); | ||
}; |
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
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,23 @@ | ||
import { formatEther, formatUnits } from "viem"; | ||
import { commify } from "./commify"; | ||
|
||
export const roundNumberDown = (value: number, fractionDigits = 0) => { | ||
const factor = 10 ** fractionDigits; | ||
return Math.floor(value * factor) / factor; | ||
}; | ||
|
||
export const formatUnitsWei = (value: bigint) => formatUnits(value, 18); | ||
|
||
export const formatValue = (value: string, fractionDigits, roundDown) => { | ||
let units = Number(value); | ||
if (roundDown) units = roundNumberDown(units, fractionDigits); | ||
return commify(units.toFixed(fractionDigits)); | ||
}; | ||
|
||
export const formatPNK = (value: bigint, fractionDigits = 0, roundDown = false) => | ||
formatValue(formatUnitsWei(value), fractionDigits, roundDown); | ||
|
||
export const formatETH = (value: bigint, fractionDigits = 4, roundDown = false) => | ||
formatValue(formatEther(value), fractionDigits, roundDown); | ||
|
||
export const formatUSD = (value: number, fractionDigits = 2) => "$" + commify(Number(value).toFixed(fractionDigits)); |
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 |
---|---|---|
@@ -1,14 +1 @@ | ||
import { formatEther, formatUnits } from "viem"; | ||
import { commify } from "./commify"; | ||
|
||
export const isUndefined = (maybeObject: any): maybeObject is undefined => typeof maybeObject === "undefined"; | ||
|
||
export const formatUnitsWei = (value: bigint) => formatUnits(value, 18); | ||
|
||
export const formatPNK = (value: bigint, fractionDigits = 0) => | ||
commify(Number(formatUnitsWei(value)).toFixed(fractionDigits)); | ||
|
||
export const formatETH = (value: bigint, fractionDigits = 4) => | ||
commify(Number(formatEther(value)).toFixed(fractionDigits)); | ||
|
||
export const formatUSD = (value: number, fractionDigits = 2) => "$" + commify(Number(value).toFixed(fractionDigits)); |