From f6de4488de6efe35b37733e88ab4a325121e8567 Mon Sep 17 00:00:00 2001 From: RainBoltz Date: Mon, 2 Dec 2024 18:48:44 +0800 Subject: [PATCH] chore: remove unused files --- package.json | 2 +- src/api/base.ts | 74 --------------- src/api/get-multisig-balances.ts | 64 ------------- src/api/get-multisigs-by-addresses.ts | 90 ------------------ src/api/get-multisigs-by-user.ts | 60 ------------ src/api/get-token-metadata.ts | 129 -------------------------- 6 files changed, 1 insertion(+), 418 deletions(-) delete mode 100644 src/api/base.ts delete mode 100644 src/api/get-multisig-balances.ts delete mode 100644 src/api/get-multisigs-by-addresses.ts delete mode 100644 src/api/get-multisigs-by-user.ts delete mode 100644 src/api/get-token-metadata.ts diff --git a/package.json b/package.json index d109b0f..00c793a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "clean": "rm -rf dist", "format": "prettier .", "format:fix": "prettier . --write", - "lint": "eslint .", + "lint": "eslint . --ignore-pattern \"**/*.js\"", "lint:fix": "eslint . --fix", "test": "jest" }, diff --git a/src/api/base.ts b/src/api/base.ts deleted file mode 100644 index 578dc72..0000000 --- a/src/api/base.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { TonNetwork } from "../constants/ton"; - -// functional programming makes me happy -export default class TonApi { - static BASE_URL = { - mainnet: "https://tonapi.io/v2", - testnet: "https://testnet.tonapi.io/v2", - }; - - static REFERER_URL = { - mainnet: "https://tonviewer.com", - testnet: "https://testnet.tonviewer.com", - }; - - static async _get( - network: TonNetwork, - path: string, - params: Record = {}, - apiKey?: string, - ): Promise { - const url = `${this.BASE_URL[network]}/${path}?${new URLSearchParams(params).toString()}`; - const response = await fetch(url, { - method: "GET", - headers: { - accept: "*/*", - "accept-language": "en-US,en;q=0.9", - authorization: `Bearer ${apiKey}`, - "content-type": "application/json", - priority: "u=1, i", - "sec-ch-ua": - '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"', - "sec-ch-ua-mobile": "?0", - "sec-ch-ua-platform": '"macOS"', - "sec-fetch-dest": "empty", - "sec-fetch-mode": "cors", - "sec-fetch-site": "cross-site", - Referer: this.REFERER_URL[network], - "Referrer-Policy": "strict-origin-when-cross-origin", - }, - body: null, - }); - return response.json(); - } - - static async _post( - network: TonNetwork, - path: string, - params: Record = {}, - apiKey?: string, - ): Promise { - const url = `${this.BASE_URL[network]}/${path}}`; - const response = await fetch(url, { - method: "POST", - headers: { - accept: "*/*", - "accept-language": "en-US,en;q=0.9", - authorization: `Bearer ${apiKey}`, - "content-type": "application/json", - priority: "u=1, i", - "sec-ch-ua": - '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"', - "sec-ch-ua-mobile": "?0", - "sec-ch-ua-platform": '"macOS"', - "sec-fetch-dest": "empty", - "sec-fetch-mode": "cors", - "sec-fetch-site": "cross-site", - Referer: this.REFERER_URL[network], - "Referrer-Policy": "strict-origin-when-cross-origin", - }, - body: JSON.stringify(params), - }); - return response.json(); - } -} diff --git a/src/api/get-multisig-balances.ts b/src/api/get-multisig-balances.ts deleted file mode 100644 index 4e31588..0000000 --- a/src/api/get-multisig-balances.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { MultisigBalancesResponse, TokenBalance } from "../interfaces/api"; -import { TonNetwork } from "../constants/ton"; -import TonApi from "./base"; - -export default async function getMultisigBalances( - multisigAddress: string, - currency: string = "usd", - network: TonNetwork = TonNetwork.testnet, -): Promise { - try { - const response1 = await TonApi._get( - network, - `accounts/${multisigAddress}`, - {}, - process.env.TONAPI_API_KEY, - ); - const tonBalance = response1["balance"]; - - const response2 = await TonApi._get( - network, - `accounts/${multisigAddress}/jettons`, - { currencies: currency }, - process.env.TONAPI_API_KEY, - ); - - const items: TokenBalance[] = [ - { - amount: tonBalance, - price: "0", // TON price not provided in this endpoint - minter_address: null, // null indicates native TON - wallet_address: multisigAddress, - }, - ]; - - // Add jetton balances - if (response2["balances"]) { - for (const balance of response2["balances"]) { - items.push({ - amount: balance.balance, - price: balance.price?.[currency]?.toString() || "0", - minter_address: balance.jetton.address, - wallet_address: balance.wallet_address.address, - }); - } - } - - return { - success: true, - data: { - items, - total: items.length, - }, - }; - } catch (error) { - console.error(error); - return { - success: false, - error: { - code: "500", - message: "Internal server error", - }, - }; - } -} diff --git a/src/api/get-multisigs-by-addresses.ts b/src/api/get-multisigs-by-addresses.ts deleted file mode 100644 index c9780e5..0000000 --- a/src/api/get-multisigs-by-addresses.ts +++ /dev/null @@ -1,90 +0,0 @@ -/* - address: ContractAddress; // Multisig contract address - version: MultisigContractVersion; // Multisig contract version - next_order_seqno: number; // Next available sequence number for new orders - threshold: number; // Required signatures to execute an order - signers: string[]; // List of wallet addresses authorized to sign orders - is_valid: boolean; // Indicates if the multisig is valid for the requesting user - */ - -/* -{ - "address": "0:1e0390dae5c10426096e05d5350222ab20c8255be7819b5da1d94903bbdfe202", - "seqno": 1, - "threshold": 2, - "signers": [ - "0:eb0b617e4b4f2cb3b7736801cf892111ca73204409e0a230653711ada15e816a", - "0:6eef3bd168e43d3f48a6dbcec3187ad7fe496ea5d7972c6fac3e7f0006f486fd" - ], - "proposers": [], - "orders": [ - { - "address": "0:06ffd1c9efe3116f46100d379e245099f200a58390a73ca21096a553d14778f1", - "order_seqno": 0, - "threshold": 2, - "sent_for_execution": false, - "signers": [ - "0:eb0b617e4b4f2cb3b7736801cf892111ca73204409e0a230653711ada15e816a", - "0:6eef3bd168e43d3f48a6dbcec3187ad7fe496ea5d7972c6fac3e7f0006f486fd" - ], - "approvals_num": 1, - "expiration_date": 1732339778, - "risk": { - "transfer_all_remaining_balance": false, - "ton": 10000000, - "jettons": [], - "nfts": [] - }, - "creation_date": 1732253396, - "signed_by": [] - } - ] -} -*/ - -import { - BaseMultisigInfo, - GetMultisigsResponse, - MultisigContractVersion, -} from "../interfaces/api"; -import { TonNetwork } from "../constants/ton"; -import TonApi from "./base"; - -export default async function getMultisigsByAddresses( - multisigAddresses: string[], - network: TonNetwork = TonNetwork.testnet, -): Promise { - const mappings: { [key: string]: BaseMultisigInfo | null } = {}; - - for (const multisigAddress of multisigAddresses) { - try { - const response = await TonApi._get( - network, - `multisig/${multisigAddress}`, - {}, - process.env.TONAPI_API_KEY, - ); - if (!response) { - mappings[multisigAddress] = null; - continue; - } - - const multisigInfo: BaseMultisigInfo = { - address: response["address"], - version: MultisigContractVersion.MULTISIG_V2, - next_order_seqno: response["seqno"], - threshold: response["threshold"], - signers: response["signers"], - }; - - mappings[multisigAddress] = multisigInfo; - } catch (error) { - console.error(error); - } - } - - return { - success: true, - data: mappings, - }; -} diff --git a/src/api/get-multisigs-by-user.ts b/src/api/get-multisigs-by-user.ts deleted file mode 100644 index b3f24db..0000000 --- a/src/api/get-multisigs-by-user.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { - GetMultisigsByUserResponse, - MultisigContractVersion, - UserMultisigInfo, -} from "../interfaces/api"; -import { TonNetwork } from "../constants/ton"; -import TonApi from "./base"; - -export default async function getMultisigsByUser( - userAddress: string, - network: TonNetwork = TonNetwork.testnet, -): Promise { - try { - const response = await TonApi._get( - network, - `accounts/${userAddress}/multisigs`, - {}, - process.env.TONAPI_API_KEY, - ); - if (!response["multisigs"]) { - return { - success: true, - data: { - items: [], - total: 0, - }, - }; - } - - const items: UserMultisigInfo[] = []; - for (const multisig of response["multisigs"]) { - const item: UserMultisigInfo = { - address: multisig.address, - version: MultisigContractVersion.MULTISIG_V2, - next_order_seqno: multisig.seqno, - threshold: multisig.threshold, - signers: multisig.signers, - is_valid: true, - }; - items.push(item); - } - - return { - success: true, - data: { - items, - total: items.length, - }, - }; - } catch (error) { - console.error(error); - return { - success: false, - error: { - code: "500", - message: "Internal server error", - }, - }; - } -} diff --git a/src/api/get-token-metadata.ts b/src/api/get-token-metadata.ts deleted file mode 100644 index e6e3ab7..0000000 --- a/src/api/get-token-metadata.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { - ContractAddress, - GetTokenMetadataResponse, - TokenMetadata, -} from "../interfaces/api"; -import { TonNetwork } from "../constants/ton"; -import TonApi from "./base"; - -export default async function getTokenMetadata( - tokenAddresses: string[], - network: TonNetwork = TonNetwork.testnet, -): Promise { - try { - const response = await TonApi._post( - network, - `jettons/_bulk`, - { - account_ids: tokenAddresses, - }, - process.env.TONAPI_API_KEY, - ); - - if (!response["jettons"]) { - return { - success: true, - data: { - items: {}, - }, - }; - } - - const notFoundAddresses: Set = new Set(tokenAddresses); - const items: { - [minter_address: ContractAddress]: TokenMetadata | null; - } = {}; - for (const jettonInfo of response["jettons"]) { - const item: TokenMetadata = { - minter_address: jettonInfo.metadata.address, - name: jettonInfo.metadata.name, - symbol: jettonInfo.metadata.symbol, - decimals: jettonInfo.metadata.decimals, - image: jettonInfo.metadata.image, - }; - notFoundAddresses.delete(jettonInfo.metadata.address); - items[jettonInfo.metadata.address] = item; - } - - for (const address of notFoundAddresses) { - items[address] = null; - } - - return { - success: true, - data: { - items, - }, - }; - } catch (error) { - return { - success: false, - error: { - code: "500", - message: `Internal server error: ${error?.message || error}`, - }, - }; - } -} - -/* -{ - "success": true, - "data": { - "items": { - "0:8888888888888888888888888888888888888888888888888888888888888888": { - "wallet_address": "0:9999999999999999999999999999999999999999999999999999999999999999", - "minter_address": "0:8888888888888888888888888888888888888888888888888888888888888888", - "name": "Example Token", - "symbol": "EXT", - "decimals": 9, - "image": "" - }, - "0:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb": null - } - } -} -*/ - -/* -{ - "mintable": true, - "total_supply": "5887105890579978", - "admin": { - "address": "0:10C1073837B93FDAAD594284CE8B8EFF7B9CF25427440EB2FC682762E1471365", - "name": "Ton foundation", - "is_scam": true, - "icon": "https://ton.org/logo.png", - "is_wallet": true - }, - "metadata": { - "address": "0:0BB5A9F69043EEBDDA5AD2E946EB953242BD8F603FE795D90698CEEC6BFC60A0", - "name": "Wrapped TON", - "symbol": "WTON", - "decimals": "9", - "image": "https://cache.tonapi.io/images/jetton.jpg", - "description": "Wrapped Toncoin", - "social": [ - [ - "https://t.me/durov_coin", - "https://twitter.com/durov_coin" - ] - ], - "websites": [ - [ - "https://durov.coin", - "ton://durov-coin.ton" - ] - ], - "catalogs": [ - [ - "https://coinmarketcap.com/currencies/drv/", - "https://www.coingecko.com/en/coins/durov" - ] - ], - "custom_payload_api_uri": "https://claim-api.tonapi.io/jettons/TESTMINT" - }, - "verification": "whitelist", - "holders_count": 2000 - } -*/