Skip to content

Commit

Permalink
feat: add setWeb3Provider, remove chain from defineWeb3Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
DiRaiks committed Aug 24, 2023
1 parent 7bc4201 commit 960fdcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const lidoSDK = new LidoSDK({
});

// Define default web3 provider in sdk (window.ethereum) if web3Provider is not defined in constructor
lidoSDK.core.defineWeb3Provider(lidoSDK.core.chain);
lidoSDK.core.defineWeb3Provider();

// Views
const balanceETH = await lidoSDK.core.balanceETH(address);
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const lidoSDK = new LidoSDK({
});

// Define default web3 provider in sdk (window.ethereum) if web3Provider is not defined in constructor
lidoSDK.core.defineWeb3Provider(lidoSDK.core.chain);
lidoSDK.core.defineWeb3Provider();

const callback: StakeStageCallback = ({ stage, payload }) => {
switch (stage) {
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ export default class LidoSDKCore {
}

@Logger("Provider:")
public defineWeb3Provider(chain: Chain): WalletClient {
public defineWeb3Provider(): WalletClient {
invariant(!this.web3Provider, "Web3 provider is already defined");

this.web3Provider = this.createWeb3Provider(chain);
this.web3Provider = this.createWeb3Provider(this.chain);

return this.web3Provider;
}

@Logger("Provider:")
public setWeb3Provider(web3Provider: WalletClient): void {
invariant(web3Provider.chain === this.chain, "Wrong chain");

this.web3Provider = web3Provider;
}
// Balances

@Logger("Balances:")
Expand Down

0 comments on commit 960fdcd

Please sign in to comment.