Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit c1ef8fb

Browse files
committed
feat: scroll to results, configurable
1 parent 9b3e120 commit c1ef8fb

6 files changed

Lines changed: 46 additions & 10 deletions

File tree

src/components/client/Transaction.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box, Divider, Flex, Grid, Heading } from "@chakra-ui/react";
2-
import React from "react";
2+
import React, { useRef } from "react";
33
import { useSessionStoreWithUndo } from "../../hooks/useSessionStore";
44
import { EditableName } from "../common/EditableName";
55
import { Instructions } from "./Instructions";
@@ -12,10 +12,13 @@ export const Transaction: React.FC = () => {
1212
state.set,
1313
]);
1414

15+
// used for scrolling to results
16+
const resultsRef = useRef<HTMLDivElement>(null);
17+
1518
return (
1619
<Grid m="2">
1720
<Box p="5">
18-
<TransactionHeader transaction={transaction} />
21+
<TransactionHeader transaction={transaction} resultsRef={resultsRef} />
1922

2023
<Flex mt="5" mb="3" alignItems="center">
2124
<Heading flex="1" size="lg">
@@ -41,7 +44,7 @@ export const Transaction: React.FC = () => {
4144
<Divider />
4245

4346
<Box mt="5">
44-
<Results />
47+
<Results ref={resultsRef} />
4548
</Box>
4649
</Grid>
4750
);

src/components/client/TransactionHeader.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
FaPlay,
2626
FaShareAlt,
2727
} from "react-icons/fa";
28+
import { usePersistentStore } from "../../hooks/usePersistentStore";
2829
import { useSendWeb3Transaction } from "../../hooks/useSendWeb3Transaction";
2930
import {
3031
useSessionStoreWithoutUndo,
@@ -34,9 +35,13 @@ import { ITransaction } from "../../types/internal";
3435
import { DEFAULT_TRANSACTION_RUN, EMPTY_TRANSACTION } from "../../utils/state";
3536
import { RpcEndpointMenu } from "../common/RpcEndpointMenu";
3637

37-
export const TransactionHeader: React.FC<{ transaction: ITransaction }> = ({
38-
transaction,
39-
}) => {
38+
export const TransactionHeader: React.FC<{
39+
transaction: ITransaction;
40+
resultsRef: React.RefObject<HTMLDivElement>;
41+
}> = ({ transaction, resultsRef }) => {
42+
const scrollToResults = usePersistentStore(
43+
(state) => state.appOptions.scrollToResults
44+
);
4045
const [transactionRun, setUI] = useSessionStoreWithoutUndo((state) => [
4146
state.transactionRun,
4247
state.set,
@@ -52,11 +57,25 @@ export const TransactionHeader: React.FC<{ transaction: ITransaction }> = ({
5257
setUI((state) => {
5358
state.transactionRun = { inProgress: true, signature };
5459
});
60+
if (scrollToResults) {
61+
resultsRef.current?.scrollIntoView({
62+
block: "end",
63+
inline: "nearest",
64+
behavior: "smooth",
65+
});
66+
}
5567
},
5668
onError: (error) => {
5769
setUI((state) => {
5870
state.transactionRun.error = error.message;
5971
});
72+
if (scrollToResults) {
73+
resultsRef.current?.scrollIntoView({
74+
block: "end",
75+
inline: "nearest",
76+
behavior: "smooth",
77+
});
78+
}
6079
},
6180
});
6281

src/components/client/results/Results.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import {
88
Button,
99
Flex,
10+
forwardRef,
1011
Grid,
1112
Heading,
1213
IconButton,
@@ -21,7 +22,7 @@ import {
2122
Tooltip,
2223
} from "@chakra-ui/react";
2324
import { TransactionConfirmationStatus } from "@solana/web3.js";
24-
import React, { useEffect, useState } from "react";
25+
import { useEffect, useState } from "react";
2526
import { useGetWeb3Transaction } from "../../../hooks/useGetWeb3Transaction";
2627
import { usePersistentStore } from "../../../hooks/usePersistentStore";
2728
import { useSessionStoreWithoutUndo } from "../../../hooks/useSessionStore";
@@ -46,7 +47,7 @@ type State = {
4647
logs?: string[];
4748
};
4849

49-
export const Results: React.FC = () => {
50+
export const Results = forwardRef<{}, "div">((_, ref) => {
5051
const [results, setResults] = useState<State>({});
5152
const finality = usePersistentStore(
5253
(state) => state.transactionOptions.finality
@@ -125,7 +126,7 @@ export const Results: React.FC = () => {
125126
};
126127

127128
return (
128-
<Grid pt="2" pl="5" pr="5">
129+
<Grid ref={ref} pt="2" pl="5" pr="5">
129130
<Flex alignItems="center" mb="4">
130131
<Heading mr="3" size="md">
131132
Results
@@ -231,4 +232,4 @@ export const Results: React.FC = () => {
231232
</Tabs>
232233
</Grid>
233234
);
234-
};
235+
});

src/components/options/GeneralOptions.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ export const GeneralOptions: React.FC = () => {
3737
}}
3838
/>
3939

40+
<ToggleOption
41+
id="scroll-to-results"
42+
name="Scroll to results"
43+
get={() => appOptions.scrollToResults}
44+
set={(x) => {
45+
set((state) => {
46+
state.appOptions.scrollToResults = x;
47+
});
48+
}}
49+
/>
50+
4051
<ToggleOption
4152
id="enable-numbering"
4253
name="Enable numbering"

src/types/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type Explorer =
2424
export interface AppOptions {
2525
readonly explorer: Explorer;
2626
readonly autoConnectWallet: boolean;
27+
readonly scrollToResults: boolean;
2728
readonly enableNumbering: boolean;
2829
readonly rpcEndpoints: SortableCollection<IRpcEndpoint>;
2930
}

src/utils/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const DEFAULT_APP_OPTIONS: AppOptions = {
6363
explorer: "solanafm",
6464
autoConnectWallet: true,
6565
enableNumbering: false,
66+
scrollToResults: true,
6667
rpcEndpoints: toSortableCollection(DEFAULT_RPC_ENDPOINTS),
6768
};
6869

0 commit comments

Comments
 (0)