Skip to content

Commit

Permalink
fix(frontend): concatenate correctly base url and path when creating …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
oana-lolea authored Sep 16, 2024
1 parent 0b92ce3 commit 230ac21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/frontend/app/routes/wallet-addresses.create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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: []
Expand Down
11 changes: 11 additions & 0 deletions packages/frontend/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 230ac21

Please sign in to comment.