Skip to content

Commit

Permalink
Merge pull request #11 from nitinmittal23/signer-fix
Browse files Browse the repository at this point in the history
Signer fix
  • Loading branch information
nitinmittal23 authored Aug 31, 2024
2 parents fca31f6 + 03f7e19 commit 4013e8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maticnetwork/maticjs-ethers",
"version": "1.0.3",
"version": "1.1.0",
"description": "ethers plugin for matic.js",
"main": "dist/npm.export.js",
"types": "dist/ts/index.d.ts",
Expand Down
34 changes: 19 additions & 15 deletions src/ethers/web3_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import { ethBlockToMaticBlock, ethReceiptToMaticReceipt, ethTxToMaticTx } from "

type ETHER_PROVIDER = providers.JsonRpcProvider;
type ETHER_SIGNER = providers.JsonRpcSigner;
type WEB3_PROVIDER = providers.Web3Provider;

export class EtherWeb3Client extends BaseWeb3Client {
name = 'ETHER';
provider: ETHER_PROVIDER;
signer: ETHER_SIGNER;

constructor(provider: ETHER_PROVIDER | Wallet, logger) {
constructor(provider: ETHER_PROVIDER | Wallet | WEB3_PROVIDER, logger) {
super(logger);
if ((provider as ETHER_PROVIDER)._isProvider) {
this.provider = provider as ETHER_PROVIDER;
this.signer = this.provider.getSigner();
}
else {
this.signer = (provider as any);
this.provider = ((provider as Wallet).provider) as any;

if (provider instanceof ethers.providers.Web3Provider) {
this.provider = provider;
this.signer = provider.getSigner();
} else if (provider instanceof ethers.providers.JsonRpcProvider) {
this.provider = provider;
this.signer = provider as any;
} else {
this.signer = provider as any;
this.provider = provider.provider || provider as any;
}
}



getBlock(blockHashOrBlockNumber) {
return this.provider.getBlock(blockHashOrBlockNumber).then(block => {
return block as any;
Expand Down Expand Up @@ -54,7 +56,9 @@ export class EtherWeb3Client extends BaseWeb3Client {


getChainId() {
return this.signer.getChainId();
return this.provider.getNetwork().then(function (res) {
return res.chainId;
});
}

getBalance(address) {
Expand Down Expand Up @@ -93,7 +97,7 @@ export class EtherWeb3Client extends BaseWeb3Client {
getTransactionReceipt(transactionHash: string) {
return this.provider.getTransactionReceipt(transactionHash).then(result => {
this.ensureTransactionNotNull_(result);

return ethReceiptToMaticReceipt(result);
});
}
Expand Down Expand Up @@ -151,14 +155,14 @@ export class EtherWeb3Client extends BaseWeb3Client {
hexToNumber(value) {
return BigNumber.from(value).toNumber();
}

hexToNumberString(value) {
return BigNumber.from(value).toString();
}

signTypedData(signer, typedData) {
const {domain, types, message: value} = typedData;
if(types.EIP712Domain) {
const { domain, types, message: value } = typedData;
if (types.EIP712Domain) {
delete types.EIP712Domain;
}
return this.signer._signTypedData(domain, types, value);
Expand Down

0 comments on commit 4013e8e

Please sign in to comment.