From 7b60175cd2e1048a4f8a4fe29f99698d79b187fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pascal=20Honor=C3=A9?= <pascal@alseyn.net>
Date: Tue, 28 Jan 2025 11:32:23 +0000
Subject: [PATCH] Use article's contributionsServiceUrl

---
 .../src/components/ArticleBody.tsx            |  1 +
 .../src/components/Island.test.tsx            |  1 +
 .../SignInGateSelector.importable.tsx         | 23 ++++++++++++++++---
 dotcom-rendering/src/lib/ArticleRenderer.tsx  |  3 +++
 .../src/lib/withSignInGateSlot.tsx            |  5 ++++
 5 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/dotcom-rendering/src/components/ArticleBody.tsx b/dotcom-rendering/src/components/ArticleBody.tsx
index 4558a4ae3b4..0c2666be631 100644
--- a/dotcom-rendering/src/components/ArticleBody.tsx
+++ b/dotcom-rendering/src/components/ArticleBody.tsx
@@ -228,6 +228,7 @@ export const ArticleBody = ({
 					isSensitive={isSensitive}
 					abTests={abTests}
 					editionId={editionId}
+					contributionsServiceUrl={contributionsServiceUrl}
 				/>
 			</div>
 		</>
diff --git a/dotcom-rendering/src/components/Island.test.tsx b/dotcom-rendering/src/components/Island.test.tsx
index bc0fcffeb56..6e6c259b6d8 100644
--- a/dotcom-rendering/src/components/Island.test.tsx
+++ b/dotcom-rendering/src/components/Island.test.tsx
@@ -380,6 +380,7 @@ describe('Island: server-side rendering', () => {
 						isPreview={false}
 						pageId={''}
 						switches={{}}
+						contributionsServiceUrl={''}
 					/>
 				</WithConfig>,
 			),
diff --git a/dotcom-rendering/src/components/SignInGateSelector.importable.tsx b/dotcom-rendering/src/components/SignInGateSelector.importable.tsx
index e22c59b61d7..7022bda2fcf 100644
--- a/dotcom-rendering/src/components/SignInGateSelector.importable.tsx
+++ b/dotcom-rendering/src/components/SignInGateSelector.importable.tsx
@@ -42,6 +42,7 @@ type Props = {
 	pageId: string;
 	idUrl?: string;
 	switches: Switches;
+	contributionsServiceUrl: string;
 };
 
 // interface for the component which shows the sign in gate
@@ -199,7 +200,14 @@ const SignInGateSelectorDefault = ({
 	pageId,
 	idUrl = 'https://profile.theguardian.com',
 	switches,
+	contributionsServiceUrl,
 }: Props) => {
+	// comment group: auxia-prototype-e55a86ef
+	// The following (useless) instruction only exists to avoid linting error
+	// so that SignInGateSelectorDefault, SignInGateSelectorAuxia and SignInGateSelector
+	// all have the same signature, while we give shape to the Auxia prototype.
+	contributionsServiceUrl;
+
 	const authStatus = useAuthStatus();
 	const isSignedIn =
 		authStatus.kind === 'SignedInWithOkta' ||
@@ -349,6 +357,7 @@ export const SignInGateSelector = ({
 	pageId,
 	idUrl = 'https://profile.theguardian.com',
 	switches,
+	contributionsServiceUrl,
 }: Props) => {
 	const abTestAPI = useAB()?.api;
 	const userIsInAuxiaExperiment = !!abTestAPI?.isUserInVariant(
@@ -367,12 +376,14 @@ export const SignInGateSelector = ({
 			pageId,
 			idUrl,
 			switches,
+			contributionsServiceUrl,
 		});
 	} else {
 		return SignInGateSelectorAuxia({
 			host,
 			pageId,
 			idUrl,
+			contributionsServiceUrl,
 		});
 	}
 };
@@ -404,6 +415,7 @@ type PropsAuxia = {
 	host?: string;
 	pageId: string;
 	idUrl?: string;
+	contributionsServiceUrl: string;
 };
 
 /*
@@ -432,8 +444,10 @@ const dismissGateAuxia = (
 	setShowGate(false);
 };
 
-const fetchAuxiaDisplayDataFromProxy = async (): Promise<SDCProxyData> => {
-	const url = 'https://contributions.guardianapis.com/auxia';
+const fetchAuxiaDisplayDataFromProxy = async (
+	contributionsServiceUrl: string,
+): Promise<SDCProxyData> => {
+	const url = `${contributionsServiceUrl}/auxia`;
 	const headers = {
 		'Content-Type': 'application/json',
 	};
@@ -455,6 +469,7 @@ const SignInGateSelectorAuxia = ({
 	host = 'https://theguardian.com/',
 	pageId,
 	idUrl = 'https://profile.theguardian.com',
+	contributionsServiceUrl,
 }: PropsAuxia) => {
 	/*
 		comment group: auxia-prototype-e55a86ef
@@ -494,7 +509,9 @@ const SignInGateSelectorAuxia = ({
 
 	useOnce(() => {
 		void (async () => {
-			const data = await fetchAuxiaDisplayDataFromProxy();
+			const data = await fetchAuxiaDisplayDataFromProxy(
+				contributionsServiceUrl,
+			);
 			setShouldShowSignInGateUsingAuxiaAnswer(data.shouldShowSignInGate);
 		})().catch((error) => {
 			console.error('Error fetching Auxia display data:', error);
diff --git a/dotcom-rendering/src/lib/ArticleRenderer.tsx b/dotcom-rendering/src/lib/ArticleRenderer.tsx
index 4343b7266a6..f509c9bc958 100644
--- a/dotcom-rendering/src/lib/ArticleRenderer.tsx
+++ b/dotcom-rendering/src/lib/ArticleRenderer.tsx
@@ -34,6 +34,7 @@ type Props = {
 	isSensitive: boolean;
 	abTests: ServerSideTests;
 	editionId: EditionId;
+	contributionsServiceUrl: string;
 };
 
 export const ArticleRenderer = ({
@@ -55,6 +56,7 @@ export const ArticleRenderer = ({
 	isDev,
 	abTests,
 	editionId,
+	contributionsServiceUrl,
 }: Props) => {
 	const isSectionedMiniProfilesArticle =
 		elements.filter(
@@ -129,6 +131,7 @@ export const ArticleRenderer = ({
 						switches,
 						isSensitive,
 						isDev,
+						contributionsServiceUrl,
 				  })}
 		</div>
 	); // classname that space finder is going to target for in-body ads in DCR
diff --git a/dotcom-rendering/src/lib/withSignInGateSlot.tsx b/dotcom-rendering/src/lib/withSignInGateSlot.tsx
index db9d970e755..d28f6ab7d6a 100644
--- a/dotcom-rendering/src/lib/withSignInGateSlot.tsx
+++ b/dotcom-rendering/src/lib/withSignInGateSlot.tsx
@@ -20,6 +20,7 @@ type Props = {
 	switches: Switches;
 	isSensitive?: boolean;
 	isDev?: boolean;
+	contributionsServiceUrl: string;
 };
 
 export const withSignInGateSlot = ({
@@ -33,6 +34,7 @@ export const withSignInGateSlot = ({
 	pageId,
 	idUrl,
 	switches,
+	contributionsServiceUrl,
 }: Props): React.ReactNode => {
 	return renderedElements.map((element, i) => {
 		return (
@@ -52,6 +54,9 @@ export const withSignInGateSlot = ({
 								pageId={pageId}
 								idUrl={idUrl}
 								switches={switches}
+								contributionsServiceUrl={
+									contributionsServiceUrl
+								}
 							/>
 						</Island>
 					</div>