From 042dd12e09f0797ce95f17b5e30a1b5c59842d2c Mon Sep 17 00:00:00 2001 From: apotdevin Date: Tue, 3 Aug 2021 11:21:59 +0200 Subject: [PATCH] chore: change download file name --- src/views/tools/backups/DownloadBackups.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/views/tools/backups/DownloadBackups.tsx b/src/views/tools/backups/DownloadBackups.tsx index 1e7d4767..5b3dd8df 100644 --- a/src/views/tools/backups/DownloadBackups.tsx +++ b/src/views/tools/backups/DownloadBackups.tsx @@ -1,7 +1,8 @@ import React, { useEffect } from 'react'; import { toast } from 'react-toastify'; import { useGetBackupsLazyQuery } from 'src/graphql/queries/__generated__/getBackups.generated'; -import { useAccount } from 'src/hooks/UseAccount'; +import { format } from 'date-fns'; +import { useNodeInfo } from 'src/hooks/UseNodeInfo'; import { DarkSubTitle, SingleLine } from '../../../components/generic/Styled'; import { saveToPc } from '../../../utils/helpers'; import { getErrorContent } from '../../../utils/error'; @@ -12,15 +13,16 @@ export const DownloadBackups = () => { onError: error => toast.error(getErrorContent(error)), }); - const account = useAccount(); + const { publicKey } = useNodeInfo(); useEffect(() => { - if (account && !loading && data && data.getBackups) { - saveToPc(data.getBackups, `ChannelBackup-${account.name}-${account.id}`); - localStorage.setItem(`lastBackup-${account.id}`, new Date().toString()); - toast.success('Downloaded'); - } - }, [data, loading, account]); + if (loading || !data?.getBackups) return; + + const date = format(new Date(), 'ddMMyyyyhhmmss'); + saveToPc(data.getBackups, `ChannelBackup-${publicKey}-${date}`); + localStorage.setItem(`lastBackup-${publicKey}`, new Date().toString()); + toast.success('Downloaded'); + }, [data, loading, publicKey]); return (