Skip to content

Commit 92ab25b

Browse files
fix: default MWA config to use a relative icon path. (#43)
* Fix default MWA config to use a relative icon path. Co-Authored-By: Cursor <cursoragent@cursor.com> * Update package.json --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e5f4ee9 commit 92ab25b

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

packages/connector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solana/connector",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Headless wallet connector client and React provider built on Wallet Standard",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

packages/connector/src/config/config.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ describe('Configuration System', () => {
243243
appUrl: 'https://test.com',
244244
});
245245

246-
expect(config.appIdentity.icon).toContain('favicon.ico');
246+
// MWA expects a relative icon path (resolved against appIdentity.uri)
247+
expect(config.appIdentity.icon).toBe('/favicon.ico');
247248
});
248249
});
249250

packages/connector/src/config/default-config.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,31 @@ export function getDefaultMobileConfig(options: {
398398
appUrl?: string;
399399
network?: 'mainnet' | 'mainnet-beta' | 'devnet' | 'testnet';
400400
}) {
401-
const baseUrl =
402-
options.appUrl || (typeof window !== 'undefined' ? window.location.origin : 'https://localhost:3000');
401+
// NOTE: Mobile Wallet Adapter expects `appIdentity.icon` to be a *relative path* (or omitted).
402+
// It resolves this relative path against `appIdentity.uri`.
403+
// @see https://docs.solanamobile.com/mobile-wallet-adapter/web-installation
404+
function getAppOrigin(appUrl?: string): string {
405+
if (appUrl) {
406+
try {
407+
return new URL(appUrl).origin;
408+
} catch {
409+
// If appUrl is already an origin-like string, use it as-is.
410+
return appUrl;
411+
}
412+
}
413+
if (typeof window !== 'undefined') return window.location.origin;
414+
return 'https://localhost:3000';
415+
}
416+
417+
const origin = getAppOrigin(options.appUrl);
403418

404419
return {
405420
appIdentity: {
406421
name: options.appName,
407-
uri: baseUrl,
408-
icon: `${baseUrl}/favicon.ico`,
422+
uri: origin,
423+
// Use a relative icon path so wallets resolve it against `uri`.
424+
// This avoids invalid URLs like: `${uri}/${uri}/favicon.ico` on mobile.
425+
icon: '/favicon.ico',
409426
},
410427
cluster: options.network || 'mainnet-beta',
411428
};

0 commit comments

Comments
 (0)