From 3658dadb793ed2ee0402a6a9d56b570953aeda5e Mon Sep 17 00:00:00 2001 From: hotequil Date: Tue, 22 Oct 2024 17:59:23 -0300 Subject: [PATCH] CU-86a5awrtq-NEON3 - BUG - Investigate issue where the app is consuming too much CPU --- .../src/components/ButtonDownloadPasswordQRCode.tsx | 3 ++- src/renderer/src/helpers/UtilsHelper.ts | 12 ++++++++++-- src/renderer/src/hooks/useExchange.ts | 1 - src/renderer/src/hooks/usePriceHistory.ts | 2 -- .../src/routes/pages/Receive/ReceivePageContent.tsx | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/components/ButtonDownloadPasswordQRCode.tsx b/src/renderer/src/components/ButtonDownloadPasswordQRCode.tsx index ac3b35cc..31e196c4 100644 --- a/src/renderer/src/components/ButtonDownloadPasswordQRCode.tsx +++ b/src/renderer/src/components/ButtonDownloadPasswordQRCode.tsx @@ -21,7 +21,8 @@ export const ButtonDownloadPasswordQRCode = ({ label, variant, leftIcon, onDownl const [decryptedPassword, setDecryptedPassword] = useState('') const handleDownload = () => { - UtilsHelper.donwloadSVGToPng('QRCode') + UtilsHelper.downloadSVGToPng('QRCode') + if (onDownload) onDownload() } diff --git a/src/renderer/src/helpers/UtilsHelper.ts b/src/renderer/src/helpers/UtilsHelper.ts index 84f49e7a..76e20bb5 100644 --- a/src/renderer/src/helpers/UtilsHelper.ts +++ b/src/renderer/src/helpers/UtilsHelper.ts @@ -114,7 +114,7 @@ export class UtilsHelper { return uuid.v4() } - static donwloadSVGToPng(elementId: string, suggestedFileName?: string) { + static downloadSVGToPng(elementId: string, suggestedFileName?: string) { const svg = document.getElementById(elementId) if (!svg) return @@ -132,13 +132,21 @@ export class UtilsHelper { img.onload = () => { canvas.width = img.width canvas.height = img.height + ctx.drawImage(img, 0, 0) + const pngFile = canvas.toDataURL('image/png') const downloadLink = document.createElement('a') + downloadLink.download = fileName - downloadLink.href = `${pngFile}` + downloadLink.href = pngFile downloadLink.click() + + canvas.remove() + downloadLink.remove() + img.remove() } + img.src = `data:image/svg+xml;base64,${btoa(svgData)}` } diff --git a/src/renderer/src/hooks/useExchange.ts b/src/renderer/src/hooks/useExchange.ts index 42c402a0..764ebd47 100644 --- a/src/renderer/src/hooks/useExchange.ts +++ b/src/renderer/src/hooks/useExchange.ts @@ -130,7 +130,6 @@ export function useExchange(params: TUseExchangeParams[]): TUseExchangeResult { currency, currencyRatio ), - staleTime: 0, enabled: !isCurrencyRatioLoading && typeof currencyRatio === 'number', })), combine: result => ({ diff --git a/src/renderer/src/hooks/usePriceHistory.ts b/src/renderer/src/hooks/usePriceHistory.ts index 60e2d696..110d18c2 100644 --- a/src/renderer/src/hooks/usePriceHistory.ts +++ b/src/renderer/src/hooks/usePriceHistory.ts @@ -42,8 +42,6 @@ export const usePriceHistory = (tokenBalances: TTokenBalance[]): TUsePriceHistor queries: tokenBalances.map(tokenBalance => ({ queryKey: ['prices', tokenBalance.token.symbol, currency], queryFn: fetchTokenData.bind(null, tokenBalance, currencyRatio), - staleTime: 0, - retry: false, enabled: !isCurrencyRatioLoading && typeof currencyRatio === 'number', })), combine: results => ({ diff --git a/src/renderer/src/routes/pages/Receive/ReceivePageContent.tsx b/src/renderer/src/routes/pages/Receive/ReceivePageContent.tsx index 0a4e2dca..752fef7e 100644 --- a/src/renderer/src/routes/pages/Receive/ReceivePageContent.tsx +++ b/src/renderer/src/routes/pages/Receive/ReceivePageContent.tsx @@ -20,7 +20,7 @@ export const ReceiveYourAddressContent = ({ account }: TProps) => { const [selectedAccount, setSelectedAccount] = useState(account) const handleDownload = () => { - UtilsHelper.donwloadSVGToPng('QRCode', selectedAccount?.address) + UtilsHelper.downloadSVGToPng('QRCode', selectedAccount?.address) } return (