Skip to content

Commit 689d426

Browse files
authored
Merge pull request #567 from alleslabs/fix/attach-funds-in-code-snippet
fix: attached funds (to main)
2 parents 8d7108d + 9cac56a commit 689d426

File tree

3 files changed

+26
-45
lines changed

3 files changed

+26
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
113113

114114
### Bug fixes
115115

116+
- [#567](https://github.com/alleslabs/celatone-frontend/pull/567) Fix attached funds in code snippet
116117
- [#539](https://github.com/alleslabs/celatone-frontend/pull/539) Fix JSON schema upload text
117118
- [#527](https://github.com/alleslabs/celatone-frontend/pull/527) Fix ellipsis explorer link
118119
- [#526](https://github.com/alleslabs/celatone-frontend/pull/526) Fix missing Tx proposal type

src/lib/pages/execute/components/JsonExecute.tsx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ export const JsonExecute = ({
9797
const isValidAssetsJsonStr =
9898
!errors.assetsJsonStr && jsonValidate(assetsJsonStr) === null;
9999

100-
const assetsSelectString = JSON.stringify(assetsSelect);
101-
102100
const enableExecute = useMemo(() => {
103101
const generalCheck = !!(
104102
msg.trim().length &&
@@ -123,6 +121,14 @@ export const JsonExecute = ({
123121
isValidAssetsJsonStr,
124122
]);
125123

124+
const assetsSelectString = JSON.stringify(assetsSelect);
125+
126+
const funds = useMemo(
127+
() => getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect),
128+
// eslint-disable-next-line react-hooks/exhaustive-deps
129+
[assetsJsonStr, assetsSelectString, attachFundsOption, getAttachFunds]
130+
);
131+
126132
// ------------------------------------------//
127133
// -----------------REACT QUERY--------------//
128134
// ------------------------------------------//
@@ -148,11 +154,6 @@ export const JsonExecute = ({
148154
// ------------------------------------------//
149155

150156
const proceed = useCallback(async () => {
151-
const funds = getAttachFunds(
152-
attachFundsOption,
153-
assetsJsonStr,
154-
assetsSelect
155-
);
156157
trackActionWithFunds(
157158
AmpEvent.ACTION_EXECUTE,
158159
funds.length,
@@ -180,10 +181,8 @@ export const JsonExecute = ({
180181
fee,
181182
contractAddress,
182183
msg,
183-
getAttachFunds,
184+
funds,
184185
trackActionWithFunds,
185-
assetsJsonStr,
186-
assetsSelect,
187186
addActivity,
188187
broadcast,
189188
]);
@@ -216,7 +215,7 @@ export const JsonExecute = ({
216215
sender: address as HumanAddr,
217216
contract: contractAddress as ContractAddr,
218217
msg: Buffer.from(msg),
219-
funds: getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect),
218+
funds,
220219
});
221220

222221
const timeoutId = setTimeout(() => {
@@ -225,17 +224,7 @@ export const JsonExecute = ({
225224
return () => clearTimeout(timeoutId);
226225
}
227226
return () => {};
228-
}, [
229-
address,
230-
contractAddress,
231-
enableExecute,
232-
msg,
233-
assetsJsonStr,
234-
assetsSelectString,
235-
getAttachFunds,
236-
attachFundsOption,
237-
assetsSelect,
238-
]);
227+
}, [address, contractAddress, enableExecute, funds, msg]);
239228

240229
useEffect(() => {
241230
const keydownHandler = (e: KeyboardEvent) => {
@@ -282,6 +271,7 @@ export const JsonExecute = ({
282271
type="execute"
283272
contractAddress={contractAddress}
284273
message={msg}
274+
funds={funds}
285275
/>
286276
</Flex>
287277
<Flex direction="row" align="center" gap={2}>

src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ export const ExecuteBox = ({
121121
const isValidAssetsJsonStr =
122122
!attachFundErrors.assetsJsonStr && jsonValidate(assetsJsonStr) === null;
123123

124-
const assetsSelectString = JSON.stringify(assetsSelect);
125-
126124
const enableExecute = useMemo(() => {
127125
const generalCheck = Boolean(
128126
msg.trim().length &&
@@ -151,6 +149,14 @@ export const ExecuteBox = ({
151149
isValidAssetsJsonStr,
152150
]);
153151

152+
const assetsSelectString = JSON.stringify(assetsSelect);
153+
154+
const funds = useMemo(
155+
() => getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect),
156+
// eslint-disable-next-line react-hooks/exhaustive-deps
157+
[assetsJsonStr, assetsSelectString, attachFundsOption, getAttachFunds]
158+
);
159+
154160
// ------------------------------------------//
155161
// -----------------REACT QUERY--------------//
156162
// ------------------------------------------//
@@ -184,11 +190,6 @@ export const ExecuteBox = ({
184190
);
185191

186192
const proceed = useCallback(async () => {
187-
const funds = getAttachFunds(
188-
attachFundsOption,
189-
assetsJsonStr,
190-
assetsSelect
191-
);
192193
trackActionWithFunds(
193194
AmpEvent.ACTION_EXECUTE,
194195
funds.length,
@@ -211,15 +212,13 @@ export const ExecuteBox = ({
211212
broadcast(stream);
212213
}
213214
}, [
214-
attachFundsOption,
215215
executeTx,
216216
fee,
217217
contractAddress,
218218
msg,
219-
getAttachFunds,
220219
trackActionWithFunds,
221-
assetsJsonStr,
222-
assetsSelect,
220+
funds,
221+
attachFundsOption,
223222
addActivity,
224223
broadcast,
225224
]);
@@ -259,7 +258,7 @@ export const ExecuteBox = ({
259258
sender: address as HumanAddr,
260259
contract: contractAddress as ContractAddr,
261260
msg: Buffer.from(msg),
262-
funds: getAttachFunds(attachFundsOption, assetsJsonStr, assetsSelect),
261+
funds,
263262
});
264263

265264
const timeoutId = setTimeout(() => {
@@ -273,17 +272,7 @@ export const ExecuteBox = ({
273272
setFee(undefined);
274273

275274
return () => {};
276-
}, [
277-
address,
278-
contractAddress,
279-
enableExecute,
280-
msg,
281-
assetsJsonStr,
282-
assetsSelectString,
283-
getAttachFunds,
284-
attachFundsOption,
285-
assetsSelect,
286-
]);
275+
}, [address, contractAddress, enableExecute, msg, funds]);
287276

288277
return (
289278
<AccordionItem className={`execute_msg_${msgSchema.schema.required?.[0]}`}>
@@ -344,6 +333,7 @@ export const ExecuteBox = ({
344333
type="execute"
345334
contractAddress={contractAddress}
346335
message={msg}
336+
funds={funds}
347337
/>
348338
</Flex>
349339
</GridItem>

0 commit comments

Comments
 (0)