Skip to content

Commit cbbfefb

Browse files
authored
Merge pull request #49 from TxnLab/txn-1267-only-reconnect-to-active-wallet
2 parents 6b7467b + 0a48316 commit cbbfefb

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/txnlab/use-wallet/issues"
1313
},
1414
"homepage": "https://txnlab.github.io/use-wallet",
15-
"version": "1.2.3",
15+
"version": "1.2.4",
1616
"description": "React hooks for using Algorand compatible wallets in dApps.",
1717
"scripts": {
1818
"dev": "yarn storybook",

src/utils/providers.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PROVIDER_ID } from "src/constants";
2+
import { useWalletStore } from "src/store";
3+
4+
export const getActiveProviders = () => {
5+
const accounts = useWalletStore.getState().accounts;
6+
return [...new Set(accounts.map((acct) => acct.providerId))];
7+
}
8+
9+
export const isActiveProvider = (id: PROVIDER_ID) => {
10+
const activeProviders = getActiveProviders();
11+
return activeProviders.includes(id);
12+
}

src/utils/reconnectProviders.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { WalletClient } from "../types";
22
import { clearAccounts } from "./clearAccounts";
3+
import { isActiveProvider } from "./providers";
34

45
type SupportedProviders = { [x: string]: Promise<WalletClient | null> };
56

@@ -9,7 +10,12 @@ export const reconnectProviders = async (providers: SupportedProviders) => {
910

1011
for (const client of clients) {
1112
const c = await client;
12-
c?.reconnect(() => clearAccounts(c?.metadata.id));
13+
const id = c?.metadata.id;
14+
15+
// Only reconnect to active providers
16+
if (id && isActiveProvider(id)) {
17+
c.reconnect(() => clearAccounts(id));
18+
}
1319
}
1420
} catch (e) {
1521
console.error(e);

0 commit comments

Comments
 (0)