|
1 |
| -import { Col, Flex, Row, Skeleton, Tag, Typography } from 'antd'; |
| 1 | +import { Button, Col, Flex, Modal, Row, Skeleton, Tag, Typography } from 'antd'; |
| 2 | +import Image from 'next/image'; |
| 3 | +import { useCallback, useEffect, useState } from 'react'; |
2 | 4 | import styled from 'styled-components';
|
3 | 5 |
|
4 | 6 | import { balanceFormat } from '@/common-util';
|
5 | 7 | import { COLOR } from '@/constants';
|
6 | 8 | import { useBalance } from '@/hooks';
|
| 9 | +import { useElectronApi } from '@/hooks/useElectronApi'; |
7 | 10 | import { useReward } from '@/hooks/useReward';
|
8 | 11 |
|
9 |
| -const { Text } = Typography; |
| 12 | +import { ConfettiAnimation } from '../common/ConfettiAnimation'; |
| 13 | + |
| 14 | +const { Text, Title } = Typography; |
10 | 15 |
|
11 | 16 | const RewardsRow = styled(Row)`
|
12 | 17 | margin: 0 -24px;
|
@@ -70,8 +75,106 @@ const DisplayRewards = () => {
|
70 | 75 | );
|
71 | 76 | };
|
72 | 77 |
|
| 78 | +const NotifyRewards = () => { |
| 79 | + const { isEligibleForRewards, availableRewardsForEpochEth } = useReward(); |
| 80 | + const { totalOlasBalance } = useBalance(); |
| 81 | + const { showNotification } = useElectronApi(); |
| 82 | + |
| 83 | + const [canShowNotification, setCanShowNotification] = useState(false); |
| 84 | + |
| 85 | + useEffect(() => { |
| 86 | + // TODO: Implement this once state persistence is available |
| 87 | + const hasAlreadyNotified = true; |
| 88 | + |
| 89 | + if (!isEligibleForRewards) return; |
| 90 | + if (hasAlreadyNotified) return; |
| 91 | + if (!availableRewardsForEpochEth) return; |
| 92 | + |
| 93 | + setCanShowNotification(true); |
| 94 | + }, [isEligibleForRewards, availableRewardsForEpochEth, showNotification]); |
| 95 | + |
| 96 | + // hook to show app notification |
| 97 | + useEffect(() => { |
| 98 | + if (!canShowNotification) return; |
| 99 | + |
| 100 | + showNotification?.( |
| 101 | + 'Your agent earned its first staking rewards!', |
| 102 | + `Congratulations! Your agent just got the first reward for you! Your current balance: ${availableRewardsForEpochEth} OLAS`, |
| 103 | + ); |
| 104 | + }, [canShowNotification, availableRewardsForEpochEth, showNotification]); |
| 105 | + |
| 106 | + const closeNotificationModal = useCallback(() => { |
| 107 | + setCanShowNotification(false); |
| 108 | + // TODO: add setter for hasAlreadyNotified |
| 109 | + }, []); |
| 110 | + |
| 111 | + if (!canShowNotification) return null; |
| 112 | + |
| 113 | + return ( |
| 114 | + <Modal |
| 115 | + open={canShowNotification} |
| 116 | + width={400} |
| 117 | + onCancel={closeNotificationModal} |
| 118 | + footer={[ |
| 119 | + <Button |
| 120 | + key="back" |
| 121 | + type="primary" |
| 122 | + block |
| 123 | + size="large" |
| 124 | + className="mt-8" |
| 125 | + disabled |
| 126 | + // TODO: add twitter share functionality |
| 127 | + > |
| 128 | + <Flex align="center" justify="center" gap={2}> |
| 129 | + Share on |
| 130 | + <Image |
| 131 | + src="/twitter.svg" |
| 132 | + width={24} |
| 133 | + height={24} |
| 134 | + alt="Share on twitter" |
| 135 | + /> |
| 136 | + </Flex> |
| 137 | + </Button>, |
| 138 | + ]} |
| 139 | + > |
| 140 | + <ConfettiAnimation /> |
| 141 | + |
| 142 | + <Flex align="center" justify="center"> |
| 143 | + <Image |
| 144 | + src="/splash-robot-head.png" |
| 145 | + width={100} |
| 146 | + height={100} |
| 147 | + alt="OLAS logo" |
| 148 | + /> |
| 149 | + </Flex> |
| 150 | + |
| 151 | + <Title level={5} className="mt-12"> |
| 152 | + Your agent just earned the first reward! |
| 153 | + </Title> |
| 154 | + |
| 155 | + <Flex vertical gap={16}> |
| 156 | + <Text> |
| 157 | + Congratulations! Your agent just earned the first |
| 158 | + <Text strong> |
| 159 | + {` ${balanceFormat(availableRewardsForEpochEth, 2)} OLAS `} |
| 160 | + </Text> |
| 161 | + for you! |
| 162 | + </Text> |
| 163 | + |
| 164 | + <Text> |
| 165 | + Your current balance: |
| 166 | + <Text strong>{` ${balanceFormat(totalOlasBalance, 2)} OLAS `}</Text> |
| 167 | + </Text> |
| 168 | + |
| 169 | + <Text>Keep it running to get even more!</Text> |
| 170 | + </Flex> |
| 171 | + </Modal> |
| 172 | + ); |
| 173 | +}; |
| 174 | + |
73 | 175 | export const MainRewards = () => (
|
74 | 176 | <>
|
75 | 177 | <DisplayRewards />
|
| 178 | + <NotifyRewards /> |
76 | 179 | </>
|
77 | 180 | );
|
0 commit comments