diff --git a/src/pages/innerMod.tsx b/src/pages/innerMod.tsx index 7135d36..5992931 100644 --- a/src/pages/innerMod.tsx +++ b/src/pages/innerMod.tsx @@ -26,6 +26,7 @@ import { DownloadUrl, ModDetails, PaymentRequest } from '../types' import { abbreviateNumber, copyTextToClipboard, + downloadFile, extractModData, formatNumber, getFilenameFromUrl, @@ -35,7 +36,6 @@ import { unformatNumber } from '../utils' -import saveAs from 'file-saver' import { ZapButtons, ZapPresets, ZapQR } from '../components/Zap' export const InnerModPage = () => { @@ -580,7 +580,7 @@ const Download = ({ // Get the filename from the URL const filename = getFilenameFromUrl(url) - saveAs(url, filename) + downloadFile(url, filename) } return ( diff --git a/src/utils/url.ts b/src/utils/url.ts index 711432c..bb9e5e6 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -90,3 +90,32 @@ export const getFilenameFromUrl = (url: string): string => { // Return the extracted filename return filename } + +/** + * Downloads a file from the given URL. + * + * @param url - The URL of the file to download. + * @param filename - The name of the file to save as. + */ +export const downloadFile = (url: string, filename: string) => { + // Create a temporary anchor element + const a = document.createElement('a') + + // Set the href attribute to the file's URL + a.href = url + + // Set the download attribute with the desired file name + a.download = filename + + // Set target="_blank" to ensure that link opens in new tab + a.setAttribute('target', '_blank') + + // Append the anchor to the body (not displayed) + document.body.appendChild(a) + + // Programmatically trigger a click event on the anchor to start the download + a.click() + + // Remove the anchor from the document + document.body.removeChild(a) +}