From 547e1f1e19e0cd3b0754b5dd368b13121ddae69d Mon Sep 17 00:00:00 2001 From: "Calum H. (IMB11)" Date: Sun, 1 Mar 2026 19:04:18 +0000 Subject: [PATCH] fix: remove tax compliance env var --- apps/labrinth/.env.docker-compose | 2 -- apps/labrinth/.env.local | 2 -- apps/labrinth/src/env.rs | 2 -- apps/labrinth/src/routes/internal/globals.rs | 2 +- apps/labrinth/src/routes/v3/payouts.rs | 26 ++++++++++++++++++-- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/apps/labrinth/.env.docker-compose b/apps/labrinth/.env.docker-compose index 5198de5ad7..813dc74e94 100644 --- a/apps/labrinth/.env.docker-compose +++ b/apps/labrinth/.env.docker-compose @@ -140,8 +140,6 @@ AVALARA_1099_API_KEY=none AVALARA_1099_API_TEAM_ID=none AVALARA_1099_COMPANY_ID=207337084 -COMPLIANCE_PAYOUT_THRESHOLD=disabled - ANROK_API_KEY=none ANROK_API_URL=none diff --git a/apps/labrinth/.env.local b/apps/labrinth/.env.local index 0040a36ba5..9e4168bb8e 100644 --- a/apps/labrinth/.env.local +++ b/apps/labrinth/.env.local @@ -150,8 +150,6 @@ AVALARA_1099_API_KEY=none AVALARA_1099_API_TEAM_ID=none AVALARA_1099_COMPANY_ID=207337084 -COMPLIANCE_PAYOUT_THRESHOLD=disabled - ANROK_API_KEY=none ANROK_API_URL=none diff --git a/apps/labrinth/src/env.rs b/apps/labrinth/src/env.rs index a78b167799..561cb3a0c5 100644 --- a/apps/labrinth/src/env.rs +++ b/apps/labrinth/src/env.rs @@ -242,8 +242,6 @@ vars! { ANROK_API_URL: String; ANROK_API_KEY: String; - COMPLIANCE_PAYOUT_THRESHOLD: String; - PAYOUT_ALERT_SLACK_WEBHOOK: String; CLOUDFLARE_INTEGRATION: bool = false; diff --git a/apps/labrinth/src/routes/internal/globals.rs b/apps/labrinth/src/routes/internal/globals.rs index 0317c5a943..a0e2ee727e 100644 --- a/apps/labrinth/src/routes/internal/globals.rs +++ b/apps/labrinth/src/routes/internal/globals.rs @@ -25,7 +25,7 @@ pub struct Globals { pub captcha_enabled: bool, } -static GLOBALS: LazyLock = LazyLock::new(|| Globals { +pub static GLOBALS: LazyLock = LazyLock::new(|| Globals { tax_compliance_thresholds: [(2025, 600), (2026, 2000)] .into_iter() .collect(), diff --git a/apps/labrinth/src/routes/v3/payouts.rs b/apps/labrinth/src/routes/v3/payouts.rs index 69a598cb37..ebd20c59a6 100644 --- a/apps/labrinth/src/routes/v3/payouts.rs +++ b/apps/labrinth/src/routes/v3/payouts.rs @@ -15,7 +15,7 @@ use crate::util::avalara1099; use crate::util::error::Context; use crate::util::gotenberg::GotenbergClient; use actix_web::{HttpRequest, HttpResponse, delete, get, post, web}; -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Datelike, Duration, Utc}; use hex::ToHex; use hmac::{Hmac, Mac}; use modrinth_util::decimal::Decimal2dp; @@ -1117,7 +1117,29 @@ async fn update_compliance_status( } fn tax_compliance_payout_threshold() -> Option { - ENV.COMPLIANCE_PAYOUT_THRESHOLD.parse().ok() + let globals = &crate::routes::internal::globals::GLOBALS; + let current_year = Utc::now().year() as u16; + let thresholds = &globals.tax_compliance_thresholds; + + if thresholds.is_empty() { + return None; + } + + let mut years: Vec = thresholds.keys().copied().collect(); + years.sort(); + + let value = if current_year <= years[0] { + thresholds[&years[0]] + } else if current_year >= *years.last().unwrap() { + thresholds[years.last().unwrap()] + } else { + thresholds + .get(¤t_year) + .copied() + .unwrap_or_else(|| thresholds[years.last().unwrap()]) + }; + + Some(Decimal::from(value)) } #[derive(Deserialize)]