INNER CODE UNIT · JavaScript
readOrbBalance
nyxxbit/discord-quest-completer · index.js:247
const readOrbBalance = async () => {
const account = Mods.UserStore?.getCurrentUser?.()?.id ?? null;
if (!account) throw new Error('no account is signed in');
const store = Mods.OrbStore;
const stored = orbBalance(store?.getCurrentBalance?.() ?? store?.balance);
if (stored !== null) return stored;
const res = await Mods.API.get({ url: '/users/@me/virtual-currency/balance' });
const after = Mods.UserStore?.getCurrentUser?.()?.id ?? null;
if (after !== account) throw new Error('the account changed during the read');
return orbBalance(res?.body?.balance);
};
// The server-sealed attribution blob Discord echoes back when enrolling in or claiming a
// quest. The server issues it per quest and ships it with the quest list; the client
// returns it unmodified. Orion sent neither sealed field, so every enrollment and claim it
// made lacked something present on every request the real client sends. Nothing is forged
// here: this is the server's own value going back where it came from.
const sealedFor = questId => {