-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add staking history items (#4690)
- Loading branch information
Showing
19 changed files
with
540 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/kit/src/views/Staking/components/LidoHistory/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
|
||
import { groupBy } from 'lodash'; | ||
|
||
import { | ||
Empty, | ||
NumberSizeableText, | ||
SectionList, | ||
YStack, | ||
} from '@onekeyhq/components'; | ||
import { ListItem } from '@onekeyhq/kit/src/components/ListItem'; | ||
import { formatDate } from '@onekeyhq/shared/src/utils/dateUtils'; | ||
import type { ILidoHistoryItem } from '@onekeyhq/shared/types/staking'; | ||
|
||
type ILidoHistoryProps = { | ||
items: ILidoHistoryItem[]; | ||
}; | ||
|
||
export const LidoHistory = ({ items }: ILidoHistoryProps) => { | ||
const sections = useMemo(() => { | ||
const result = groupBy(items, (item) => | ||
formatDate(new Date(item.timestamp * 1000), { hideTimeForever: true }), | ||
); | ||
return Object.entries(result) | ||
.map(([title, data]) => ({ title, data })) | ||
.sort((a, b) => b.data[0].timestamp - a.data[0].timestamp); | ||
}, [items]); | ||
|
||
const renderItem = useCallback( | ||
({ item }: { item: ILidoHistoryItem }) => ( | ||
<ListItem | ||
avatarProps={{ | ||
src: item.receive?.token.logoURI ?? item.send?.token.logoURI, | ||
}} | ||
title={item.label} | ||
subtitle="Lido" | ||
> | ||
<YStack alignItems="flex-end"> | ||
{item.receive ? ( | ||
<NumberSizeableText | ||
size="$bodyLgMedium" | ||
formatter="balance" | ||
formatterOptions={{ tokenSymbol: item.receive.token.symbol }} | ||
> | ||
{`+${item.receive.amount}`} | ||
</NumberSizeableText> | ||
) : null} | ||
{item.send ? ( | ||
<NumberSizeableText | ||
size="$bodyMd" | ||
formatter="balance" | ||
color="$textSubdued" | ||
formatterOptions={{ tokenSymbol: item.send.token.symbol }} | ||
> | ||
{`-${item.send.amount}`} | ||
</NumberSizeableText> | ||
) : null} | ||
</YStack> | ||
</ListItem> | ||
), | ||
[], | ||
); | ||
|
||
const renderSectionHeader = useCallback( | ||
({ | ||
section, | ||
}: { | ||
section: { | ||
title: string; | ||
}; | ||
}) => ( | ||
<SectionList.SectionHeader | ||
title={section.title} | ||
justifyContent="space-between" | ||
/> | ||
), | ||
[], | ||
); | ||
|
||
return ( | ||
<SectionList | ||
estimatedItemSize="$14" | ||
sections={sections} | ||
renderItem={renderItem} | ||
renderSectionHeader={renderSectionHeader} | ||
ListEmptyComponent={ | ||
<Empty | ||
icon="ClockTimeHistoryOutline" | ||
title="No Transactions Yet" | ||
description="Your transaction will appear here" | ||
/> | ||
} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.