Skip to content

Commit

Permalink
feat: add warning to download filenames
Browse files Browse the repository at this point in the history
closes #623
  • Loading branch information
dni authored and michael1011 committed Jul 15, 2024
1 parent ebb59de commit e4e76c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
13 changes: 5 additions & 8 deletions src/components/DownloadRefund.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ import QRCode from "qrcode/lib/server";

import { useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";
import { download, downloadJson } from "../utils/download";
import { download, downloadJson, getRefundFileName } from "../utils/download";
import { isIos, isMobile } from "../utils/helper";

const getRefundFileName = (swap: any): string => {
return `boltz-refund-${swap.id}`;
};

const downloadRefundJson = (swap: any) => {
downloadJson(getRefundFileName(swap), swap);
downloadJson(getRefundFileName(swap.id), swap);
};

const DownloadRefund = () => {
Expand All @@ -27,11 +23,12 @@ const DownloadRefund = () => {
newTab.document.body.innerHTML = `
<!DOCTYPE html>
<body>
<h1>${t("ios_image_download_do_not_share")}</h1>
<h2>${t("ios_image_download")}</h2>
<img src="${url}">
<h1>${t("ios_image_download")}</h1>
</body>`;
} else {
download(`${getRefundFileName(swap)}.png`, url);
download(`${getRefundFileName(swap.id)}.png`, url);
}
})
.catch((err: Error) => {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const dict = {
refund_explainer: "You will be able to refund after the timeout",
swap_not_refundable_yet: "Your swap is not refundable yet",
wasm_not_supported: "Please activate WebAssembly in your browser",
ios_image_download_do_not_share: "SECRET! DO NOT SHARE!",
ios_image_download:
'Long press and select "Save to Photos" to download refund file',
created: "Created",
Expand Down
4 changes: 2 additions & 2 deletions src/pages/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SwapList from "../components/SwapList";
import SettingsCog from "../components/settings/SettingsCog";
import SettingsMenu from "../components/settings/SettingsMenu";
import { useGlobalContext } from "../context/Global";
import { downloadJson } from "../utils/download";
import { downloadJson, getBackupFileName } from "../utils/download";
import { isIos } from "../utils/helper";
import { latestStorageVersion, migrateBackupFile } from "../utils/migration";
import { SomeSwap } from "../utils/swapCreator";
Expand Down Expand Up @@ -63,7 +63,7 @@ const History = () => {
};

const backupLocalStorage = async () => {
downloadJson(`boltz-backup-${Math.floor(Date.now() / 1000)}`, {
downloadJson(getBackupFileName(), {
version: latestStorageVersion,
swaps: await getSwaps(),
});
Expand Down
8 changes: 8 additions & 0 deletions src/utils/download.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export const getBackupFileName = (): string => {
return `boltz-backup-${Math.floor(Date.now() / 1000)}-SECRET_DO_NOT_SHARE`;
};

export const getRefundFileName = (swapId: string): string => {
return `boltz-refund-${swapId}-SECRET_DO_NOT_SHARE`;
};

export const download = (file: string, content: string) => {
const hidden = document.createElement("a");
hidden.download = file;
Expand Down

0 comments on commit e4e76c5

Please sign in to comment.