INNER CODE UNIT · JavaScript
fmtOrbs
nyxxbit/discord-quest-completer · index.js:232
const fmtOrbs = (reward, boosted) => (reward ? `${orbPayout(reward, boosted)} Orbs` : '');
// The Orb balance Discord reports for the account, or null for anything that is not a whole
// non-negative number. Zero is a real balance and is kept, unlike a payout of zero.
const orbBalance = v => (typeof v === 'number' && Number.isInteger(v) && v >= 0 ? v : null);
// Orbs on the account. VirtualCurrencyStore holds the figure Discord's own Orb pill shows
// once the client has fetched it, so that is read first. Discord keeps it current itself:
// the gateway pushes VIRTUAL_CURRENCY_BALANCE_UPDATE into it and LOGIN_SUCCESS clears it,
// so a number there belongs to the account of the last login. Before then it is null and one
// GET of the balance endpoint fills it in. Nothing polls; this runs once when the picker opens.
// The store clears on LOGIN_SUCCESS and not on LOGOUT, so between the two it still holds the
// old number. The read stops first when no account is signed in, which covers that gap and
// the GET alike. The GET is also checked on both sides of the await, and a switch in between
// discards the response.
const readOrbBalance = async () => {
const account = Mods.UserStore?.getCurrentUser?.()?.id ?? null;
if (!account) throw new Error('no account is signed in');