Skip to content
Merged
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
44 changes: 44 additions & 0 deletions apps/frontend/e2e/product-discovery.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { expect, test } from "@playwright/test";

test.use({ viewport: { height: 844, width: 320 } });

for (const locale of ["en", "pt-BR"]) {
for (const audience of ["individuals", "business"]) {
test(`${locale} ${audience}: Brazilian product entries fit a narrow screen`, async ({ page }) => {
await page.route("**/maintenance/status", route =>
route.fulfill({
json: { is_maintenance_active: false, maintenance_details: null }
})
);
const path = audience === "business" ? `/${locale}/business` : `/${locale}/`;
await page.goto(`${path}#discover-${audience}`);
const section = page.locator(`section[aria-labelledby="discover-${audience}"]`);
await expect(section).toBeVisible();
await expect(section.locator('a[href="/pt-br/gold/"]')).toHaveCount(1);
await expect(section.locator('a[href="/pt-br/stocks/"]')).toHaveCount(1);
await expect(section.getByRole("heading", { level: 2 })).toContainText(
locale === "pt-BR"
? audience === "business"
? "Veja o que"
: "Ouro e tokens"
: audience === "business"
? "See what"
: "Gold and US"
);
// The old fixed-width footer columns pushed both pages to 368px at this viewport.
await expect.poll(() => page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(320);
if (audience === "business") {
await expect
.poll(() =>
section.evaluate(element =>
[...element.querySelectorAll<HTMLImageElement>(".product-discovery__preview")].every(image => {
const frame = image.parentElement?.getBoundingClientRect();
return frame && image.getBoundingClientRect().bottom <= frame.bottom - 20;
})
)
)
.toBe(true);
}
});
}
}
1 change: 0 additions & 1 deletion apps/frontend/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
X-Content-Type-Options = "nosniff"
Referrer-Policy = "strict-origin-when-cross-origin"
Permissions-Policy = "camera=(self), microphone=(), geolocation=()"
X-Robots-Tag = "noindex"

[[headers]]
for = "/en/stocks/*"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/frontend/src/assets/products/gold-bar.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion apps/frontend/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const PoweredBySatoshipay = () => {
};

const FooterSection = ({ title, children }: { title: string; children: ReactNode }) => (
<div className="mr-8 mb-8 flex min-w-[160px] flex-col">
<div className="mr-8 mb-8 flex min-w-0 flex-col">
<h3 className="mb-4 font-bold text-gray-900">{title}</h3>
<div className="flex flex-col gap-3 text-gray-600 text-sm">{children}</div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions apps/frontend/src/i18n.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, it, vi } from "vitest";

it.each([
["/pt-BR/business", "en-US", "pt-BR"],
["/pt-br/", "en-US", "pt-BR"],
["/en/business", "pt-BR", "en"],
["/", "pt-BR", "pt-BR"]
])("initializes %s in %s's correct route language", async (pathname, browserLanguage, expected) => {
vi.resetModules();
vi.stubGlobal("window", { location: { pathname }, navigator: { language: browserLanguage, languages: [browserLanguage] } });
try {
const { default: i18n } = await import("./i18n");
expect(i18n.resolvedLanguage).toBe(expected);
} finally { vi.unstubAllGlobals(); }
});
6 changes: 3 additions & 3 deletions apps/frontend/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import enTranslations from "./translations/en.json";
import { getBrowserLanguage, Language } from "./translations/helpers";
import { getLanguageFromPath, Language } from "./translations/helpers";
import ptTranslations from "./translations/pt.json";

// Initialize i18n with browser language as default (falls back to English during SSR,
// Initialize i18n from the URL before browser preferences (falls back to English during SSR,
// where there is no navigator). The actual language is set by the locale route's beforeLoad.
//
// This is a module singleton whose language the `{-$locale}` route switches on every
// navigation. Prerendering therefore runs with `concurrency: 1` (see vite.config.ts) so that
// pages cannot race over the active language — do not make either side concurrent alone.
i18n.use(initReactI18next).init({
fallbackLng: "en",
lng: getBrowserLanguage(),
lng: getLanguageFromPath(),
resources: {
[Language.English]: {
translation: enTranslations
Expand Down
2 changes: 2 additions & 0 deletions apps/frontend/src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { BaseLayout } from "../../layouts";
import { FAQAccordion, FeeComparison, HowToSell, PopularTokens, TrustedBy, WhyVortex } from "../../sections";
import { GotQuestions } from "../../sections/individuals/GotQuestions";
import { Hero } from "../../sections/individuals/Hero";
import { ProductDiscovery } from "../../sections/ProductDiscovery";

export const Main = () => {
const main = (
<main>
<Hero />
<ProductDiscovery audience="individuals" />
<TrustedBy />
<FeeComparison />
<WhyVortex />
Expand Down
2 changes: 2 additions & 0 deletions apps/frontend/src/routes/{-$locale}/business.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BaseLayout } from "../../layouts";
import { WhyVortexApi, WhyVortexBusiness, WhyVortexWidget } from "../../sections";
import { GotQuestions } from "../../sections/business/GotQuestions";
import { Hero } from "../../sections/business/Hero";
import { ProductDiscovery } from "../../sections/ProductDiscovery";

export const Route = createFileRoute("/{-$locale}/business")({
component: BusinessRouteComponent
Expand All @@ -12,6 +13,7 @@ function BusinessRouteComponent() {
const main = (
<>
<Hero />
<ProductDiscovery audience="business" />
<WhyVortexBusiness />
<WhyVortexApi />
<WhyVortexWidget />
Expand Down
13 changes: 13 additions & 0 deletions apps/frontend/src/sections/ProductDiscovery/index.ssr.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { renderToString } from "react-dom/server";
import { expect, it, vi } from "vitest";
import { ProductDiscovery } from ".";

vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key, i18n: { resolvedLanguage: "en" } }) }));

it.each(["individuals", "business"] as const)("prerenders the %s discovery section without browser globals", audience => {
expect(typeof window).toBe("undefined");
const html = renderToString(<ProductDiscovery audience={audience} />);
expect(html).toContain('href="/pt-br/gold/"');
expect(html).toContain('href="/pt-br/stocks/"');
expect(html).not.toMatch(/style="[^\"]*(width|height):\s*\d/);
});
51 changes: 51 additions & 0 deletions apps/frontend/src/sections/ProductDiscovery/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// @vitest-environment jsdom
import { createInstance } from "i18next";
import { renderToString } from "react-dom/server";
import { I18nextProvider, initReactI18next } from "react-i18next";
import { describe, expect, it } from "vitest";
import en from "../../translations/en.json";
import pt from "../../translations/pt.json";
import { ProductDiscovery } from ".";

describe.each(["en", "pt-BR"])("Product discovery in %s", language => {
async function render(audience: "individuals" | "business") {
const i18n = createInstance();
await i18n.use(initReactI18next).init({
fallbackLng: "en",
lng: language,
resources: { en: { translation: en }, "pt-BR": { translation: pt } }
});
const container = document.createElement("div");
container.innerHTML = renderToString(<I18nextProvider i18n={i18n}><ProductDiscovery audience={audience} /></I18nextProvider>);
return container;
}

it.each(["individuals", "business"] as const)("%s links directly to the separate Brazilian apps", async audience => {
const dom = await render(audience);
try {
const document = dom;
expect(document.querySelectorAll('a[href="/pt-br/gold/"]').length).toBe(1);
expect(document.querySelectorAll('a[href="/pt-br/stocks/"]').length).toBe(1);
expect(document.querySelectorAll("h2").length).toBe(1);
expect(document.querySelectorAll("h3").length).toBe(2);
expect(document.textContent).not.toContain("sections.productDiscovery");
expect(document.textContent).not.toMatch(/50\s*bps|0[.,]25\s*%|guaranteed|garantido/i);
expect([...document.querySelectorAll("img")].every(img => img.hasAttribute("alt") && img.hasAttribute("width") && img.hasAttribute("height"))).toBe(true);
for (const link of document.querySelectorAll("a[aria-labelledby]")) {
expect(link.getAttribute("aria-labelledby")?.split(" ").every(id => document.querySelector(`[id="${id}"]`)?.textContent)).toBe(true);
}
} finally { dom.replaceChildren(); }
});

it("gives consumers cost clarity and businesses a localized sales/docs path", async () => {
const consumer = await render("individuals"), business = await render("business");
try {
expect(consumer.textContent).toContain(language === "en" ? "Fair fees. Clear costs." : "Taxas justas. Custos claros.");
expect(consumer.querySelector(".product-discovery__qualification")?.textContent).toContain(language === "en" ? "You buy tokens" : "Você compra tokens");
expect(consumer.querySelector(".product-discovery__business-actions")).toBeNull();
expect(business.querySelector('a[href="' + (language === "en" ? "/en/contact" : "/pt-BR/contact") + '"]')?.textContent).toBe(language === "en" ? "Build with Vortex" : "Crie com a Vortex");
expect(business.querySelector('a[href="https://api-docs.vortexfinance.co/"]')?.getAttribute("rel")).toContain("noopener");
expect(business.querySelectorAll(".product-discovery__preview").length).toBe(2);
} finally { consumer.replaceChildren(); business.replaceChildren(); }
});
});
141 changes: 141 additions & 0 deletions apps/frontend/src/sections/ProductDiscovery/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { ArrowRightIcon, ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline";
import { useTranslation } from "react-i18next";
import brazil from "../../assets/countries/brazil.png";
import fatiaLight from "../../assets/products/fatia-wordmark-reversed.svg";
import goldBar from "../../assets/products/gold-bar.webp";
import goldPreview from "../../assets/products/gold-preview.jpg";
import ouro from "../../assets/products/ouro-wordmark.png";
import stocksMan800 from "../../assets/products/stocks-man-800.jpg";
import stocksMan1440 from "../../assets/products/stocks-man-1440.jpg";
import stocksPreview from "../../assets/products/stocks-preview.jpg";
import "./styles.css";

const PRODUCTS = [
{ href: "/pt-br/gold/", key: "gold", preview: goldPreview },
{ href: "/pt-br/stocks/", key: "stocks", preview: stocksPreview }
] as const;

export function ProductDiscovery({ audience }: { audience: "individuals" | "business" }) {
const { t, i18n } = useTranslation();
const business = audience === "business";
const key = `sections.productDiscovery.${audience}`;
const headingId = `discover-${audience}`;
return (
<section aria-labelledby={headingId} className={`product-discovery product-discovery--${audience}`}>
<div className="product-discovery__inner">
<p className="product-discovery__eyebrow">{t(`${key}.eyebrow`)}</p>
<div className="product-discovery__heading-row">
<h2 id={headingId}>
{t(`${key}.title`)}
{!business && <span>{t(`${key}.accent`)}</span>}
</h2>
<p className="product-discovery__market">
<img alt="" height="20" loading="lazy" src={brazil} width="20" />
{t(`${key}.market`)}
</p>
</div>
<p className="product-discovery__description">{t(`${key}.description`)}</p>
<div className="product-discovery__grid">
{PRODUCTS.map(product => {
const id = `${headingId}-${product.key}`;
return (
<a
aria-labelledby={`${id}-title ${id}-action`}
className={`product-discovery__card product-discovery__card--${product.key}`}
href={product.href}
key={product.key}
>
{business ? (
<>
<div className="product-discovery__example-copy">
<h3 id={`${id}-title`}>{t(`${key}.${product.key}.title`)}</h3>
<span className="product-discovery__example-link" id={`${id}-action`}>
{t(`${key}.${product.key}.action`)}
<ArrowRightIcon aria-hidden="true" />
</span>
</div>
<img
alt={t(`${key}.${product.key}.previewAlt`)}
className="product-discovery__preview"
decoding="async"
height="800"
loading="lazy"
src={product.preview}
width="1200"
/>
</>
) : (
<>
{product.key === "gold" ? (
<img
alt=""
className="product-discovery__gold"
decoding="async"
height="1536"
loading="lazy"
src={goldBar}
width="1024"
/>
) : (
<img
alt=""
className="product-discovery__photo"
decoding="async"
height="960"
loading="lazy"
sizes="(min-width: 1280px) 640px, (min-width: 768px) 50vw, 100vw"
src={stocksMan800}
srcSet={`${stocksMan800} 800w, ${stocksMan1440} 1440w`}
width="1440"
/>
)}
<div className="product-discovery__card-copy">
<div className="product-discovery__brand">
<img
alt={product.key === "gold" ? "ouro." : "fatia."}
height="60"
loading="lazy"
src={product.key === "stocks" ? fatiaLight : ouro}
width="160"
/>
<span>by Vortex</span>
</div>
<div>
<h3 id={`${id}-title`}>{t(`${key}.${product.key}.title`)}</h3>
<p>{t(`${key}.${product.key}.description`)}</p>
</div>
<span className="product-discovery__action" id={`${id}-action`}>
{t(`${key}.${product.key}.action`)}
<ArrowRightIcon aria-hidden="true" />
</span>
</div>
</>
)}
</a>
);
})}
</div>
{!business && <p className="product-discovery__qualification">{t(`${key}.qualification`)}</p>}
{business && (
<div className="product-discovery__business-actions">
<a
className="btn btn-vortex-primary"
href={i18n.resolvedLanguage?.startsWith("pt") ? "/pt-BR/contact" : "/en/contact"}
>
{t(`${key}.build`)}
</a>
<a
className="product-discovery__docs"
href="https://api-docs.vortexfinance.co/"
rel="noopener noreferrer"
target="_blank"
>
{t(`${key}.docs`)}
<ArrowTopRightOnSquareIcon aria-hidden="true" />
</a>
</div>
)}
</div>
</section>
);
}
Loading
Loading