harden: decimals || "18" collapses absent and zero if a backend ever sends numeric 0 #246
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
decimals || "18"appears insrc/shared/transactions.jsandsrc/shared/balances.js. Zero decimals is legal ERC-20.Not a live bug: Blockscout sends
decimalsas a string, and"0"is truthy, so absent and zero stay distinct today. The defect is latent — a backend that sends numeric0, or any change that coerces the field before it reaches this line, silently turns a 0-decimal token into an 18-decimal one. That misreports every balance and every amount for that token by a factor of 10^18, in a wallet, with no error.Found during the coercion sweep in #244 and deliberately left out of its scope as a different field.
Implementation requirements
"0"being truthy — the current correctness depends on an upstream serialisation detail nobody controls.decimalsmakes the same assumption.Definition of done
decimals, as both the string"0"and the number0, yields 0 rather than 18.decimalsstill falls back to 18.TODO.mdupdated in the same commit.make checkpasses.