Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"next/core-web-vitals",
"plugin:@tanstack/query/recommended",
Comment thread
jeesunikim marked this conversation as resolved.
"prettier"
],
"rules": {
Expand Down
4 changes: 2 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"arrowParens:": "always",
"arrowParens": "always",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"bracketSameLine": false,
"printWidth": 80,
"proseWrap": "always",
"semi": true,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@
"devDependencies": {
"@next/eslint-plugin-next": "^15.4.4",
"@playwright/test": "^1.57.0",
"@tanstack/eslint-plugin-query": "^5.101.1",
"@types/jest": "^30.0.0",
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4.17.20",
"@types/node": "^24.1.0",
"@types/papaparse": "^5.3.15",
"@types/react": "^19.1.9",
"@types/react-dom": "^19.1.7",
"@typescript-eslint/eslint-plugin": "^8.30.1",
"@typescript-eslint/eslint-plugin": "^8.62.0",
"@typescript-eslint/parser": "^8.62.0",
"eslint": "^9.32.0",
"eslint-config-next": "15.4.4",
"eslint-config-prettier": "^10.1.8",
Expand Down
291 changes: 178 additions & 113 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions src/app/(sidebar)/transactions-explorer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export default function Explorer() {
return map;
});

const txsQuery = useGetRpcTxs({
const {
refetch: refetchTxs,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the object returned from the query hook is not referentially stable. the official doc recommends to destructure the return value of the query hook and pass them into dep array instead.

isError,
error,
} = useGetRpcTxs({
rpcUrl: network.rpcUrl,
headers: getNetworkHeaders(network, "rpc"),
startLedger,
Expand Down Expand Up @@ -104,10 +108,10 @@ export default function Explorer() {
}

try {
await txsQuery.refetch();
const txsResult = await refetchTxs();

if (txsQuery.data?.transactions && !txsQuery.error) {
for (const txinfo of txsQuery.data.transactions) {
if (txsResult.data?.transactions && !txsResult.error) {
for (const txinfo of txsResult.data.transactions) {
const normalizedTx = await normalizeTransaction(txinfo);

if (normalizedTx) {
Expand All @@ -126,8 +130,8 @@ export default function Explorer() {
.splice(-500);
localStorage.setItem(localStorageKey, jsonStringify(txs)!);

if (txsQuery.data.latestLedger) {
setStartLedger(txsQuery.data.latestLedger);
if (txsResult.data.latestLedger) {
setStartLedger(txsResult.data.latestLedger);
}
}
} catch (e) {
Expand All @@ -144,16 +148,16 @@ export default function Explorer() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
network?.rpcUrl,
txsQuery,
refetchTxs,
iter,
nextFetchAt,
transactions,
localStorageKey,
]);

const errorElement = txsQuery.isError ? (
const errorElement = isError ? (
<Alert variant="error" placement="inline">
{txsQuery.error.message}
{error?.message}
</Alert>
) : null;
Comment on lines +158 to 162

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe, should we me checking for the error.message instead of isError?

Suggested change
const errorElement = isError ? (
<Alert variant="error" placement="inline">
{txsQuery.error.message}
{error?.message}
</Alert>
) : null;
const errorElement = error?.message ? (
<Alert variant="error" placement="inline">
{error.message}
</Alert>
) : null;


Expand Down
16 changes: 10 additions & 6 deletions src/app/(sidebar)/xdr/view/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ export default function ViewXdr() {
isFetching: isLatestTxnFetching,
isLoading: isLatestTxnLoading,
refetch: fetchLatestTxn,
} = useLatestTxn(
network.rpcUrl,
getNetworkHeaders(network, "rpc"),
["xdr", "latestTxn"],
);
} = useLatestTxn(network.rpcUrl, getNetworkHeaders(network, "rpc"), [
"xdr",
"latestTxn",
]);

const queryClient = useQueryClient();

Expand Down Expand Up @@ -208,7 +207,12 @@ export default function ViewXdr() {
if (latestTxn) {
// Reset query to clear old data
queryClient.resetQueries({
queryKey: ["xdr", "latestTxn", network.rpcUrl],
queryKey: [
"xdr",
"latestTxn",
network.rpcUrl,
getNetworkHeaders(network, "rpc"),
],
exact: true,
});
updateXdrBlob("");
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/errorUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/**
* Extracts a human-readable message from an unknown error value.
*
* Handles `Error` instances, raw strings, and arbitrary objects (falling back
* to `JSON.stringify`, then `String`).
*/
export const getErrorMessage = (error: unknown): string => {
if (error instanceof Error) {
return error.message;
}

if (typeof error === "string") {
return error;
}

try {
return JSON.stringify(error);
} catch {
return String(error);
}
};

export const isExternalError = (error: Error) => {
const stack = error.stack || "";

Expand Down
7 changes: 6 additions & 1 deletion src/query/external/useSEContractStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export const useSEContractStorage = ({
totalEntriesCount: number | undefined;
}) => {
const query = useQuery<ContractStorageResponseItem[] | null>({
queryKey: ["useSEContractStorage", networkId, contractId],
queryKey: [
"useSEContractStorage",
networkId,
contractId,
totalEntriesCount,
],
queryFn: async () => {
// No entries
if (!totalEntriesCount) {
Expand Down
7 changes: 4 additions & 3 deletions src/query/useAccountInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getErrorMessage } from "@/helpers/errorUtils";
import { NetworkHeaders } from "@/types/types";
import { useQuery } from "@tanstack/react-query";

Expand All @@ -11,7 +12,7 @@ export const useAccountInfo = ({
headers: NetworkHeaders;
}) => {
const query = useQuery({
queryKey: ["accountInfo", publicKey],
queryKey: ["accountInfo", publicKey, horizonUrl, headers],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is headers a string or an object? Just want to make sure the query won't be triggered too often.

queryFn: async () => {
try {
const response = await fetch(`${horizonUrl}/accounts/${publicKey}`, {
Expand All @@ -31,8 +32,8 @@ export const useAccountInfo = ({
isFunded: true,
details: responseJson,
};
} catch (e: any) {
throw `Something went wrong. ${e}`;
} catch (error) {
throw new Error(`Something went wrong. ${getErrorMessage(error)}`);
}
},
enabled: false,
Expand Down
7 changes: 6 additions & 1 deletion src/query/useAccountSequenceNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export const useAccountSequenceNumber = ({
enabled?: boolean;
}) => {
const query = useQuery({
queryKey: ["accountSequenceNumber", { publicKey, uniqueId }],
queryKey: [
"accountSequenceNumber",
{ publicKey, uniqueId },
horizonUrl,
headers,
],
queryFn: async () => {
let sourceAccount = publicKey;

Expand Down
10 changes: 9 additions & 1 deletion src/query/useAddTrustline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ export const useAddTrustline = ({
headers: NetworkHeaders;
}) => {
const query = useQuery({
queryKey: ["addTrustline", publicKey],
queryKey: [
"addTrustline",
publicKey,
asset.assetCode,
asset.assetIssuer,
network.horizonUrl,
network.passphrase,
headers,
],
queryFn: async () => {
if (!asset.assetCode || !asset.assetIssuer) {
throw new Error("Asset code and issuer are required");
Expand Down
11 changes: 10 additions & 1 deletion src/query/useBuildRpcTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ export const useBuildRpcTransaction = ({
timeoutInSeconds?: number;
}) => {
const query = useQuery({
queryKey: ["buildRpcTransaction", publicKey, operation],
queryKey: [
"buildRpcTransaction",
publicKey,
rpcUrl,
operation,
networkPassphrase,
timeoutInSeconds,
headers,
rpcUrl,
],
Comment thread
Copilot marked this conversation as resolved.
Comment thread
jeesunikim marked this conversation as resolved.
queryFn: async () => {
if (!publicKey) {
throw "Public key is required.";
Expand Down
2 changes: 1 addition & 1 deletion src/query/useBuildVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useBuildVerification = ({
}) => {
const queries = useQueries({
queries: contractIds.map((contractId) => ({
queryKey: ["buildVerification", contractId, rpcUrl],
queryKey: ["buildVerification", contractId, rpcUrl, headers],
queryFn: () =>
getBuildVerification({
contractId,
Expand Down
2 changes: 1 addition & 1 deletion src/query/useCheckTxSignatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useCheckTxSignatures = ({
headers: NetworkHeaders;
}) => {
const query = useQuery({
queryKey: ["tx", "signatures"],
queryKey: ["tx", "signatures", xdr, networkPassphrase, networkUrl, headers],
queryFn: async () => {
try {
return await fetchTxSignatures({
Expand Down
2 changes: 1 addition & 1 deletion src/query/useEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useEndpoint = ({
headers: NetworkHeaders;
}) => {
const query = useQuery({
queryKey: ["endpoint", "response", postData],
queryKey: ["endpoint", "response", postData, requestUrl, headers],
queryFn: async () => {
const endpointResponse = await fetch(sanitizeUrl(requestUrl), {
headers,
Expand Down
2 changes: 1 addition & 1 deletion src/query/useFetchRpcTxDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useFetchRpcTxDetails = ({
txHash: string;
}) => {
const query = useQuery({
queryKey: ["useFetchRpcTxDetails", rpcUrl, txHash],
queryKey: ["useFetchRpcTxDetails", rpcUrl, txHash, headers],
queryFn: async () => {
try {
const response = await fetch(rpcUrl, {
Expand Down
9 changes: 8 additions & 1 deletion src/query/useFriendBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ export const useFriendBot = ({
: "https://friendbot.stellar.org";

const query = useQuery({
queryKey: ["friendBot", publicKey, key],
queryKey: [
"friendBot",
publicKey,
key,
network,
knownFriendbotURL,
headers,
],
queryFn: async () => {
if (!network.horizonUrl) {
throw new Error(`Please use a network that supports Horizon`);
Expand Down
9 changes: 8 additions & 1 deletion src/query/useGetContractDataFromRpcById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export const useGetContractDataFromRpcById = ({
| null
| undefined
>({
queryKey: ["useGetContractDataFromRpcById", contractId, rpcUrl],
queryKey: [
"useGetContractDataFromRpcById",
contractId,
rpcUrl,
execWasmType,
execStellarAssetType,
headers,
],
queryFn: async () => {
if (!contractId || !rpcUrl) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/query/useGetRpcTxDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useGetRpcTxDetails = ({
tx: string;
}) => {
const query = useQuery({
queryKey: ["useGetRpcTxDetails", rpcUrl, tx],
queryKey: ["useGetRpcTxDetails", rpcUrl, tx, headers],
queryFn: async () => {
const rpcServer = new StellarRpc.Server(rpcUrl, {
headers,
Expand Down
11 changes: 8 additions & 3 deletions src/query/useGetRpcTxs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getErrorMessage } from "@/helpers/errorUtils";
import { NetworkHeaders } from "@/types/types";
import { rpc as StellarRpc } from "@stellar/stellar-sdk";

Expand All @@ -13,7 +14,7 @@ export const useGetRpcTxs = ({
startLedger: number;
}) => {
const query = useQuery({
queryKey: ["useGetRpcTxs", rpcUrl, startLedger],
queryKey: ["useGetRpcTxs", rpcUrl, startLedger, headers],
queryFn: async () => {
const rpcServer = new StellarRpc.Server(rpcUrl, {
headers,
Expand All @@ -33,15 +34,19 @@ export const useGetRpcTxs = ({
params.startLedger = latestLedger.sequence;
}
} catch (error) {
throw `there was an error with fetching latest ledger. e: ${error}`;
throw new Error(
`there was an error with fetching latest ledger. e: ${getErrorMessage(error)}`,
);
}

try {
const response = await rpcServer.getTransactions(params);

return response;
} catch (error) {
throw `there was an error with fetching transactions. e: ${error}`;
throw new Error(
`there was an error with fetching transactions. e: ${getErrorMessage(error)}`,
);
}
},
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion src/query/useHorizonHealthCheckUntilReady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useHorizonHealthCheckUntilReady = (
headers: AnyObject,
) => {
const query = useQuery({
queryKey: ["useHorizonHealthCheckUntilReady", horizonUrl],
queryKey: ["useHorizonHealthCheckUntilReady", horizonUrl, headers],
queryFn: async () => {
if (!horizonUrl) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/query/useLatestLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useLatestLedger = ({
headers: NetworkHeaders;
}) => {
const query = useQuery({
queryKey: ["latestLedger"],
queryKey: ["latestLedger", rpcUrl, headers],
queryFn: async () => {
const rpcServer = new StellarRpc.Server(rpcUrl, {
headers,
Expand Down
2 changes: 1 addition & 1 deletion src/query/useLatestTxn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const useLatestTxn = (
queryKey: string[] = ["latestTxn"],
) => {
const query = useQuery({
queryKey: [...queryKey, rpcUrl],
queryKey: [...queryKey, rpcUrl, headers],
Comment thread
jeesunikim marked this conversation as resolved.
queryFn: async () => {
try {
const rpcServer = new StellarRpc.Server(rpcUrl, {
Expand Down
2 changes: 1 addition & 1 deletion src/query/useRpcHealthCheckUntilReady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useRpcHealthCheckUntilReady = (
headers: AnyObject,
) => {
const query = useQuery({
queryKey: ["useRpcHealthCheckUntilReady", rpcUrl],
queryKey: ["useRpcHealthCheckUntilReady", rpcUrl, headers],
queryFn: async () => {
if (!rpcUrl) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/query/useWasmBinaryFromRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useWasmBinaryFromRpc = ({
headers?: NetworkHeaders;
}) => {
const query = useQuery<Buffer | null>({
queryKey: ["useWasmBinaryFromRpc", wasmHash, rpcUrl],
queryKey: ["useWasmBinaryFromRpc", wasmHash, rpcUrl, headers],
queryFn: async () => {
if (!wasmHash || !rpcUrl) {
return null;
Expand Down
Loading
Loading