Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signer fix #11

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading