From 519dde948c06a8086fadabd5850828d0296743f2 Mon Sep 17 00:00:00 2001 From: TG-Brad Date: Tue, 25 Oct 2022 14:19:56 +1000 Subject: [PATCH] Fix lockForever not being taken into consideration (Resolves #54) --- .../@filterswap-libs/sdk/dist/sdk.esm.js | 2 +- .../AddLiquidity/ConfirmAddModalBottom.tsx | 8 ++++++++ src/pages/AddLiquidity/index.tsx | 18 +++++------------ src/state/mint/actions.ts | 8 +++++++- src/state/mint/reducer.ts | 20 ++++++++++++++++++- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/custom_modules/@filterswap-libs/sdk/dist/sdk.esm.js b/src/custom_modules/@filterswap-libs/sdk/dist/sdk.esm.js index c0fd8c5..5a4b02b 100644 --- a/src/custom_modules/@filterswap-libs/sdk/dist/sdk.esm.js +++ b/src/custom_modules/@filterswap-libs/sdk/dist/sdk.esm.js @@ -1483,7 +1483,7 @@ var Router = /*#__PURE__*/function () { newTokenParams.tokenSymbol, // _tokenSymbol (unint256) valuesToSend, // _tokenArgs (bytes32[]) options.ownerShare * 100, // _ownerShare (uint256) - options.lockForever ? 2 ^ (256 - 1) : options.daysToLock * 86400, // _liquidityLockTime (uint256) + options.lockForever ? Number.MAX_SAFE_INTEGER - 1 : options.daysToLock * 86400, // _liquidityLockTime (uint256) ] if (options.inputCurrency == ETHER || options.inputCurrency.address == WETH[ChainId.BSCTESTNET].address) { diff --git a/src/pages/AddLiquidity/ConfirmAddModalBottom.tsx b/src/pages/AddLiquidity/ConfirmAddModalBottom.tsx index 12a48a4..522e7c7 100644 --- a/src/pages/AddLiquidity/ConfirmAddModalBottom.tsx +++ b/src/pages/AddLiquidity/ConfirmAddModalBottom.tsx @@ -5,6 +5,7 @@ import { TranslateString } from 'utils/translateTextHelpers' import { RowBetween, RowFixed } from '../../components/Row' import CurrencyLogo from '../../components/CurrencyLogo' import { Field } from '../../state/mint/actions' +import { useMintState } from '../../state/mint/hooks' export function ConfirmAddModalBottom({ noLiquidity, @@ -21,6 +22,8 @@ export function ConfirmAddModalBottom({ poolTokenPercentage?: Percent onAdd: () => void }) { + const { daysToLock, lockForever } = useMintState() + return ( <> @@ -56,6 +59,11 @@ export function ConfirmAddModalBottom({ Share of Pool: {noLiquidity ? '100' : poolTokenPercentage?.toSignificant(4)}% + + Liquidity Lock Time + {/* */} + {lockForever ? 'Forever' : `${daysToLock} Days`} + diff --git a/src/pages/AddLiquidity/index.tsx b/src/pages/AddLiquidity/index.tsx index acc024e..7fdbbf0 100644 --- a/src/pages/AddLiquidity/index.tsx +++ b/src/pages/AddLiquidity/index.tsx @@ -21,6 +21,7 @@ import { useCurrency } from 'hooks/Tokens' import { ApprovalState, useApproveCallback } from 'hooks/useApproveCallback' import { Field } from 'state/mint/actions' import { useDerivedMintInfo, useMintActionHandlers, useMintState } from 'state/mint/hooks' +import { useDaysToLock } from 'state/deploy/hooks' import { useTransactionAdder } from 'state/transactions/hooks' import { useIsExpertMode, useUserDeadline, useUserSlippageTolerance } from 'state/user/hooks' @@ -62,7 +63,7 @@ export default function AddLiquidity({ const expertMode = useIsExpertMode() // mint state - const { independentField, typedValue, otherTypedValue } = useMintState() + const { independentField, typedValue, otherTypedValue, daysToLock, lockForever } = useMintState() const { dependentField, currencies, @@ -122,17 +123,8 @@ export default function AddLiquidity({ const addTransaction = useTransactionAdder() // const { isSm, isXs } = useMatchBreakpoints() - const [lockForever, setBurnForever] = useState(false) - const [daysToLock, setDaysToLock] = useState(365) - const handleDaysToLockChange = (evt: React.ChangeEvent) => { - const { value: inputValue } = evt.target - const num: number = parseFloat(inputValue || '0') - const min: number = parseFloat(evt.target.min || '-1') - const max: number = parseFloat(evt.target.max || '1000000000000') - - setDaysToLock(Math.min(Math.max(num, min), max)) - } + const { handleDaysToLockChange, handleLockForever } = useDaysToLock() async function onAdd() { if (!chainId || !library || !account) return @@ -149,7 +141,7 @@ export default function AddLiquidity({ } const deadlineFromNow = Math.ceil(Date.now() / 1000) + deadline - const liquidityLockTime = daysToLock * 86400 // Convert Days to Hours to Minutes + const liquidityLockTime = lockForever ? Number.MAX_SAFE_INTEGER - 1 : daysToLock * 86400 // Convert Days to Hours to Minutes let estimate let method: (...args: any) => Promise @@ -413,7 +405,7 @@ export default function AddLiquidity({ {/* setBurnForever(!burnForever)} /> */} - setBurnForever(!lockForever)} /> + diff --git a/src/state/mint/actions.ts b/src/state/mint/actions.ts index 655f337..27fe1e4 100644 --- a/src/state/mint/actions.ts +++ b/src/state/mint/actions.ts @@ -5,5 +5,11 @@ export enum Field { CURRENCY_B = 'CURRENCY_B' } -export const typeInput = createAction<{ field: Field; typedValue: string; noLiquidity: boolean }>('mint/typeInputMint') +export const typeInput = createAction<{ + field: Field; + typedValue: string; + noLiquidity: boolean +}>('mint/typeInputMint') export const resetMintState = createAction('mint/resetMintState') +export const daysToLockChange = createAction<{ daysToLock: number }>('mint/daysToLockChange') +export const toggleLockForever = createAction('mint/toggleLockForever') \ No newline at end of file diff --git a/src/state/mint/reducer.ts b/src/state/mint/reducer.ts index c4efc2e..2135550 100644 --- a/src/state/mint/reducer.ts +++ b/src/state/mint/reducer.ts @@ -1,16 +1,22 @@ import { createReducer } from '@reduxjs/toolkit' import { Field, resetMintState, typeInput } from './actions' +import { daysToLockChange, toggleLockForever } from '../deploy/actions' + export interface MintState { readonly independentField: Field readonly typedValue: string readonly otherTypedValue: string // for the case when there's no liquidity + readonly daysToLock: number + readonly lockForever: boolean } const initialState: MintState = { independentField: Field.CURRENCY_A, typedValue: '', - otherTypedValue: '' + otherTypedValue: '', + daysToLock: 365, + lockForever: false, } export default createReducer(initialState, builder => @@ -44,4 +50,16 @@ export default createReducer(initialState, builder => } }) + .addCase(daysToLockChange, (state, { payload: { daysToLock } }) => { + return { + ...state, + daysToLock + } + }) + .addCase(toggleLockForever, (state) => { + return { + ...state, + lockForever: !state.lockForever, + } + }) )