-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for odd values in sendTransaction
- Loading branch information
1 parent
50edde9
commit 9f695ba
Showing
3 changed files
with
38 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Deferrable } from "@ethersproject/properties"; | ||
import { type TransactionRequest } from "@ethersproject/providers"; | ||
import { hexlify } from "ethers/lib/utils"; | ||
|
||
/** | ||
* We need to support odd value and data fields in a tx, as that data comes from WC | ||
* ZeroDev implements hexlify, but doesn't support to send an odd string in value or data fields | ||
* so we need to make the hexlify fix manually when sending a transaction. | ||
* That fix can be found here: | ||
* https://github.com/ethers-io/ethers.js/commit/a12030ad29aa13c02aa75d9e0860f4986a0043b4#diff-047e7ebfdbd5c41e762cda03593bd15ed8b3121dece67262729dfcbde7040818R221 | ||
* And more context on this issue: | ||
* https://github.com/ethers-io/ethers.js/issues/614 | ||
* | ||
* Applying to it hexValue is used as a workaround on Crossbit, but doesn't cover all the cases (i.e. 0x71afd498d0000). | ||
* This function is the same as hexValue but without hexStripZeros, which is what makes it to not work. | ||
*/ | ||
export async function decorateSendTransactionData(transaction: Deferrable<TransactionRequest>) { | ||
const decoratedTransaction = { ...transaction }; | ||
if (transaction.value) { | ||
const awaitedValue = await transaction.value; | ||
if (awaitedValue) { | ||
decoratedTransaction.value = hexlify(awaitedValue, { hexPad: "left" }); | ||
} | ||
} | ||
|
||
if (transaction.data) { | ||
const awaitedData = await transaction.data; | ||
if (awaitedData) { | ||
decoratedTransaction.data = hexlify(awaitedData, { hexPad: "left" }); | ||
} | ||
} | ||
|
||
return decoratedTransaction; | ||
} |