From 31fad07130a628e0b066201376adba5e98d6bd2c Mon Sep 17 00:00:00 2001 From: 0xDeon <110722148+0xDeon@users.noreply.github.com> Date: Fri, 6 Nov 2026 23:34:04 +0100 Subject: [PATCH] fix(dapp): name the connected wallet on every deployment, not only multi-network ones The fetch wrapper that adds the wallet header was installed only where several Stellar networks are served. Prod is built with mainnet alone, so plain fetch calls carried no wallet: naira payouts answered "Connect your wallet to cash out" to connected wallets, and payout history came back empty. --- apps/dapp/components/connect/connect-home.tsx | 4 ++-- apps/dapp/lib/__tests__/network-fetch.test.ts | 23 ++++++++++++++++++- apps/dapp/lib/api/network-fetch.ts | 11 +++++++++ apps/dapp/providers/chain-provider.tsx | 5 ++-- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/apps/dapp/components/connect/connect-home.tsx b/apps/dapp/components/connect/connect-home.tsx index 5951f2c9..e9e39970 100644 --- a/apps/dapp/components/connect/connect-home.tsx +++ b/apps/dapp/components/connect/connect-home.tsx @@ -12,7 +12,7 @@ import type { ChainSlug } from '@intent/types' import dynamic from 'next/dynamic' import { useRouter, useSearchParams } from 'next/navigation' -import { installNetworkFetch } from '../../lib/api/network-fetch' +import { installPageFetch } from '../../lib/api/network-fetch' import { rememberChain } from '../../lib/wallet/chain-cookie' import { screenAfterConnect } from '../../lib/wallet/chain-path' @@ -37,7 +37,7 @@ export function ConnectHome(): JSX.Element { const network = parseChainSegment(stellarHome)?.network ?? defaultNetwork() if (typeof window !== 'undefined') { setClientNetwork(network) - if (isMultiNetwork()) installNetworkFetch(network) + installPageFetch(network) } function onConnected(slug: ChainSlug): void { diff --git a/apps/dapp/lib/__tests__/network-fetch.test.ts b/apps/dapp/lib/__tests__/network-fetch.test.ts index 14fb6512..2f9aa3ca 100644 --- a/apps/dapp/lib/__tests__/network-fetch.test.ts +++ b/apps/dapp/lib/__tests__/network-fetch.test.ts @@ -1,6 +1,7 @@ -import { describe, expect, it } from 'vitest' +import { describe, expect, it, vi } from 'vitest' import { + installPageFetch, networkFetch, setAttributedRace, setConnectedWallet, @@ -112,3 +113,23 @@ describe('networkFetch wallet header', () => { expect(seen[1]?.get('x-intent-wallet')).toBeNull() }) }) + +describe('installPageFetch', () => { + it('names the wallet on every call to this app, on a deployment that serves one network', async () => { + vi.stubEnv('NEXT_PUBLIC_STELLAR_NETWORKS', 'mainnet') + const { base, calls } = spy() + const page = { fetch: base, location: { origin: ORIGIN } } as unknown as Window + vi.stubGlobal('window', page) + try { + setConnectedWallet('GWALLET') + installPageFetch('mainnet') + await page.fetch(`${ORIGIN}/api/naira/orders`) + await page.fetch(`${ORIGIN}/api/naira/rate`) + } finally { + setConnectedWallet(undefined) + vi.unstubAllGlobals() + vi.unstubAllEnvs() + } + expect(calls.map((c) => c.headers.get('x-intent-wallet'))).toEqual(['GWALLET', 'GWALLET']) + }) +}) diff --git a/apps/dapp/lib/api/network-fetch.ts b/apps/dapp/lib/api/network-fetch.ts index 36fa374b..e7c9d284 100644 --- a/apps/dapp/lib/api/network-fetch.ts +++ b/apps/dapp/lib/api/network-fetch.ts @@ -71,6 +71,17 @@ export function walletFetch(input: string, init?: RequestInit): Promise(() => {