Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support pro api #154

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/components/asset-change.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/middlelayers/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const prefix = "!ent:"
const fixId = "1"
const cloudSyncFixId = "2"
const clientInfoFixId = "998"
const licenseFixId = "997"

export async function getConfiguration(): Promise<GlobalConfig | undefined> {
const model = await getConfigurationById(fixId)
Expand Down Expand Up @@ -120,3 +121,13 @@ async function getConfigurationModelById(id: string): Promise<ConfigurationModel

return configurations[0]
}

export async function saveLicense(license: string) {
return saveConfigurationById(licenseFixId, license)
}

// if user has pro license, return license string
export async function getLicenseIfIsPro(): Promise<string | undefined> {
const model = await getConfigurationById(licenseFixId)
return model?.data
}
4 changes: 2 additions & 2 deletions src/middlelayers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function loadPortfolios(config: CexConfig & TokenConfig): Promise<W
}

async function loadPortfoliosByConfig(config: CexConfig & TokenConfig): Promise<WalletCoin[]> {
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)
Expand Down
58 changes: 56 additions & 2 deletions src/middlelayers/datafetch/coins/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -112,8 +114,8 @@ class BscERC20Query extends DeBankERC20Query {
}


export class ERC20Analyzer implements Analyzer {
private readonly config: Pick<TokenConfig, 'erc20'>
export class ERC20NormalAnalyzer implements Analyzer {
protected readonly config: Pick<TokenConfig, 'erc20'>
private readonly queries = [new BscERC20Query(), new EthERC20Query()]

private readonly errorResolver: DeBank429ErrorResolver = new DeBank429ErrorResolverImpl()
Expand Down Expand Up @@ -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<TokenConfig, 'erc20'>) {
super(config)
}

async loadPortfolio(): Promise<WalletCoin[]> {
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 super.loadPortfolio()
}

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<WalletCoin[]> {
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()
}
}
Loading