Skip to content

Commit

Permalink
fix url constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kieled committed Sep 20, 2024
1 parent 1cf2285 commit 970c7c5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 81 deletions.
11 changes: 3 additions & 8 deletions src/background/controllers/apiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { IToken } from "@/shared/interfaces/token";
import { customFetch, fetchProps } from "@/shared/utils";
import { storageService } from "../services";
import { networks } from "belcoinjs-lib";
import { DEFAULT_FEES } from "@/shared/constant";

export interface UtxoQueryParams {
Expand Down Expand Up @@ -58,19 +57,15 @@ export interface IApiController {
}

type FetchType = <T>(
props: Omit<fetchProps, "testnet">
props: Omit<fetchProps, "network">
) => Promise<T | undefined>;

class ApiController implements IApiController {
private fetch: FetchType = async (p: Omit<fetchProps, "testnet">) => {
private fetch: FetchType = async (p: Omit<fetchProps, "network">) => {
try {
return await customFetch({
...p,
testnet:
storageService.appState.network.pubKeyHash ===
networks.testnet.pubKeyHash &&
storageService.appState.network.scriptHash ===
networks.testnet.scriptHash,
network: storageService.appState.network,
});
} catch {
return;
Expand Down
42 changes: 18 additions & 24 deletions src/shared/constant/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isTestnet } from "@/ui/utils";
import { Network, networks } from "belcoinjs-lib";
import { AddressType } from "bellhdw/src/hd/types";

Expand Down Expand Up @@ -55,38 +56,31 @@ export const EVENTS = {
},
};

export const COIN_NAME = "BELL";
export const COIN_SYMBOL = "BELL";

export const SATS_DOMAIN = ".sats";

export const CHANNEL = "chrome";

export const NINTONDO_API_URL =
const NINTONDO_API_URL =
process.env.API_URL ?? "https://electrs.nintondo.io/api";

export const PREVIEW_URL =
process.env.PREVIEW_URL ?? "https://content.nintondo.io/api/pub/preview";
export const HTML_PREVIEW_URL =
process.env.PREVIEW_URL ?? "https://content.nintondo.io/api/pub/html";
export const CONTENT_URL =
const CONTENT_URL =
process.env.CONTENT_URL ?? "https://content.nintondo.io/api/pub";
export const HISTORY_URL =
const HISTORY_URL =
process.env.HISTORY_URL ?? "https://history.nintondo.io/pub";

export const NINTONDO_URL = process.env.NINTONDO_URL ?? "https://nintondo.io";
export const NINTONDO_URL = "https://nintondo.io";

export const TESTNET_NINTONDO_API_URL =
const TESTNET_NINTONDO_API_URL =
process.env.TESTNET_API_URL ?? "https://testnet.nintondo.io/electrs";

export const TESTNET_PREVIEW_URL =
process.env.TESTNET_PREVIEW_URL ??
"https://testnet.nintondo.io/api/pub/preview";
export const TESTNET_HTML_PREVIEW_URL =
process.env.TESTNET_HTML_URL ?? "https://testnet.nintondo.io/api/pub/html";
export const TESTNET_CONTENT_URL =
const TESTNET_CONTENT_URL =
process.env.TESTNET_CONTENT_URL ?? "https://testnet.nintondo.io/api/pub";
export const TESTNET_HISTORY_URL =

export const getContentUrl = (network: Network) =>
isTestnet(network) ? TESTNET_CONTENT_URL : CONTENT_URL;

export const getApiUrl = (network: Network) =>
isTestnet(network) ? TESTNET_NINTONDO_API_URL : NINTONDO_API_URL;

export const getHistoryUrl = (network: Network) =>
isTestnet(network) ? TESTNET_HISTORY_URL : HISTORY_URL;

const TESTNET_HISTORY_URL =
process.env.TESTNET_HISTORY_URL ?? "https://testnet.nintondo.io/history/pub";

export const DEFAULT_FEES = {
Expand Down
24 changes: 9 additions & 15 deletions src/shared/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
CONTENT_URL,
HISTORY_URL,
NINTONDO_API_URL,
TESTNET_CONTENT_URL,
TESTNET_HISTORY_URL,
TESTNET_NINTONDO_API_URL,
} from "@/shared/constant";
import { Network } from "belcoinjs-lib";
import browser from "./browser";
import { getApiUrl, getContentUrl, getHistoryUrl } from "../constant";

export const t = (name: string) => browser.i18n.getMessage(name);

Expand All @@ -21,29 +15,29 @@ export interface fetchProps extends RequestInit {
params?: Record<string, string>;
error?: boolean;
json?: boolean;
testnet: boolean;
network: Network;
service: "electrs" | "content" | "history";
}

const getBaseUrl = (service: fetchProps["service"], testnet: boolean) => {
const getBaseUrl = (service: fetchProps["service"], testnet: Network) => {
switch (service) {
case "electrs":
return testnet ? TESTNET_NINTONDO_API_URL : NINTONDO_API_URL;
return getApiUrl(testnet);
case "content":
return testnet ? TESTNET_CONTENT_URL : CONTENT_URL;
return getContentUrl(testnet);
case "history":
return testnet ? TESTNET_HISTORY_URL : HISTORY_URL;
return getHistoryUrl(testnet);
}
};

export const customFetch = async <T>({
path,
json = true,
testnet,
network,
service,
...props
}: fetchProps): Promise<T | undefined> => {
const url = `${getBaseUrl(service, testnet)}${path}`;
const url = `${getBaseUrl(service, network)}${path}`;
const params = props.params
? Object.entries(props.params)
.map((k) => `${k[0]}=${k[1]}`)
Expand Down
8 changes: 3 additions & 5 deletions src/ui/components/inscription-card/components.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FC, useEffect, useRef } from "react";
import { useNavigate } from "react-router-dom";
import { shortAddress } from "@/shared/utils/transactions";
import { PREVIEW_URL, TESTNET_PREVIEW_URL } from "@/shared/constant";
import { useAppState } from "@/ui/states/appState";
import { isTestnet, ss } from "@/ui/utils";
import { ss } from "@/ui/utils";
import { getContentUrl } from "@/shared/constant";

interface Props {
inscriptionId: string;
Expand Down Expand Up @@ -48,9 +48,7 @@ const InscriptionCard: FC<Props> = ({ inscriptionId }) => {
<div className="rounded-xl w-full bg-slate-950 bg-opacity-50">
<img
ref={imageRef}
src={`${
isTestnet(network) ? TESTNET_PREVIEW_URL : PREVIEW_URL
}/${inscriptionId}`}
src={`${getContentUrl(network)}/preview/${inscriptionId}`}
alt="content"
className="object-cover rounded-xl h-38 w-38"
style={{
Expand Down
10 changes: 3 additions & 7 deletions src/ui/components/sign-psbt-fileds/component.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FC } from "react";

import { IField } from "@/shared/interfaces/provider";
import { PREVIEW_URL, TESTNET_PREVIEW_URL } from "@/shared/constant";
import { t } from "i18next";
import cn from "classnames";
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
import { useAppState } from "@/ui/states/appState";
import { isTestnet, ss } from "@/ui/utils";
import { ss } from "@/ui/utils";
import { getContentUrl } from "@/shared/constant";

interface SignPsbtFiledsProps {
fields: IField[];
Expand Down Expand Up @@ -47,8 +47,6 @@ const SignPsbtFileds: FC<SignPsbtFiledsProps> = ({
className={cn(
"rounded-xl px-5 py-2 break-all w-full flex justify-center border-2 bg-input-bg",
{
// "border-lime-800": !f.input && f.important,
// "border-light-orange": f.input && f.important,
"border-input-bg": true,
}
)}
Expand All @@ -61,9 +59,7 @@ const SignPsbtFileds: FC<SignPsbtFiledsProps> = ({
className="flex flex-col items-center justify-center p-2"
>
<img
src={`${
isTestnet(network) ? TESTNET_PREVIEW_URL : PREVIEW_URL
}/${k}`}
src={`${getContentUrl(network)}/preview/${k}`}
className="object-cover w-full rounded-xl"
/>
<p className="text-xs">
Expand Down
29 changes: 8 additions & 21 deletions src/ui/pages/main/inscriptions/inscription-details/components.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import { CompletedInscription } from "@/shared/interfaces/inscriptions";
import { useCallback, useEffect, useState } from "react";
import { t } from "i18next";
import { browserTabsCreate } from "@/shared/utils/browser";
import { useLocation, useNavigate } from "react-router-dom";
import { TailSpin } from "react-loading-icons";
import {
CONTENT_URL,
HTML_PREVIEW_URL,
PREVIEW_URL,
TESTNET_CONTENT_URL,
TESTNET_HTML_PREVIEW_URL,
} from "@/shared/constant";
import s from "./styles.module.scss";
import Iframe from "@/ui/components/iframe";
import { useAppState } from "@/ui/states/appState";
import { isTestnet, ss } from "@/ui/utils";
import { ss } from "@/ui/utils";
import { useControllersState } from "@/ui/states/controllerState";
import { parseLocation } from "@/shared/utils";
import { getContentUrl } from "@/shared/constant";

type PathOf<T> = T extends object
? {
Expand Down Expand Up @@ -178,9 +171,9 @@ const InscriptionDetails = () => {
<div className="px-4">
<div className="flex justify-center w-[318px] h-[318px] rounded-xl overflow-hidden">
<Iframe
preview={`${
isTestnet(network) ? TESTNET_HTML_PREVIEW_URL : HTML_PREVIEW_URL
}/${inscription.inscription_id}`}
preview={`${getContentUrl(network)}/html/${
inscription.inscription_id
}`}
size="big"
/>
</div>
Expand All @@ -197,15 +190,9 @@ const InscriptionDetails = () => {
<div
onClick={async () => {
await openContent(
`${
f.key === "content"
? isTestnet(network)
? CONTENT_URL
: TESTNET_CONTENT_URL
: isTestnet(network)
? TESTNET_HTML_PREVIEW_URL
: PREVIEW_URL
}/content/${inscription.inscription_id}`
`${getContentUrl(network)}/${
f.key === "content" ? "content" : "preview"
}/${inscription.inscription_id}`
);
}}
className="text-orange-400 cursor-pointer text-sm font-medium"
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/main/transaction-info/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import cn from "classnames";
import { shortAddress } from "@/shared/utils/transactions";
import toast from "react-hot-toast";
import { t } from "i18next";
import { NINTONDO_URL } from "@/shared/constant";
import { useGetCurrentAccount } from "@/ui/states/walletState";
import { NINTONDO_URL } from "@/shared/constant";

const TransactionInfo = () => {
const [openModal, setOpenModal] = useState<boolean>(false);
Expand Down

0 comments on commit 970c7c5

Please sign in to comment.