Skip to content

Commit

Permalink
fix(spaceward): show correct tx count and more details for tx msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Jul 17, 2024
1 parent 6c34348 commit 56199cf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spaceward/src/components/BlockDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function BlockDetails({ block, txs }: { block: Block; txs: Tx[] }) {
{formatDateTime(block.header.time)}
</CardRow>
<CardRow label="Transactions">
{block.data.txs.length} txs
{txs.length} txs
</CardRow>

<div className="flex flex-row gap-4 pt-8">
Expand Down
31 changes: 31 additions & 0 deletions spaceward/src/components/TxMsgDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import AddressAvatar from "./AddressAvatar";
import { MsgSend } from "@wardenprotocol/wardenjs/codegen/cosmos/bank/v1beta1/tx";
import { MsgApproveAction, MsgNewRule } from "@wardenprotocol/wardenjs/codegen/warden/act/v1beta1/tx";
import { MsgAddSpaceOwner, MsgNewKeyRequest, MsgNewKeychain, MsgNewSpace, MsgRemoveSpaceOwner, MsgUpdateSpace } from "@wardenprotocol/wardenjs/codegen/warden/warden/v1beta3/tx";
import { cosmosProtoRegistry, wardenProtoRegistry } from "@wardenprotocol/wardenjs";

export function TxMsgDetails({ msg }: { msg: DecodeObject }) {
try {
Expand Down Expand Up @@ -222,6 +223,15 @@ function MsgNewRuleDetails({ msg }: { msg: MsgNewRule }) {

function MsgFallback({ msg }: { msg: DecodeObject }) {
const type = msg.typeUrl;

const t = [
...wardenProtoRegistry,
...cosmosProtoRegistry,
].find((r) => r[0] === type)?.[1];
if (t) {
return <MsgFallbackDetails type={type} msg={t.decode(msg.value)} />;
}

return (
<Card className="bg-background">
<CardHeader>
Expand All @@ -241,3 +251,24 @@ function MsgFallback({ msg }: { msg: DecodeObject }) {
</Card>
);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function MsgFallbackDetails({ type, msg }: { type: string, msg: any }) {
return (
<Card className="bg-background">
<CardHeader>
<CardTitle>{type}</CardTitle>
<CardDescription>
<span className="text-sm text-red-500">
Partially supported message type.
</span>
</CardDescription>
</CardHeader>
<CardContent>
{Object.entries(msg).map(([key, value]) => (
<CardRow label={key} key={key}>{String(value)}</CardRow>
))}
</CardContent>
</Card>
);
}
7 changes: 4 additions & 3 deletions spaceward/src/features/explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function Explorer() {
queryKey: ["block", latestHeight - BigInt(i)],
queryFn: async () => {
const client = await getClient();
return client.cosmos.base.tendermint.v1beta1.getBlockByHeight({
return client.cosmos.tx.v1beta1.getBlockWithTxs({
height: (latestHeight - BigInt(i)),
});
},
Expand Down Expand Up @@ -55,6 +55,7 @@ export function Explorer() {
<Block
key={q.data?.block?.header?.height}
block={q.data?.block}
txCount={q.data?.txs?.length ?? 0}
/>
) : null
))}
Expand All @@ -64,7 +65,7 @@ export function Explorer() {
);
}

function Block({ block }: { block: BlockModel }) {
function Block({ block, txCount }: { block: BlockModel, txCount: number }) {
return (
<TableRow
className={
Expand All @@ -88,7 +89,7 @@ function Block({ block }: { block: BlockModel }) {
</span>
</TableCell>
<TableCell className="text-right">
{block.data.txs.length} txs
{txCount} txs
</TableCell>
<TableCell className="text-right">
<Button variant="outline" size={"sm"}>
Expand Down

0 comments on commit 56199cf

Please sign in to comment.