Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Dec 4, 2023
1 parent 1da9e86 commit 3b0324c
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 1 deletion.
128 changes: 128 additions & 0 deletions dapp/src/components/TokenBalanceInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// import { FC, useEffect, useRef } from "react"
// import {
// Button,
// Icon,
// InputGroup,
// InputLeftElement,
// InputProps,
// InputRightElement,
// FormControl,
// FormLabel,
// useColorModeValue,
// NumberFormatInput,
// NumberFormatInputValues,
// NumberFormatInputProps,
// } from "@threshold-network/components"
// import { createIcon } from "@chakra-ui/icons"
// import { formatUnits, parseUnits } from "@ethersproject/units"
// import { Zero } from "@ethersproject/constants"
// import { BigNumber } from "@ethersproject/bignumber"
// import { web3 as web3Constants } from "../../constants"
// import HelperErrorText from "../Forms/HelperErrorText"

// export interface TokenBalanceInputProps
// extends InputProps,
// Omit<NumberFormatInputProps, "onValueChange"> {
// icon: ReturnType<typeof createIcon>
// max: number | string
// amount?: string | number
// setAmount: (val?: string | number) => void
// label?: string | JSX.Element
// hasError?: boolean
// errorMsgText?: string | JSX.Element
// helperText?: string | JSX.Element
// tokenDecimals?: number
// }

// const TokenBalanceInput: FC<TokenBalanceInputProps> = ({
// icon,
// max,
// amount,
// setAmount,
// label,
// errorMsgText,
// helperText,
// hasError = false,
// tokenDecimals = web3Constants.STANDARD_ERC20_DECIMALS,
// ...inputProps
// }) => {
// const inputRef = useRef<HTMLInputElement>()
// const valueRef = useRef<string | number | undefined>(amount)
// const labelColor = useColorModeValue("gray.700", "gray.300")

// useEffect(() => {
// if (amount === "" && inputRef.current) {
// const setValue = Object.getOwnPropertyDescriptor(
// window.HTMLInputElement.prototype,
// "value",
// )?.set
// setValue!.call(inputRef.current, "")
// const event = new Event("change", { bubbles: true })
// inputRef.current.dispatchEvent(event)
// valueRef.current = undefined
// }
// })

// const setToMax = () => {
// let remainder = Zero
// const { decimalScale } = inputProps
// if (decimalScale && decimalScale > 0 && decimalScale < tokenDecimals) {
// remainder = BigNumber.from(max).mod(
// BigNumber.from(10).pow(tokenDecimals - decimalScale),
// )
// }
// _setAmount(formatUnits(BigNumber.from(max).sub(remainder), tokenDecimals))
// setAmount(valueRef.current)
// }

// const _setAmount = (value: string | number) => {
// valueRef.current = value
// ? parseUnits(value.toString(), tokenDecimals).toString()
// : undefined
// }

// return (
// <FormControl isInvalid={hasError} isDisabled={inputProps.isDisabled}>
// {label && (
// <FormLabel htmlFor={inputProps.name} color={labelColor}>
// {label}
// </FormLabel>
// )}
// <InputGroup size="md">
// <InputLeftElement>
// <Icon boxSize="20px" as={icon} />
// </InputLeftElement>
// <NumberFormatInput
// // @ts-ignore
// ref={inputRef}
// placeholder="Enter an amount"
// paddingLeft="2.5rem"
// paddingRight="4.5rem"
// {...inputProps}
// onValueChange={(values: NumberFormatInputValues) =>
// _setAmount(values.value)
// }
// value={amount ? formatUnits(amount, tokenDecimals) : undefined}
// onChange={() => {
// setAmount(valueRef.current)
// }}
// id={inputProps.name}
// />
// {!inputProps.isDisabled && (
// <InputRightElement width="4.5rem">
// <Button h="1.75rem" size="sm" onClick={setToMax}>
// MAX
// </Button>
// </InputRightElement>
// )}
// </InputGroup>
// <HelperErrorText
// helperText={helperText}
// errorMsgText={errorMsgText}
// hasError={hasError}
// />
// </FormControl>
// )
// }

// export default TokenBalanceInput
2 changes: 1 addition & 1 deletion dapp/src/contexts/WalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function WalletContextProvider({
}): React.ReactElement {
const [btcAccount, setBtcAccount] = useState<Account | undefined>(undefined)
const [ethAccount, setEthAccount] = useState<Account | undefined>(undefined)

console.log("btcAccount ", btcAccount)

Check warning on line 25 in dapp/src/contexts/WalletContext.tsx

View workflow job for this annotation

GitHub Actions / dapp-format

Unexpected console statement
const contextValue: WalletContextValue = useMemo<WalletContextValue>(
() => ({
btcAccount,
Expand Down
1 change: 1 addition & 0 deletions dapp/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./ledger-live-app"
export * from "./currency"
export * from "./staking"
export * from "./wallet"

Check failure on line 4 in dapp/src/types/index.ts

View workflow job for this annotation

GitHub Actions / dapp-format

Dependency cycle detected
8 changes: 8 additions & 0 deletions dapp/src/types/wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable import/no-cycle */
import { Currency } from "."

export type Account = {
address: string
balance: number
currency: Currency
}

0 comments on commit 3b0324c

Please sign in to comment.