|
9 | 9 | import { addAPToDropdown, findDeploymentEnvironment, globalState } from "$lib/state/state.svelte"; |
10 | 10 | import { attempt } from "$lib/utils/attempt"; |
11 | 11 | import { encodeConstructorArgs, getConstructorInputsWizard, getContractBytecode } from "$lib/utils/contracts"; |
12 | | - import { isMultisig, isUpgradeable } from "$lib/utils/helpers"; |
| 12 | + import { debouncer, isMultisig, isUpgradeable } from "$lib/utils/helpers"; |
13 | 13 | import Button from "./shared/Button.svelte"; |
14 | 14 | import Input from "./shared/Input.svelte"; |
15 | 15 | import Message from "./shared/Message.svelte"; |
16 | 16 |
|
| 17 | + // debounce the compile call to avoid sending too many requests while the user is editing. |
| 18 | + const compileDebounced = debouncer(compile, 600); |
| 19 | +
|
17 | 20 | let inputsWithValue = $state<Record<string, string | number | boolean>>({}); |
18 | | - let busy = $state(false); |
| 21 | + let isDeploying = $state(false); |
19 | 22 | let successMessage = $state<string>(""); |
20 | 23 | let errorMessage = $state<string>(""); |
21 | 24 | let compilationError = $state<string>(""); |
|
24 | 27 | let deploymentResult = $state<DeploymentResult | undefined>(undefined); |
25 | 28 | let isDeterministic = $state(false); |
26 | 29 | let salt: string = $state(""); |
| 30 | + let isCompiling = $state(false); |
27 | 31 |
|
28 | 32 | let contractBytecode = $derived.by(() => { |
29 | 33 | if (!globalState.contract?.target || !compilationResult) return; |
|
61 | 65 | : undefined |
62 | 66 | ); |
63 | 67 |
|
64 | | -
|
65 | 68 | let inputs: ABIParameter[] = $state([]); |
66 | 69 |
|
67 | 70 | $effect(() => { |
68 | 71 | if (globalState.contract?.source?.sources) { |
69 | | - compile(); |
| 72 | + isCompiling = true; |
| 73 | + compileDebounced(); |
70 | 74 | } |
71 | 75 | }); |
72 | 76 |
|
|
75 | 79 | inputsWithValue[target.name] = target.value; |
76 | 80 | } |
77 | 81 |
|
78 | | - async function compile() { |
| 82 | + async function compile(): Promise<void> { |
79 | 83 | const sources = globalState.contract?.source?.sources; |
80 | 84 | if (!sources) { |
81 | 85 | return; |
|
94 | 98 | if (globalState.contract?.target && compilationResult) { |
95 | 99 | inputs = getConstructorInputsWizard(globalState.contract.target, compilationResult.output.contracts); |
96 | 100 | } |
| 101 | + isCompiling = false; |
97 | 102 | } |
98 | 103 |
|
99 | 104 | function displayMessage(message: string, type: "success" | "error") { |
|
304 | 309 | }; |
305 | 310 |
|
306 | 311 | async function triggerDeploy() { |
307 | | - busy = true; |
| 312 | + isDeploying = true; |
308 | 313 | await deploy(); |
309 | | - busy = false; |
| 314 | + isDeploying = false; |
310 | 315 | } |
311 | 316 |
|
312 | 317 | </script> |
|
316 | 321 | <Message type="warn" message="Upgradable contracts are not yet fully supported. This action will only deploy the implementation contract without initializing. <br />We recommend using <u><a href='https://github.com/OpenZeppelin/openzeppelin-upgrades' target='_blank'>openzeppelin-upgrades</a></u> package instead." /> |
317 | 322 | {/if} |
318 | 323 |
|
319 | | - {#if inputs.length > 0} |
| 324 | + {#if isCompiling} |
| 325 | + <Message type="loading" message="Compiling..." /> |
| 326 | + {:else if inputs.length > 0} |
320 | 327 | <h6 class="text-sm">Constructor Arguments</h6> |
321 | 328 | {#each inputs as input} |
322 | 329 | <Input name={input.name} placeholder={`${input.name} (${input.type})`} onchange={handleInputChange} value={''} type="text"/> |
|
352 | 359 | <Message message={compilationError} type="error" /> |
353 | 360 | {/if} |
354 | 361 |
|
355 | | - <Button disabled={!globalState.authenticated || busy} loading={busy} label="Deploy" onClick={triggerDeploy} /> |
| 362 | + <Button disabled={!globalState.authenticated || isDeploying || isCompiling} loading={isDeploying} label="Deploy" onClick={triggerDeploy} /> |
356 | 363 |
|
357 | 364 | {#if successMessage || errorMessage} |
358 | 365 | <Message message={successMessage || errorMessage} type={successMessage ? "success" : "error"} /> |
|
0 commit comments