Skip to content

Commit

Permalink
Fix number input and add favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgyytyy committed May 16, 2023
1 parent aaa44f4 commit c1a5fad
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
Binary file added public/favicon.ico
Binary file not shown.
18 changes: 2 additions & 16 deletions src/components/Display/DebtDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import { useAccount, useContractRead } from "wagmi"
import { useZkafiContractAddressHook } from "../../hooks/useContractAddress.hook"
import { zkafiABI } from "../../contracts/zkafi"
import { formatted } from "../../utils/ether-big-number"
import { Typography } from "@mui/material"

export function DebtDisplay ({
onChange
debt
}: any) {
const { address } = useAccount()
const zkafiAddress = useZkafiContractAddressHook()
const { data: debt } = useContractRead({
address: zkafiAddress,
abi: zkafiABI,
functionName: 'calculateRepayAmount',
args: [address]
})
const value = debt !== undefined ? formatted(debt).toString() : null
onChange(value)
return (
<Typography
sx={{
fontSize: '18px',
fontWeight: 'bold'
}}
>
current debt: {value}
current debt: {debt}
</Typography>
)
}
6 changes: 1 addition & 5 deletions src/components/Display/GetMaxBalanceDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ export function GetMaxBalanceDisplay({
<TextField
placeholder="Amount"
value={amount}
onKeyPress={(event) => {
if (!/[0-9]/.test(event.key)) {
event.preventDefault();
}
}}
type="number"
onChange={(e) => {
const value = e.target.value
setAmount(Number(value))
Expand Down
19 changes: 12 additions & 7 deletions src/components/Form/RepayForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { DebtDisplay } from "../Display/DebtDisplay"
import { CurrentBalanceDisplay } from "../Display/CurrentBalanceDisplay"
import { useCurrentBalance } from "../../hooks/current-balance.hook"
import { BigNumber } from "ethers"
import { zkafiABI } from "../../contracts/zkafi"
import { formatted } from "../../utils/ether-big-number"

export function RepayForm ({
loading,
onStart,
onComplete
}: any) {
const [amount, setAmount] = useState<number>()
const [debt, setDebt] = useState<number>()
const [transactionLoading, setTransactionLoading] = useState(false)
const { address } = useAccount()
const balance = useCurrentBalance()
Expand All @@ -28,6 +29,13 @@ export function RepayForm ({
functionName: 'allowance',
args: [address!, zkafiAddress]
})
const { data: debtValue } = useContractRead({
address: zkafiAddress,
abi: zkafiABI,
functionName: 'calculateRepayAmount',
args: [address]
})
const debt = debtValue !== undefined ? formatted(debtValue).toString() : null
return (
<Grid container justifyContent="center" rowSpacing={4}>
<Grid container item>
Expand All @@ -37,11 +45,7 @@ export function RepayForm ({
{
transactionLoading || loading ?
<Skeleton variant="rectangular" width={260} height={10} />
: <DebtDisplay
onChange={(debt: any) => {
setDebt(debt)
}}
/>
: <DebtDisplay debt={debt}/>
}
</Grid>
<Grid container item xs={12}>
Expand All @@ -51,6 +55,7 @@ export function RepayForm ({
<OutlinedInput
value={amount}
placeholder="enter repay amount"
type="number"
onChange={(e) => {
setAmount(Number(e.target.value))
}}
Expand All @@ -74,7 +79,7 @@ export function RepayForm ({
textTransform: 'none',
}}
onClick={() => {
setAmount(debt)
setAmount(Number(debt))
}}
>
Max
Expand Down
1 change: 1 addition & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function App({ Component, pageProps }: AppProps) {
<ConnectKitProvider>
<NextHead>
<title>Zkafi</title>
<link rel="shortcut icon" href="/favicon.ico" />
</NextHead>
<ApplicationBar />
<Container>
Expand Down
11 changes: 11 additions & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ body {
to {
transform: rotate(360deg);
}
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}

/* Firefox */
input[type=number] {
-moz-appearance: textfield;
}

0 comments on commit c1a5fad

Please sign in to comment.