Skip to content

Commit

Permalink
chore: display steps even though we only have txMeta.id
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Nov 13, 2024
1 parent 2a6a2b2 commit 4359f25
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
18 changes: 13 additions & 5 deletions ui/pages/bridge/transaction-details/bridge-step-description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,19 @@ const getSwapActionText = (
]);
};

export const getStepStatus = (
bridgeHistoryItem: BridgeHistoryItem,
step: Step,
srcChainTxMeta?: TransactionMeta,
) => {
export const getStepStatus = ({
bridgeHistoryItem,
step,
srcChainTxMeta,
}: {
bridgeHistoryItem?: BridgeHistoryItem;
step: Step;
srcChainTxMeta?: TransactionMeta;
}) => {
if (!bridgeHistoryItem) {
return StatusTypes.UNKNOWN;
}

if (step.action === ActionTypes.SWAP) {
return getSwapActionStatus(bridgeHistoryItem, step, srcChainTxMeta);
} else if (step.action === ActionTypes.BRIDGE) {
Expand Down
34 changes: 28 additions & 6 deletions ui/pages/bridge/transaction-details/bridge-step-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { Box } from '../../../components/component-library';
import {
BridgeHistoryItem,
StatusTypes,
Step,
} from '../../../../shared/types/bridge-status';
import { formatDate } from '../../../helpers/utils/util';
import { Numeric } from '../../../../shared/modules/Numeric';
import BridgeStepDescription, {
getStepStatus,
} from './bridge-step-description';
Expand All @@ -29,7 +31,7 @@ const getTime = (
};

type BridgeStepsProps = {
bridgeHistoryItem: BridgeHistoryItem;
bridgeHistoryItem?: BridgeHistoryItem;
srcChainTxMeta?: TransactionMeta;
networkConfigurationsByChainId: Record<Hex, NetworkConfiguration>;
};
Expand All @@ -39,9 +41,29 @@ export default function BridgeStepList({
srcChainTxMeta,
networkConfigurationsByChainId,
}: BridgeStepsProps) {
const { steps } = bridgeHistoryItem.quote;
const steps =
bridgeHistoryItem?.quote.steps ||
srcChainTxMeta?.bridgeSteps?.map((step) => ({
// Convert hex to numbers
...step,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
action: step.action as any,
srcChainId: new Numeric(step.srcChainId, 16).toBase(10).toNumber(),
destChainId: step.destChainId
? new Numeric(step.destChainId, 16).toBase(10).toNumber()
: undefined,
srcAsset: {
...step.srcAsset,
chainId: new Numeric(step.srcAsset.chainId, 16).toBase(10).toNumber(),
},
destAsset: {
...step.destAsset,
chainId: new Numeric(step.destAsset.chainId, 16).toBase(10).toNumber(),
},
})) ||
[];
const stepStatuses = steps.map((step) =>
getStepStatus(bridgeHistoryItem, step, srcChainTxMeta),
getStepStatus({ bridgeHistoryItem, step: step as Step, srcChainTxMeta }),
);

return (
Expand Down Expand Up @@ -71,8 +93,8 @@ export default function BridgeStepList({
getTime(
i,
i === steps.length - 1,
bridgeHistoryItem.startTime,
bridgeHistoryItem.estimatedProcessingTimeInSeconds,
bridgeHistoryItem?.startTime || srcChainTxMeta?.time,
bridgeHistoryItem?.estimatedProcessingTimeInSeconds || 0,
),
'hh:mm a',
);
Expand All @@ -85,7 +107,7 @@ export default function BridgeStepList({
isEdgeComplete={isEdgeComplete}
>
<BridgeStepDescription
step={step}
step={step as Step}
networkConfigurationsByChainId={networkConfigurationsByChainId}
stepStatus={displayedStepStatus}
time={time}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function StepProgressBarItem({
return (
<>
{/* Indicator dots */}
{stepStatus === null && (
{(stepStatus === null || stepStatus === StatusTypes.UNKNOWN) && (
<HollowCircle size={ICON_SIZE} color={IconColor.iconMuted} />
)}
{stepStatus === StatusTypes.PENDING && (
Expand Down
36 changes: 17 additions & 19 deletions ui/pages/bridge/transaction-details/transaction-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,24 @@ const CrossChainSwapTxDetails = () => {
flexDirection={FlexDirection.Column}
gap={4}
>
{bridgeHistoryItem && (
<>
{status !== StatusTypes.COMPLETE && bridgeHistoryItem && (
<BridgeStepList
bridgeHistoryItem={bridgeHistoryItem}
srcChainTxMeta={srcChainTxMeta}
networkConfigurationsByChainId={
networkConfigurationsByChainId
}
/>
)}

{/* Links to block explorers */}
<BridgeExplorerLinks
srcBlockExplorerUrl={srcBlockExplorerUrl}
destBlockExplorerUrl={destBlockExplorerUrl}
{status !== StatusTypes.COMPLETE &&
(bridgeHistoryItem || srcChainTxMeta) && (
<BridgeStepList
bridgeHistoryItem={bridgeHistoryItem}
srcChainTxMeta={srcChainTxMeta}
networkConfigurationsByChainId={
networkConfigurationsByChainId
}
/>
<Divider />
</>
)}
)}

{/* Links to block explorers */}
<BridgeExplorerLinks
srcBlockExplorerUrl={srcBlockExplorerUrl}
destBlockExplorerUrl={destBlockExplorerUrl}
/>
<Divider />

{/* General tx details */}
<Box
display={Display.Flex}
Expand Down

0 comments on commit 4359f25

Please sign in to comment.