Hotfix for erc1155 holders count

pull/273/head
artemkolodko 2 years ago
parent 5966a5b6fe
commit ae778f25d0
  1. 7
      src/pages/AddressPage/AddressDetails.tsx
  2. 21
      src/pages/AddressPage/index.tsx
  3. 4
      src/pages/AddressPage/tabs/holders/HoldersTab.tsx

@ -38,10 +38,11 @@ interface AddressDetailsProps {
tokens: any[]; tokens: any[];
balance?: string; balance?: string;
delegations: StakingDelegation[] delegations: StakingDelegation[]
holdersCount?: number
} }
export function AddressDetailsDisplay(props: AddressDetailsProps) { export function AddressDetailsDisplay(props: AddressDetailsProps) {
const { address, addressDescription, contracts, contractShardId, tokens, balance, delegations } = props; const { address, addressDescription, contracts, contractShardId, tokens, balance, delegations, holdersCount } = props;
const erc20Map = useERC20Pool(); const erc20Map = useERC20Pool();
const erc721Map = useERC721Pool(); const erc721Map = useERC721Pool();
const erc1155Map = useERC1155Pool(); const erc1155Map = useERC1155Pool();
@ -78,6 +79,10 @@ export function AddressDetailsDisplay(props: AddressDetailsProps) {
contractShardId contractShardId
}; };
if(holdersCount) {
data.holders = holdersCount
}
if (!data) { if (!data) {
return null; return null;
} }

@ -53,6 +53,7 @@ export function AddressPage() {
IUserERC721Assets[] IUserERC721Assets[]
>([]); >([]);
const [activeIndex, setActiveIndex] = useState(activeTab); const [activeIndex, setActiveIndex] = useState(activeTab);
const [holdersCount, setHoldersCount] = useState<number | undefined>()
const erc20Map = useERC20Pool(); const erc20Map = useERC20Pool();
const erc721Map = useERC721Pool(); const erc721Map = useERC721Pool();
const erc1155Map = useERC1155Pool(); const erc1155Map = useERC1155Pool();
@ -171,7 +172,25 @@ export function AddressPage() {
item.type = type; item.type = type;
return item; return item;
}) })
if(type === 'erc1155') {
items = items.filter((item) => item && item.ownerAddress && item.ownerAddress.startsWith('0x'))
}
setInventory(items); setInventory(items);
// TODO remove after fix on backend, workaround
if(type === "erc1155") {
const holdersMap = items
.reduce((acc, nextItem) => {
const { ownerAddress } = nextItem
if(ownerAddress && !acc[ownerAddress.toLowerCase()]) {
acc[ownerAddress.toLowerCase()] = true
}
return acc
}, {} as Record<string, boolean>)
setHoldersCount(Object.keys(holdersMap).length)
}
} else { } else {
setInventory([]); setInventory([]);
} }
@ -289,6 +308,7 @@ export function AddressPage() {
tokens={tokens} tokens={tokens}
balance={balance} balance={balance}
delegations={delegations} delegations={delegations}
holdersCount={holdersCount}
/> />
</BasePage> </BasePage>
<BasePage margin={{ top: "15px" }}> <BasePage margin={{ top: "15px" }}>
@ -329,6 +349,7 @@ export function AddressPage() {
id={id} id={id}
type={type} type={type}
inventory={inventory} inventory={inventory}
holdersCount={holdersCount}
/> />
</Tab> </Tab>
) : null} ) : null}

@ -81,12 +81,14 @@ export function HoldersTab(props: {
id: string; id: string;
type: "erc20" | "erc721" | "erc1155"; type: "erc20" | "erc721" | "erc1155";
inventory?: IUserERC721Assets[]; inventory?: IUserERC721Assets[];
holdersCount?: number
}) { }) {
const erc20Map = useERC20Pool(); const erc20Map = useERC20Pool();
const erc721Map = useERC721Pool(); const erc721Map = useERC721Pool();
const erc1155Map = useERC1155Pool(); const erc1155Map = useERC1155Pool();
const holdersTotal = let holdersTotal =
props.holdersCount ||
erc20Map[props.id]?.holders || erc20Map[props.id]?.holders ||
erc721Map[props.id]?.holders || erc721Map[props.id]?.holders ||
erc1155Map[props.id]?.holders; erc1155Map[props.id]?.holders;

Loading…
Cancel
Save