Skip to content

Commit

Permalink
Merge pull request #138 from dappforce/fix-shuffle-creators
Browse files Browse the repository at this point in the history
Fix shuffle of creators list
  • Loading branch information
olehmell authored Jan 19, 2024
2 parents 9a1c9b9 + 02e9726 commit 2510121
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
13 changes: 8 additions & 5 deletions src/components/creatorsStaking/Creators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className='h-[261px] flex items-center justify-center'>
Expand Down Expand Up @@ -119,14 +122,14 @@ const CreatorsSectionInner = ({
id: 'all-creators',
text: 'All Creators',
content: () => (
<CreatorsCards spaceIds={spaceIds} era={era} sortBy={sortBy} />
<CreatorsCards isMyCreators={false} spaceIds={spaceIds} era={era} sortBy={sortBy} />
),
},
{
id: 'my-creators',
text: `My Creators (${isMulti ? 0 : myCreatorsIds.length || 0})`,
content: () => (
<CreatorsCards spaceIds={myCreatorsIds} era={era} sortBy={sortBy} />
<CreatorsCards isMyCreators={true} spaceIds={myCreatorsIds} era={era} sortBy={sortBy} />
),
disabled: myCreatorsIds.length === 0 || isMulti,
},
Expand Down
11 changes: 7 additions & 4 deletions src/components/creatorsStaking/hooks/useSortCreators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const sortValues = <T extends BackerInfoRecord | EraStakesBySpaceIdsRecord>(
export const useSortBy = (
sortBy: string,
spaceIds?: string[],
era?: string
era?: string,
isMyCreators?: boolean
) => {
const myAddress = useMyAddress()
const backersInfo = useBackerInfoBySpaces(spaceIds, myAddress)
Expand All @@ -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))
}

Expand All @@ -57,5 +59,6 @@ export const useSortBy = (
myAddress,
])


return sortedSpaceIds
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const PreviewAccountsGrid: FC = () => {
return (
<div>
<Row justify='space-between'>
<Col className={clsx({['w-100']: isMobile})}>
<Col className={clsx({ ['w-100']: isMobile })}>
<SectionTitle
title={t('interestingAccounts.title')}
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/txHistory/transactions/Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ const MobileTransfer = ({
const [ open, setOpen ] = useState(false)
const titleByKind = txKind === 'TRANSFER_TO' ? 'Received from' : 'Sent to'

console.log(extrinsicHash)
return (
<>
<div className={styles.TransferRow} onClick={() => setOpen(true)}>
Expand Down

0 comments on commit 2510121

Please sign in to comment.