diff --git a/theme/components/Badge.ts b/theme/components/Badge.ts index e3034f706a..01cb9fb948 100644 --- a/theme/components/Badge.ts +++ b/theme/components/Badge.ts @@ -33,7 +33,7 @@ const variantSubtle = defineStyle((props) => { if (c === 'black-purple') { return { - bg: mode('purple.50', 'purple.800')(props), + bg: mode('purple.100', 'purple.800')(props), color: mode('blackAlpha.800', 'whiteAlpha.800')(props), }; } diff --git a/ui/address/contract/methods/ContractAbiItem.tsx b/ui/address/contract/methods/ContractAbiItem.tsx index a47d187c39..1b3bb6621d 100644 --- a/ui/address/contract/methods/ContractAbiItem.tsx +++ b/ui/address/contract/methods/ContractAbiItem.tsx @@ -11,7 +11,7 @@ import CopyToClipboard from 'ui/shared/CopyToClipboard'; import Hint from 'ui/shared/Hint'; import ContractMethodForm from './form/ContractMethodForm'; -import { getElementName } from './useScrollToMethod'; +import { getElementId, getElementName } from './useScrollToMethod'; import { isReadMethod } from './utils'; interface Props { @@ -29,10 +29,6 @@ const ContractAbiItem = ({ data, index, id, addressHash, sourceAddress, tab, onS const [ attempt, setAttempt ] = React.useState(0); const url = React.useMemo(() => { - if (!('method_id' in data)) { - return ''; - } - return config.app.baseUrl + route({ pathname: '/address/[hash]', query: { @@ -40,7 +36,7 @@ const ContractAbiItem = ({ data, index, id, addressHash, sourceAddress, tab, onS tab, ...(sourceAddress ? { source_address: sourceAddress } : {}), }, - hash: data.method_id, + hash: getElementId(data), }); }, [ addressHash, data, tab, sourceAddress ]); @@ -62,7 +58,7 @@ const ContractAbiItem = ({ data, index, id, addressHash, sourceAddress, tab, onS { ({ isExpanded }) => ( <> - + - { 'method_id' in data && } + { index + 1 }. { data.type === 'fallback' || data.type === 'receive' ? data.type : data.name } { data.type === 'fallback' && ( diff --git a/ui/address/contract/methods/useScrollToMethod.ts b/ui/address/contract/methods/useScrollToMethod.ts index 34ed8daec1..9649800e50 100644 --- a/ui/address/contract/methods/useScrollToMethod.ts +++ b/ui/address/contract/methods/useScrollToMethod.ts @@ -3,19 +3,33 @@ import { scroller } from 'react-scroll'; import type { SmartContractMethod } from './types'; -export const getElementName = (id: string) => `method_${ id }`; +export const getElementId = (data: SmartContractMethod) => { + if ('method_id' in data) { + return data.method_id; + } + + if ('name' in data) { + return data.name; + } + + return data.type; +}; + +export const getElementName = (data: SmartContractMethod) => { + return `method_${ getElementId(data) }`; +}; export default function useScrollToMethod(data: Array, onScroll: (indices: Array) => void) { React.useEffect(() => { - const id = window.location.hash.replace('#', ''); + const hash = window.location.hash.replace('#', ''); - if (!id) { + if (!hash) { return; } - const index = data.findIndex((item) => 'method_id' in item && item.method_id === id); + const index = data.findIndex((item) => getElementId(item) === hash); if (index > -1) { - scroller.scrollTo(getElementName(id), { + scroller.scrollTo(getElementName(data[ index ]), { duration: 500, smooth: true, offset: -100,