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

bugfix: logic when coin sold out is incorrect #370

Closed
domechn opened this issue Apr 5, 2024 · 0 comments
Closed

bugfix: logic when coin sold out is incorrect #370

domechn opened this issue Apr 5, 2024 · 0 comments
Milestone

Comments

@domechn
Copy link
Owner

domechn commented Apr 5, 2024

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant