Skip to content

Commit 405f900

Browse files
fix build error (#54)
1 parent 615cbde commit 405f900

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

app/components/transaction/Result.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import {
1919
AlertTitle,
2020
} from "@/components/ui/alert";
2121

22+
const shortenAddress = (address: string) => {
23+
if (!address || address.length < 10) return address;
24+
return `${address.substring(0, 6)}...${address.substring(address.length - 4)}`;
25+
};
26+
2227
export default function Result({ result }: any) {
2328
const [hashesExpanded, setHashesExpanded] = useState(true);
2429
const [transactionExpanded, setTransactionExpanded] = useState(false);
@@ -30,33 +35,26 @@ export default function Result({ result }: any) {
3035
const [warnings, setWarnings] = useState<{title: string, description: string}[]>([]);
3136
const [infoNotices, setInfoNotices] = useState<{title: string, description: string}[]>([]);
3237

33-
if (!result) return null;
34-
else if (result.error) {
35-
return <div className="max-w-3xl mx-auto">
36-
<h3 className="text-lg font-medium mb-4">Error</h3>
37-
<p className="text-red-500">{result.error}</p>
38-
</div>
39-
}
40-
41-
const execParams = result.transaction?.exec_transaction?.decoded?.parameters;
42-
43-
// Mapping the parameters by name for easy access
38+
// Process all hooks before conditionals
39+
const execParams = result?.transaction?.exec_transaction?.decoded?.parameters;
40+
4441
const params = useMemo(() => {
45-
return execParams
46-
? execParams.reduce((acc: any, param: any) => {
47-
acc[param.name] = param.value;
48-
return acc;
49-
}, {})
50-
: {};
42+
if (!execParams) return {};
43+
return execParams.reduce((acc: any, param: any) => {
44+
acc[param.name] = param.value;
45+
return acc;
46+
}, {});
5147
}, [execParams]);
5248

53-
const networkDetails = result.network?.name ?
49+
const networkDetails = result?.network?.name ?
5450
NETWORKS.find((n) => n.value === result.network.name || n.label === result.network.name) :
5551
null;
56-
52+
5753
const networkLogo = networkDetails?.logo || '';
58-
54+
5955
useEffect(() => {
56+
if (!params) return;
57+
6058
const newWarnings: {title: string, description: string}[] = [];
6159
const newInfoNotices: {title: string, description: string}[] = [];
6260

@@ -116,10 +114,16 @@ export default function Result({ result }: any) {
116114
setInfoNotices(newInfoNotices);
117115
}, [params]);
118116

119-
const shortenAddress = (address: string) => {
120-
if (!address || address.length < 10) return address;
121-
return `${address.substring(0, 6)}...${address.substring(address.length - 4)}`;
122-
};
117+
// Early returns after all hooks
118+
if (!result) return null;
119+
if (result.error) {
120+
return (
121+
<div className="max-w-3xl mx-auto">
122+
<h3 className="text-lg font-medium mb-4">Error</h3>
123+
<p className="text-red-500">{result.error}</p>
124+
</div>
125+
);
126+
}
123127

124128
return (
125129
<div className="max-w-3xl mx-auto">

0 commit comments

Comments
 (0)