domechn / track3

Analyze all your crypto assets in cex and web3 wallet
Apache License 2.0
89 stars 7 forks source link

bugfix: logic when coin sold out is incorrect #370

Closed domechn closed 3 months ago

domechn commented 3 months ago

when coin is sold out, it will not be save in db with amount and usdPrice is 0.

fix code:

// ...
    const filteredTotals = _(totals).filter(t => !_(t.wallet).startsWith("md5:")).filter(t => {
        // already handled in loadPortfolios
        if (t.usdValue === 0){
                    return true
        }
        if (t.usdValue > 1) {
            return true
        }
        const totalWallet = md5(t.wallet)
        const lastAsset = _(lastAssets).flatten().find(a => a.symbol === t.symbol && a.wallet === totalWallet)
                // not found in last asset, which means coin has already been removed before last record
        if (!lastAsset) {
            return false
        }
                // coin has been sold out in last time
        if (lastAsset.usdValue === 0) {
            return false
        }
        return true
    }).map(t=>({
        ...t,
                // if usdValue < 1, means it has been sold out this time. update it to 0, because coin whose usdValue < 1 will be ignored before saving to database
        usdValue: t.usdValue > 1 ? t.usdValue : 0,
    })).value()