-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constructor array parameters are displayed as concatenated strings in…
- Loading branch information
Showing
8 changed files
with
127 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Box } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
|
||
import type { SmartContract } from 'types/api/contract'; | ||
|
||
import AddressEntity from 'ui/shared/entities/address/AddressEntity'; | ||
import type { Truncation } from 'ui/shared/entities/base/components'; | ||
import RawDataSnippet from 'ui/shared/RawDataSnippet'; | ||
|
||
import { matchArray } from './methods/form/utils'; | ||
|
||
interface DecodedItemProps { | ||
value: unknown; | ||
type: string; | ||
addressTruncation?: Truncation; | ||
} | ||
|
||
const DecodedItemValue = ({ value, type, addressTruncation = 'dynamic' }: DecodedItemProps) => { | ||
const arrayMatch = matchArray(type); | ||
|
||
if (arrayMatch && Array.isArray(value)) { | ||
return value.map((item, index) => ( | ||
<> | ||
<DecodedItemValue key={ index } value={ item } type={ arrayMatch.itemType } addressTruncation="constant"/> | ||
{ index < value.length - 1 && ', ' } | ||
</> | ||
)); | ||
} | ||
|
||
if (type === 'address' && typeof value === 'string') { | ||
return ( | ||
<AddressEntity | ||
address={{ hash: value }} | ||
noIcon | ||
display="inline-flex" | ||
maxW="100%" | ||
truncation={ addressTruncation } | ||
/> | ||
); | ||
} | ||
|
||
const content = (() => { | ||
if (value === null || value === undefined || value === '') { | ||
return '""'; | ||
} | ||
|
||
if (typeof value === 'object') { | ||
return JSON.stringify(value); | ||
} | ||
|
||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | ||
return value; | ||
} | ||
|
||
return String(value); | ||
})(); | ||
|
||
return <span>{ content }</span>; | ||
}; | ||
|
||
interface Props { | ||
data: SmartContract | undefined; | ||
isLoading: boolean; | ||
} | ||
|
||
const ContractDetailsConstructorArgs = ({ data, isLoading }: Props) => { | ||
|
||
const content = React.useMemo(() => { | ||
if (!data?.decoded_constructor_args) { | ||
return data?.constructor_args; | ||
} | ||
|
||
const decoded = data.decoded_constructor_args | ||
.map(([ value, { name, type } ], index) => { | ||
return ( | ||
<Box key={ index }> | ||
<span>Arg [{ index }] { name || '' } ({ type }): </span> | ||
<DecodedItemValue value={ value } type={ type }/> | ||
</Box> | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
<span>{ data.constructor_args }</span> | ||
<br/><br/> | ||
{ decoded } | ||
</> | ||
); | ||
}, [ data?.constructor_args, data?.decoded_constructor_args ]); | ||
|
||
if (!content) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<RawDataSnippet | ||
data={ content } | ||
title="Constructor Arguments" | ||
textareaMaxHeight="200px" | ||
isLoading={ isLoading } | ||
/> | ||
); | ||
}; | ||
|
||
export default React.memo(ContractDetailsConstructorArgs); |
Binary file modified
BIN
+607 Bytes
(100%)
...__/ContractDetails.pw.tsx_dark-color-mode_full-view-source-code-dark-mode-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+637 Bytes
(100%)
...eenshots__/ContractDetails.pw.tsx_default_full-view-source-code-dark-mode-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+656 Bytes
(100%)
...ct/__screenshots__/ContractDetails.pw.tsx_default_mobile-view-source-code-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters