From 179400fe082a555237350ae6114dee947186988d Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Mon, 21 Aug 2023 08:02:20 -0300 Subject: [PATCH] [bugfix] re-ordering of fund inputs (#380) --- .../Modals/FundWithdraw/FundAccount.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/Modals/FundWithdraw/FundAccount.tsx b/src/components/Modals/FundWithdraw/FundAccount.tsx index 1853090c..9c1c681a 100644 --- a/src/components/Modals/FundWithdraw/FundAccount.tsx +++ b/src/components/Modals/FundWithdraw/FundAccount.tsx @@ -82,14 +82,16 @@ export default function FundAccount(props: Props) { const updateFundingAssets = useCallback( (amount: BigNumber, denom: string) => { - const assetToUpdate = fundingAssets.find(byDenom(denom)) - if (assetToUpdate) { - assetToUpdate.amount = amount - setFundingAssets([...fundingAssets.filter((a) => a.denom !== denom), assetToUpdate]) - } - setChange({ deposits: fundingAssets }) + setFundingAssets((prevAssets) => { + const assetToUpdateIdx = prevAssets.findIndex(byDenom(denom)) + if (assetToUpdateIdx > -1) { + prevAssets[assetToUpdateIdx].amount = amount + } + setChange({ deposits: prevAssets }) + return prevAssets + }) }, - [fundingAssets, setChange], + [setChange], ) useEffect(() => {