Skip to content

Commit a90ae85

Browse files
committed
frontend: use shared function in utils for url origin
1 parent 100ba06 commit a90ae85

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

frontends/web/src/routes/exchange/bitrefill.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { parseExternalBtcAmount } from '@/api/coins';
2929
import { useLoad } from '@/hooks/api';
3030
import { BitrefillTerms, localeMapping } from '@/components/terms/bitrefill-terms';
3131
import { getBitrefillInfo } from '@/api/exchanges';
32+
import { getURLOrigin } from '@/utils/url';
3233

3334
// Map coins supported by Bitrefill
3435
const coinMapping: Readonly<Record<string, string>> = {
@@ -45,14 +46,6 @@ type TProps = {
4546
code: AccountCode;
4647
};
4748

48-
const getURLOrigin = (uri: string): string | null => {
49-
try {
50-
return new URL(uri).origin;
51-
} catch (e) {
52-
return null;
53-
}
54-
};
55-
5649
export const Bitrefill = ({ accounts, code }: TProps) => {
5750
const { t } = useTranslation();
5851
const { isDarkMode } = useDarkmode();

frontends/web/src/routes/exchange/btcdirect.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { useLoad } from '@/hooks/api';
2424
import { useDarkmode } from '@/hooks/darkmode';
2525
import { UseDisableBackButton } from '@/hooks/backbutton';
2626
import { getConfig } from '@/utils/config';
27+
import { getURLOrigin } from '@/utils/url';
2728
import { Header } from '@/components/layout';
2829
import { Spinner } from '@/components/spinner/Spinner';
2930
import { findAccount, isBitcoinOnly } from '@/routes/account/utils';
@@ -45,14 +46,6 @@ type TProps = {
4546
code: AccountCode;
4647
}
4748

48-
const getURLOrigin = (uri: string): string | null => {
49-
try {
50-
return new URL(uri).origin;
51-
} catch (e) {
52-
return null;
53-
}
54-
};
55-
5649
export const BTCDirect = ({ accounts, code }: TProps) => {
5750
const { i18n, t } = useTranslation();
5851
const { isDevServers } = useContext(AppContext);

frontends/web/src/utils/url.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2025 Shift Crypto AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export const getURLOrigin = (uri: string): string | null => {
18+
try {
19+
return new URL(uri).origin;
20+
} catch (e) {
21+
return null;
22+
}
23+
};

0 commit comments

Comments
 (0)