From 2ef0abc98c489b2b8f9108882d6354a0fdc2eefb Mon Sep 17 00:00:00 2001 From: readme-bot Date: Sat, 11 Nov 2023 04:20:47 +0800 Subject: [PATCH 1/4] support pro api --- src/components/asset-change.tsx | 1 - src/middlelayers/configuration.ts | 11 +++++ src/middlelayers/data.ts | 4 +- src/middlelayers/datafetch/coins/erc20.ts | 58 ++++++++++++++++++++++- 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/components/asset-change.tsx b/src/components/asset-change.tsx index 02b760f..0140ff4 100644 --- a/src/components/asset-change.tsx +++ b/src/components/asset-change.tsx @@ -38,7 +38,6 @@ const App = ({ autoSkip: false, labelOffset: -5, callback: function (val: number, index: number) { - console.log(index === 0 || index === _(data.timestamps).size() - 1); const total = _(data.timestamps).size() - 1; // only show start and end date diff --git a/src/middlelayers/configuration.ts b/src/middlelayers/configuration.ts index 34831ae..f1f8315 100644 --- a/src/middlelayers/configuration.ts +++ b/src/middlelayers/configuration.ts @@ -9,6 +9,7 @@ const prefix = "!ent:" const fixId = "1" const cloudSyncFixId = "2" const clientInfoFixId = "998" +const licenseFixId = "997" export async function getConfiguration(): Promise { const model = await getConfigurationById(fixId) @@ -120,3 +121,13 @@ async function getConfigurationModelById(id: string): Promise { + const model = await getConfigurationById(licenseFixId) + return model?.data +} diff --git a/src/middlelayers/data.ts b/src/middlelayers/data.ts index 7627a8e..09befb8 100644 --- a/src/middlelayers/data.ts +++ b/src/middlelayers/data.ts @@ -6,7 +6,7 @@ import { combineCoinLists } from './datafetch/utils/coins' import { DOGEAnalyzer } from './datafetch/coins/doge' import { OthersAnalyzer } from './datafetch/coins/others' import { SOLAnalyzer } from './datafetch/coins/sol' -import { ERC20Analyzer } from './datafetch/coins/erc20' +import { ERC20ProAnalyzer } from './datafetch/coins/erc20' import { CexAnalyzer } from './datafetch/coins/cex/cex' import { CacheCenter } from './datafetch/utils/cache' import { ASSETS_TABLE_NAME, queryHistoricalData } from './charts' @@ -39,7 +39,7 @@ export async function loadPortfolios(config: CexConfig & TokenConfig): Promise { - const anas = [ERC20Analyzer, CexAnalyzer, SOLAnalyzer, OthersAnalyzer, BTCAnalyzer, DOGEAnalyzer] + const anas = [ERC20ProAnalyzer, CexAnalyzer, SOLAnalyzer, OthersAnalyzer, BTCAnalyzer, DOGEAnalyzer] const coinLists = await bluebird.map(anas, async ana => { const a = new ana(config) diff --git a/src/middlelayers/datafetch/coins/erc20.ts b/src/middlelayers/datafetch/coins/erc20.ts index c56c550..267aa10 100644 --- a/src/middlelayers/datafetch/coins/erc20.ts +++ b/src/middlelayers/datafetch/coins/erc20.ts @@ -5,6 +5,8 @@ import { sendHttpRequest } from '../utils/http' import { getAddressList } from '../utils/address' import bluebird from 'bluebird' import { invoke } from '@tauri-apps/api' +import { getLicenseIfIsPro } from '@/middlelayers/configuration' +import { getClientID } from '@/utils/app' type QueryAssetResp = { data: { @@ -112,8 +114,8 @@ class BscERC20Query extends DeBankERC20Query { } -export class ERC20Analyzer implements Analyzer { - private readonly config: Pick +export class ERC20NormalAnalyzer implements Analyzer { + protected readonly config: Pick private readonly queries = [new BscERC20Query(), new EthERC20Query()] private readonly errorResolver: DeBank429ErrorResolver = new DeBank429ErrorResolverImpl() @@ -174,3 +176,55 @@ export class ERC20Analyzer implements Analyzer { } } } + +export class ERC20ProAnalyzer extends ERC20NormalAnalyzer { + private readonly queryUrl = "https://track3-pro-api.domc.me/api/erc20/assetsBalances" + + constructor(config: Pick) { + super(config) + } + + async loadPortfolio(): Promise { + const license = await getLicenseIfIsPro() + + // if not pro license, use normal analyzer + if (!license) { + // return super.loadPortfolio() + console.debug("not pro license, fallback to normal erc20 analyzer") + return [] + } + + try { + const res = await this.loadPortfolioPro(license) + return res + } catch (e) { + // fallback to normal analyzer + console.error("failed to query pro erc20 assets, fallback to normal erc20 analyzer", e) + return super.loadPortfolio() + } + + } + + async loadPortfolioPro(license: string): Promise { + const wallets = getAddressList(this.config.erc20) + const resp = await sendHttpRequest<{ + data: { + wallet: string + assets: { + symbol: string + amount: number + }[] + }[] + }>("POST", this.queryUrl, 10000, { + "x-track3-client-id": await getClientID(), + 'x-track3-api-key': license + }, { + wallets, + }) + + return _(resp.data).map(d => _(d.assets).map(a => ({ + ...a, + wallet: d.wallet + })).value()).flatten().value() + } +} \ No newline at end of file From 6e4ad7bdf897ad82c937773c989fb67374c92c20 Mon Sep 17 00:00:00 2001 From: readme-bot Date: Sat, 11 Nov 2023 04:26:46 +0800 Subject: [PATCH 2/4] support pro api --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d072f6..d8c1e49 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,14 @@ 1. **No backend server, all data is stored locally by default** 2. Support Binance and OKX. How to create api key: [Binance](https://www.binance.com/en-BH/support/faq/how-to-create-api-360002502072), [OKX](https://use.autoview.com/hc/en-us/articles/360004576632-OKEx-Creating-an-API) -3. Support BTC, ETH, BNB, SOL and Doge. +3. Support BTC, ETH, BNB, SOL and Doge ( Base Users ). 4. Support dozens of charts to analyze data such as wallet proportion, proportion of each currency asset, changes, etc. 5. Support Cloud Sync, users can sync their data to cloud and restore it on another device. +## Pro Users + +1. Support 15+ ERC20 Chains: Ethereum, BSC, Polygon, Fantom, Arbitrum, Avalanche, Gnosis, Celo, OKC, Cronos, Optimism, Cardano, Terra 2.0, Cosmos, Osmosis, Base. + ## Installation [Download In Release Page](https://github.com/domechn/track3/releases) From 491cd6741335a292b21b491e44cb8cd667dff76f Mon Sep 17 00:00:00 2001 From: readme-bot Date: Sat, 11 Nov 2023 04:27:31 +0800 Subject: [PATCH 3/4] fix --- src/middlelayers/datafetch/coins/erc20.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlelayers/datafetch/coins/erc20.ts b/src/middlelayers/datafetch/coins/erc20.ts index 267aa10..820c9de 100644 --- a/src/middlelayers/datafetch/coins/erc20.ts +++ b/src/middlelayers/datafetch/coins/erc20.ts @@ -191,7 +191,7 @@ export class ERC20ProAnalyzer extends ERC20NormalAnalyzer { if (!license) { // return super.loadPortfolio() console.debug("not pro license, fallback to normal erc20 analyzer") - return [] + return super.loadPortfolio() } try { From d005d2ed4baf25a97a054e2c22b0eff02484ca35 Mon Sep 17 00:00:00 2001 From: readme-bot Date: Sat, 11 Nov 2023 04:27:42 +0800 Subject: [PATCH 4/4] fmt --- src/middlelayers/datafetch/coins/erc20.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middlelayers/datafetch/coins/erc20.ts b/src/middlelayers/datafetch/coins/erc20.ts index 820c9de..6f5aeb7 100644 --- a/src/middlelayers/datafetch/coins/erc20.ts +++ b/src/middlelayers/datafetch/coins/erc20.ts @@ -186,7 +186,7 @@ export class ERC20ProAnalyzer extends ERC20NormalAnalyzer { async loadPortfolio(): Promise { const license = await getLicenseIfIsPro() - + // if not pro license, use normal analyzer if (!license) { // return super.loadPortfolio() @@ -227,4 +227,4 @@ export class ERC20ProAnalyzer extends ERC20NormalAnalyzer { wallet: d.wallet })).value()).flatten().value() } -} \ No newline at end of file +}