From 77058e097c73aac82e89ee89a28feb80ff02e82b Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 10:21:33 +0200 Subject: [PATCH 01/14] fix transation details --- src/components/Swap/ExchangeRate/ExchangeRate.tsx | 7 ++++++- .../Swap/TransactionDetailsBox/TransactionDetailsBox.tsx | 2 +- src/store/sagas/swap.ts | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Swap/ExchangeRate/ExchangeRate.tsx b/src/components/Swap/ExchangeRate/ExchangeRate.tsx index 2a9cb7ae..3de7e86c 100644 --- a/src/components/Swap/ExchangeRate/ExchangeRate.tsx +++ b/src/components/Swap/ExchangeRate/ExchangeRate.tsx @@ -29,7 +29,12 @@ const ExchangeRate: React.FC = ({ ) : ( - 1 {tokenFromSymbol} = {isNaN(amount) ? 0 : formatNumber(amount.toFixed(tokenToDecimals))}{' '} + 1 {tokenFromSymbol} ={' '} + {isNaN(amount) + ? 0 + : formatNumber(amount.toFixed(tokenToDecimals)) === '0' + ? '~0' + : formatNumber(amount.toFixed(tokenToDecimals))}{' '} {tokenToSymbol} ) diff --git a/src/components/Swap/TransactionDetailsBox/TransactionDetailsBox.tsx b/src/components/Swap/TransactionDetailsBox/TransactionDetailsBox.tsx index 79be311b..1b59cdde 100644 --- a/src/components/Swap/TransactionDetailsBox/TransactionDetailsBox.tsx +++ b/src/components/Swap/TransactionDetailsBox/TransactionDetailsBox.tsx @@ -39,7 +39,7 @@ const TransactionDetailsBox: React.FC = ({ {exchangeRate.val === Infinity ? '-' - : `${formatNumber(exchangeRate.val.toFixed(exchangeRate.decimal))} ${exchangeRate.symbol}`} + : `${formatNumber(exchangeRate.val.toFixed(exchangeRate.decimal)) === '0' ? '~0' : formatNumber(exchangeRate.val.toFixed(exchangeRate.decimal))} ${exchangeRate.symbol}`} )} diff --git a/src/store/sagas/swap.ts b/src/store/sagas/swap.ts index c00fab77..23bd133a 100644 --- a/src/store/sagas/swap.ts +++ b/src/store/sagas/swap.ts @@ -310,6 +310,7 @@ export function* handleGetSimulateResult(action: PayloadAction) { insufficientLiquidityAmountOut = byAmountIn ? result.amountOut : result.amountIn fee = pool.poolKey.feeTier.fee insufficientLiquidityPoolKey = pool.poolKey + priceImpact = 1 errors.push(SwapError.MaxSwapStepsReached) } From 8221cf76d53da68763529050ccfce35d1144e4e3 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 10:51:47 +0200 Subject: [PATCH 02/14] align buttons on init pool --- src/components/NewPosition/PoolInit/PoolInit.tsx | 2 +- src/components/NewPosition/PoolInit/style.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/NewPosition/PoolInit/PoolInit.tsx b/src/components/NewPosition/PoolInit/PoolInit.tsx index 4fedccaf..bbc39973 100644 --- a/src/components/NewPosition/PoolInit/PoolInit.tsx +++ b/src/components/NewPosition/PoolInit/PoolInit.tsx @@ -407,7 +407,7 @@ export const PoolInit: React.FC = ({ /> ) : ( - + diff --git a/src/components/NewPosition/PoolInit/style.ts b/src/components/NewPosition/PoolInit/style.ts index 514ba843..b89d4550 100644 --- a/src/components/NewPosition/PoolInit/style.ts +++ b/src/components/NewPosition/PoolInit/style.ts @@ -77,8 +77,9 @@ const useStyles = makeStyles()(theme => { } }, buttons: { - marginTop: 38, + marginTop: 4, width: '100%', + height: 70, flexDirection: 'row', gap: 16, alignItems: 'center' From 5b3b4a40ee0b4ad9d2ef1e36b8f7b7ba553070f3 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 11:12:55 +0200 Subject: [PATCH 03/14] block swap when insufficient liquidity --- src/store/sagas/swap.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/store/sagas/swap.ts b/src/store/sagas/swap.ts index 23bd133a..97ee069b 100644 --- a/src/store/sagas/swap.ts +++ b/src/store/sagas/swap.ts @@ -282,7 +282,6 @@ export function* handleGetSimulateResult(action: PayloadAction) { let fee = 0n let swapPossible = false - let insufficientLiquidityPoolKey = null const errors = [] @@ -300,7 +299,7 @@ export function* handleGetSimulateResult(action: PayloadAction) { byAmountIn, xToY ? MIN_SQRT_PRICE : MAX_SQRT_PRICE ) - + console.log(result) if (result.maxSwapStepsReached || result.globalInsufficientLiquidity) { if ( byAmountIn @@ -309,7 +308,6 @@ export function* handleGetSimulateResult(action: PayloadAction) { ) { insufficientLiquidityAmountOut = byAmountIn ? result.amountOut : result.amountIn fee = pool.poolKey.feeTier.fee - insufficientLiquidityPoolKey = pool.poolKey priceImpact = 1 errors.push(SwapError.MaxSwapStepsReached) } @@ -347,7 +345,7 @@ export function* handleGetSimulateResult(action: PayloadAction) { yield put( actions.setSimulateResult({ - poolKey: swapPossible ? poolKey : insufficientLiquidityPoolKey, + poolKey: swapPossible ? poolKey : null, amountOut: validatedAmountOut, priceImpact, targetSqrtPrice, From 28fdde44c869e08d38c950c9f3978502d1c32111 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 14:55:58 +0200 Subject: [PATCH 04/14] show devtools --- src/store/index.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index 170a2b31..97ab0cda 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -32,14 +32,12 @@ const configureAppStore = (initialState = {}) => { } }).concat(middleware), preloadedState: initialState, - devTools: isLocalhost - ? { - serialize: { - replacer: (_key, value) => (typeof value === 'bigint' ? value.toString() : value), - options: true - } - } - : false + devTools: { + serialize: { + replacer: (_key, value) => (typeof value === 'bigint' ? value.toString() : value), + options: true + } + } }) sagaMiddleware.run(rootSaga) From 360cd0b50f8ee180662ee3b0988a4b1f00b72952 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 15:03:37 +0200 Subject: [PATCH 05/14] fix build --- src/store/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/index.ts b/src/store/index.ts index 97ab0cda..280939b8 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -3,7 +3,7 @@ import { configureStore, isPlain } from '@reduxjs/toolkit' import combinedReducers from './reducers' import rootSaga from './sagas' -const isLocalhost = window.location.hostname === 'localhost' +// const isLocalhost = window.location.hostname === 'localhost' const isSerializable = (value: unknown) => { return typeof value === 'bigint' || isPlain(value) From ace2de75f1af5cb83a9440503bdf3860751ab60c Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 15:15:36 +0200 Subject: [PATCH 06/14] add test console logs --- src/containers/NewPositionWrapper/NewPositionWrapper.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx index 46c803be..cd094a27 100644 --- a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx +++ b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx @@ -255,7 +255,9 @@ export const NewPositionWrapper: React.FC = ({ }, [isWaitingForNewPool, tokenA, tokenB, feeIndex, poolKey, allPoolKeys, allPools.length]) useEffect(() => { + console.log(poolKey) if (poolKey !== '') { + console.log('get ticks') dispatch( positionsActions.getCurrentPlotTicks({ poolKey: allPoolKeys[poolKey], From de1cffaf34759012042c8e162df800d43f0a4e4e Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 15:44:59 +0200 Subject: [PATCH 07/14] add test console log --- src/components/NewPosition/RangeSelector/RangeSelector.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/NewPosition/RangeSelector/RangeSelector.tsx b/src/components/NewPosition/RangeSelector/RangeSelector.tsx index f0720814..5d1a2352 100644 --- a/src/components/NewPosition/RangeSelector/RangeSelector.tsx +++ b/src/components/NewPosition/RangeSelector/RangeSelector.tsx @@ -175,6 +175,7 @@ export const RangeSelector: React.FC = ({ } const resetPlot = () => { + console.log('resetPlot') if (positionOpeningMethod === 'range') { const initSideDist = Math.abs( midPrice.x - From 41a69596efd1c221d6397d73c79b09ac414b6069 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 15:55:59 +0200 Subject: [PATCH 08/14] trigger reset when data is loaded --- src/components/NewPosition/RangeSelector/RangeSelector.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/NewPosition/RangeSelector/RangeSelector.tsx b/src/components/NewPosition/RangeSelector/RangeSelector.tsx index 5d1a2352..f30948e3 100644 --- a/src/components/NewPosition/RangeSelector/RangeSelector.tsx +++ b/src/components/NewPosition/RangeSelector/RangeSelector.tsx @@ -176,6 +176,7 @@ export const RangeSelector: React.FC = ({ const resetPlot = () => { console.log('resetPlot') + console.log('data', data) if (positionOpeningMethod === 'range') { const initSideDist = Math.abs( midPrice.x - @@ -277,7 +278,8 @@ export const RangeSelector: React.FC = ({ isMountedRef.current && poolKey !== '' && currentMidPrice !== midPrice && - !shouldReversePlot + !shouldReversePlot && + Object.keys(data).length > 0 ) { if (!shouldNotUpdatePriceRange) { setTriggerReset(prev => !prev) @@ -285,7 +287,7 @@ export const RangeSelector: React.FC = ({ unblockUpdatePriceRange() } - }, [ticksLoading, isMountedRef, midPrice.index, poolKey]) + }, [ticksLoading, isMountedRef, midPrice.index, poolKey, data]) useEffect(() => { setCachedConcentrationArray(concentrationArray) From 0eae24572d14e725469712112cff6920f606443b Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 17:18:18 +0200 Subject: [PATCH 09/14] add loop to fetch tickmaps --- .../NewPositionWrapper/NewPositionWrapper.tsx | 1 - src/store/sagas/pools.ts | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx index cd094a27..faec1015 100644 --- a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx +++ b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx @@ -255,7 +255,6 @@ export const NewPositionWrapper: React.FC = ({ }, [isWaitingForNewPool, tokenA, tokenB, feeIndex, poolKey, allPoolKeys, allPools.length]) useEffect(() => { - console.log(poolKey) if (poolKey !== '') { console.log('get ticks') dispatch( diff --git a/src/store/sagas/pools.ts b/src/store/sagas/pools.ts index c6533b54..de48c523 100644 --- a/src/store/sagas/pools.ts +++ b/src/store/sagas/pools.ts @@ -3,9 +3,9 @@ import { PayloadAction } from '@reduxjs/toolkit' import { findPairs, getTokenBalances, getTokenDataByAddresses } from '@utils/utils' import { FetchTicksAndTickMaps, PairTokens, PoolWithPoolKey, actions } from '@store/reducers/pools' import { actions as walletActions } from '@store/reducers/wallet' -import { tokens } from '@store/selectors/pools' +import { poolsArraySortedByFees, tokens } from '@store/selectors/pools' import { address } from '@store/selectors/wallet' -import { all, call, put, select, spawn, takeEvery, takeLatest } from 'typed-redux-saga' +import { all, call, delay, put, select, spawn, takeEvery, takeLatest } from 'typed-redux-saga' import { MAX_POOL_KEYS_RETURNED } from '@invariant-labs/a0-sdk/target/consts' import { getInvariant, getPSP22 } from './connection' @@ -77,11 +77,19 @@ export function* fetchAllPoolsForPairData(action: PayloadAction) { } export function* fetchTicksAndTickMaps(action: PayloadAction) { - const { tokenFrom, tokenTo, allPools } = action.payload - + const { tokenFrom, tokenTo } = action.payload + let poolsData = yield* select(poolsArraySortedByFees) + + let i = 0 + while (Object.keys(poolsData).length === 0 && i < 30) { + console.log('no poolsData') + yield* delay(100) + i++ + poolsData = yield* select(poolsArraySortedByFees) + } try { const invariant = yield* getInvariant() - const pools = findPairs(tokenFrom.toString(), tokenTo.toString(), allPools) + const pools = findPairs(tokenFrom.toString(), tokenTo.toString(), poolsData) const tickmapCalls = pools.map(pool => call([invariant, invariant.getFullTickmap], pool.poolKey) From de6f8a40596930044b37c4e70245197cdb1ef1d8 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 1 Oct 2024 17:20:11 +0200 Subject: [PATCH 10/14] revert changes --- .../NewPosition/RangeSelector/RangeSelector.tsx | 7 ++----- .../NewPositionWrapper/NewPositionWrapper.tsx | 1 - src/store/index.ts | 16 +++++++++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/NewPosition/RangeSelector/RangeSelector.tsx b/src/components/NewPosition/RangeSelector/RangeSelector.tsx index f30948e3..f0720814 100644 --- a/src/components/NewPosition/RangeSelector/RangeSelector.tsx +++ b/src/components/NewPosition/RangeSelector/RangeSelector.tsx @@ -175,8 +175,6 @@ export const RangeSelector: React.FC = ({ } const resetPlot = () => { - console.log('resetPlot') - console.log('data', data) if (positionOpeningMethod === 'range') { const initSideDist = Math.abs( midPrice.x - @@ -278,8 +276,7 @@ export const RangeSelector: React.FC = ({ isMountedRef.current && poolKey !== '' && currentMidPrice !== midPrice && - !shouldReversePlot && - Object.keys(data).length > 0 + !shouldReversePlot ) { if (!shouldNotUpdatePriceRange) { setTriggerReset(prev => !prev) @@ -287,7 +284,7 @@ export const RangeSelector: React.FC = ({ unblockUpdatePriceRange() } - }, [ticksLoading, isMountedRef, midPrice.index, poolKey, data]) + }, [ticksLoading, isMountedRef, midPrice.index, poolKey]) useEffect(() => { setCachedConcentrationArray(concentrationArray) diff --git a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx index faec1015..46c803be 100644 --- a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx +++ b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx @@ -256,7 +256,6 @@ export const NewPositionWrapper: React.FC = ({ useEffect(() => { if (poolKey !== '') { - console.log('get ticks') dispatch( positionsActions.getCurrentPlotTicks({ poolKey: allPoolKeys[poolKey], diff --git a/src/store/index.ts b/src/store/index.ts index 280939b8..170a2b31 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -3,7 +3,7 @@ import { configureStore, isPlain } from '@reduxjs/toolkit' import combinedReducers from './reducers' import rootSaga from './sagas' -// const isLocalhost = window.location.hostname === 'localhost' +const isLocalhost = window.location.hostname === 'localhost' const isSerializable = (value: unknown) => { return typeof value === 'bigint' || isPlain(value) @@ -32,12 +32,14 @@ const configureAppStore = (initialState = {}) => { } }).concat(middleware), preloadedState: initialState, - devTools: { - serialize: { - replacer: (_key, value) => (typeof value === 'bigint' ? value.toString() : value), - options: true - } - } + devTools: isLocalhost + ? { + serialize: { + replacer: (_key, value) => (typeof value === 'bigint' ? value.toString() : value), + options: true + } + } + : false }) sagaMiddleware.run(rootSaga) From bcdf862f5fe9fc44e69694fd38078bef45eb1438 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Wed, 2 Oct 2024 10:11:08 +0200 Subject: [PATCH 11/14] get tickmaps for correct poolkey --- .../NewPositionWrapper/NewPositionWrapper.tsx | 26 +++++++++++++------ src/store/reducers/pools.ts | 1 + src/store/sagas/pools.ts | 21 +++++++++------ src/store/sagas/positions.ts | 3 ++- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx index 46c803be..83286c86 100644 --- a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx +++ b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx @@ -255,14 +255,24 @@ export const NewPositionWrapper: React.FC = ({ }, [isWaitingForNewPool, tokenA, tokenB, feeIndex, poolKey, allPoolKeys, allPools.length]) useEffect(() => { - if (poolKey !== '') { - dispatch( - positionsActions.getCurrentPlotTicks({ - poolKey: allPoolKeys[poolKey], - isXtoY, - fetchTicksAndTickmap: true - }) - ) + if (poolKey !== '' && !isWaitingForNewPool) { + const isCurrentTokenX = isXtoY + ? allPoolKeys[poolKey].tokenX === tokenA + : allPoolKeys[poolKey].tokenX === tokenB + + const isCurrentTokenY = isXtoY + ? allPoolKeys[poolKey].tokenY === tokenB + : allPoolKeys[poolKey].tokenY === tokenA + + if (isCurrentTokenX && isCurrentTokenY) { + dispatch( + positionsActions.getCurrentPlotTicks({ + poolKey: allPoolKeys[poolKey], + isXtoY, + fetchTicksAndTickmap: true + }) + ) + } } }, [isWaitingForNewPool, tokenA, tokenB, poolKey, allPoolKeys]) diff --git a/src/store/reducers/pools.ts b/src/store/reducers/pools.ts index b0333bfc..8b3addc8 100644 --- a/src/store/reducers/pools.ts +++ b/src/store/reducers/pools.ts @@ -77,6 +77,7 @@ export interface FetchTicksAndTickMaps { tokenFrom: string tokenTo: string allPools: PoolWithPoolKey[] + poolKey?: PoolKey } const network = diff --git a/src/store/sagas/pools.ts b/src/store/sagas/pools.ts index de48c523..19ab8f11 100644 --- a/src/store/sagas/pools.ts +++ b/src/store/sagas/pools.ts @@ -1,6 +1,6 @@ import { PoolKey, newPoolKey } from '@invariant-labs/a0-sdk' import { PayloadAction } from '@reduxjs/toolkit' -import { findPairs, getTokenBalances, getTokenDataByAddresses } from '@utils/utils' +import { findPairs, getTokenBalances, getTokenDataByAddresses, poolKeyToString } from '@utils/utils' import { FetchTicksAndTickMaps, PairTokens, PoolWithPoolKey, actions } from '@store/reducers/pools' import { actions as walletActions } from '@store/reducers/wallet' import { poolsArraySortedByFees, tokens } from '@store/selectors/pools' @@ -77,16 +77,21 @@ export function* fetchAllPoolsForPairData(action: PayloadAction) { } export function* fetchTicksAndTickMaps(action: PayloadAction) { - const { tokenFrom, tokenTo } = action.payload + const { tokenFrom, tokenTo, poolKey } = action.payload let poolsData = yield* select(poolsArraySortedByFees) - let i = 0 - while (Object.keys(poolsData).length === 0 && i < 30) { - console.log('no poolsData') - yield* delay(100) - i++ - poolsData = yield* select(poolsArraySortedByFees) + if (poolKey) { + let pools = poolsData.filter(pool => poolKeyToString(pool.poolKey) === poolKeyToString(poolKey)) + let i = 0 + + while (pools.length === 0 && i < 20) { + yield* delay(50) + poolsData = yield* select(poolsArraySortedByFees) + pools = poolsData.filter(pool => poolKeyToString(pool.poolKey) === poolKeyToString(poolKey)) + i++ + } } + try { const invariant = yield* getInvariant() const pools = findPairs(tokenFrom.toString(), tokenTo.toString(), poolsData) diff --git a/src/store/sagas/positions.ts b/src/store/sagas/positions.ts index a7013d0c..51dc557b 100644 --- a/src/store/sagas/positions.ts +++ b/src/store/sagas/positions.ts @@ -275,7 +275,8 @@ export function* handleGetCurrentPlotTicks(action: PayloadAction Date: Wed, 2 Oct 2024 12:05:48 +0200 Subject: [PATCH 12/14] fix deposit max amount of azero tokens --- src/store/sagas/positions.ts | 8 +++++++- src/store/sagas/swap.ts | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/store/sagas/positions.ts b/src/store/sagas/positions.ts index a7013d0c..fe0d8d52 100644 --- a/src/store/sagas/positions.ts +++ b/src/store/sagas/positions.ts @@ -9,6 +9,7 @@ import { INVARIANT_CREATE_POSITION_OPTIONS, INVARIANT_REMOVE_POSITION_OPTIONS, INVARIANT_WITHDRAW_ALL_WAZERO, + POOL_SAFE_TRANSACTION_FEE, POSITIONS_PER_QUERY, PSP22_APPROVE_OPTIONS, U128MAX, @@ -122,8 +123,13 @@ function* handleInitPosition(action: PayloadAction): Generator (tokenY === wazeroAddress && tokenYAmount !== 0n) ) { const isTokenX = tokenX === wazeroAddress + const azeroInputAmount = isTokenX ? tokenXAmount : tokenYAmount + const slippageAmount = isTokenX ? xAmountWithSlippage : yAmountWithSlippage - const azeroAmount = azeroBalance > slippageAmount ? slippageAmount : azeroBalance + const azeroAmount = + azeroBalance - POOL_SAFE_TRANSACTION_FEE > slippageAmount + ? slippageAmount + : azeroInputAmount const depositTx = wazero.depositTx(azeroAmount, WAZERO_DEPOSIT_OPTIONS) txs.push(depositTx) diff --git a/src/store/sagas/swap.ts b/src/store/sagas/swap.ts index 97ee069b..1675fa7a 100644 --- a/src/store/sagas/swap.ts +++ b/src/store/sagas/swap.ts @@ -15,6 +15,7 @@ import { ErrorMessage, INVARIANT_SWAP_OPTIONS, PSP22_APPROVE_OPTIONS, + SWAP_SAFE_TRANSACTION_FEE, U128MAX, WAZERO_DEPOSIT_OPTIONS, WAZERO_WITHDRAW_OPTIONS @@ -98,7 +99,10 @@ export function* handleSwap(action: PayloadAction>): Generato if ((xToY && poolKey.tokenX === wazeroAddress) || (!xToY && poolKey.tokenY === wazeroAddress)) { const azeroBalance = yield* select(balance) const azeroAmountInWithSlippage = - azeroBalance > calculatedAmountIn ? calculatedAmountIn : azeroBalance + azeroBalance - SWAP_SAFE_TRANSACTION_FEE > calculatedAmountIn + ? calculatedAmountIn + : amountIn + const depositTx = wazero.depositTx(azeroAmountInWithSlippage, WAZERO_DEPOSIT_OPTIONS) txs.push(depositTx) } From e2a46b1eb01d275cf47b03f82efdc60fb595c6bc Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Wed, 2 Oct 2024 14:07:27 +0200 Subject: [PATCH 13/14] fix fetch tokens from positions list --- .../SinglePositionWrapper/SinglePositionWrapper.tsx | 2 +- .../WrappedPositionsList/WrappedPositionsList.tsx | 2 +- src/store/reducers/positions.ts | 2 +- src/store/sagas/positions.ts | 9 ++++++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx b/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx index 146dcd54..f98161ed 100644 --- a/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx +++ b/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx @@ -272,7 +272,7 @@ export const SinglePositionWrapper: React.FC = ({ id }) => { } useEffect(() => { - dispatch(actions.getRemainingPositions()) + dispatch(actions.getRemainingPositions({ setLoaded: false })) const timer = setTimeout(() => { setIsFinishedDelayRender(true) }, 1000) diff --git a/src/containers/WrappedPositionsList/WrappedPositionsList.tsx b/src/containers/WrappedPositionsList/WrappedPositionsList.tsx index 96d7fff7..de44689a 100644 --- a/src/containers/WrappedPositionsList/WrappedPositionsList.tsx +++ b/src/containers/WrappedPositionsList/WrappedPositionsList.tsx @@ -187,7 +187,7 @@ export const WrappedPositionsList: React.FC = () => { length={length} loadedPages={loadedPages} getRemainingPositions={() => { - dispatch(actions.getRemainingPositions()) + dispatch(actions.getRemainingPositions({ setLoaded: true })) }} noInitialPositions={list.length === 0} /> diff --git a/src/store/reducers/positions.ts b/src/store/reducers/positions.ts index 124ceb09..e215aa2e 100644 --- a/src/store/reducers/positions.ts +++ b/src/store/reducers/positions.ts @@ -161,7 +161,7 @@ const positionsSlice = createSlice({ state.positionsList.loading = true return state }, - getRemainingPositions(state, _action: PayloadAction) { + getRemainingPositions(state, _action: PayloadAction<{ setLoaded: boolean }>) { state.positionsList.loading = true return state }, diff --git a/src/store/sagas/positions.ts b/src/store/sagas/positions.ts index a7013d0c..6b63a7d1 100644 --- a/src/store/sagas/positions.ts +++ b/src/store/sagas/positions.ts @@ -327,7 +327,8 @@ export function* handleGetCurrentPlotTicks(action: PayloadAction) { } } -export function* handleGetRemainingPositions(): Generator { +export function* handleGetRemainingPositions( + action: PayloadAction<{ setLoaded: boolean }> +): Generator { const walletAddress = yield* select(address) const { length, list, loadedPages } = yield* select(positionsList) @@ -641,7 +644,7 @@ export function* handleGetRemainingPositions(): Generator { yield* put( actions.setPositionsListLoadedStatus({ indexes: pages.map(({ index }: { index: number }) => index), - isLoaded: true + isLoaded: action.payload.setLoaded }) ) } catch (error) { From 041f38df896458c3ab4414db570a8b2b248e5aa4 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Wed, 2 Oct 2024 16:28:27 +0200 Subject: [PATCH 14/14] use take instead of delay --- src/hideErrors.ts | 2 ++ src/store/sagas/pools.ts | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hideErrors.ts b/src/hideErrors.ts index 74eae44f..1ad3e612 100644 --- a/src/hideErrors.ts +++ b/src/hideErrors.ts @@ -6,6 +6,8 @@ export const messagesToHide: string[] = [ ' attribute d: Expected moveto path command' ] +if (process.env.NODE_ENV === 'production') console.log = () => {} + export function filterConsoleMessages(hideMessages: string[]): void { if (typeof window === 'undefined') { return diff --git a/src/store/sagas/pools.ts b/src/store/sagas/pools.ts index 19ab8f11..5642101e 100644 --- a/src/store/sagas/pools.ts +++ b/src/store/sagas/pools.ts @@ -5,7 +5,7 @@ import { FetchTicksAndTickMaps, PairTokens, PoolWithPoolKey, actions } from '@st import { actions as walletActions } from '@store/reducers/wallet' import { poolsArraySortedByFees, tokens } from '@store/selectors/pools' import { address } from '@store/selectors/wallet' -import { all, call, delay, put, select, spawn, takeEvery, takeLatest } from 'typed-redux-saga' +import { all, call, put, select, spawn, take, takeEvery, takeLatest } from 'typed-redux-saga' import { MAX_POOL_KEYS_RETURNED } from '@invariant-labs/a0-sdk/target/consts' import { getInvariant, getPSP22 } from './connection' @@ -82,13 +82,11 @@ export function* fetchTicksAndTickMaps(action: PayloadAction poolKeyToString(pool.poolKey) === poolKeyToString(poolKey)) - let i = 0 - while (pools.length === 0 && i < 20) { - yield* delay(50) + if (pools.length === 0) { + yield* take(actions.addPool) + poolsData = yield* select(poolsArraySortedByFees) - pools = poolsData.filter(pool => poolKeyToString(pool.poolKey) === poolKeyToString(poolKey)) - i++ } }