Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
657ba3b059 |
@@ -49,8 +49,7 @@ but the review is broader than any of them.
|
|||||||
unknown, not read in part
|
unknown, not read in part
|
||||||
([#251](https://git.eeqj.de/sneak/AutistMask/issues/251)). `parseInt` read
|
([#251](https://git.eeqj.de/sneak/AutistMask/issues/251)). `parseInt` read
|
||||||
`1,000` as 1, `0x10` as 0 and `1e3` as 1, a reported low count that hides the
|
`1,000` as 1, `0x10` as 0 and `1e3` as 1, a reported low count that hides the
|
||||||
token in the transaction history and the send-screen token selector. A count
|
token in the transaction history and the send-screen token selector. The
|
||||||
above `Number.MAX_SAFE_INTEGER` is unknown too, not rounded or `Infinity`. The
|
|
||||||
balance list's `holders !== null` check, which did nothing, is dropped.
|
balance list's `holders !== null` check, which did nothing, is dropped.
|
||||||
`README.md` and `docs/README.md` now say how each filter treats an unknown
|
`README.md` and `docs/README.md` now say how each filter treats an unknown
|
||||||
count and that the token screen leaves out its "Holders:" row then, and
|
count and that the token screen leaves out its "Holders:" row then, and
|
||||||
|
|||||||
@@ -13,17 +13,12 @@ const LOW_HOLDER_THRESHOLD = 1000;
|
|||||||
// not one. Only a whole number of zero or more, or a string made of nothing
|
// not one. Only a whole number of zero or more, or a string made of nothing
|
||||||
// but the digits 0-9, is a count. Anything else is null, never read in part:
|
// but the digits 0-9, is a count. Anything else is null, never read in part:
|
||||||
// "1,000", "0x10" and "1e3" are unknown, not 1, 0 and 1, because a count we
|
// "1,000", "0x10" and "1e3" are unknown, not 1, 0 and 1, because a count we
|
||||||
// cannot read is not a low count. A count above Number.MAX_SAFE_INTEGER is
|
// cannot read is not a low count.
|
||||||
// null too: a number cannot hold it exactly, so it would come back rounded,
|
|
||||||
// or as Infinity.
|
|
||||||
function parseHoldersCount(raw) {
|
function parseHoldersCount(raw) {
|
||||||
if (typeof raw === "number") {
|
if (typeof raw === "number") {
|
||||||
return Number.isSafeInteger(raw) && raw >= 0 ? raw : null;
|
return Number.isInteger(raw) && raw >= 0 ? raw : null;
|
||||||
}
|
|
||||||
if (typeof raw === "string" && /^[0-9]+$/.test(raw)) {
|
|
||||||
const count = Number(raw);
|
|
||||||
return Number.isSafeInteger(count) ? count : null;
|
|
||||||
}
|
}
|
||||||
|
if (typeof raw === "string" && /^[0-9]+$/.test(raw)) return Number(raw);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,24 +72,6 @@ describe("parseHoldersCount", () => {
|
|||||||
expect(parseHoldersCount("-5")).toBeNull();
|
expect(parseHoldersCount("-5")).toBeNull();
|
||||||
expect(parseHoldersCount(-5)).toBeNull();
|
expect(parseHoldersCount(-5)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
// A number holds a whole number exactly only up to 2^53 - 1. Past that a
|
|
||||||
// string of digits would come back rounded, and a long enough one as
|
|
||||||
// Infinity, which would pass every holder-count floor.
|
|
||||||
test("a count too large for a number to hold exactly is unknown", () => {
|
|
||||||
expect(parseHoldersCount("9007199254740993")).toBeNull();
|
|
||||||
expect(parseHoldersCount("9".repeat(400))).toBeNull();
|
|
||||||
expect(parseHoldersCount(2 ** 53)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("the largest count a number holds exactly still parses", () => {
|
|
||||||
expect(parseHoldersCount("9007199254740991")).toBe(
|
|
||||||
Number.MAX_SAFE_INTEGER,
|
|
||||||
);
|
|
||||||
expect(parseHoldersCount(Number.MAX_SAFE_INTEGER)).toBe(
|
|
||||||
Number.MAX_SAFE_INTEGER,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isLowHolderCount", () => {
|
describe("isLowHolderCount", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user