use URL api to stringify payto://

This commit is contained in:
Sebastian 2023-01-16 19:34:44 -03:00
parent 99d7cbae04
commit 3cde52effc
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1

View File

@ -81,13 +81,12 @@ export function addPaytoQueryParams(
* @returns
*/
export function stringifyPaytoUri(p: PaytoUri): string {
const url = `${paytoPfx}${p.targetType}/${p.targetPath}`;
const url = new URL(`${paytoPfx}${p.targetType}/${p.targetPath}`);
const paramList = !p.params ? [] : Object.entries(p.params);
if (paramList.length > 0) {
const search = paramList.map(([key, value]) => `${key}=${value}`).join("&");
return `${url}?${search}`;
}
return url;
paramList.forEach(([key, value]) => {
url.searchParams.set(key, value)
})
return url.href;
}
/**