-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use just the public vault * Update opus-pool sdk * Update vault details hook * Add mint * Update unstake and vault comps * Update form and stake comps * Update tsconfig * Add health query, add mint form * Update forms, hooks, css, add input and user details comps
- Loading branch information
1 parent
42e9b57
commit 1246161
Showing
29 changed files
with
868 additions
and
255 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,73 @@ | ||
import { ChangeEvent, useEffect, useState } from 'react'; | ||
import { parseEther } from 'viem'; | ||
import { number } from 'yup'; | ||
|
||
export const AmountInput = ({ | ||
setAmount, | ||
isSuccess, | ||
disabled, | ||
title, | ||
}: { | ||
setAmount: React.Dispatch<React.SetStateAction<bigint>>; | ||
isSuccess: boolean; | ||
disabled: boolean; | ||
title: string; | ||
}) => { | ||
const [inputValue, setInputValue] = useState<string>(''); | ||
useEffect(() => { | ||
if (isSuccess) { | ||
setInputValue(''); | ||
} | ||
}, [isSuccess]); | ||
|
||
const onChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
const regex = /^\d*(\.\d{0,18})?$/; // only allow 18 digits after the decimal | ||
const stringValue = e.target.value.replaceAll('+', '').replaceAll('-', ''); | ||
let isValid = false; | ||
let validValue: bigint | undefined; | ||
if (stringValue !== '' && !regex.test(stringValue)) { | ||
return; | ||
} | ||
try { | ||
if (stringValue === '') { | ||
validValue = undefined; | ||
} else { | ||
number().validateSync(stringValue); | ||
validValue = parseEther(stringValue); | ||
setAmount(validValue); | ||
} | ||
isValid = true; | ||
} catch (_error) { | ||
// Swallow parsing errors, just don't update the value | ||
} | ||
if (!isValid) return; | ||
setInputValue(stringValue); | ||
}; | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
border: '1px solid #168F9C', | ||
borderRadius: '0.5rem', | ||
padding: '0.5rem', | ||
}} | ||
> | ||
<input | ||
style={{ | ||
border: 'none', | ||
width: '100%', | ||
outline: 'none', | ||
}} | ||
type="text" | ||
placeholder="ETH amount" | ||
onChange={onChange} | ||
value={inputValue} | ||
disabled={disabled} | ||
title={title} | ||
/> | ||
<span>ETH</span> | ||
</div> | ||
); | ||
}; |
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,49 @@ | ||
import React from 'react'; | ||
import { useAccount, useWalletClient } from 'wagmi'; | ||
import { useState } from 'react'; | ||
import { parseEther } from 'viem'; | ||
import { useNetworkAndVaultContext } from '../context/neworkAndVaultContext'; | ||
import { useVaultDetails } from '../hooks/useVaultDetails'; | ||
import { BurnForm } from './BurnForm'; | ||
import { useBurnMutation } from '../hooks/useBurnMutation'; | ||
|
||
export const BurnComponent = () => { | ||
const { address } = useAccount(); | ||
const [amount, setAmount] = useState<bigint>(parseEther('0')); | ||
const { networkType, vaultForChain } = useNetworkAndVaultContext(); | ||
|
||
const { data: vaultDetails } = useVaultDetails({ | ||
network: networkType, | ||
vault: vaultForChain, | ||
address: address, | ||
}); | ||
const { mutate: burn, isError, isLoading, isSuccess } = useBurnMutation(); | ||
|
||
const { data: walletClient } = useWalletClient(); | ||
|
||
const handleBurn = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
if (!address || !vaultForChain) return; | ||
burn({ | ||
userAddress: address, | ||
network: networkType, | ||
vault: vaultForChain, | ||
amount, | ||
walletClient, | ||
}); | ||
setAmount(parseEther('0')); | ||
}; | ||
|
||
return ( | ||
<> | ||
<BurnForm | ||
onSubmit={(e) => handleBurn(e)} | ||
maxAmount={vaultDetails?.minted} | ||
setAmount={setAmount} | ||
isError={isError} | ||
isLoading={isLoading} | ||
isSuccess={isSuccess} | ||
/> | ||
</> | ||
); | ||
}; |
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,85 @@ | ||
import React, { useEffect } from 'react'; | ||
import { formatEther } from 'viem'; | ||
import { useNetworkAndVaultContext } from '../context/neworkAndVaultContext'; | ||
import { useAccount } from 'wagmi'; | ||
import toast, { LoaderIcon } from 'react-hot-toast'; | ||
import { AmountInput } from './AmountInput'; | ||
|
||
export const BurnForm = ({ | ||
onSubmit, | ||
maxAmount, | ||
setAmount, | ||
isError, | ||
isLoading, | ||
isSuccess, | ||
}: { | ||
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void; | ||
maxAmount: bigint | undefined; | ||
setAmount: React.Dispatch<React.SetStateAction<bigint>>; | ||
isError: boolean; | ||
isLoading: boolean; | ||
isSuccess: boolean; | ||
}) => { | ||
const { wrongNetwork } = useNetworkAndVaultContext(); | ||
const { isConnected } = useAccount(); | ||
|
||
useEffect(() => { | ||
if (isError) { | ||
toast.error('Something went wrong'); | ||
} | ||
}, [isError]); | ||
|
||
return ( | ||
<div style={{ padding: '1rem', border: '1px', display: 'flex', flexDirection: 'column', alignItems: 'center' }}> | ||
<h2>Burn osETH</h2> | ||
<form | ||
onSubmit={(e) => { | ||
onSubmit(e); | ||
}} | ||
style={{ width: '450px', margin: '1rem auto' }} | ||
> | ||
<AmountInput | ||
disabled={!isConnected || isLoading || wrongNetwork} | ||
title={!isConnected ? 'Connect wallet' : 'Enter the amount to stake'} | ||
isSuccess={isSuccess} | ||
setAmount={setAmount} | ||
/> | ||
<div | ||
style={{ | ||
width: '100%', | ||
display: 'flex', | ||
justifyContent: 'flex-start', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
marginBottom: '0.5rem', | ||
}} | ||
> | ||
<div style={{ fontSize: '0.8rem', color: '#168F9C' }}>Available to burn:</div> | ||
<div style={{ fontSize: '0.8rem', color: '#168F9C', fontWeight: 'bold' }}> | ||
{maxAmount ? formatEther(maxAmount) : '0'} ETH | ||
</div> | ||
</div> | ||
<button disabled={!isConnected || isLoading || wrongNetwork} type="submit"> | ||
{isConnected ? ( | ||
isLoading ? ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
}} | ||
> | ||
<LoaderIcon /> | ||
<span>Waiting for confirmation</span> | ||
</div> | ||
) : ( | ||
'Burn osETH' | ||
) | ||
) : ( | ||
'Connect wallet to burn osETH' | ||
)} | ||
</button> | ||
</form> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.