-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dedicated notifications, add control hooks
- Loading branch information
Showing
10 changed files
with
331 additions
and
136 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
libs/oeth/shared/src/components/ActivityProvider/components/ActivityButton.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
40 changes: 0 additions & 40 deletions
40
libs/oeth/shared/src/components/ActivityProvider/components/ActivityIcon.tsx
This file was deleted.
Oops, something went wrong.
87 changes: 0 additions & 87 deletions
87
libs/oeth/shared/src/components/ActivityProvider/components/ActivityItem.tsx
This file was deleted.
Oops, something went wrong.
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
84 changes: 84 additions & 0 deletions
84
libs/oeth/shared/src/components/ActivityProvider/components/ApprovalNotification.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,84 @@ | ||
import { Box, Stack, Typography } from '@mui/material'; | ||
import { ActivityIcon, LinkIcon } from '@origin/shared/components'; | ||
import { isNilOrEmpty } from '@origin/shared/utils'; | ||
import { defineMessage, useIntl } from 'react-intl'; | ||
import { formatUnits } from 'viem'; | ||
|
||
import type { StackProps } from '@mui/material'; | ||
import type { Token } from '@origin/shared/contracts'; | ||
import type { MessageDescriptor } from 'react-intl'; | ||
import type { TransactionReceipt } from 'viem'; | ||
|
||
import type { GlobalActivityStatus } from '../types'; | ||
|
||
type ApprovalNotificationProps = { | ||
status: GlobalActivityStatus; | ||
tokenIn: Token; | ||
tokenOut: Token; | ||
amountIn?: bigint; | ||
txReceipt?: TransactionReceipt; | ||
error?: string; | ||
} & StackProps; | ||
|
||
const title: Record<GlobalActivityStatus, MessageDescriptor> = { | ||
pending: defineMessage({ defaultMessage: 'Approving' }), | ||
success: defineMessage({ defaultMessage: 'Approved' }), | ||
error: defineMessage({ defaultMessage: 'Error while approving' }), | ||
idle: defineMessage({ defaultMessage: 'Approve' }), | ||
}; | ||
|
||
export const ApprovalNotification = ({ | ||
status, | ||
tokenIn, | ||
tokenOut, | ||
amountIn, | ||
txReceipt, | ||
error, | ||
...rest | ||
}: ApprovalNotificationProps) => { | ||
const intl = useIntl(); | ||
|
||
return ( | ||
<Stack {...rest} direction="row" justifyContent="space-between"> | ||
<Stack spacing={1}> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
<ActivityIcon status={status} sx={{ width: 20, height: 20 }} /> | ||
<Typography>{intl.formatMessage(title[status])}</Typography> | ||
{!isNilOrEmpty(txReceipt?.transactionHash) && ( | ||
<LinkIcon | ||
size={10} | ||
url={`https://etherscan.io/tx/${txReceipt.transactionHash}`} | ||
/> | ||
)} | ||
</Stack> | ||
<Stack direction="row" alignItems="center"> | ||
{isNilOrEmpty(error) ? ( | ||
<Typography color="text.tertiary"> | ||
{intl.formatMessage( | ||
{ | ||
defaultMessage: '{amountIn} {symbolIn}', | ||
}, | ||
{ | ||
amountIn: intl.formatNumber( | ||
+formatUnits(amountIn, tokenIn.decimals), | ||
{ minimumFractionDigits: 4, maximumFractionDigits: 4 }, | ||
), | ||
symbolIn: tokenIn.symbol, | ||
}, | ||
)} | ||
</Typography> | ||
) : ( | ||
<Typography color="error">{error}</Typography> | ||
)} | ||
</Stack> | ||
</Stack> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
<Box | ||
component="img" | ||
src={tokenIn.icon} | ||
sx={{ width: 24, height: 24 }} | ||
/> | ||
</Stack> | ||
</Stack> | ||
); | ||
}; |
104 changes: 104 additions & 0 deletions
104
libs/oeth/shared/src/components/ActivityProvider/components/RedeemNotification.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,104 @@ | ||
import { Box, Stack, Typography } from '@mui/material'; | ||
import { ActivityIcon, LinkIcon, Mix } from '@origin/shared/components'; | ||
import { isNilOrEmpty } from '@origin/shared/utils'; | ||
import { defineMessage, useIntl } from 'react-intl'; | ||
import { formatUnits } from 'viem'; | ||
|
||
import type { StackProps } from '@mui/material'; | ||
import type { Token } from '@origin/shared/contracts'; | ||
import type { MessageDescriptor } from 'react-intl'; | ||
import type { TransactionReceipt } from 'viem'; | ||
|
||
import type { GlobalActivityStatus } from '../types'; | ||
|
||
type RedeemNotificationProps = { | ||
status: GlobalActivityStatus; | ||
tokenIn: Token; | ||
tokenOut: Token; | ||
amountIn?: bigint; | ||
amountOut?: bigint; | ||
txReceipt?: TransactionReceipt; | ||
error?: string; | ||
} & StackProps; | ||
|
||
const title: Record<GlobalActivityStatus, MessageDescriptor> = { | ||
pending: defineMessage({ defaultMessage: 'Redeeming' }), | ||
success: defineMessage({ defaultMessage: 'Redeemed' }), | ||
error: defineMessage({ defaultMessage: 'Error while redeeming' }), | ||
idle: defineMessage({ defaultMessage: 'Redeem' }), | ||
}; | ||
|
||
export const RedeemNotification = ({ | ||
status, | ||
tokenIn, | ||
tokenOut, | ||
amountIn, | ||
amountOut, | ||
txReceipt, | ||
error, | ||
...rest | ||
}: RedeemNotificationProps) => { | ||
const intl = useIntl(); | ||
|
||
return ( | ||
<Stack {...rest} direction="row" justifyContent="space-between"> | ||
<Stack spacing={1}> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
<ActivityIcon status={status} sx={{ width: 20, height: 20 }} /> | ||
<Typography>{intl.formatMessage(title[status])}</Typography> | ||
{!isNilOrEmpty(txReceipt?.transactionHash) && ( | ||
<LinkIcon | ||
size={10} | ||
url={`https://etherscan.io/tx/${txReceipt.transactionHash}`} | ||
/> | ||
)} | ||
</Stack> | ||
<Stack direction="row" alignItems="center"> | ||
{isNilOrEmpty(error) ? ( | ||
<Typography color="text.tertiary"> | ||
{intl.formatMessage( | ||
{ | ||
defaultMessage: '{amountIn} {symbolIn}', | ||
}, | ||
{ | ||
amountIn: intl.formatNumber( | ||
+formatUnits(amountIn, tokenIn.decimals), | ||
{ minimumFractionDigits: 4, maximumFractionDigits: 4 }, | ||
), | ||
symbolIn: tokenIn.symbol, | ||
amountOut: intl.formatNumber( | ||
+formatUnits(amountOut, tokenOut.decimals), | ||
{ minimumFractionDigits: 4, maximumFractionDigits: 4 }, | ||
), | ||
}, | ||
)} | ||
</Typography> | ||
) : ( | ||
<Typography color="error">{error}</Typography> | ||
)} | ||
</Stack> | ||
</Stack> | ||
<Stack direction="row" alignItems="center" spacing={1}> | ||
<Box | ||
component="img" | ||
src={tokenIn.icon} | ||
sx={{ width: 24, height: 24 }} | ||
/> | ||
<Box | ||
component="img" | ||
src="images/arrow-right.svg" | ||
sx={{ width: 12, height: 12 }} | ||
/> | ||
<Mix | ||
imgSrc={[ | ||
'/images/currency/weth-icon-small.png', | ||
'/images/currency/reth-icon-small.png', | ||
'/images/currency/steth-icon-small.svg', | ||
'/images/currency/frxeth-icon-small.svg', | ||
]} | ||
size={1.5} | ||
/> | ||
</Stack> | ||
</Stack> | ||
); | ||
}; |
Oops, something went wrong.