Skip to content

Commit

Permalink
Merge pull request #567 from alleslabs/fix/attach-funds-in-code-snippet
Browse files Browse the repository at this point in the history
fix: attached funds (to main)
  • Loading branch information
tansawit authored Oct 12, 2023
2 parents 8d7108d + 9cac56a commit 689d426
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#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
Expand Down
34 changes: 12 additions & 22 deletions src/lib/pages/execute/components/JsonExecute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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--------------//
// ------------------------------------------//
Expand All @@ -148,11 +154,6 @@ export const JsonExecute = ({
// ------------------------------------------//

const proceed = useCallback(async () => {
const funds = getAttachFunds(
attachFundsOption,
assetsJsonStr,
assetsSelect
);
trackActionWithFunds(
AmpEvent.ACTION_EXECUTE,
funds.length,
Expand Down Expand Up @@ -180,10 +181,8 @@ export const JsonExecute = ({
fee,
contractAddress,
msg,
getAttachFunds,
funds,
trackActionWithFunds,
assetsJsonStr,
assetsSelect,
addActivity,
broadcast,
]);
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -282,6 +271,7 @@ export const JsonExecute = ({
type="execute"
contractAddress={contractAddress}
message={msg}
funds={funds}
/>
</Flex>
<Flex direction="row" align="center" gap={2}>
Expand Down
36 changes: 13 additions & 23 deletions src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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--------------//
// ------------------------------------------//
Expand Down Expand Up @@ -184,11 +190,6 @@ export const ExecuteBox = ({
);

const proceed = useCallback(async () => {
const funds = getAttachFunds(
attachFundsOption,
assetsJsonStr,
assetsSelect
);
trackActionWithFunds(
AmpEvent.ACTION_EXECUTE,
funds.length,
Expand All @@ -211,15 +212,13 @@ export const ExecuteBox = ({
broadcast(stream);
}
}, [
attachFundsOption,
executeTx,
fee,
contractAddress,
msg,
getAttachFunds,
trackActionWithFunds,
assetsJsonStr,
assetsSelect,
funds,
attachFundsOption,
addActivity,
broadcast,
]);
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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 (
<AccordionItem className={`execute_msg_${msgSchema.schema.required?.[0]}`}>
Expand Down Expand Up @@ -344,6 +333,7 @@ export const ExecuteBox = ({
type="execute"
contractAddress={contractAddress}
message={msg}
funds={funds}
/>
</Flex>
</GridItem>
Expand Down

4 comments on commit 689d426

@vercel
Copy link

@vercel vercel bot commented on 689d426 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 689d426 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 689d426 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 689d426 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.