Skip to content

Commit 7267f37

Browse files
feat: download image and gho success image events (#1698)
1 parent 6fd6660 commit 7267f37

File tree

4 files changed

+78
-29
lines changed

4 files changed

+78
-29
lines changed

src/components/transactions/Borrow/GhoBorrowSuccessView.tsx

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { InterestRate } from '@aave/contract-helpers';
22
import { ExternalLinkIcon } from '@heroicons/react/outline';
33
import { CheckIcon } from '@heroicons/react/solid';
44
import { Trans } from '@lingui/macro';
5-
import { ContentCopyOutlined, Twitter } from '@mui/icons-material';
5+
import { ContentCopyOutlined, Download, Twitter } from '@mui/icons-material';
66
import {
77
Box,
88
Button,
@@ -21,6 +21,8 @@ import { LensterIcon } from 'src/components/icons/LensterIcon';
2121
import { compactNumber, FormattedNumber } from 'src/components/primitives/FormattedNumber';
2222
import { useModalContext } from 'src/hooks/useModal';
2323
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';
24+
import { useRootStore } from 'src/store/root';
25+
import { GHO_SUCCESS_MODAL } from 'src/utils/mixPanelEvents';
2426

2527
const GhoSuccessImage = dynamic(() => import('./GhoSuccessImage'));
2628

@@ -42,7 +44,7 @@ const CopyImageButton = styled(Button)(() => ({
4244
},
4345
backdropFilter: 'blur(5px)',
4446
border: '1px solid #FFFFFF20',
45-
}));
47+
})) as typeof Button;
4648

4749
const IconButtonCustom = styled(IconButton)(() => ({
4850
backgroundColor: 'white',
@@ -60,7 +62,7 @@ const ImageContainer = styled(Box)(() => ({
6062
position: 'relative',
6163
overflow: 'hidden',
6264
'&:hover': {
63-
'.image-bar': {
65+
'.image-bar-gho': {
6466
display: 'flex',
6567
bottom: 30,
6668
},
@@ -109,10 +111,11 @@ export const GhoBorrowSuccessView = ({ txHash, action, amount, symbol }: Success
109111
const canvasRef = useRef<HTMLCanvasElement>(null);
110112
const theme = useTheme();
111113
const downToXSM = useMediaQuery(theme.breakpoints.down('xsm'));
114+
const trackEvent = useRootStore((store) => store.trackEvent);
112115

113116
const compactedNumber = compactNumber({ value: amount, visibleDecimals: 2, roundDown: true });
114117
const finalNumber = `${compactedNumber.prefix}${compactedNumber.postfix}`;
115-
const isFirefox = navigator.userAgent.indexOf('Firefox') > -1;
118+
const canCopyImage = typeof ClipboardItem !== 'undefined';
116119

117120
const onCopyImage = () => {
118121
if (generatedBlob) {
@@ -123,10 +126,14 @@ export const GhoBorrowSuccessView = ({ txHash, action, amount, symbol }: Success
123126
}),
124127
])
125128
.then(() => {
129+
trackEvent(GHO_SUCCESS_MODAL.GHO_COPY_IMAGE);
126130
setClickedCopyImage(true);
127131
setTimeout(() => {
128132
setClickedCopyImage(false);
129133
}, COPY_IMAGE_TIME);
134+
})
135+
.catch(() => {
136+
trackEvent(GHO_SUCCESS_MODAL.GHO_FAIL_COPY_IMAGE);
130137
});
131138
}
132139
};
@@ -204,6 +211,7 @@ export const GhoBorrowSuccessView = ({ txHash, action, amount, symbol }: Success
204211
variant="outlined"
205212
size="small"
206213
endIcon={<ExtLinkIcon style={{ fontSize: 12 }} />}
214+
onClick={() => trackEvent(GHO_SUCCESS_MODAL.GHO_BORROW_VIEW_TX_DETAILS)}
207215
href={currentNetworkConfig.explorerLinkBuilder({
208216
tx: txHash ? txHash : mainTxState.txHash,
209217
})}
@@ -217,50 +225,78 @@ export const GhoBorrowSuccessView = ({ txHash, action, amount, symbol }: Success
217225
<Trans>Save and share</Trans>
218226
</Typography>
219227
<canvas style={{ display: 'none' }} width={1169} height={900} ref={canvasRef} />
220-
{generatedImage ? (
228+
{generatedImage && generatedBlob ? (
221229
<ImageContainer>
222230
<img
223231
src={generatedImage}
224232
alt="minted gho"
225233
style={{ maxWidth: '100%', borderRadius: '10px' }}
226234
/>
227-
<ImageBar className="image-bar">
228-
<CopyImageButton
229-
disabled={clickedCopyImage}
230-
onClick={onCopyImage}
231-
sx={{
232-
display: isFirefox ? 'none' : 'flex',
233-
}}
234-
variant="outlined"
235-
size="large"
236-
startIcon={
237-
clickedCopyImage ? (
238-
<SvgIcon sx={{ color: 'white', fontSize: 16 }}>
239-
<CheckIcon />
240-
</SvgIcon>
241-
) : (
242-
<ContentCopyOutlined style={{ fontSize: 16, fill: 'white' }} />
243-
)
244-
}
245-
>
246-
<Typography variant="buttonS" color="white">
247-
{clickedCopyImage ? <Trans>COPIED!</Trans> : <Trans>COPY IMAGE</Trans>}
248-
</Typography>
249-
</CopyImageButton>
235+
<ImageBar className="image-bar-gho">
236+
{canCopyImage ? (
237+
<CopyImageButton
238+
disabled={clickedCopyImage}
239+
onClick={onCopyImage}
240+
sx={{
241+
display: 'flex',
242+
}}
243+
variant="outlined"
244+
size="large"
245+
startIcon={
246+
clickedCopyImage ? (
247+
<SvgIcon sx={{ color: 'white', fontSize: 16 }}>
248+
<CheckIcon />
249+
</SvgIcon>
250+
) : (
251+
<ContentCopyOutlined style={{ fontSize: 16, fill: 'white' }} />
252+
)
253+
}
254+
>
255+
<Typography variant="buttonS" color="white">
256+
{clickedCopyImage ? <Trans>COPIED!</Trans> : <Trans>COPY IMAGE</Trans>}
257+
</Typography>
258+
</CopyImageButton>
259+
) : (
260+
<CopyImageButton
261+
download={'minted_gho.png'}
262+
href={URL.createObjectURL(generatedBlob)}
263+
onClick={() => trackEvent(GHO_SUCCESS_MODAL.GHO_DOWNLOAD_IMAGE)}
264+
sx={{
265+
display: 'flex',
266+
}}
267+
variant="outlined"
268+
size="large"
269+
startIcon={
270+
clickedCopyImage ? (
271+
<SvgIcon sx={{ color: 'white', fontSize: 16 }}>
272+
<CheckIcon />
273+
</SvgIcon>
274+
) : (
275+
<Download style={{ fontSize: 16, fill: 'white' }} />
276+
)
277+
}
278+
>
279+
<Typography variant="buttonS" color="white">
280+
<Trans>Download</Trans>
281+
</Typography>
282+
</CopyImageButton>
283+
)}
250284
<IconButtonCustom
251285
target="_blank"
252286
href={`https://lenster.xyz/?url=${
253287
window.location.href
254288
}&text=${`I just minted ${finalNumber} GHO`}&hashtags=Aave&preview=true`}
255289
size="small"
256290
sx={{ ml: 'auto' }}
291+
onClick={() => trackEvent(GHO_SUCCESS_MODAL.GHO_SHARE_LENSTER)}
257292
>
258293
<LensterIcon sx={{ fill: '#845EEE' }} fontSize="small" />
259294
</IconButtonCustom>
260295
<IconButtonCustom
261296
target="_blank"
262297
href={`https://twitter.com/intent/tweet?text=I Just minted ${finalNumber} GHO`}
263298
sx={{ ml: 2 }}
299+
onClick={() => trackEvent(GHO_SUCCESS_MODAL.GHO_SHARE_TWITTER)}
264300
>
265301
<Twitter fontSize="small" sx={{ fill: '#33CEFF' }} />
266302
</IconButtonCustom>

src/locales/en/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ msgstr "Discountable amount"
881881
msgid "Docs"
882882
msgstr "Docs"
883883

884+
#: src/components/transactions/Borrow/GhoBorrowSuccessView.tsx
885+
msgid "Download"
886+
msgstr "Download"
887+
884888
#: src/components/Warnings/StETHCollateralWarning.tsx
885889
msgid "Due to internal stETH mechanics required for rebasing support, it is not possible to perform a collateral switch where stETH is the source token."
886890
msgstr "Due to internal stETH mechanics required for rebasing support, it is not possible to perform a collateral switch where stETH is the source token."

src/utils/mixPanelEvents.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,12 @@ export const SETTINGS = {
9595
LANGUAGE: 'Language selector',
9696
LANGUAGE_SELECTED: 'Language selected',
9797
};
98+
99+
export const GHO_SUCCESS_MODAL = {
100+
GHO_SHARE_TWITTER: 'Click share GHO borrow on Twitter',
101+
GHO_SHARE_LENSTER: 'Click share GHO borrow on Lenster',
102+
GHO_COPY_IMAGE: 'Click copy image on GHO borrow',
103+
GHO_DOWNLOAD_IMAGE: 'Click download image on GHO borrow',
104+
GHO_BORROW_VIEW_TX_DETAILS: 'Click view TX details on GHO borrow',
105+
GHO_FAIL_COPY_IMAGE: 'Failed to copy image to clipboard',
106+
};

0 commit comments

Comments
 (0)