-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Wallets] fix gas estimations for local and embedded wallets (#2143)
- Loading branch information
1 parent
756d5cc
commit 85e3171
Showing
9 changed files
with
94 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@thirdweb-dev/wallets": patch | ||
"@thirdweb-dev/sdk": patch | ||
--- | ||
|
||
Fix gas estimations for local and embedded wallets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/wallets/src/evm/connectors/local-wallet/wrapped-signer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { getDefaultGasOverrides } from "@thirdweb-dev/sdk"; | ||
import { Bytes, Signer, providers } from "ethers"; | ||
import { Deferrable, defineReadOnly } from "ethers/lib/utils"; | ||
|
||
export class WrappedSigner extends Signer { | ||
constructor(private signer: Signer) { | ||
super(); | ||
defineReadOnly(this, "provider", signer.provider); | ||
} | ||
|
||
override async getAddress(): Promise<string> { | ||
return await this.signer.getAddress(); | ||
} | ||
|
||
override async signMessage(message: Bytes | string): Promise<string> { | ||
return await this.signer.signMessage(message); | ||
} | ||
|
||
override async signTransaction( | ||
transaction: Deferrable<providers.TransactionRequest>, | ||
): Promise<string> { | ||
return await this.signer.signTransaction(transaction); | ||
} | ||
|
||
override connect(provider: providers.Provider): Signer { | ||
return new WrappedSigner(this.signer.connect(provider)); | ||
} | ||
|
||
override async sendTransaction( | ||
transaction: Deferrable<providers.TransactionRequest>, | ||
): Promise<providers.TransactionResponse> { | ||
if (!this.provider) { | ||
throw new Error("Provider not found"); | ||
} | ||
const gas = await getDefaultGasOverrides(this.provider); | ||
const txWithGas = { | ||
...gas, | ||
...transaction, | ||
}; | ||
return await this.signer.sendTransaction(txWithGas); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters