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
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ const handleExecuted = async ({ success, response, receipt }: ExecutedData) => {
const handleSubmit = async (id: number, body: string) => {
isProcessed.value = true;
const targetNodeId: TransactionNodeId = { transactionId: id };
const targetNodeId: TransactionNodeId = {
transactionId: id,
sdkTransactionId: transaction.value.transactionId?.toString(),
};
await nextTransaction.routeDown(targetNodeId, [targetNodeId], router, null, true, true);
emit('submitted', id, body);
};
Expand All @@ -278,7 +281,10 @@ const handleGroupSubmit = async (id: number) => {
};
const handleLocalStored = async (id: string) => {
const targetNodeId: TransactionNodeId = { transactionId: id };
const targetNodeId: TransactionNodeId = {
transactionId: id,
sdkTransactionId: transaction.value.transactionId?.toString(),
};
await nextTransaction.routeDown(targetNodeId, [targetNodeId], router, null, true, true);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import useSetDynamicLayout, { LOGGED_IN_LAYOUT } from '@renderer/composables/use
import useWebsocketSubscription from '@renderer/composables/useWebsocketSubscription';
import { parseTransactionActionPayload } from '@renderer/utils/parseTransactionActionPayload';
import { isInProgressStatus } from '@renderer/utils/transactionStatusGuards';
import { redirectToPreviousTransactionsTab } from '@renderer/utils/router';

import { getTransactionGroupById } from '@renderer/services/organization';
import { getTransaction } from '@renderer/services/transactionService';
Expand Down Expand Up @@ -67,6 +68,9 @@ import useNotificationsStore from '@renderer/stores/storeNotifications.ts';
import { ToastManager } from '@renderer/utils/ToastManager.ts';
import { isSignableStatus } from '@renderer/utils/transactionStatusGuards';
import { CREATOR_SIGNATURE_TEXT } from '@renderer/utils/creatorSignatureText';
import { createLogger } from '@renderer/utils/logger';

const logger = createLogger('renderer.pages.TransactionDetails');

/* Injectables */
const toastManager = ToastManager.inject();
Expand Down Expand Up @@ -228,9 +232,39 @@ const formattedId = computed(() => {
return id ? (Array.isArray(id) ? id[0] : id) : null;
});

// The real Hedera-format transaction id (e.g. "0.0.x@seconds.nanos"), carried on the route by
// whichever list the user navigated from. Only used for error reporting below - never to
// perform the actual lookup, which always happens by the local/DB id.
const knownSdkTransactionId = computed(() => {
const txId = route.query.txId;
return typeof txId === 'string' ? txId : null;
});

/* Functions */

// Logs everything we know about a failed fetch (both the DB/local id and the real Hedera id,
// when available) and returns the error to throw. The user-facing message never exposes the DB
// id: it uses the real transaction id when known, otherwise a generic message. Diagnosis relies
// on the log.
function buildTransactionFetchError(
error: unknown,
dbId: string,
previousSdkTransactionId?: string,
): Error {
const sdkTransactionId = previousSdkTransactionId || knownSdkTransactionId.value || undefined;
logger.error('Failed to load transaction', { dbId, sdkTransactionId, cause: error });
return new Error(
sdkTransactionId
? `Failed to load transaction ${sdkTransactionId}`
: 'Failed to load transaction. Please contact your administrator.',
);
}

async function fetchTransaction() {
const id = formattedId.value!;
// Captured before any lookup so a failed refetch can still report the id from a prior load
const previousSdkTransactionId =
orgTransaction.value?.transactionId || localTransaction.value?.transaction_id;
let transactionBytes: Uint8Array;
try {
if (isLoggedInOrganization(user.selectedOrganization) && !isNaN(Number(id))) {
Expand Down Expand Up @@ -266,13 +300,17 @@ async function fetchTransaction() {
}
}
} catch (error) {
throw error;
throw buildTransactionFetchError(error, id, previousSdkTransactionId);
}

try {
sdkTransaction.value = SDKTransaction.fromBytes(transactionBytes);
} catch {
throw new Error('Failed to deserialize transaction');
} catch (error) {
throw buildTransactionFetchError(
new Error('Failed to deserialize transaction', { cause: error }),
id,
previousSdkTransactionId,
);
}

if (!(sdkTransaction.value instanceof SDKTransaction)) {
Expand Down Expand Up @@ -302,6 +340,12 @@ async function fetchTransaction() {
);
} catch (error) {
signatureKeyObject.value = null;
logger.error('Failed to compute signature key', {
dbId: id,
sdkTransactionId:
orgTransaction.value?.transactionId ?? knownSdkTransactionId.value ?? undefined,
cause: error,
});
toastManager.error(getErrorMessage(error, 'Failed to compute signature key'));
}
}
Expand Down Expand Up @@ -329,7 +373,21 @@ onBeforeMount(async () => {
return;
}

await fetchTransaction();
try {
await fetchTransaction();
} catch (error) {
// Nothing useful can be shown on this page if the initial load failed; send the user back
// to whatever transactions tab they came from (or its default) instead of leaving them on
// an infinite loader. Toast manually since catching here stops it from reaching the global
// onErrorCaptured handler.
logger.error('Initial transaction load failed; redirecting to transactions list', {
dbId: id,
sdkTransactionId: knownSdkTransactionId.value ?? undefined,
cause: error,
});
toastManager.error(getErrorMessage(error, 'Failed to load transaction'));
await redirectToPreviousTransactionsTab(router);
}
});

onBeforeRouteLeave(to => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,18 @@ const handleBack = async () => {
router.back();
};
const handleDetails = async (id: number) => {
const handleDetails = async (id: number, sdkTransactionId?: string) => {
// Before routing to details, we update nextTransaction store
const groupItems = group.value?.groupItems ?? [];
const nodeIds = groupItems.map(item => {
return { transactionId: item.transactionId };
return { transactionId: item.transactionId, sdkTransactionId: item.transaction.transactionId };
});
await nextTransaction.routeDown({ transactionId: id }, nodeIds, router, pageTitle.value);
await nextTransaction.routeDown(
{ transactionId: id, sdkTransactionId },
nodeIds,
router,
pageTitle.value,
);
};
const didSignAll = async (groupId: number | null, signed: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const props = defineProps<{
/* Emits */
const emit = defineEmits<{
(event: 'handleDetails', transactionId: number): Promise<void>;
(event: 'handleDetails', transactionId: number, sdkTransactionId?: string): Promise<void>;
(event: 'transactionSigned', transaction: ITransactionFull): void;
}>();
Expand Down Expand Up @@ -216,7 +216,14 @@ useRevealed(container, () => {
:data-testid="`button-group-transaction-${props.rowIndex}`"
color="secondary"
type="button"
@click.prevent="() => emit('handleDetails', props.groupItem.transactionId)"
@click.prevent="
() =>
emit(
'handleDetails',
props.groupItem.transactionId,
props.groupItem.transaction.transactionId,
)
"
log-label="view-group-transaction-details"
:log-metadata="{ rowIndex: props.rowIndex, transactionId: props.groupItem.transactionId }"
><span>Details</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,25 @@ const handleSort = async (
currentPage.value = 1;
};
const handleDetails = async (id: string | number) => {
const handleDetails = async (id: string | number, sdkTransactionId?: string) => {
let nodeIds: TransactionNodeId[];
if (isLoggedInOrganization(user.selectedOrganization)) {
nodeIds = organizationTransactions.value.map(t => {
return {
transactionId: t.transactionRaw.id,
sdkTransactionId: t.transactionRaw.transactionId,
};
});
} else {
nodeIds = transactions.value.map(t => {
return {
transactionId: t.id,
sdkTransactionId: t.transaction_id,
};
});
}
await nextTransaction.routeDown(
{ transactionId: id },
{ transactionId: id, sdkTransactionId },
nodeIds,
router,
TransactionNodeCollection.HISTORY,
Expand Down Expand Up @@ -508,7 +510,7 @@ watch(
<td class="text-center">
<AppButton
:data-testid="`button-transaction-details-${index}`"
@click="handleDetails(transaction.id)"
@click="handleDetails(transaction.id, transaction.transaction_id)"
color="secondary"
log-label="view-transaction-details"
:log-metadata="{ transactionId: transaction.id }"
Expand Down Expand Up @@ -594,7 +596,12 @@ watch(
<td class="text-center">
<AppButton
:data-testid="`button-transaction-details-${index}`"
@click="handleDetails(transactionData.transactionRaw.id)"
@click="
handleDetails(
transactionData.transactionRaw.id,
transactionData.transactionRaw.transactionId,
)
"
color="secondary"
log-label="view-transaction-details"
:log-metadata="{ transactionId: transactionData.transactionRaw.id }"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const routeToDetails = async (node: ITransactionNode) => {
const nodeIds: TransactionNodeId[] = [];
for (const n of visibleNodes.value) {
if (n.transactionId) {
nodeIds.push({ transactionId: n.transactionId });
nodeIds.push({ transactionId: n.transactionId, sdkTransactionId: n.sdkTransactionId });
} else if (n.groupId) {
nodeIds.push({ groupId: n.groupId });
} else {
Expand All @@ -218,7 +218,7 @@ const routeToDetails = async (node: ITransactionNode) => {
}
if (node.transactionId) {
await nextTransaction.routeDown(
{ transactionId: node.transactionId },
{ transactionId: node.transactionId, sdkTransactionId: node.sdkTransactionId },
nodeIds,
router,
props.collection,
Expand Down
6 changes: 6 additions & 0 deletions front-end/src/renderer/stores/storeNextTransactionV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ const logger = createLogger('renderer.store.nextTransactionV2');
export type TransactionNodeId =
| {
transactionId: number | string;
// The real Hedera-format transaction id (e.g. "0.0.x@seconds.nanos"), when already known
// at navigation time. Carried through purely so TransactionDetails.vue can show/log a
// meaningful id if the fetch-by-id fails; never used to perform the lookup itself.
sdkTransactionId?: string;
groupId?: never;
}
| {
transactionId?: never;
sdkTransactionId?: never;
groupId: number | string;
};

Expand Down Expand Up @@ -196,6 +201,7 @@ const useNextTransactionV2 = defineStore(
await router.push({
name: 'transactionDetails',
params: { id: nodeId.transactionId },
query: nodeId.sdkTransactionId ? { txId: nodeId.sdkTransactionId } : undefined,
replace,
});
} else if (nodeId.groupId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const mocks = vi.hoisted(() => ({
loadedDraftDescription: '',
infoControlsDescription: null as string | null,
infoControlsDelayMs: 0,
routeDown: vi.fn(),
}));

vi.mock('vue-router', () => ({
Expand All @@ -34,7 +35,7 @@ vi.mock('@renderer/stores/storeNetwork', () => ({
default: () => ({ mirrorNodeBaseURL: 'http://localhost' }),
}));
vi.mock('@renderer/stores/storeNextTransactionV2.ts', () => ({
default: () => ({}),
default: () => ({ routeDown: mocks.routeDown }),
}));

vi.mock('@renderer/utils/ToastManager', () => ({
Expand Down Expand Up @@ -133,7 +134,11 @@ vi.mock('@renderer/components/ui/AppInput.vue', () => ({
default: { name: 'AppInput', template: '<div></div>' },
}));
vi.mock('@renderer/components/Transaction/TransactionProcessor', () => ({
default: { name: 'TransactionProcessor', template: '<div></div>' },
default: {
name: 'TransactionProcessor',
props: ['onExecuted', 'onSubmitted', 'onGroupSubmitted', 'onLocalStored'],
template: '<div></div>',
},
CustomRequest: class {},
TransactionRequest: class {},
}));
Expand Down Expand Up @@ -271,3 +276,57 @@ describe('BaseTransaction.vue – initial valid start', () => {
}
});
});

describe('BaseTransaction.vue – routing after submit carries the real transaction id', () => {
beforeEach(() => {
mockRouteQuery = {};
mocks.loadedDraftTransaction = null;
mocks.loadedDraftDescription = '';
mocks.infoControlsDescription = null;
mocks.infoControlsDelayMs = 0;
mocks.routeDown.mockClear();
});

test('handleSubmit passes the SDK transactionId alongside the DB id', async () => {
const wrapper = mountBase();
await flushPromises();

const onSubmitted = wrapper.findComponent({ name: 'TransactionProcessor' }).props('onSubmitted');
await onSubmitted(93, 'deadbeef');

expect(mocks.routeDown).toHaveBeenCalledTimes(1);
const [targetNodeId, collection] = mocks.routeDown.mock.calls[0];
expect(targetNodeId.transactionId).toBe(93);
expect(targetNodeId.sdkTransactionId).toMatch(/^0\.0\.2@\d+\.\d+$/);
expect(collection).toEqual([targetNodeId]);
});

test('handleLocalStored passes the SDK transactionId alongside the local id', async () => {
const wrapper = mountBase();
await flushPromises();

const onLocalStored = wrapper
.findComponent({ name: 'TransactionProcessor' })
.props('onLocalStored');
await onLocalStored('local-uuid-1');

expect(mocks.routeDown).toHaveBeenCalledTimes(1);
const [targetNodeId] = mocks.routeDown.mock.calls[0];
expect(targetNodeId.transactionId).toBe('local-uuid-1');
expect(targetNodeId.sdkTransactionId).toMatch(/^0\.0\.2@\d+\.\d+$/);
});

test('handleGroupSubmit does not carry a single-transaction sdkTransactionId', async () => {
const wrapper = mountBase();
await flushPromises();

const onGroupSubmitted = wrapper
.findComponent({ name: 'TransactionProcessor' })
.props('onGroupSubmitted');
await onGroupSubmitted(55);

expect(mocks.routeDown).toHaveBeenCalledTimes(1);
const [targetNodeId] = mocks.routeDown.mock.calls[0];
expect(targetNodeId).toEqual({ groupId: 55 });
});
});
Loading
Loading