|
| 1 | +// SPDX-License-Identifier: LicenseRef-Blockscout |
| 2 | + |
| 3 | +import { Flex, Grid } from '@chakra-ui/react'; |
| 4 | +import React from 'react'; |
| 5 | + |
| 6 | +import type { schemas } from '@blockscout/api-types'; |
| 7 | + |
| 8 | +import AddressEntity from 'src/slices/address/components/entity/AddressEntity'; |
| 9 | + |
| 10 | +import * as DetailedInfo from 'src/shared/detailed-info/DetailedInfo'; |
| 11 | +import CopyToClipboard from 'src/shared/texts/CopyToClipboard'; |
| 12 | +import NativeCoinValue from 'src/shared/values/entity/NativeCoinValue'; |
| 13 | + |
| 14 | +import { Skeleton } from 'src/toolkit/chakra/skeleton'; |
| 15 | +import { TruncatedText } from 'src/toolkit/components/truncation/TruncatedText'; |
| 16 | + |
| 17 | +/** One call of a sponsored batch transaction. `to` is `null` for a contract-creation call. */ |
| 18 | +type TransactionEdenCall = NonNullable<schemas['TransactionResponse']['calls']>[number]; |
| 19 | + |
| 20 | +interface Props { |
| 21 | + data: schemas['TransactionResponse']; |
| 22 | + isLoading?: boolean; |
| 23 | +} |
| 24 | + |
| 25 | +const HeaderItem = ({ children, isLoading }: { children: React.ReactNode; isLoading?: boolean }) => { |
| 26 | + return ( |
| 27 | + <Skeleton |
| 28 | + fontWeight="semibold" |
| 29 | + pb={ 1 } |
| 30 | + loading={ isLoading } |
| 31 | + > |
| 32 | + { children } |
| 33 | + </Skeleton> |
| 34 | + ); |
| 35 | +}; |
| 36 | + |
| 37 | +const CallRow = ({ to, value, input, isLoading }: TransactionEdenCall & { isLoading?: boolean }) => { |
| 38 | + return ( |
| 39 | + <> |
| 40 | + <div> |
| 41 | + { to ? |
| 42 | + <AddressEntity address={{ hash: to }} isLoading={ isLoading }/> : |
| 43 | + <Skeleton loading={ isLoading } display="inline-block"><span>[ Contract creation ]</span></Skeleton> |
| 44 | + } |
| 45 | + </div> |
| 46 | + <div> |
| 47 | + <NativeCoinValue amount={ value } loading={ isLoading }/> |
| 48 | + </div> |
| 49 | + <Flex alignItems="flex-start" whiteSpace="normal" wordBreak="break-all"> |
| 50 | + <TruncatedText text={ input } loading={ isLoading }/> |
| 51 | + <CopyToClipboard text={ input } isLoading={ isLoading }/> |
| 52 | + </Flex> |
| 53 | + </> |
| 54 | + ); |
| 55 | +}; |
| 56 | + |
| 57 | +const TxDetailsEden = ({ data, isLoading }: Props) => { |
| 58 | + const { fee_payer: feePayer, calls } = data; |
| 59 | + |
| 60 | + if (!feePayer && !calls?.length) { |
| 61 | + return null; |
| 62 | + } |
| 63 | + |
| 64 | + return ( |
| 65 | + <> |
| 66 | + { feePayer && ( |
| 67 | + <> |
| 68 | + <DetailedInfo.ItemLabel |
| 69 | + hint="Address that paid the transaction fee on behalf of the sender" |
| 70 | + isLoading={ isLoading } |
| 71 | + > |
| 72 | + Fee payer |
| 73 | + </DetailedInfo.ItemLabel> |
| 74 | + <DetailedInfo.ItemValue> |
| 75 | + <AddressEntity address={ feePayer } isLoading={ isLoading }/> |
| 76 | + </DetailedInfo.ItemValue> |
| 77 | + </> |
| 78 | + ) } |
| 79 | + |
| 80 | + { calls && calls.length > 0 && ( |
| 81 | + <> |
| 82 | + <DetailedInfo.ItemLabel |
| 83 | + hint="Ordered list of calls batched into this sponsored transaction" |
| 84 | + isLoading={ isLoading } |
| 85 | + > |
| 86 | + Calls |
| 87 | + </DetailedInfo.ItemLabel> |
| 88 | + <DetailedInfo.ItemValue alignItems="flex-start" flexWrap="wrap"> |
| 89 | + <Grid |
| 90 | + gridTemplateColumns="minmax(140px, 1fr) minmax(50px, 1fr) 1fr" |
| 91 | + textStyle="sm" |
| 92 | + bgColor={{ _light: 'blackAlpha.50', _dark: 'whiteAlpha.50' }} |
| 93 | + p={ 4 } |
| 94 | + mt={ 2 } |
| 95 | + w="100%" |
| 96 | + columnGap={ 5 } |
| 97 | + rowGap={ 5 } |
| 98 | + borderRadius="md" |
| 99 | + > |
| 100 | + <HeaderItem isLoading={ isLoading }>To</HeaderItem> |
| 101 | + <HeaderItem isLoading={ isLoading }>Value</HeaderItem> |
| 102 | + <HeaderItem isLoading={ isLoading }>Input</HeaderItem> |
| 103 | + { calls.map((call, index) => ( |
| 104 | + // a batch can repeat the same call, so the position in the batch is the only stable key |
| 105 | + <CallRow key={ index } { ...call } isLoading={ isLoading }/> |
| 106 | + )) } |
| 107 | + </Grid> |
| 108 | + </DetailedInfo.ItemValue> |
| 109 | + </> |
| 110 | + ) } |
| 111 | + </> |
| 112 | + ); |
| 113 | +}; |
| 114 | + |
| 115 | +export default React.memo(TxDetailsEden); |
0 commit comments