-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add low activity wallet warning
- Loading branch information
Showing
6 changed files
with
180 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { Address } from 'viem' | ||
import { isAddress } from 'viem' | ||
import { useTransactionCount } from 'wagmi' | ||
import { useFieldValues } from '../stores/form/useFieldValues.js' | ||
|
||
interface AddressActivity { | ||
hasActivity: boolean | ||
isLoading: boolean | ||
isFetched: boolean | ||
toAddress: string | undefined | ||
} | ||
|
||
export const useAddressActivity = (chainId?: number): AddressActivity => { | ||
const [toAddress, toChainId] = useFieldValues('toAddress', 'toChain') | ||
|
||
const destinationChainId = chainId ?? toChainId | ||
|
||
const { | ||
data: transactionCount, | ||
isLoading, | ||
isFetched, | ||
error, | ||
} = useTransactionCount({ | ||
address: toAddress as Address, | ||
chainId: destinationChainId, | ||
query: { | ||
enabled: Boolean(toAddress && destinationChainId && isAddress(toAddress)), | ||
refetchInterval: 300_000, | ||
staleTime: 300_000, | ||
}, | ||
}) | ||
|
||
return { | ||
toAddress, | ||
hasActivity: Boolean(transactionCount && transactionCount > 0), | ||
isLoading, | ||
isFetched: isFetched && !error, | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
packages/widget/src/pages/TransactionPage/ConfirmToAddressSheet.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,93 @@ | ||
import { Wallet, WarningRounded } from '@mui/icons-material' | ||
import { Button, Typography } from '@mui/material' | ||
import type { MutableRefObject } from 'react' | ||
import { forwardRef } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { BottomSheet } from '../../components/BottomSheet/BottomSheet.js' | ||
import type { BottomSheetBase } from '../../components/BottomSheet/types.js' | ||
import { AlertMessage } from '../../components/Messages/AlertMessage.js' | ||
import { useChain } from '../../hooks/useChain.js' | ||
import { useWidgetEvents } from '../../hooks/useWidgetEvents.js' | ||
import { WidgetEvent } from '../../types/events.js' | ||
import { | ||
IconContainer, | ||
SendToWalletButtonRow, | ||
SendToWalletSheetContainer, | ||
SheetAddressContainer, | ||
} from '../SendToWallet/SendToWalletPage.style.js' | ||
|
||
interface ConfirmToAddressSheetProps { | ||
onContinue: () => void | ||
toAddress: string | ||
toChainId: number | ||
} | ||
|
||
interface ConfirmToAddressSheetContentProps extends ConfirmToAddressSheetProps { | ||
onClose: () => void | ||
} | ||
|
||
export const ConfirmToAddressSheet = forwardRef< | ||
BottomSheetBase, | ||
ConfirmToAddressSheetProps | ||
>((props, ref) => { | ||
const handleClose = () => { | ||
;(ref as MutableRefObject<BottomSheetBase>).current?.close() | ||
} | ||
|
||
return ( | ||
<BottomSheet ref={ref}> | ||
<ConfirmToAddressSheetContent {...props} onClose={handleClose} /> | ||
</BottomSheet> | ||
) | ||
}) | ||
|
||
const ConfirmToAddressSheetContent: React.FC< | ||
ConfirmToAddressSheetContentProps | ||
> = ({ onContinue, onClose, toAddress, toChainId }) => { | ||
const { t } = useTranslation() | ||
const { chain } = useChain(toChainId) | ||
const emitter = useWidgetEvents() | ||
|
||
const handleContinue = () => { | ||
emitter.emit(WidgetEvent.LowAddressActivityConfirmed, { | ||
address: toAddress, | ||
chainId: toChainId, | ||
}) | ||
onClose() | ||
onContinue() | ||
} | ||
|
||
return ( | ||
<SendToWalletSheetContainer> | ||
<IconContainer> | ||
<Wallet sx={{ fontSize: 40 }} /> | ||
</IconContainer> | ||
<Typography variant="h6" sx={{ textAlign: 'center', mb: 2 }}> | ||
{t('warning.title.lowAddressActivity')} | ||
</Typography> | ||
<SheetAddressContainer> | ||
<Typography>{toAddress}</Typography> | ||
</SheetAddressContainer> | ||
<AlertMessage | ||
severity="warning" | ||
title={ | ||
<Typography variant="body2" sx={{ color: 'text.primary' }}> | ||
{t('warning.message.lowAddressActivity', { | ||
chainName: chain?.name, | ||
})} | ||
</Typography> | ||
} | ||
icon={<WarningRounded />} | ||
multiline | ||
/> | ||
<SendToWalletButtonRow> | ||
<Button variant="text" onClick={onClose} fullWidth> | ||
{t('button.cancel')} | ||
</Button> | ||
<Button variant="contained" onClick={handleContinue} fullWidth> | ||
{t('button.continue')} | ||
</Button> | ||
</SendToWalletButtonRow> | ||
</SendToWalletSheetContainer> | ||
) | ||
} |
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