Skip to content

Commit 7f30696

Browse files
committed
nits
1 parent 2e7855a commit 7f30696

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/App.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type TransactionReceipt,
1111
} from "viem";
1212
import { getAddresses, requestAddresses, waitForTransactionReceipt } from "viem/actions";
13+
1314
import { api, applyChainId, isOk, renderJSON } from "./utils/helpers.ts";
1415
import type {
1516
ApiErr,
@@ -91,7 +92,7 @@ export function App() {
9192
try {
9293
const resp = await api<ApiOk<PendingAny> | ApiErr>("/api/transaction/request");
9394

94-
if (!resp || (resp as ApiErr).status !== "ok") {
95+
if (!isOk(resp)) {
9596
if (pending) {
9697
setPending(null);
9798
lastPendingIdRef.current = null;
@@ -101,7 +102,7 @@ export function App() {
101102

102103
if (!lastPendingIdRef.current || lastPendingIdRef.current !== tx.id) {
103104
setPending(tx);
104-
lastPendingIdRef.current = tx.id ?? null;
105+
lastPendingIdRef.current = tx.id;
105106
setLastTxHash(null);
106107
setLastTxReceipt(null);
107108
} else if (!pending) {
@@ -131,19 +132,17 @@ export function App() {
131132
const signAndSendCurrent = async () => {
132133
if (!walletClient || !selected || !pending) return;
133134

134-
const tx = pending;
135-
136135
try {
137136
const hash = (await selected.provider.request({
138137
method: "eth_sendTransaction",
139-
params: [tx.request],
138+
params: [pending.request],
140139
})) as `0x${string}`;
141140
setLastTxHash(hash);
142141

143142
const receipt = await waitForTransactionReceipt(walletClient, { hash });
144143
setLastTxReceipt(receipt);
145144

146-
await api("/api/transaction/response", "POST", { id: tx.id, hash, error: null });
145+
await api("/api/transaction/response", "POST", { id: pending.id, hash, error: null });
147146
await pollTick();
148147
} catch (e: unknown) {
149148
const msg =
@@ -158,7 +157,7 @@ export function App() {
158157

159158
try {
160159
await api("/api/transaction/response", "POST", {
161-
id: (pending as { id?: string }).id,
160+
id: pending.id,
162161
hash: null,
163162
error: msg,
164163
});

src/utils/helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { type Chain, hexToBigInt } from "viem";
22
import * as chains from "viem/chains";
33

4+
import type { ApiErr, ApiOk } from "./types";
5+
46
export const ALL_CHAINS: readonly Chain[] = Object.freeze(Object.values(chains) as Chain[]);
57
export const getChainById = (id: number) => ALL_CHAINS.find((c) => c.id === id);
68

@@ -31,7 +33,7 @@ export const applyChainId = (
3133

3234
export const toBig = (h?: `0x${string}`) => (h ? hexToBigInt(h) : undefined);
3335

34-
import type { ApiErr, ApiOk } from "./types";
36+
3537

3638
export const ENDPOINT = "http://127.0.0.1:9545";
3739

0 commit comments

Comments
 (0)