-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
493 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { useGetAutoClaimQuery, useGetTimestampForHeightQuery, useGetHeightInfoQuery } from '@chia-network/api-react'; | ||
import { defineMessage } from '@lingui/macro'; | ||
import moment from 'moment'; | ||
|
||
import useTrans from './useTrans'; | ||
|
||
function getTextFromTransaction( | ||
transactionRow: any, | ||
t: any, | ||
lastBlockTimeStamp: number, | ||
isAutoClaimEnabled: any, | ||
isGetHeightInfoLoading: boolean, | ||
isGetTimestampForHeightLoading: boolean | ||
) { | ||
let text = ''; | ||
const canBeClaimedAt = moment((transactionRow?.timestamp || 0) * 1000); | ||
if (transactionRow?.timeLock) { | ||
canBeClaimedAt.add(transactionRow.timeLock, 'seconds'); | ||
} | ||
const currentTime = moment.unix(lastBlockTimeStamp - 20); // extra 20 seconds so if the auto claim is enabled, it will not show to button to claim it | ||
const timeLeft = canBeClaimedAt.diff(currentTime, 'seconds'); | ||
if (isGetHeightInfoLoading || isGetTimestampForHeightLoading || !lastBlockTimeStamp || transactionRow.claimed) | ||
return null; | ||
if (timeLeft > 0 && !transactionRow.passedTimeLock) { | ||
text = isAutoClaimEnabled | ||
? t( | ||
defineMessage({ | ||
message: 'Will be autoclaimed in ', | ||
}) | ||
) | ||
: t( | ||
defineMessage({ | ||
message: 'Can be claimed in ', | ||
}) | ||
); | ||
text += canBeClaimedAt.from(currentTime, true); // ... 3 days | ||
} else if (transactionRow?.sent === 0) { | ||
text = t( | ||
defineMessage({ | ||
message: 'Claim transaction', | ||
}) | ||
); | ||
} else { | ||
text = t( | ||
defineMessage({ | ||
message: 'Claiming...', | ||
}) | ||
); | ||
} | ||
return text; | ||
} | ||
|
||
export default function useGetTextFromTransaction(notification: any) { | ||
const { data: height, isLoading: isGetHeightInfoLoading } = useGetHeightInfoQuery(undefined, { | ||
pollingInterval: 3000, | ||
}); | ||
|
||
const { data: lastBlockTimeStampData, isLoading: isGetTimestampForHeightLoading } = useGetTimestampForHeightQuery({ | ||
height: height || 0, | ||
}); | ||
|
||
const { data: autoClaimData, isLoading: isGetAutoClaimLoading } = useGetAutoClaimQuery(); | ||
const isAutoClaimEnabled = !isGetAutoClaimLoading && autoClaimData?.enabled; | ||
|
||
let lastBlockTimeStamp: number = 0; | ||
|
||
if (!isGetTimestampForHeightLoading) { | ||
lastBlockTimeStamp = lastBlockTimeStampData?.timestamp || 0; | ||
} | ||
|
||
const t = useTrans(); | ||
|
||
return getTextFromTransaction( | ||
notification, | ||
t, | ||
lastBlockTimeStamp, | ||
isAutoClaimEnabled, | ||
isGetHeightInfoLoading, | ||
isGetTimestampForHeightLoading | ||
); | ||
} |
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
72 changes: 72 additions & 0 deletions
72
packages/gui/src/components/notification/NotificationClawbackTransaction.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,72 @@ | ||
import { useGetAutoClaimQuery, useGetTimestampForHeightQuery, useGetHeightInfoQuery } from '@chia-network/api-react'; | ||
import { Flex, MojoToChia, useTrans, useGetTextFromTransaction } from '@chia-network/core'; | ||
import { Trans } from '@lingui/macro'; | ||
import AccessTimeIcon from '@mui/icons-material/AccessTime'; | ||
import { Typography } from '@mui/material'; | ||
import React from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import HumanTimestamp from '../helpers/HumanTimestamp'; | ||
|
||
import NotificationWrapper from './NotificationWrapper'; | ||
|
||
export default function NotificationClawbackTransaction(props: any) { | ||
const { notification, onClick = () => {} } = props; | ||
|
||
const { data: height, isLoading: isGetHeightInfoLoading } = useGetHeightInfoQuery(undefined, { | ||
pollingInterval: 3000, | ||
}); | ||
|
||
const { data: lastBlockTimeStampData, isLoading: isGetTimestampForHeightLoading } = useGetTimestampForHeightQuery({ | ||
height: height || 0, | ||
}); | ||
|
||
const { data: autoClaimData, isLoading: isGetAutoClaimLoading } = useGetAutoClaimQuery(); | ||
const isAutoClaimEnabled = !isGetAutoClaimLoading && autoClaimData?.enabled; | ||
|
||
const lastBlockTimeStamp = lastBlockTimeStampData?.timestamp || 0; | ||
|
||
const t = useTrans(); | ||
|
||
const navigate = useNavigate(); | ||
|
||
function handleClick() { | ||
navigate('/dashboard/wallets'); | ||
onClick(); | ||
} | ||
|
||
function renderMessage() { | ||
if (notification.passedTimeLock) { | ||
return <Trans>Claw back transaction can be claimed</Trans>; | ||
} | ||
if (notification.claimed) { | ||
return <Trans>Transaction claimed</Trans>; | ||
} | ||
return <Trans>You have a new claw back transaction</Trans>; | ||
} | ||
|
||
return ( | ||
<NotificationWrapper onClick={handleClick} icon={<AccessTimeIcon sx={{ fontSize: '32px !important' }} />}> | ||
<Flex flexDirection="column"> | ||
<Typography variant="subtitle2" color="textSecondary"> | ||
{renderMessage()} | ||
{' · '} | ||
(<HumanTimestamp value={notification.timestamp} fromNow /> ago) | ||
<Flex> | ||
{useGetTextFromTransaction( | ||
notification, | ||
t, | ||
lastBlockTimeStamp, | ||
isAutoClaimEnabled, | ||
isGetHeightInfoLoading, | ||
isGetTimestampForHeightLoading | ||
)} | ||
</Flex> | ||
</Typography> | ||
<Typography variant="body2"> | ||
<MojoToChia value={notification.amount} /> | ||
</Typography> | ||
</Flex> | ||
</NotificationWrapper> | ||
); | ||
} |
132 changes: 132 additions & 0 deletions
132
packages/gui/src/components/notification/NotificationHistory.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,132 @@ | ||
import { | ||
Flex, | ||
LayoutDashboardSub, | ||
TableControlled, | ||
Row, | ||
MojoToChia, | ||
useGetTextFromTransaction, | ||
} from '@chia-network/core'; | ||
import { t, Trans } from '@lingui/macro'; | ||
import { Typography, Box } from '@mui/material'; | ||
import moment from 'moment'; | ||
import React, { useMemo } from 'react'; | ||
|
||
import NotificationType from '../../constants/NotificationType'; | ||
import useValidNotifications from '../../hooks/useValidNotifications'; | ||
import OfferDetails from '../offers2/OfferDetails'; | ||
|
||
function renderOfferText(notification: any, type: string) { | ||
const offerURLOrData = | ||
'offerURL' in notification | ||
? notification.offerURL | ||
: 'offerData' in notification | ||
? notification.offerData | ||
: undefined; | ||
|
||
if (type === 'asset') { | ||
return <OfferDetails id={offerURLOrData} forcePlainText />; | ||
} | ||
return <OfferDetails id={offerURLOrData} forcePlainText requested />; | ||
} | ||
|
||
const getCols = (getNotificationText: any) => [ | ||
{ | ||
field: (row: Row) => ( | ||
<Box | ||
component="span" | ||
sx={{ | ||
position: 'relative', | ||
top: '2px', | ||
marginRight: '2px', | ||
}} | ||
> | ||
{row.type === NotificationType.INCOMING_CLAWBACK_RECEIVE ? <Trans>Claw Back</Trans> : <Trans>Offer</Trans>} | ||
</Box> | ||
), | ||
title: t`Type`, | ||
}, | ||
{ | ||
field: (row: Row) => ( | ||
<Box | ||
component="span" | ||
sx={{ | ||
position: 'relative', | ||
top: '2px', | ||
marginRight: '2px', | ||
}} | ||
> | ||
{row.type === NotificationType.INCOMING_CLAWBACK_RECEIVE ? ( | ||
<MojoToChia value={row.amount} /> | ||
) : ( | ||
renderOfferText(row, 'asset') | ||
)} | ||
</Box> | ||
), | ||
title: t`Asset`, | ||
}, | ||
{ | ||
field: (row: Row) => ( | ||
<Box | ||
component="span" | ||
sx={{ | ||
position: 'relative', | ||
top: '2px', | ||
marginRight: '2px', | ||
}} | ||
> | ||
{row.type === NotificationType.INCOMING_CLAWBACK_RECEIVE | ||
? getNotificationText(row) | ||
: renderOfferText(row, 'requested')} | ||
</Box> | ||
), | ||
title: t`Status`, | ||
}, | ||
{ | ||
field: (row: Row) => ( | ||
<Box | ||
component="span" | ||
sx={{ | ||
position: 'relative', | ||
top: '2px', | ||
marginRight: '2px', | ||
}} | ||
> | ||
{moment(row.timestamp * 1000).format('LLL')} | ||
</Box> | ||
), | ||
title: t`Creation Date`, | ||
}, | ||
]; | ||
|
||
export default function NotificationHistory() { | ||
const { notifications = [] } = useValidNotifications(); | ||
|
||
const [page, setPage] = React.useState(0); | ||
|
||
function onPageChange(_: any, pageLocal: number) { | ||
setPage(pageLocal); | ||
} | ||
|
||
const limited = notifications.slice(page * 10, page * 10 + 10); | ||
|
||
const cols = useMemo(() => getCols(useGetTextFromTransaction), []); | ||
|
||
return ( | ||
<LayoutDashboardSub> | ||
<Flex flexDirection="column" gap={1}> | ||
<Typography variant="h5"> | ||
<Trans>Notification history</Trans> | ||
</Typography> | ||
<TableControlled | ||
cols={cols} | ||
rows={limited ?? []} | ||
page={page} | ||
count={notifications.length} | ||
uniqueField="name" | ||
pages={!!notifications.length} | ||
onPageChange={onPageChange} | ||
/> | ||
</Flex> | ||
</LayoutDashboardSub> | ||
); | ||
} |
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
Oops, something went wrong.