From 02e9726c6f5034e6036438eac1998fb1b5488338 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 19 Jan 2024 17:26:30 +0200 Subject: [PATCH] Fix shuffle of creators list --- src/components/creatorsStaking/Creators/index.tsx | 13 ++++++++----- .../creatorsStaking/hooks/useSortCreators.tsx | 11 +++++++---- .../interesting-accounts/InterestingAccounts.tsx | 2 +- src/components/txHistory/transactions/Transfer.tsx | 1 - 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/components/creatorsStaking/Creators/index.tsx b/src/components/creatorsStaking/Creators/index.tsx index 24f06347..24734158 100644 --- a/src/components/creatorsStaking/Creators/index.tsx +++ b/src/components/creatorsStaking/Creators/index.tsx @@ -31,20 +31,23 @@ type AllCreatorsProps = { spaceIds?: string[] era?: string sortBy: string + isMyCreators: boolean } const CreatorsCards = ({ spaceIds, era, sortBy, + isMyCreators, ...modalProps }: AllCreatorsProps) => { // const [ page, setPage ] = useState(1) - const sortedSpaceIds = useSortBy(sortBy, spaceIds, era) + const sortedSpaceIds = useSortBy(sortBy, spaceIds, era, isMyCreators) + const ids = - sortedSpaceIds && !isEmptyArray(sortedSpaceIds) ? sortedSpaceIds : spaceIds - + sortedSpaceIds && !isEmptyArray(sortedSpaceIds) ? sortedSpaceIds : spaceIds + if (!ids || isEmptyArray(ids)) return (
@@ -119,14 +122,14 @@ const CreatorsSectionInner = ({ id: 'all-creators', text: 'All Creators', content: () => ( - + ), }, { id: 'my-creators', text: `My Creators (${isMulti ? 0 : myCreatorsIds.length || 0})`, content: () => ( - + ), disabled: myCreatorsIds.length === 0 || isMulti, }, diff --git a/src/components/creatorsStaking/hooks/useSortCreators.tsx b/src/components/creatorsStaking/hooks/useSortCreators.tsx index 81de59e2..a3610466 100644 --- a/src/components/creatorsStaking/hooks/useSortCreators.tsx +++ b/src/components/creatorsStaking/hooks/useSortCreators.tsx @@ -22,7 +22,8 @@ const sortValues = ( export const useSortBy = ( sortBy: string, spaceIds?: string[], - era?: string + era?: string, + isMyCreators?: boolean ) => { const myAddress = useMyAddress() const backersInfo = useBackerInfoBySpaces(spaceIds, myAddress) @@ -39,11 +40,12 @@ export const useSortBy = ( } else if (sortBy === 'my-stake') { return sortValues(backersInfo, 'totalStaked') } else { - const isNewSpaceIdsArr = !isEmptyArray( + const isNewSpaceIdsArr = isMyCreators ? !isEmptyArray( spaceIds?.filter((spaceId) => shuffledSpaceIds?.includes(spaceId)) || [] - ) - + ) : true + if (!shuffledSpaceIds?.length && isNewSpaceIdsArr) { + setShuffledSpaceIds(shuffle(spaceIds)) } @@ -57,5 +59,6 @@ export const useSortBy = ( myAddress, ]) + return sortedSpaceIds } diff --git a/src/components/interesting-accounts/InterestingAccounts.tsx b/src/components/interesting-accounts/InterestingAccounts.tsx index 08cd0465..0a5365b2 100644 --- a/src/components/interesting-accounts/InterestingAccounts.tsx +++ b/src/components/interesting-accounts/InterestingAccounts.tsx @@ -36,7 +36,7 @@ export const PreviewAccountsGrid: FC = () => { return (
- + diff --git a/src/components/txHistory/transactions/Transfer.tsx b/src/components/txHistory/transactions/Transfer.tsx index 95a7e263..3e501a31 100644 --- a/src/components/txHistory/transactions/Transfer.tsx +++ b/src/components/txHistory/transactions/Transfer.tsx @@ -226,7 +226,6 @@ const MobileTransfer = ({ const [ open, setOpen ] = useState(false) const titleByKind = txKind === 'TRANSFER_TO' ? 'Received from' : 'Sent to' - console.log(extrinsicHash) return ( <>
setOpen(true)}>