Initial commit
This commit is contained in:
18
scripts/build.sh
Normal file
18
scripts/build.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
export REACT_APP_API_URL="${REACT_APP_API_URL:-}"
|
||||
|
||||
if command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
export REACT_APP_GIT_SHA="$(git rev-parse --short HEAD 2>/dev/null || true)"
|
||||
fi
|
||||
|
||||
NODE_MAJOR="$(node -p "process.versions.node.split('.')[0]")"
|
||||
|
||||
# CRA 4 + webpack 4 on Node 17+ need legacy OpenSSL; pass flag on the CLI (not NODE_OPTIONS).
|
||||
if [ "$NODE_MAJOR" -ge 17 ]; then
|
||||
exec node --openssl-legacy-provider ./node_modules/react-app-rewired/bin/index.js build
|
||||
fi
|
||||
|
||||
exec yarn build
|
||||
30
scripts/check-format-display-datetime.js
Normal file
30
scripts/check-format-display-datetime.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* ponytail: assert Tehran display formatting (fixed +03:30).
|
||||
* Run: node scripts/check-format-display-datetime.js
|
||||
*
|
||||
* Standalone copy of offset math — CRA ESM can't require() the helper.
|
||||
* Keep in sync with src/core/helper/formatDisplayDateTime.js
|
||||
*/
|
||||
const assert = require("assert");
|
||||
|
||||
const TEHRAN_UTC_OFFSET_MINUTES = 210;
|
||||
|
||||
function formatTehranFromUnixSec(unixSec, pattern) {
|
||||
// 2024-01-15T12:00:00Z → Tehran 15:30
|
||||
const ms = unixSec * 1000 + TEHRAN_UTC_OFFSET_MINUTES * 60 * 1000;
|
||||
const d = new Date(ms);
|
||||
const hh = String(d.getUTCHours()).padStart(2, "0");
|
||||
const mm = String(d.getUTCMinutes()).padStart(2, "0");
|
||||
const ss = String(d.getUTCSeconds()).padStart(2, "0");
|
||||
if (pattern === "time") return `${Number(hh)}:${mm}:${ss}`.replace(/^0/, "") || `${hh}:${mm}:${ss}`;
|
||||
// Just assert hour/minute components for smoke
|
||||
return { hour: d.getUTCHours(), minute: d.getUTCMinutes() };
|
||||
}
|
||||
|
||||
// 1705320000 = 2024-01-15T12:00:00.000Z → Tehran 15:30
|
||||
const parts = formatTehranFromUnixSec(1705320000, "full");
|
||||
assert.strictEqual(parts.hour, 15, "Tehran hour for 12:00Z");
|
||||
assert.strictEqual(parts.minute, 30, "Tehran minute for 12:00Z");
|
||||
assert.strictEqual(TEHRAN_UTC_OFFSET_MINUTES, 210);
|
||||
|
||||
console.log("check-format-display-datetime: ok");
|
||||
66
scripts/check-ranger-mappers.js
Normal file
66
scripts/check-ranger-mappers.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* ponytail: assert ranger mapper invariants (standalone — CRA ESM can't require()).
|
||||
* Keep in sync with src/lib/ranger/{helpers,mapTickers,depth}.js
|
||||
* Run: node scripts/check-ranger-mappers.js
|
||||
*/
|
||||
const assert = require("assert");
|
||||
|
||||
function generateSocketURI(baseUrl, streams) {
|
||||
const sorted = [...(streams || []).filter(Boolean)].sort();
|
||||
return `${String(baseUrl).replace(/\/+$/, "")}/?stream=${sorted.join("&stream=")}`;
|
||||
}
|
||||
|
||||
function marketIdToShahooStatKeys(marketId) {
|
||||
const id = String(marketId || "").toLowerCase();
|
||||
const match = id.match(/^([a-z0-9]+?)(cad|irt|usdt)$/);
|
||||
if (!match) return [];
|
||||
return [`${match[1].toUpperCase()}_${match[2].toUpperCase()}`];
|
||||
}
|
||||
|
||||
function shahooMarketToDenaId(marketKeyOrRoute) {
|
||||
const normalized = String(marketKeyOrRoute || "")
|
||||
.replace(/-/g, "_")
|
||||
.toUpperCase();
|
||||
const [base, quote] = normalized.split("_");
|
||||
if (!base || !quote) return null;
|
||||
return `${base.toLowerCase()}${quote.toLowerCase()}`;
|
||||
}
|
||||
|
||||
function marketPublicStreams(marketId, { incremental = true } = {}) {
|
||||
const id = String(marketId || "").toLowerCase();
|
||||
if (!id) return [];
|
||||
const depth = incremental ? `${id}.ob-inc` : `${id}.update`;
|
||||
return [`${id}.trades`, depth];
|
||||
}
|
||||
|
||||
function handleIncrementalUpdate(depthOld, newLevel, type) {
|
||||
const prev = depthOld || [];
|
||||
const index = prev.findIndex(([price]) => +price === +newLevel[0]);
|
||||
if (index === -1 && +newLevel[1]) {
|
||||
const data = [...prev, newLevel];
|
||||
return type === "asks"
|
||||
? data.sort((a, b) => +a[0] - +b[0])
|
||||
: data.sort((a, b) => +b[0] - +a[0]);
|
||||
}
|
||||
const result = [...prev];
|
||||
if (Number(newLevel[1]) !== 0) result[index] = newLevel;
|
||||
else result.splice(index, 1);
|
||||
return type === "asks"
|
||||
? result.sort((a, b) => +a[0] - +b[0])
|
||||
: result.sort((a, b) => +b[0] - +a[0]);
|
||||
}
|
||||
|
||||
assert.deepStrictEqual(marketIdToShahooStatKeys("btcirt"), ["BTC_IRT"]);
|
||||
assert.strictEqual(shahooMarketToDenaId("BTC-IRT"), "btcirt");
|
||||
assert.deepStrictEqual(marketPublicStreams("btcirt"), [
|
||||
"btcirt.trades",
|
||||
"btcirt.ob-inc",
|
||||
]);
|
||||
const uri = generateSocketURI("wss://x/public", ["b", "a"]);
|
||||
assert.ok(uri.endsWith("?stream=a&stream=b"));
|
||||
assert.deepStrictEqual(
|
||||
handleIncrementalUpdate([["100", "1"]], ["100", "0"], "asks"),
|
||||
[]
|
||||
);
|
||||
|
||||
console.log("check-ranger-mappers: ok");
|
||||
Reference in New Issue
Block a user