fix: its often not clear when a new site

was loaded #23
pull/35/head
VPcodebase 3 years ago
parent ffa1217cc9
commit 2e68d7d56c
  1. 16
      src/components/block/BlockDetails.tsx
  2. 58
      src/components/block/helpers.tsx
  3. 65
      src/pages/AddressPage/AddressDetails.tsx

@ -1,4 +1,4 @@
import React, { FunctionComponent, useState } from "react"; import React, { FunctionComponent, useEffect, useState } from "react";
import { Block } from "../../types"; import { Block } from "../../types";
import { import {
blockPropertyDisplayNames, blockPropertyDisplayNames,
@ -51,6 +51,18 @@ export const BlockDetails: FunctionComponent<BlockDetailsProps> = ({
blockNumber, blockNumber,
}) => { }) => {
const [showDetails, setShowDetails] = useState(true); const [showDetails, setShowDetails] = useState(true);
const [isNewAddress, setIsNewAddress] = useState<boolean>(false);
useEffect(() => {
let tId = 0;
const getActiveIndex = () => {
setIsNewAddress(true);
tId = window.setTimeout(() => setIsNewAddress(false), 1000);
};
getActiveIndex();
return () => clearTimeout(tId);
}, [block]);
const keys = Object.keys({ ...block, shard: blockNumber }); const keys = Object.keys({ ...block, shard: blockNumber });
const sortedKeys = keys.sort( const sortedKeys = keys.sort(
@ -64,7 +76,7 @@ export const BlockDetails: FunctionComponent<BlockDetailsProps> = ({
key === "shard" ? ( key === "shard" ? (
<Text size={"small"}>{blockNumber}</Text> <Text size={"small"}>{blockNumber}</Text>
) : ( ) : (
blockDisplayValues(block, key, (block as any)[key]) blockDisplayValues(block, key, (block as any)[key], isNewAddress)
); );
arr.push({ key, value } as tableEntry); arr.push({ key, value } as tableEntry);

@ -21,6 +21,12 @@ import { toaster } from "src/App";
import { Box, Text } from "grommet"; import { Box, Text } from "grommet";
import styled from "styled-components"; import styled from "styled-components";
export const StyledBox = styled(Box)`
transition: all 0.2s linear;
border-radius: 2px;
padding-left: 5px;
`;
const Icon = styled(StatusGood)` const Icon = styled(StatusGood)`
margin-right: 5px; margin-right: 5px;
`; `;
@ -115,18 +121,39 @@ const emptyMixHash =
export const blockPropertyDisplayValues: any = { export const blockPropertyDisplayValues: any = {
// @ts-ignore // @ts-ignore
number: (value: any) => ( number: (value: any, data, isNewAddress) => (
<> <>
<BlockNumber number={value} /> <StyledBox
&nbsp; direction={"row"}
{value > 0 && ( background={isNewAddress ? "backgroundSuccess" : ""}
<Link to={`/block/${+value - 1}`}> style={{ maxWidth: "125px" }}
<FormPreviousLink size="small" color="brand" /> align={"center"}
>
<CopyBtn
value={value}
onClick={() =>
toaster.show({
message: () => (
<Box direction={"row"} align={"center"} pad={"small"}>
<Icon size={"small"} color={"headerText"} />
<Text size={"small"}>Copied to clipboard</Text>
</Box>
),
})
}
/>
&nbsp;
<BlockNumber number={value} />
&nbsp;
{value > 0 && (
<Link to={`/block/${+value - 1}`}>
<FormPreviousLink size="small" color="brand" />
</Link>
)}
<Link to={`/block/${+value + 1}`}>
<FormNextLink size="small" color="brand" />
</Link> </Link>
)} </StyledBox>
<Link to={`/block/${+value + 1}`}>
<FormNextLink size="small" color="brand" />
</Link>
</> </>
), ),
transactions: (value: any[]) => transactions: (value: any[]) =>
@ -188,13 +215,18 @@ export const blockPropertyDisplayValues: any = {
size: (value: any) => <>{formatNumber(+value)}</>, size: (value: any) => <>{formatNumber(+value)}</>,
}; };
export const blockDisplayValues = (block: Block, key: string, value: any) => { export const blockDisplayValues = (
block: Block,
key: string,
value: any,
isNewAddress: boolean
) => {
const f = blockPropertyDisplayValues[key]; const f = blockPropertyDisplayValues[key];
let displayValue = value; let displayValue = value;
if (f) { if (f) {
displayValue = f(value, block); displayValue = f(value, block, isNewAddress);
} else { } else {
if (Array.isArray(value)) { if (Array.isArray(value)) {
displayValue = value.join(", "); displayValue = value.join(", ");
@ -217,7 +249,7 @@ export const blockDisplayValues = (block: Block, key: string, value: any) => {
key key
) && ) &&
!["0x", "0", 0, null].includes(displayValue) && !["0x", "0", 0, null].includes(displayValue) &&
!["miner"].find((item) => item === key) && ( !["miner", "number"].find((item) => item === key) && (
<> <>
<CopyBtn <CopyBtn
value={value} value={value}

@ -1,4 +1,4 @@
import React from "react"; import React, { useEffect, useState } from "react";
import { Box, Text, Tip } from "grommet"; import { Box, Text, Tip } from "grommet";
import { import {
Address, Address,
@ -15,7 +15,13 @@ import { ONEValueDropdown } from "src/components/ui/OneValueDropdown";
import { binanceAddressMap } from "src/config/BinanceAddressMap"; import { binanceAddressMap } from "src/config/BinanceAddressMap";
import { useERC1155Pool } from "src/hooks/ERC1155_Pool"; import { useERC1155Pool } from "src/hooks/ERC1155_Pool";
import { CircleQuestion } from "grommet-icons"; import { CircleQuestion } from "grommet-icons";
import styled from "styled-components";
export const StyledBox = styled(Box)`
transition: all .2s linear;
border-radius: 2px;
padding-left: 5px;
`
interface AddressDetailsProps { interface AddressDetailsProps {
address: string; address: string;
contracts: AddressDetails | null; contracts: AddressDetails | null;
@ -27,12 +33,24 @@ export function AddressDetailsDisplay(props: AddressDetailsProps) {
const { address, contracts, tokens, balance } = props; const { address, contracts, tokens, balance } = props;
const erc20Map = useERC20Pool(); const erc20Map = useERC20Pool();
const erc1155Map = useERC1155Pool(); const erc1155Map = useERC1155Pool();
const [isNewAddress, setIsNewAddress] = useState<boolean>(false);
const erc20Token = erc20Map[address] || null; const erc20Token = erc20Map[address] || null;
const type = getType(contracts, erc20Token); const type = getType(contracts, erc20Token);
const erc1151data = erc1155Map[address] || {}; const erc1151data = erc1155Map[address] || {};
const { meta = {}, ...restErc1151data } = erc1151data; const { meta = {}, ...restErc1151data } = erc1151data;
useEffect(() => {
let tId = 0;
const getActiveIndex = () => {
setIsNewAddress(true);
tId = window.setTimeout(() => setIsNewAddress(false), 1000);
};
getActiveIndex();
return () => clearTimeout(tId);
}, [address]);
const data = { const data = {
...contracts, ...contracts,
...erc20Token, ...erc20Token,
@ -53,7 +71,13 @@ export function AddressDetailsDisplay(props: AddressDetailsProps) {
<Box> <Box>
{items.sort(sortByOrder).map((i) => ( {items.sort(sortByOrder).map((i) => (
//@ts-ignore //@ts-ignore
<DetailItem key={i} name={i} data={data} type={type} /> <DetailItem
key={i}
name={i}
data={data}
type={type}
isNewAddress={isNewAddress}
/>
))} ))}
</Box> </Box>
); );
@ -83,8 +107,13 @@ export const Item = (props: { label: any; value: any }) => {
); );
}; };
function DetailItem(props: { data: any; name: string; type: TAddressType }) { function DetailItem(props: {
const { data, name, type } = props; data: any;
name: string;
type: TAddressType;
isNewAddress: boolean;
}) {
const { data, name, type, isNewAddress } = props;
if ( if (
!addressPropertyDisplayNames[name] || !addressPropertyDisplayNames[name] ||
@ -97,7 +126,12 @@ function DetailItem(props: { data: any; name: string; type: TAddressType }) {
return ( return (
<Item <Item
label={addressPropertyDisplayNames[name](data, { type })} label={addressPropertyDisplayNames[name](data, { type })}
value={addressPropertyDisplayValues[name](data[name], data, { type })} value={addressPropertyDisplayValues[name](
data[name],
data,
{ type },
isNewAddress
)}
/> />
); );
} }
@ -128,13 +162,24 @@ const addressPropertyDisplayNames: Record<
const addressPropertyDisplayValues: Record< const addressPropertyDisplayValues: Record<
string, string,
(value: any, data: any, options: { type: TAddressType }) => React.ReactNode (
value: any,
data: any,
options: { type: TAddressType },
isNewAddress: boolean
) => React.ReactNode
> = { > = {
address: (value, data, options: { type: TAddressType }) => { address: (value, data, options: { type: TAddressType }, isNewAddress) => {
return ( return (
<> <>
<Address address={value} displayHash /> <StyledBox
{binanceAddressMap[value] ? ` (${binanceAddressMap[value]})` : null} direction={"row"}
background={isNewAddress ? "backgroundSuccess" : ""}
style={{ maxWidth: "550px" }}
>
<Address address={value} displayHash />
{binanceAddressMap[value] ? ` (${binanceAddressMap[value]})` : null}
</StyledBox>
</> </>
); );
}, },
@ -203,7 +248,6 @@ const addressPropertyDisplayValues: Record<
description: (value) => <>{value}</>, description: (value) => <>{value}</>,
transactionHash: (value) => <Address address={value} type={"tx"} />, transactionHash: (value) => <Address address={value} type={"tx"} />,
circulatingSupply: (value, data) => ( circulatingSupply: (value, data) => (
<Box direction={"row"}> <Box direction={"row"}>
<TokenValue <TokenValue
value={value} value={value}
@ -227,7 +271,6 @@ const addressPropertyDisplayValues: Record<
</span> </span>
</Tip> </Tip>
</Box> </Box>
), ),
}; };

Loading…
Cancel
Save