Skip to content

Commit

Permalink
Add workaround on wallet connectors to remove from localStorage (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadai2010 authored Aug 21, 2024
1 parent ea4379a commit ca6fde4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/nextjs/services/web3/connectors.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { argent, braavos } from "@starknet-react/core";
import { argent, braavos, InjectedConnector } from "@starknet-react/core";
import { getTargetNetworks } from "~~/utils/scaffold-stark";
import { BurnerConnector } from "./stark-burner/BurnerConnector";
import scaffoldConfig from "~~/scaffold.config";
Expand All @@ -7,6 +7,17 @@ const targetNetworks = getTargetNetworks();

export const connectors = getConnectors();

// workaround helper function to properly disconnect with removing local storage (prevent autoconnect infinite loop)
function withDisconnectWrapper(connector: InjectedConnector) {
const connectorDisconnect = connector.disconnect;
const _disconnect = (): Promise<void> => {
localStorage.removeItem("lastUsedConnector");
return connectorDisconnect();
};
connector.disconnect = _disconnect.bind(connector);
return connector;
}

function getConnectors() {
const { targetNetworks } = scaffoldConfig;

Expand All @@ -18,7 +29,7 @@ function getConnectors() {
connectors.push(new BurnerConnector());
}

return connectors.sort(() => Math.random() - 0.5);
return connectors.sort(() => Math.random() - 0.5).map(withDisconnectWrapper);
}

export const appChains = targetNetworks;
2 changes: 1 addition & 1 deletion packages/snfoundry/scripts-ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const deployScript = async (): Promise<void> => {
// },
// ],
// {
// maxFee: 1e18,
// maxFee: 1e15,
// }
// );
// };
Expand Down

0 comments on commit ca6fde4

Please sign in to comment.