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(() => {