Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill offer bugfixes #749

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/diva-app/src/component/ApproveActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ export const ApproveActionButtons = ({
CREATE_POOL_TYPE,
formik.values.signature,
account,
parseUnits(formik.values.yourShare.toString(), decimal)
parseUnits(
Number(formik.values.yourShare).toFixed(decimal).toString(),
decimal
)
).then((res) => {
if (!res.success) {
setErrorMessage(res.message)
Expand Down Expand Up @@ -565,7 +568,6 @@ export const ApproveActionButtons = ({
})
break
case 'liquidity':
console.log(formik.values.longRecipient)
diva!
.addLiquidity(
window.location.pathname.split('/')[1],
Expand Down
1 change: 1 addition & 0 deletions packages/diva-app/src/component/CreatePool/CreatePool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function CreatePool() {
}, [formik.values.collateralToken])
const handleConfigPick = (event: SelectChangeEvent) => {
setConfigPicked(event.target.value)
formik.setFieldValue('configPicked', event.target.value)
}
// actions after pool is successfully created
const handlePoolSuccess = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/diva-app/src/component/CreatePool/Offer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function Offer() {
Number(formatUnits(jsonResponse.data.data.inflection))
)
formik.setFieldValue('collateralWalletBalance', jsonResponse.data.data)

formik.setFieldValue('collateralToken', token.symbol())
formik.setFieldValue(
'collateralToken.id',
jsonResponse.data.data.collateralToken
Expand Down
31 changes: 15 additions & 16 deletions packages/diva-app/src/component/CreatePool/ReviewAndSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ export function ReviewAndSubmit({
ERC20,
provider.getSigner()
)

useEffect(() => {
token.decimals().then((decimals: number) => {
setDecimal(decimals)
})
token.symbol().then((symbol) => {
setTokenSymbol(symbol)
})
}, [formik.values.collateralToken.id])
useEffect(() => {
if (
diva != undefined &&
Expand All @@ -116,7 +125,10 @@ export function ReviewAndSubmit({
CREATE_POOL_TYPE,
formik.values.signature,
address,
parseUnits(formik.values.yourShare.toString(), decimal)
parseUnits(
Number(formik.values.yourShare).toFixed(decimal).toString(),
decimal
)
).then((res) => {
if (!res.success) {
setErrorMessage(res.message)
Expand All @@ -127,10 +139,6 @@ export function ReviewAndSubmit({
}
}, [formik.values, address, diva, divaDomain])

// QUESTION WHy not move this part into a useEffect hook?
token.decimals().then((decimals: number) => {
setDecimal(decimals)
})
useEffect(() => {
if (
transaction === 'filloffer' &&
Expand Down Expand Up @@ -183,16 +191,7 @@ export function ReviewAndSubmit({
setMaxPayout(parseFloat(actualFillableAmount) * maxYieldTaker)
}
}, [actualFillableAmount, decimal])
useEffect(() => {
const tokenContract = new ethers.Contract(
formik.values.collateralToken.id,
ERC20,
provider.getSigner()
)
tokenContract.symbol().then((symbol) => {
setTokenSymbol(symbol)
})
}, [])

useEffect(() => {
if (window.innerWidth < 768) {
setMobile(true)
Expand Down Expand Up @@ -678,7 +677,7 @@ export function ReviewAndSubmit({
maxPayout,
2,
2
)} ${'dUSD'}`}
)} ${tokenSymbol}`}
</FormHelperText>
<FormHelperText
sx={{
Expand Down
11 changes: 11 additions & 0 deletions packages/diva-app/src/component/CreatePool/formik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type Values = {
poolId?: string
offerHash?: string
permissionedERC721Token: string
configPicked: string
}

export const initialValues: Values = {
Expand Down Expand Up @@ -71,6 +72,7 @@ export const initialValues: Values = {
poolId: '',
offerHash: '',
permissionedERC721Token: ethers.constants.AddressZero,
configPicked: '',
}

type Errors = {
Expand Down Expand Up @@ -104,6 +106,7 @@ export const useCreatePoolFormik = () => {
longRecipient,
shortRecipient,
permissionedERC721Token,
offerExpiry,
} = values

if (collateralToken != null && dataProvider != null) {
Expand Down Expand Up @@ -190,6 +193,14 @@ export const useCreatePoolFormik = () => {
threshold / 1000 / 60
} minutes from now`
}
if (
values.expiryTime.getTime() < Number(values.offerExpiry) * 1000 &&
values.configPicked === 'createoffer'
) {
console.log(values.configPicked)
errors.offerExpiry =
'Offer expiry must be earlier than observation time'
}
if (values.takerAddress == null) {
errors.takerAddress = 'Taker address must not be empty'
}
Expand Down