feat: fix download flow
All checks were successful
Release to Staging / build_and_release (push) Successful in 42s

This commit is contained in:
daniyal 2024-08-14 15:06:13 +05:00
parent 62a8207bcd
commit 36f9f976ac
2 changed files with 31 additions and 2 deletions

View File

@ -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 (

View File

@ -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)
}