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 +}