Skip to content

Commit

Permalink
0.2.5.5 | Refactoring (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
kieled committed Aug 5, 2024
1 parent 4a98ef0 commit 29f57ab
Show file tree
Hide file tree
Showing 43 changed files with 361 additions and 353 deletions.
3 changes: 2 additions & 1 deletion build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ const buildOptions: BuildOptions = {
"import.meta.url": '""',
"process.browser": "false",
},
target: ["es2016"],
target: ["chrome58", "firefox57"],
treeShaking: true,
platform: "browser",
sourcemap: Bun.argv.includes("--sourcemap") || Bun.argv.includes("-s"),
plugins: [
Expand Down
68 changes: 35 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nintondo-extension",
"version": "0.2.5.4",
"version": "0.2.5.5",
"private": true,
"scripts": {
"dev": "bun build.ts --watch",
Expand Down Expand Up @@ -30,60 +30,62 @@
]
},
"dependencies": {
"@headlessui/react": "2.0.4",
"@heroicons/react": "2.1.1",
"@noble/hashes": "1.3.3",
"bel-ord-utils": "0.2.7",
"belcoinjs-lib": "0.1.1",
"bellhdw": "0.5.38",
"bells-inscriber": "0.2.0",
"@headlessui/react": "2.1.2",
"@heroicons/react": "2.1.5",
"@noble/hashes": "1.4.0",
"bel-ord-utils": "^0.2.8",
"belcoinjs-lib": "^0.1.2",
"bellhdw": "^0.5.40",
"bells-inscriber": "^0.2.1",
"big.js": "6.2.1",
"classnames": "2.5.1",
"eth-rpc-errors": "4.0.3",
"i18next": "23.7.16",
"events": "^3.3.0",
"i18next": "23.12.2",
"immer": "^10.1.1",
"koa-compose": "4.1.0",
"nintondo-bip39": "1.0.0",
"nintondo-browser-passworder": "0.0.1",
"nintondo-sdk": "0.1.11",
"nintondo-bip39": "^1.0.0",
"nintondo-browser-passworder": "^0.0.1",
"nintondo-sdk": "^0.1.13",
"qr-code-styling": "1.6.0-rc.1",
"rc-progress": "3.5.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "7.49.3",
"rc-progress": "4.0.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-hook-form": "7.52.2",
"react-hot-toast": "2.4.1",
"react-intersection-observer": "9.5.3",
"react-loading": "2.0.3",
"react-router-dom": "6.21.1",
"reflect-metadata": "0.2.1",
"react-intersection-observer": "9.13.0",
"react-loading-icons": "1.1.0",
"react-router-dom": "6.26.0",
"reflect-metadata": "0.2.2",
"zustand": "4.5.4"
},
"devDependencies": {
"@types/big.js": "^6.2.2",
"@types/chrome": "^0.0.263",
"@types/chrome": "^0.0.269",
"@types/koa-compose": "^3.2.8",
"@types/node": "^20.10.7",
"@types/node": "^22.1.0",
"@types/react": "^18.2.47",
"@types/react-dom": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.18.1",
"autoprefixer": "^10.4.18",
"bun-types": "^1.0.21",
"esbuild": "^0.19.11",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"autoprefixer": "^10.4.20",
"bun-types": "^1.1.21",
"esbuild": "^0.23.0",
"esbuild-plugin-copy": "^2.1.1",
"esbuild-plugin-svg": "^0.1.0",
"esbuild-plugin-svgj": "^1.0.3",
"esbuild-plugin-wasm": "^1.1.0",
"esbuild-plugins-node-modules-polyfill": "^1.6.3",
"esbuild-sass-plugin": "^2.16.1",
"esbuild-sass-plugin": "^3.3.1",
"esbuild-svg": "^1.0.3",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.33.2",
"eslint": "^9.8.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.0",
"postcss-modules": "^6.0.0",
"sass": "^1.69.7",
"sass-loader": "^13.3.3",
"sass-loader": "^16.0.0",
"svgo": "^3.2.0",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
"tailwindcss": "^3.4.7",
"typescript": "^5.5.4"
}
}
71 changes: 25 additions & 46 deletions src/background/controllers/apiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import {
Inscription,
} from "@/shared/interfaces/inscriptions";
import { IToken } from "@/shared/interfaces/token";
import {
fetchBELLContent,
fetchBELLElectrs,
fetchBELLHistory,
fetchProps,
} from "@/shared/utils";
import { customFetch, fetchProps } from "@/shared/utils";
import { storageService } from "../services";
import { networks } from "belcoinjs-lib";
import { DEFAULT_FEES } from "@/shared/constant";
Expand Down Expand Up @@ -45,7 +40,6 @@ export interface IApiController {
getLastBlockBEL(): Promise<number | undefined>;
getFees(): Promise<{ fast: number; slow: number } | undefined>;
getInscriptions(address: string): Promise<Inscription[] | undefined>;
getDiscovery(): Promise<Inscription[] | undefined>;
getAccountStats(address: string): Promise<IAccountStats | undefined>;
getInscription({
inscriptionNumber,
Expand Down Expand Up @@ -82,37 +76,7 @@ type FetchType = <T>(
class ApiController implements IApiController {
private fetch: FetchType = async (p: Omit<fetchProps, "testnet">) => {
try {
return await fetchBELLElectrs({
...p,
testnet:
storageService.appState.network.pubKeyHash ===
networks.testnet.pubKeyHash &&
storageService.appState.network.scriptHash ===
networks.testnet.scriptHash,
});
} catch {
return;
}
};

private fetchContent: FetchType = async (p: Omit<fetchProps, "testnet">) => {
try {
return await fetchBELLContent({
...p,
testnet:
storageService.appState.network.pubKeyHash ===
networks.testnet.pubKeyHash &&
storageService.appState.network.scriptHash ===
networks.testnet.scriptHash,
});
} catch {
return;
}
};

private fetchHistory: FetchType = async (p: Omit<fetchProps, "testnet">) => {
try {
return await fetchBELLHistory({
return await customFetch({
...p,
testnet:
storageService.appState.network.pubKeyHash ===
Expand All @@ -129,20 +93,23 @@ class ApiController implements IApiController {
const data = await this.fetch<ApiUTXO[]>({
path: `/address/${address}/utxo`,
params: params as Record<string, string>,
service: "electrs",
});
return data;
}

async getOrdUtxos(address: string) {
const data = await this.fetch<ApiOrdUTXO[]>({
path: `/address/${address}/ords`,
service: "electrs",
});
return data;
}

async getFees() {
const data = await this.fetch<Record<string, number>>({
path: "/fee-estimates",
service: "electrs",
});
if (data) {
return {
Expand All @@ -162,6 +129,7 @@ class ApiController implements IApiController {
},
json: false,
body: rawTx,
service: "electrs",
});
if (data) {
return {
Expand All @@ -173,12 +141,14 @@ class ApiController implements IApiController {
async getTransactions(address: string): Promise<ITransaction[] | undefined> {
return await this.fetch<ITransaction[]>({
path: `/address/${address}/txs`,
service: "electrs",
});
}

async getInscriptions(address: string): Promise<Inscription[] | undefined> {
return await this.fetch<Inscription[]>({
path: `/address/${address}/ords`,
service: "electrs",
});
}

Expand All @@ -189,6 +159,7 @@ class ApiController implements IApiController {
try {
return await this.fetch<ITransaction[]>({
path: `/address/${address}/txs/chain/${txid}`,
service: "electrs",
});
} catch (e) {
return undefined;
Expand All @@ -202,6 +173,7 @@ class ApiController implements IApiController {
try {
return await this.fetch<Inscription[]>({
path: `/address/${address}/ords/chain/${location}`,
service: "electrs",
});
} catch (e) {
return undefined;
Expand All @@ -211,6 +183,7 @@ class ApiController implements IApiController {
async getLastBlockBEL() {
const data = await this.fetch<string>({
path: "/blocks/tip/height",
service: "electrs",
});
if (data) {
return Number(data);
Expand All @@ -220,6 +193,7 @@ class ApiController implements IApiController {
async getBELPrice() {
const data = await this.fetch<{ price_usd: number }>({
path: "/last-price",
service: "electrs",
});
if (!data) {
return undefined;
Expand All @@ -231,14 +205,11 @@ class ApiController implements IApiController {
};
}

async getDiscovery(): Promise<Inscription[] | undefined> {
return await this.fetch<Inscription[]>({ path: "/discovery" });
}

async getAccountStats(address: string): Promise<IAccountStats | undefined> {
try {
return await this.fetch({
path: `/address/${address}/stats`,
service: "electrs",
});
} catch {
return { amount: 0, count: 0, balance: 0 };
Expand All @@ -258,19 +229,22 @@ class ApiController implements IApiController {
path: `/address/${address}/ords?search=${
inscriptionId ?? inscriptionNumber
}`,
service: "electrs",
});
}

async getTokens(address: string): Promise<IToken[] | undefined> {
return await this.fetch<IToken[]>({
path: `/address/${address}/tokens`,
service: "electrs",
});
}

async getTransactionHex(txid: string) {
return await this.fetch<string>({
path: "/tx/" + txid + "/hex",
json: false,
service: "electrs",
});
}

Expand All @@ -279,34 +253,39 @@ class ApiController implements IApiController {
path: "/prev",
body: JSON.stringify({ locations: outpoints }),
method: "POST",
service: "electrs",
});
return result?.values;
}

async getContentPaginatedInscriptions(address: string, page: number) {
return await this.fetchContent<ContentInscriptionResopnse>({
return await this.fetch<ContentInscriptionResopnse>({
path: `/search?account=${address}&page_size=6&page=${page}`,
service: "content",
});
}

async searchContentInscriptionByInscriptionId(inscriptionId: string) {
return await this.fetchContent<ContentDetailedInscription>({
return await this.fetch<ContentDetailedInscription>({
path: `/${inscriptionId}/info`,
service: "content",
});
}

async searchContentInscriptionByInscriptionNumber(
address: string,
number: number
) {
return await this.fetchContent<ContentInscriptionResopnse>({
return await this.fetch<ContentInscriptionResopnse>({
path: `/search?account=${address}&page_size=6&page=1&from=${number}&to=${number}`,
service: "content",
});
}

async getLocationByInscriptionId(inscriptionId: string) {
return await this.fetchHistory<{ location: string; owner: string }>({
return await this.fetch<{ location: string; owner: string }>({
path: `/${inscriptionId}/owner`,
service: "history",
});
}
}
Expand Down
Loading

0 comments on commit 29f57ab

Please sign in to comment.