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

Convert values coming in from WalletConnect #70

Merged
merged 5 commits into from
Dec 5, 2021
Merged
Changes from 2 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
20 changes: 15 additions & 5 deletions src/lib/walletAdapters/WalletConnectAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransactionResponse } from '@ethersproject/providers'
import { Signer, constants, utils } from 'ethers'
import { Signer, constants, utils, BigNumber } from 'ethers'
import { RIFWallet } from '../core'
export class WalletConnectAdapter {
private resolvers: IResolver[]
Expand Down Expand Up @@ -41,13 +41,23 @@ class SendTransactionResolver implements IResolver {
async resolve(params: any[]) {
const payload = params.reduce((prev, curr) => ({ ...prev, ...curr }), {})

if (payload.data === '') {
// TODO: assign undefined once the RIFWallet changes are applied
payload.data = constants.HashZero
if (payload.gas) {
delete payload.gas
}
jessgusclark marked this conversation as resolved.
Show resolved Hide resolved

const toNumber = (value?: any) =>
value ? BigNumber.from(value).toNumber() : undefined
jessgusclark marked this conversation as resolved.
Show resolved Hide resolved

const formattedPayload = {
jessgusclark marked this conversation as resolved.
Show resolved Hide resolved
...payload,
data: payload.data || constants.HashZero,
Copy link
Contributor

@ilanolkies ilanolkies Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need 0x here as no data. HashZero produces 32 bytes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to be 0x but I also made the default for gasPrice and gasLimit undefined. I think this adapter should not set them to zero in case it is reused in a different app. In #72, if the gasLimit/gasPrice are undefined, then it will use the estimates.

gasLimit: toNumber(payload.gasLimit),
jessgusclark marked this conversation as resolved.
Show resolved Hide resolved
gasPrice: toNumber(payload.gasPrice),
value: toNumber(payload.value),
}

return this.signer
.sendTransaction(payload)
.sendTransaction(formattedPayload)
.then((tx: TransactionResponse) => tx.hash)
}
}
Expand Down