From 979c8cde294c9bcfa1f1c6777f0901da086cbc78 Mon Sep 17 00:00:00 2001 From: evilpeach Date: Thu, 12 Oct 2023 21:52:08 +0700 Subject: [PATCH 1/2] fix: attached funds --- CHANGELOG.md | 1 + .../pages/execute/components/JsonExecute.tsx | 34 +++++++----------- .../components/schema-execute/ExecuteBox.tsx | 36 +++++++------------ 3 files changed, 26 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 548ffd808..52ae32cbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes +- [#566](https://github.com/alleslabs/celatone-frontend/pull/566) Fix attached funds in code snippet - [#539](https://github.com/alleslabs/celatone-frontend/pull/539) Fix JSON schema upload text - [#527](https://github.com/alleslabs/celatone-frontend/pull/527) Fix ellipsis explorer link - [#526](https://github.com/alleslabs/celatone-frontend/pull/526) Fix missing Tx proposal type diff --git a/src/lib/pages/execute/components/JsonExecute.tsx b/src/lib/pages/execute/components/JsonExecute.tsx index febcb971a..b565d1060 100644 --- a/src/lib/pages/execute/components/JsonExecute.tsx +++ b/src/lib/pages/execute/components/JsonExecute.tsx @@ -97,8 +97,6 @@ export const JsonExecute = ({ const isValidAssetsJsonStr = !errors.assetsJsonStr && jsonValidate(assetsJsonStr) === null; - const assetsSelectString = JSON.stringify(assetsSelect); - const enableExecute = useMemo(() => { const generalCheck = !!( msg.trim().length && @@ -123,6 +121,14 @@ export const JsonExecute = ({ isValidAssetsJsonStr, ]); + const assetsSelectString = JSON.stringify(assetsSelect); + + const funds = useMemo( + () => getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect), + // eslint-disable-next-line react-hooks/exhaustive-deps + [assetsJsonStr, assetsSelectString, attachFundsOption, getAttachFunds] + ); + // ------------------------------------------// // -----------------REACT QUERY--------------// // ------------------------------------------// @@ -148,11 +154,6 @@ export const JsonExecute = ({ // ------------------------------------------// const proceed = useCallback(async () => { - const funds = getAttachFunds( - attachFundsOption, - assetsJsonStr, - assetsSelect - ); trackActionWithFunds( AmpEvent.ACTION_EXECUTE, funds.length, @@ -180,10 +181,8 @@ export const JsonExecute = ({ fee, contractAddress, msg, - getAttachFunds, + funds, trackActionWithFunds, - assetsJsonStr, - assetsSelect, addActivity, broadcast, ]); @@ -216,7 +215,7 @@ export const JsonExecute = ({ sender: address as HumanAddr, contract: contractAddress as ContractAddr, msg: Buffer.from(msg), - funds: getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect), + funds, }); const timeoutId = setTimeout(() => { @@ -225,17 +224,7 @@ export const JsonExecute = ({ return () => clearTimeout(timeoutId); } return () => {}; - }, [ - address, - contractAddress, - enableExecute, - msg, - assetsJsonStr, - assetsSelectString, - getAttachFunds, - attachFundsOption, - assetsSelect, - ]); + }, [address, contractAddress, enableExecute, funds, msg]); useEffect(() => { const keydownHandler = (e: KeyboardEvent) => { @@ -282,6 +271,7 @@ export const JsonExecute = ({ type="execute" contractAddress={contractAddress} message={msg} + funds={funds} /> diff --git a/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx b/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx index ecb13ec62..60dc6ad50 100644 --- a/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx +++ b/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx @@ -121,8 +121,6 @@ export const ExecuteBox = ({ const isValidAssetsJsonStr = !attachFundErrors.assetsJsonStr && jsonValidate(assetsJsonStr) === null; - const assetsSelectString = JSON.stringify(assetsSelect); - const enableExecute = useMemo(() => { const generalCheck = Boolean( msg.trim().length && @@ -151,6 +149,14 @@ export const ExecuteBox = ({ isValidAssetsJsonStr, ]); + const assetsSelectString = JSON.stringify(assetsSelect); + + const funds = useMemo( + () => getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect), + // eslint-disable-next-line react-hooks/exhaustive-deps + [assetsJsonStr, assetsSelectString, attachFundsOption, getAttachFunds] + ); + // ------------------------------------------// // -----------------REACT QUERY--------------// // ------------------------------------------// @@ -184,11 +190,6 @@ export const ExecuteBox = ({ ); const proceed = useCallback(async () => { - const funds = getAttachFunds( - attachFundsOption, - assetsJsonStr, - assetsSelect - ); trackActionWithFunds( AmpEvent.ACTION_EXECUTE, funds.length, @@ -211,15 +212,13 @@ export const ExecuteBox = ({ broadcast(stream); } }, [ - attachFundsOption, executeTx, fee, contractAddress, msg, - getAttachFunds, trackActionWithFunds, - assetsJsonStr, - assetsSelect, + funds, + attachFundsOption, addActivity, broadcast, ]); @@ -259,7 +258,7 @@ export const ExecuteBox = ({ sender: address as HumanAddr, contract: contractAddress as ContractAddr, msg: Buffer.from(msg), - funds: getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect), + funds, }); const timeoutId = setTimeout(() => { @@ -273,17 +272,7 @@ export const ExecuteBox = ({ setFee(undefined); return () => {}; - }, [ - address, - contractAddress, - enableExecute, - msg, - assetsJsonStr, - assetsSelectString, - getAttachFunds, - attachFundsOption, - assetsSelect, - ]); + }, [address, contractAddress, enableExecute, msg, funds]); return ( @@ -344,6 +333,7 @@ export const ExecuteBox = ({ type="execute" contractAddress={contractAddress} message={msg} + funds={funds} /> From 9cac56a9a0b348b1b1c5c2dba6eccc26f65d8a0b Mon Sep 17 00:00:00 2001 From: evilpeach Date: Thu, 12 Oct 2023 21:54:39 +0700 Subject: [PATCH 2/2] docs: edit pr number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52ae32cbd..2ae6ad1aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,7 +113,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes -- [#566](https://github.com/alleslabs/celatone-frontend/pull/566) Fix attached funds in code snippet +- [#567](https://github.com/alleslabs/celatone-frontend/pull/567) Fix attached funds in code snippet - [#539](https://github.com/alleslabs/celatone-frontend/pull/539) Fix JSON schema upload text - [#527](https://github.com/alleslabs/celatone-frontend/pull/527) Fix ellipsis explorer link - [#526](https://github.com/alleslabs/celatone-frontend/pull/526) Fix missing Tx proposal type