From 1ff0477bcc25906bd8672f1ddc5a4e91584bc165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=B1=B1=E6=A0=8B?= Date: Wed, 8 Jan 2025 11:30:15 +0800 Subject: [PATCH] fix: to token detail price MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王山栋 --- .../src/states/jotai/contexts/swap/actions.ts | 86 +++++++++++-------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/packages/kit/src/states/jotai/contexts/swap/actions.ts b/packages/kit/src/states/jotai/contexts/swap/actions.ts index f14acf65ce6..c060b7ca07e 100644 --- a/packages/kit/src/states/jotai/contexts/swap/actions.ts +++ b/packages/kit/src/states/jotai/contexts/swap/actions.ts @@ -1273,10 +1273,11 @@ class ContentJotaiActionsSwap extends ContextJotaiActionsBase { } let balanceDisplay; if ( - token && - accountAddress && - accountNetworkId && - accountNetworkId === token?.networkId + (token && + accountAddress && + accountNetworkId && + accountNetworkId === token?.networkId) || + (!token?.price && token) ) { if ( token.accountAddress === accountAddress && @@ -1315,40 +1316,49 @@ class ContentJotaiActionsSwap extends ContextJotaiActionsBase { balanceDisplay = balanceParsedBN.isNaN() ? '0.0' : balanceParsedBN.toFixed(); - if ( - detailInfo[0].price && - detailInfo[0].fiatValue && - detailInfo[0].balanceParsed - ) { - if (type === ESwapDirectionType.FROM) { - set(swapSelectFromTokenAtom(), (pre) => { - if (pre) { - return { - ...pre, - price: detailInfo[0].price, - fiatValue: detailInfo[0].fiatValue, - balanceParsed: detailInfo[0].balanceParsed, - reservationValue: detailInfo[0].reservationValue, - logoURI: detailInfo[0].logoURI ?? pre.logoURI, - accountAddress, - }; - } - }); - } else { - set(swapSelectToTokenAtom(), (pre) => { - if (pre) { - return { - ...pre, - price: detailInfo[0].price, - fiatValue: detailInfo[0].fiatValue, - balanceParsed: detailInfo[0].balanceParsed, - reservationValue: detailInfo[0].reservationValue, - logoURI: detailInfo[0].logoURI ?? pre.logoURI, - accountAddress, - }; - } - }); - } + const condition: { + price?: string; + fiatValue?: string; + balanceParsed?: string; + reservationValue?: string; + logoURI?: string; + } = {}; + if (detailInfo[0].price) { + condition.price = detailInfo[0].price; + } + if (detailInfo[0].fiatValue) { + condition.fiatValue = detailInfo[0].fiatValue; + } + if (detailInfo[0].balanceParsed) { + condition.balanceParsed = detailInfo[0].balanceParsed; + } + if (detailInfo[0].reservationValue) { + condition.reservationValue = detailInfo[0].reservationValue; + } + if (detailInfo[0].logoURI) { + condition.logoURI = detailInfo[0].logoURI; + } + + if (type === ESwapDirectionType.FROM) { + set(swapSelectFromTokenAtom(), (pre) => { + if (pre) { + return { + ...pre, + ...condition, + accountAddress, + }; + } + }); + } else { + set(swapSelectToTokenAtom(), (pre) => { + if (pre) { + return { + ...pre, + ...condition, + accountAddress, + }; + } + }); } } } catch (e: any) {