Skip to content

Commit

Permalink
Merge pull request #271 from lidofinance/feature/si-1274-bug-transact…
Browse files Browse the repository at this point in the history
…ion-error-if-user-changes-the-chain

fix: transaction error after user changed the chain
  • Loading branch information
jake4take authored Mar 19, 2024
2 parents 74803db + 052a025 commit ca149a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const ClaimFormProvider: FC<PropsWithChildren> = ({ children }) => {
// for regular updates generate new list but keep user input
const oldValues = getValues('requests');
const checkedIds = new Set(
oldValues.filter((req) => req.checked).map((req) => req.token_id),
oldValues?.filter((req) => req.checked).map((req) => req.token_id),
);
const newRequests = generateDefaultValues(
data,
Expand Down
13 changes: 12 additions & 1 deletion providers/sdk-legacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ export const SDKLegacyProvider = (props: {
void (async () => {
if (!providerWeb3 && connector && isConnected) {
const provider = await connector.getProvider();
const wrappedProvider = new Web3Provider(provider);
// `any` param + page reload on network change
// are described here: https://github.com/ethers-io/ethers.js/issues/866
// this approach is needed to fix a NETWORK_ERROR after chain changing
const wrappedProvider = new Web3Provider(provider, 'any');
wrappedProvider.on('network', (newNetwork, oldNetwork) => {
// When a Provider makes its initial connection, it emits a "network"
// event with a null oldNetwork along with the newNetwork. So, if the
// oldNetwork exists, it represents a changing network
if (oldNetwork) {
window.location.reload();
}
});
wrappedProvider.pollingInterval = pollingInterval;
setProviderWeb3(wrappedProvider);
}
Expand Down

0 comments on commit ca149a2

Please sign in to comment.