Skip to content

Commit 2d4b37d

Browse files
committed
fix: preserve firefoxId from dynamically detected extensions
1 parent d8f41b7 commit 2d4b37d

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

packages/beacon-transport-postmessage/src/PostMessageTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class PostMessageTransport<
108108

109109
const data = event.data as ExtensionMessage<
110110
string,
111-
{ id: string; name: string; iconURL: string }
111+
{ id: string; name: string; iconURL: string; firefoxId?: string }
112112
>
113113
const sender = data.sender
114114
if (data && data.payload === 'pong' && sender) {

packages/beacon-types/src/types/Extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ export interface Extension {
44
shortName?: string
55
iconUrl?: string
66
color?: string
7+
/**
8+
* Firefox extension ID. Used by dynamically detected extensions to enable
9+
* proper pairing on Firefox. When an extension responds to a ping with a
10+
* firefoxId in the sender object, it should be preserved here so the SDK
11+
* can send pairing messages to both the Chrome and Firefox extension IDs.
12+
*/
13+
firefoxId?: string
714
}

packages/beacon-ui/src/ui/alert/hooks/useConnect.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const useConnect = (
3131
!wallet ||
3232
(wallet.types.length <= 1 &&
3333
!wallet.types.includes('ios') &&
34-
!wallet.types.includes('desktop')) ||
34+
!wallet.types.includes('desktop') &&
35+
!wallet.types.includes('extension')) ||
3536
(isMobileOS(window) && wallet.types.length === 1 && wallet.types.includes('desktop'))
3637
) {
3738
return

packages/beacon-ui/src/ui/alert/hooks/useWallets.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,16 @@ const useWallets = (networkType?: NetworkType, featuredWallets?: string[]) => {
8686
.filter((e) => !extensionList.some((w) => w.id === e.id))
8787
.map((e) => ({
8888
id: e.id,
89-
key: e.id,
89+
// If extension provides firefoxId, include it in the key so mergeWallets()
90+
// can detect it and set the firefoxId property on the merged wallet
91+
key: e.firefoxId ? `${e.id}-firefox` : e.id,
9092
name: e.shortName ?? e.name ?? '',
9193
image: e.iconUrl ?? '',
9294
description: 'Browser Extension',
9395
type: 'extension' as const,
94-
link: (e as any).link ?? ''
96+
link: (e as any).link ?? '',
97+
// Also pass through the firefoxId for direct access
98+
firefoxId: e.firefoxId
9599
}))
96100
]
97101

packages/beacon-ui/src/utils/wallets.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface Wallet {
88
link: string
99
supportedInteractionStandards?: ('wallet_connect' | 'beacon')[] // 'wallet_connect' or 'beacon'
1010
deepLink?: string
11+
firefoxId?: string // Firefox extension ID for dynamically detected extensions
1112
}
1213

1314
export interface MergedWallet {
@@ -113,16 +114,18 @@ export function mergeWallets(wallets: Wallet[]): MergedWallet[] {
113114
}
114115
mergedWallets[index].types.push(wallet.type)
115116
mergedWallets[index].deepLink = wallet.deepLink
116-
mergedWallets[index].firefoxId = wallet.key.includes('firefox')
117-
? wallet.id
118-
: mergedWallets[index].firefoxId
117+
// Set firefoxId from: 1) wallet's explicit firefoxId, 2) key containing 'firefox', 3) existing value
118+
mergedWallets[index].firefoxId = wallet.firefoxId
119+
?? (wallet.key.includes('firefox') ? wallet.id : undefined)
120+
?? mergedWallets[index].firefoxId
119121
} else {
120122
const newWallet: MergedWallet = {
121123
...wallet,
122124
descriptions: [wallet.description],
123125
links: ['', '', '', ''],
124126
types: [wallet.type],
125-
firefoxId: wallet.key.includes('firefox') ? wallet.id : undefined
127+
// Set firefoxId from explicit property or from key pattern
128+
firefoxId: wallet.firefoxId ?? (wallet.key.includes('firefox') ? wallet.id : undefined)
126129
}
127130

128131
setWallet(newWallet, wallet)

0 commit comments

Comments
 (0)