Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions public/Assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@
"description": "Check out the changelog to see what changed in this version.",
"viewChangelog": "See what's new"
},
"devexEstimate": {
"title": "Estimated DevEx earnings",
"tooltip": "Estimated DevEx earnings for the selected period, with Robux from US players aged 18+ at the higher rate.",
"loading": "Loading...",
"loadFailed": "Couldn't load the DevEx estimate.",
"earnings": "Estimated earnings",
"payout": "You'd receive",
"eligibleRobux": "US 18+ Robux",
"standardRobux": "Other Robux"
},
"onboarding": {
"title": "Welcome to RoValra!",
"thankYou": "Thank you for installing <strong>RoValra</strong>!",
Expand Down
13 changes: 13 additions & 0 deletions src/content/core/idExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export function getUniverseIdFromUrl(url = window.location.href) {
}
}

export function getCreatorHubUniverseIdFromUrl(url = window.location.href) {
try {
return (
new URL(url, window.location.origin).pathname.match(
/\/dashboard\/creations\/experiences\/(\d+)/i,
)?.[1] || null
);
} catch (e) {
console.warn('RoValra: URL parsing failed', e);
return null;
}
}

export function getGamePassIdFromUrl(url = window.location.href) {
try {
const urlObj = new URL(url, window.location.origin);
Expand Down
16 changes: 16 additions & 0 deletions src/content/core/settings/settingConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DEVEX_PAYOUT_METHOD_OPTIONS,
ROBUX_FIAT_ESTIMATE_DEFAULT_GRADIENT,
TRANSACTION_FIAT_CURRENCY_OPTIONS,
TRANSACTION_FIAT_RATE_OPTIONS,
Expand Down Expand Up @@ -2079,6 +2080,21 @@ export const SETTINGS_CONFIG = {
type: 'checkbox',
default: false,
},
devexEstimateEnabled: {
label: 'DevEx Earnings Estimate',
description:
'Shows your estimated DevEx earnings on the Monetization overview and next to Robux in its charts.',
type: 'checkbox',
default: true,
},
devexPayoutMethod: {
label: 'DevEx Payment Method',
description:
'Your DevEx portal payment method, used to take its fees, US tax withholding and currency exchange out of the DevEx estimate.',
type: 'select',
options: DEVEX_PAYOUT_METHOD_OPTIONS,
default: 'paypal',
},
},
},
totalspentEnabled: {
Expand Down
62 changes: 59 additions & 3 deletions src/content/core/transactions/fiat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { callRobloxApiJson } from '../api.js';
import { get as getCache, set as setCache } from '../storage/cacheHandler.js';
export {
DEVEX_EXCHANGE_FEE_PERCENT,
DEVEX_O18_USD_RATE,
DEVEX_PAYOUT_FEES,
DEVEX_USD_RATE,
ROBUX_FIAT_ESTIMATE_DEFAULT_COLOR,
ROBUX_FIAT_ESTIMATE_DEFAULT_GRADIENT,
Expand All @@ -14,9 +17,8 @@ export {
TRANSACTION_FIAT_RATE_OPTIONS,
} from './fiatConfig.js';
import {
DEVEX_USD_RATE,
ROBUX_FIAT_RATE_MODE_DEVEX,
ROBUX_FIAT_RATE_MODE_NORMAL,
DEVEX_EXCHANGE_FEE_PERCENT,
DEVEX_PAYOUT_FEES,
ROBUX_FIAT_SETTINGS_DEFAULTS,
} from './fiatConfig.js';

Expand All @@ -34,6 +36,7 @@ chrome.storage.onChanged.addListener((changes, areaName) => {
changes.robuxFiatEstimatesEnabled ||
changes.robuxFiatDisplayCurrency ||
changes.robuxFiatRateMode ||
changes.devexPayoutMethod ||
changes.robuxFiatEstimateColor ||
changes.robuxFiatEstimateStyleMode ||
changes.robuxFiatEstimateGradient ||
Expand Down Expand Up @@ -156,3 +159,56 @@ export function formatDisplayCurrency(amount, currencyCode = 'USD') {
maximumFractionDigits: 2,
}).format(roundedValue);
}

let payoutDetailsPromise = null;

function getPayoutDetails() {
payoutDetailsPromise ??= Promise.all([
callRobloxApiJson({
subdomain: 'apis',
endpoint:
'/creator-tax/withholding-rate?paymentType=PAYMENT_TYPE_ROYALTY',
})
.then((data) => (data?.rate?.withholdingRateBps || 0) / 10000)
.catch(() => 0),
callRobloxApiJson({
subdomain: 'users',
endpoint: '/v1/users/authenticated/country-code',
})
.then((data) => data?.countryCode || null)
.catch(() => null),
]).then(([withholdingRate, countryCode]) => ({
withholdingRate,
countryCode,
}));
return payoutDetailsPromise;
}

export async function getDevexPayoutUsd(
usdAmount,
currency,
{ includeFlatFee = true } = {},
) {
const { devexPayoutMethod: method } = await getRobuxFiatSettings();
if (!method || method === 'none') return null;

const { withholdingRate, countryCode } = await getPayoutDetails();
const fees =
method === 'paypal'
? DEVEX_PAYOUT_FEES[
countryCode === 'US'
? 'paypalDomestic'
: 'paypalInternational'
]
: DEVEX_PAYOUT_FEES[method];
if (!fees) return null;

const afterTax = usdAmount * (1 - withholdingRate);
const percentFee = (afterTax * (fees.percent || 0)) / 100;
const fee = includeFlatFee
? Math.min(fees.cap ?? Infinity, fees.flat + percentFee)
: percentFee;
const exchangeRate =
currency === 'USD' ? 1 : 1 - DEVEX_EXCHANGE_FEE_PERCENT / 100;
return Math.max(0, afterTax - fee) * exchangeRate;
}
20 changes: 20 additions & 0 deletions src/content/core/transactions/fiatConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
export const ROBUX_FIAT_RATE_MODE_NORMAL = 'normal';
export const ROBUX_FIAT_RATE_MODE_DEVEX = 'devex';
export const DEVEX_USD_RATE = 0.0038;
export const DEVEX_O18_USD_RATE = 0.0054;
export const DEVEX_EXCHANGE_FEE_PERCENT = 2.5;
export const DEVEX_PAYOUT_FEES = {
paypalDomestic: { flat: 0.1, percent: 2, cap: 1 },
paypalInternational: { flat: 1, percent: 2, cap: 21 },
ach: { flat: 0 },
echeck: { flat: 5 },
wire: { flat: 26 },
check: { flat: 6 },
};

export const DEVEX_PAYOUT_METHOD_OPTIONS = [
{ value: 'none', label: 'Do not include fees' },
{ value: 'paypal', label: 'PayPal' },
{ value: 'ach', label: 'ACH' },
{ value: 'echeck', label: 'eCheck / bank transfer' },
{ value: 'wire', label: 'Wire transfer' },
{ value: 'check', label: 'Check' },
];

export const ROBUX_FIAT_ESTIMATE_DEFAULT_COLOR = '#7a7d81';

Expand All @@ -19,6 +38,7 @@ export const ROBUX_FIAT_SETTINGS_DEFAULTS = {
robuxFiatEstimatesEnabled: false,
robuxFiatDisplayCurrency: 'USD',
robuxFiatRateMode: ROBUX_FIAT_RATE_MODE_NORMAL,
devexPayoutMethod: 'paypal',
robuxFiatEstimateColor: ROBUX_FIAT_ESTIMATE_DEFAULT_COLOR,
robuxFiatEstimateStyleMode: ROBUX_FIAT_ESTIMATE_STYLE_MODE_SOLID,
robuxFiatEstimateGradient: ROBUX_FIAT_ESTIMATE_DEFAULT_GRADIENT,
Expand Down
47 changes: 36 additions & 11 deletions src/content/core/ui/robuxIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
observeElement,
observeChildren,
observeAttributes,
observeText,
} from '../observer.js';
import { callRobloxApiJson } from '../api.js';
import { cleanPrice } from '../utils/priceCleaner.js';
import { addTooltip } from './tooltip.js';
import {
convertCurrencyAmount,
getDevexPayoutUsd,
DEVEX_USD_RATE,
formatDisplayCurrency,
getRobuxFiatSettings,
Expand Down Expand Up @@ -131,7 +133,7 @@
streamerRobuxRevealed,
);
});
} catch (error) {}
} catch {}
}

function isTransactionsPage() {
Expand Down Expand Up @@ -418,6 +420,14 @@
);
}

function isCashOutBalance(element) {
return (
isNavbarRobuxBalance(element) ||
(element instanceof HTMLElement &&
element.closest('#transactions-web-app .balance-label') !== null)
);
}

function getDevexUsdAmount(robuxAmount, useEstimateApi) {
if (!useEstimateApi) return robuxAmount * DEVEX_USD_RATE;

Expand Down Expand Up @@ -459,12 +469,13 @@
const style = buildEstimateStyle(fiatSettings);

if (fiatSettings.robuxFiatRateMode === ROBUX_FIAT_RATE_MODE_DEVEX) {
const usdAmount = await getDevexUsdAmount(
robuxAmount,
isNavbarRobuxBalance(element),
);
const cashOut = isCashOutBalance(element);
const usdAmount = await getDevexUsdAmount(robuxAmount, cashOut);
const payoutUsd = await getDevexPayoutUsd(usdAmount, targetCurrency, {
includeFlatFee: cashOut,
});
const convertedAmount = await convertCurrencyAmount(
usdAmount,
payoutUsd ?? usdAmount,
'USD',
targetCurrency,
);
Expand Down Expand Up @@ -617,7 +628,7 @@
}
}

function getTransactionsLabelAnchor(element) {

Check warning on line 631 in src/content/core/ui/robuxIcon.js

View workflow job for this annotation

GitHub Actions / eslint

'getTransactionsLabelAnchor' is defined but never used
if (!isTransactionsPage() || !(element instanceof HTMLElement)) return null;

const row = element.closest('tr');
Expand Down Expand Up @@ -664,7 +675,10 @@
if (!(targetCell instanceof HTMLElement)) return;

const amount = getRobuxAmountFromElement(targetCell);
if (!amount) return;
if (!amount) {
targetCell.querySelector('.rovalra-usd-estimate')?.remove();
return;
}

try {
const resolvedAmount = await resolveEstimateRobuxAmount(
Expand All @@ -678,18 +692,19 @@
targetCell,
);
if (!formattedEstimate) return;
if (getRobuxAmountFromElement(targetCell) !== amount) return;

upsertEstimate(targetCell, formattedEstimate, {
compact: true,
appendInside: true,
});
labelCell.dataset.rovalraUsdAmount = String(resolvedAmount);
} catch (error) {
} catch {
/* ignore */
}
}

function shouldIgnoreEstimateMutation(mutations) {

Check warning on line 707 in src/content/core/ui/robuxIcon.js

View workflow job for this annotation

GitHub Actions / eslint

'shouldIgnoreEstimateMutation' is defined but never used
return mutations.every((mutation) => {
if (mutation.target instanceof HTMLElement) {
return mutation.target.closest('.rovalra-usd-estimate') !== null;
Expand Down Expand Up @@ -735,6 +750,14 @@
if (!(labelCell instanceof HTMLElement)) return;
attachTransactionsCellEstimate(labelCell);
});

summaryRoot.querySelectorAll('td.amount').forEach((amountCell) => {
if (amountCell.dataset.rovalraObserved) return;
amountCell.dataset.rovalraObserved = 'true';
observeChildren(amountCell, () =>
processTransactionsTable(summaryRoot),
);
});
}

async function attachGroupRevenueEstimate(amountCell) {
Expand All @@ -760,7 +783,7 @@

upsertEstimate(amountCell, formattedEstimate, { compact: true });
amountCell.dataset.rovalraUsdAmount = String(resolvedAmount);
} catch (error) {
} catch {
/* ignore */
}
}
Expand Down Expand Up @@ -857,7 +880,7 @@

upsertEstimate(element, formattedEstimate);
icon.dataset.rovalraUsdAmount = String(resolvedAmount);
} catch (error) {
} catch {
/* ignore */
}
}
Expand Down Expand Up @@ -892,7 +915,7 @@

upsertEstimate(amountElement, formattedEstimate);
amountElement.dataset.rovalraUsdAmount = String(resolvedAmount);
} catch (error) {
} catch {
/* ignore */
}
}
Expand All @@ -900,9 +923,9 @@
function injectNavbarEstimateStyles() {
if (document.getElementById('rovalra-navbar-estimate-styles')) return;

const style = document.createElement('style');

Check failure on line 926 in src/content/core/ui/robuxIcon.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ Do not create <style> tags dynamically. Use the centralized SCSS files in 'src/css/'
style.id = 'rovalra-navbar-estimate-styles';
style.textContent = `

Check failure on line 928 in src/content/core/ui/robuxIcon.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ Avoid writing raw CSS in JavaScript. Please define styles in 'src/css/' (SCSS) and use class names instead to promote reuse and maintainability
#navbar-robux button:has(.rovalra-usd-estimate),
#navbar-robux .nav-robux-icon:has(.rovalra-usd-estimate),
#navbar-robux .nav-robux-icon:has(.rovalra-usd-estimate) > .rbx-text-navbar-right {
Expand Down Expand Up @@ -1050,6 +1073,7 @@
'robuxFiatEstimatesEnabled',
'robuxFiatDisplayCurrency',
'robuxFiatRateMode',
'devexPayoutMethod',
];

if ('streamermode' in changes || 'hideRobux' in changes) {
Expand Down Expand Up @@ -1136,6 +1160,7 @@
(element) => {
processTransactionsTable(element);
observeChildren(element, () => processTransactionsTable(element));
observeText(element, () => processTransactionsTable(element));
observeAttributes(
element,
() => processTransactionsTable(element),
Expand Down
Loading
Loading