Skip to content

Commit

Permalink
Basic form validation, fix data size & deduplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiker committed Aug 18, 2023
1 parent 28ce0c2 commit 7540ab2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
52 changes: 22 additions & 30 deletions web/islands/TestWebhookDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { useEffect, useRef } from "preact/hooks";
import { Modal } from "web/components/Modal.tsx";
import type { ToastProps } from "web/components/Toast.tsx";

const Input = (props: { name: string }) => (
<input
type="text"
pattern="^0x[a-fA-F0-9]{64}$"
placeholder="0x0000000000000000000000000000000000000000000000000000000000000000"
class="input input-bordered w-full max-w-xs"
{...props}
/>
);

export interface TestWebhookProps {
address: string;
abiHash: string;
Expand Down Expand Up @@ -41,51 +51,33 @@ export const TestWebhookDialog = ({ setToast, ...props }: TestWebhookProps) => {
<form onSubmit={handleSubmit} class="form-control w-full">
<label class="label">
Transaction Hash
<input
type="text"
name="txHash"
class="input input-bordered w-full max-w-xs"
/>
<Input name="txHash" />
</label>
<label class="label">
Block Hash
<input
type="text"
name="blockHash"
class="input input-bordered w-full max-w-xs"
/>
<Input name="blockHash" />
</label>
<label class="label">
Topic 1
<input
type="text"
name="topic1"
class="input input-bordered w-full max-w-xs"
/>
<Input name="topic1" />
</label>
<label class="label">
Topic 2
<input
type="text"
name="topic2"
class="input input-bordered w-full max-w-xs"
/>
<Input name="topic2" />
</label>
<label class="label">
Topic 3
<input
type="text"
name="topic3"
class="input input-bordered w-full max-w-xs"
/>
<Input name="topic3" />
</label>
<label class="label">
Data
<input
type="text"
name="data"
class="input input-bordered w-full max-w-xs"
/>
<Input name="data" />
</label>
<label class="label">
<span class="label-text-alt">
* 32 bytes hex string (64 characters) prepended by 0x (total 66
characters)
</span>
</label>
<input type="submit" class="btn" />
</form>
Expand Down
2 changes: 1 addition & 1 deletion web/routes/api/sources/testWebhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const handler: Handlers = {
sigHash,
abi: abi.json,
topics: [topic1, topic2, topic3].flatMap((t) => t ? [toBytes(t)] : []),
data: data ? toBytes(data) : new Uint8Array(64),
data: data ? toBytes(data) : new Uint8Array(32),
txHash: txHash ? toBytes(txHash) : new Uint8Array(32),
blockHash: blockHash ? toBytes(blockHash) : new Uint8Array(32),
logIndex: -1n,
Expand Down

0 comments on commit 7540ab2

Please sign in to comment.