From 230ac21b6b0a07ba8eb0507757f440a053867622 Mon Sep 17 00:00:00 2001 From: oana-lolea Date: Mon, 16 Sep 2024 12:14:13 +0300 Subject: [PATCH] fix(frontend): concatenate correctly base url and path when creating a wallet address (#2960) * Added a function that removes trailing slashes if they exist in a string. * Renamed the helper function to 'removeTrailingAndLeadingSlash' and reverted original changes made to the URLs --- .../frontend/app/routes/wallet-addresses.create.tsx | 10 ++++++++-- packages/frontend/app/shared/utils.ts | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/frontend/app/routes/wallet-addresses.create.tsx b/packages/frontend/app/routes/wallet-addresses.create.tsx index 5681b3589f..75a352f430 100644 --- a/packages/frontend/app/routes/wallet-addresses.create.tsx +++ b/packages/frontend/app/routes/wallet-addresses.create.tsx @@ -12,7 +12,10 @@ import { createWalletAddress } from '~/lib/api/wallet-address.server' import { messageStorage, setMessageAndRedirect } from '~/lib/message.server' import { createWalletAddressSchema } from '~/lib/validate.server' import type { ZodFieldErrors } from '~/shared/types' -import { getOpenPaymentsUrl } from '~/shared/utils' +import { + getOpenPaymentsUrl, + removeTrailingAndLeadingSlash +} from '~/shared/utils' import { checkAuthAndRedirect } from '../lib/kratos_checks.server' import { type LoaderFunctionArgs } from '@remix-run/node' @@ -109,8 +112,11 @@ export async function action({ request }: ActionFunctionArgs) { return json({ errors }, { status: 400 }) } + const baseUrl = removeTrailingAndLeadingSlash(getOpenPaymentsUrl()) + const path = removeTrailingAndLeadingSlash(result.data.name) + const response = await createWalletAddress({ - url: `${getOpenPaymentsUrl()}${result.data.name}`, + url: `${baseUrl}/${path}`, publicName: result.data.publicName, assetId: result.data.asset, additionalProperties: [] diff --git a/packages/frontend/app/shared/utils.ts b/packages/frontend/app/shared/utils.ts index bbfaaa66fb..011b5f4638 100644 --- a/packages/frontend/app/shared/utils.ts +++ b/packages/frontend/app/shared/utils.ts @@ -100,3 +100,14 @@ export const paymentSubpathByType: { export const parseBool = (str: string) => { return ['true', 't', '1'].includes(str.toLowerCase()) } + +export function removeTrailingAndLeadingSlash(str: string): string { + if (!str.length) { + return str + } + + str = str.endsWith('/') ? str.slice(0, str.length - 1) : str + str = str.startsWith('/') ? str.substring(1) : str + + return str +}