Skip to content

Commit e2e54ff

Browse files
authored
pancake zap widget update validate amountsIn (#2858)
* Update validate amountsIn * Pump version
1 parent dcbf63b commit e2e54ff

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

packages/pancake-liquidity-widgets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kyberswap/pancake-liquidity-widgets",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"license": "MIT",
55
"type": "module",
66
"exports": {

packages/pancake-liquidity-widgets/src/hooks/useZapInState.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export const ZapContextProvider = ({
254254
listAmountsIn[index] === "0" ||
255255
!parseFloat(listAmountsIn[index])
256256
);
257-
if (listTokenEmptyAmount.length)
257+
if (tokensIn.length === listTokenEmptyAmount.length)
258258
return (
259259
ERROR_MESSAGE.ENTER_AMOUNT +
260260
" " +
@@ -274,7 +274,6 @@ export const ZapContextProvider = ({
274274
} catch (e) {
275275
return ERROR_MESSAGE.INVALID_INPUT_AMOUNTT;
276276
}
277-
278277
if (zapApiError) return zapApiError;
279278
return "";
280279
}, [
@@ -383,21 +382,40 @@ export const ZapContextProvider = ({
383382
error === ERROR_MESSAGE.INSUFFICIENT_BALANCE ||
384383
error === ERROR_MESSAGE.WRONG_NETWORK)
385384
) {
386-
let formattedAmountsInWeis = "";
387385
const listAmountsIn = amountsIn.split(",");
386+
let tokensInParam = "";
387+
let formattedAmountsInWeis = "";
388388

389389
try {
390-
formattedAmountsInWeis = tokensIn
391-
.map((token: Token, index: number) =>
392-
parseUnits(listAmountsIn[index] || "0", token.decimals).toString()
393-
)
390+
const tokenAmountPairs = tokensIn
391+
.map((token: Token, index: number) => {
392+
const amountInWei = parseUnits(
393+
listAmountsIn[index] || "0",
394+
token.decimals
395+
);
396+
397+
if (amountInWei === 0n) return null;
398+
399+
return {
400+
address: token.address as string,
401+
amountWei: amountInWei.toString(),
402+
};
403+
})
404+
.filter((item): item is { address: string; amountWei: string } => {
405+
return !!item?.address && !!item.amountWei;
406+
});
407+
408+
tokensInParam = tokenAmountPairs.map((item) => item.address).join(",");
409+
410+
formattedAmountsInWeis = tokenAmountPairs
411+
.map((item) => item.amountWei)
394412
.join(",");
395413
} catch (error) {
396414
console.log(error);
397415
}
398416

399417
if (
400-
!tokensInAddress ||
418+
!tokensInParam ||
401419
!formattedAmountsInWeis ||
402420
!formattedAmountsInWeis.length ||
403421
!formattedAmountsInWeis[0] ||
@@ -416,7 +434,7 @@ export const ZapContextProvider = ({
416434
"pool.fee": pool.fee,
417435
"position.tickUpper": debounceTickUpper,
418436
"position.tickLower": debounceTickLower,
419-
tokensIn: tokensInAddress,
437+
tokensIn: tokensInParam,
420438
amountsIn: formattedAmountsInWeis,
421439
slippage,
422440
...(positionId ? { "position.id": positionId } : {}),

0 commit comments

Comments
 (0)