|
1 | 1 | "use client"; |
2 | 2 | import { useQuery } from "@tanstack/react-query"; |
| 3 | +import { useMemo } from "react"; |
3 | 4 | import { trackPayEvent } from "../../../../../analytics/track/pay.js"; |
4 | 5 | import type { ThirdwebClient } from "../../../../../client/client.js"; |
5 | 6 | import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js"; |
6 | 7 | import { radius, spacing } from "../../../../core/design-system/index.js"; |
| 8 | +import { useChainsQuery } from "../../../../core/hooks/others/useChainQuery.js"; |
7 | 9 | import type { BridgePrepareResult } from "../../../../core/hooks/useBridgePrepare.js"; |
8 | 10 | import type { PaymentMethod } from "../../../../core/machines/paymentMachine.js"; |
9 | 11 | import { |
@@ -102,6 +104,15 @@ export function PaymentDetails({ |
102 | 104 | queryKey: ["payment_details", preparedQuote.type], |
103 | 105 | }); |
104 | 106 |
|
| 107 | + const chainsQuery = useChainsQuery( |
| 108 | + preparedQuote.steps.flatMap((s) => s.transactions.map((t) => t.chain)), |
| 109 | + 10, |
| 110 | + ); |
| 111 | + const chainsMetadata = useMemo( |
| 112 | + () => chainsQuery.map((c) => c.data), |
| 113 | + [chainsQuery], |
| 114 | + ).filter((c) => !!c); |
| 115 | + |
105 | 116 | // Extract common data based on quote type |
106 | 117 | const getDisplayData = () => { |
107 | 118 | switch (preparedQuote.type) { |
@@ -321,12 +332,48 @@ export function PaymentDetails({ |
321 | 332 | > |
322 | 333 | <Container flex="column" gap="3xs" style={{ flex: 1 }}> |
323 | 334 | <Text color="primaryText" size="sm"> |
324 | | - {step.originToken.symbol} →{" "} |
325 | | - {step.destinationToken.symbol} |
| 335 | + {step.destinationToken.chainId !== |
| 336 | + step.originToken.chainId ? ( |
| 337 | + <> |
| 338 | + Bridge{" "} |
| 339 | + {step.originToken.symbol === |
| 340 | + step.destinationToken.symbol |
| 341 | + ? step.originToken.symbol |
| 342 | + : `${step.originToken.symbol} to ${step.destinationToken.symbol}`} |
| 343 | + </> |
| 344 | + ) : ( |
| 345 | + <> |
| 346 | + Swap {step.originToken.symbol} to{" "} |
| 347 | + {step.destinationToken.symbol} |
| 348 | + </> |
| 349 | + )} |
326 | 350 | </Text> |
327 | 351 | <Text color="secondaryText" size="xs"> |
328 | | - {step.originToken.name} to{" "} |
329 | | - {step.destinationToken.name} |
| 352 | + {step.originToken.chainId !== |
| 353 | + step.destinationToken.chainId ? ( |
| 354 | + <> |
| 355 | + { |
| 356 | + chainsMetadata.find( |
| 357 | + (c) => c.chainId === step.originToken.chainId, |
| 358 | + )?.name |
| 359 | + }{" "} |
| 360 | + to{" "} |
| 361 | + { |
| 362 | + chainsMetadata.find( |
| 363 | + (c) => |
| 364 | + c.chainId === step.destinationToken.chainId, |
| 365 | + )?.name |
| 366 | + } |
| 367 | + </> |
| 368 | + ) : ( |
| 369 | + <> |
| 370 | + { |
| 371 | + chainsMetadata.find( |
| 372 | + (c) => c.chainId === step.originToken.chainId, |
| 373 | + )?.name |
| 374 | + } |
| 375 | + </> |
| 376 | + )} |
330 | 377 | </Text> |
331 | 378 | </Container> |
332 | 379 | </Container> |
|
0 commit comments