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 * @returns
*/ */
export function stringifyPaytoUri(p: PaytoUri): string { 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); const paramList = !p.params ? [] : Object.entries(p.params);
if (paramList.length > 0) { paramList.forEach(([key, value]) => {
const search = paramList.map(([key, value]) => `${key}=${value}`).join("&"); url.searchParams.set(key, value)
return `${url}?${search}`; })
} return url.href;
return url;
} }
/** /**