From c40814d2233852ab11d2d2abffab0b77dc294770 Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Thu, 26 Sep 2024 13:51:46 +0200 Subject: [PATCH] review updates --- .../ui/tx/actions-views/ibc-relay.tsx | 135 +++++++++--------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/packages/ui/components/ui/tx/actions-views/ibc-relay.tsx b/packages/ui/components/ui/tx/actions-views/ibc-relay.tsx index 6ba7a781d..d7e371f48 100644 --- a/packages/ui/components/ui/tx/actions-views/ibc-relay.tsx +++ b/packages/ui/components/ui/tx/actions-views/ibc-relay.tsx @@ -16,6 +16,7 @@ import { uint8ArrayToBase64 } from '@penumbra-zone/types/base64'; import { ReactElement } from 'react'; import { Packet } from '@penumbra-zone/protobuf/ibc/core/channel/v1/channel_pb'; import { getUtcTime } from './isc20-withdrawal.tsx'; +import { CircleX } from 'lucide-react'; // Attempt to parse data w/ fallbacks if unknown or failures const ParsedPacketData = ({ @@ -50,23 +51,11 @@ const PacketRows = ({ return ( <> - {!!packet.sequence && ( - {Number(packet.sequence)} - )} - {!!packet.sourcePort && ( - {packet.sourcePort} - )} - {!!packet.sourceChannel && ( - {packet.sourceChannel} - )} - {!!packet.destinationPort && ( - {packet.destinationPort} - )} - {!!packet.destinationChannel && ( - - {packet.destinationChannel} - - )} + {Number(packet.sequence)} + {packet.sourcePort} + {packet.sourceChannel} + {packet.destinationPort} + {packet.destinationChannel} {!!packet.timeoutHeight?.revisionHeight && ( {Number(packet.timeoutHeight.revisionHeight)} @@ -77,34 +66,28 @@ const PacketRows = ({ {Number(packet.timeoutHeight.revisionNumber)} )} - {!!packet.timeoutTimestamp && ( - - {getUtcTime(packet.timeoutTimestamp)} - - )} + + {getUtcTime(packet.timeoutTimestamp)} + ); }; // Packet data stored as json string encoded into bytes -const parseRecvPacket = (packetData: Uint8Array) => { +const parseFungibleTokenData = (packetData: Uint8Array) => { const dataString = new TextDecoder().decode(packetData); const parsed = FungibleTokenPacketData.fromJsonString(dataString); return ( <> - {!!parsed.sender && ( - - {parsed.sender} - - )} - {!!parsed.receiver && ( - - {parsed.receiver} - - )} - {!!parsed.denom && {parsed.denom}} - {!!parsed.amount && {parsed.amount}} - {'memo' in parsed && {parsed.memo}} + + {parsed.sender} + + + {parsed.receiver} + + {parsed.denom} + {parsed.amount} + {parsed.memo} ); }; @@ -115,7 +98,9 @@ const MsgResvComponent = ({ packet }: { packet: MsgRecvPacket }) => { label='IBC Relay: Msg Received' visibleContent={ - {!!packet.packet && } + {!!packet.packet && ( + + )} {packet.signer} {!!packet.proofHeight?.revisionHeight && ( @@ -159,7 +144,9 @@ const MsgTimeoutComponent = ({ timeout }: { timeout: MsgTimeout }) => { label='IBC Relay: Msg Timeout' visibleContent={ - {!!timeout.packet && } + {!!timeout.packet && ( + + )} {!!timeout.proofHeight?.revisionHeight && ( {Number(timeout.proofHeight.revisionHeight)} @@ -191,7 +178,7 @@ const MsgAckComponent = ({ ack }: { ack: MsgAcknowledgement }) => { label='IBC Relay: Msg Acknowledgement' visibleContent={ - {!!ack.packet && } + {!!ack.packet && } {!!ack.proofHeight?.revisionHeight && ( {Number(ack.proofHeight.revisionHeight)} @@ -220,34 +207,48 @@ const MsgAckComponent = ({ ack }: { ack: MsgAcknowledgement }) => { }; export const IbcRelayComponent = ({ value }: { value: IbcRelay }) => { - if (value.rawAction?.is(MsgRecvPacket.typeName)) { - const packet = new MsgRecvPacket(); - value.rawAction.unpackTo(packet); - return ; - } - - if (value.rawAction?.is(MsgUpdateClient.typeName)) { - const update = new MsgUpdateClient(); - value.rawAction.unpackTo(update); - return ; - } - - if (value.rawAction?.is(MsgTimeout.typeName)) { - const timeout = new MsgTimeout(); - value.rawAction.unpackTo(timeout); - return ; - } - - if (value.rawAction?.is(MsgTimeoutOnClose.typeName)) { - const timeout = new MsgTimeoutOnClose(); - value.rawAction.unpackTo(timeout); - return ; - } - - if (value.rawAction?.is(MsgAcknowledgement.typeName)) { - const ack = new MsgAcknowledgement(); - value.rawAction.unpackTo(ack); - return ; + try { + if (value.rawAction?.is(MsgRecvPacket.typeName)) { + const packet = new MsgRecvPacket(); + value.rawAction.unpackTo(packet); + return ; + } + + if (value.rawAction?.is(MsgUpdateClient.typeName)) { + const update = new MsgUpdateClient(); + value.rawAction.unpackTo(update); + return ; + } + + if (value.rawAction?.is(MsgTimeout.typeName)) { + const timeout = new MsgTimeout(); + value.rawAction.unpackTo(timeout); + return ; + } + + if (value.rawAction?.is(MsgTimeoutOnClose.typeName)) { + const timeout = new MsgTimeoutOnClose(); + value.rawAction.unpackTo(timeout); + return ; + } + + if (value.rawAction?.is(MsgAcknowledgement.typeName)) { + const ack = new MsgAcknowledgement(); + value.rawAction.unpackTo(ack); + return ; + } + } catch (e) { + return ( + + + Error while parsing details + + } + /> + ); } return ;