Skip to content

Commit 44060c8

Browse files
authored
chore: Emit once per environment (#13)
1 parent b132402 commit 44060c8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/lib/EIP6963Emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import {
66
import { config } from "./config";
77
import { getWallet } from "./wallet";
88

9-
let hasEmitted = false;
9+
const emittedEnvironments = new Set<string>();
1010

1111
export const EIP6963Emitter = (environmentId: string) => {
12-
// Ensure we only emit once per app lifetime
13-
if (hasEmitted) {
12+
// Ensure we only emit once per environment
13+
if (emittedEnvironments.has(environmentId)) {
1414
return;
1515
}
1616

17-
hasEmitted = true;
17+
emittedEnvironments.add(environmentId);
1818

1919
// Get wallet instance with the proper environment ID
2020
const wallet = getWallet(environmentId);

src/lib/wallet.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55

66
import { DYNAMIC_ENVIRONMENT_IDS } from "../constants";
77

8-
let walletInstance: GlobalWalletClient | null = null;
8+
const walletInstances = new Map<string, GlobalWalletClient>();
99

1010
/**
1111
* Get the wallet URL based on the environment ID
@@ -23,13 +23,14 @@ const getWalletUrl = (environmentId: string): string => {
2323
* Get or create the GlobalWalletClient instance with the specified environment ID
2424
*/
2525
export const getWallet = (environmentId: string): GlobalWalletClient => {
26-
if (!walletInstance) {
27-
walletInstance = createGlobalWalletClient({
26+
if (!walletInstances.has(environmentId)) {
27+
const walletInstance = createGlobalWalletClient({
2828
environmentId,
2929
popup: {
3030
url: getWalletUrl(environmentId),
3131
},
3232
});
33+
walletInstances.set(environmentId, walletInstance);
3334
}
34-
return walletInstance;
35+
return walletInstances.get(environmentId)!;
3536
};

0 commit comments

Comments
 (0)