Skip to content

Commit

Permalink
Add real slot info to transactions table (#16)
Browse files Browse the repository at this point in the history
* Add real slot info to transactions table

* npm run format:fix
  • Loading branch information
jstarry authored and mvines committed Jun 12, 2020
1 parent 56409a2 commit e7010ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion explorer/src/components/TransactionsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ const renderTransactionRow = (transaction: Transaction) => {
return assertUnreachable(transaction.status);
}

const slotText = `${transaction.slot || "-"}`;

return (
<tr key={transaction.signature}>
<td>
Expand All @@ -152,7 +154,7 @@ const renderTransactionRow = (transaction: Transaction) => {
<code>{transaction.signature}</code>
</td>
<td>-</td>
<td>-</td>
<td>{slotText}</td>
</tr>
);
};
Expand Down
26 changes: 17 additions & 9 deletions explorer/src/providers/transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Transaction {
id: number;
status: Status;
source: Source;
slot?: number;
signature: TransactionSignature;
}

Expand All @@ -38,6 +39,7 @@ interface UpdateStatus {
type: ActionType.UpdateStatus;
id: number;
status: Status;
slot?: number;
}

interface InputSignature {
Expand Down Expand Up @@ -66,7 +68,11 @@ function reducer(state: State, action: Action): State {
case ActionType.UpdateStatus: {
let transaction = state.transactions[action.id];
if (transaction) {
transaction = { ...transaction, status: action.status };
transaction = {
...transaction,
status: action.status,
slot: action.slot
};
const transactions = {
...state.transactions,
[action.id]: transaction
Expand Down Expand Up @@ -136,23 +142,25 @@ export async function checkTransactionStatus(
});

let status;
let slot;
try {
const signatureStatus = await new Connection(url).getSignatureStatus(
signature
);
const result = await new Connection(url).getSignatureStatus(signature);

if (signatureStatus === null) {
if (result === null) {
status = Status.Missing;
} else if ("Ok" in signatureStatus.status) {
status = Status.Success;
} else {
status = Status.Failure;
slot = result.slot;
if ("Ok" in result.status) {
status = Status.Success;
} else {
status = Status.Failure;
}
}
} catch (error) {
console.error("Failed to check transaction status", error);
status = Status.CheckFailed;
}
dispatch({ type: ActionType.UpdateStatus, status, id });
dispatch({ type: ActionType.UpdateStatus, status, slot, id });
}

export function useTransactions() {
Expand Down

0 comments on commit e7010ac

Please sign in to comment.