-
Notifications
You must be signed in to change notification settings - Fork 369
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
Add useSendTransaction, refactor useContractFunction #207
Conversation
🦋 Changeset detectedLatest commit: ce9ff76 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
99dcf83
to
9f4f972
Compare
import { TransactionStatus } from '../../src' | ||
import { useEthers } from './useEthers' | ||
|
||
async function handleTransactionState( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks like you could use this function in useContractFunction
interface Options { | ||
signer?: Signer | ||
transactionName?: string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extract common TransactionHookOptions and use the same for type for useContractFunction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can than reuse connectContractToSigner
as well in both functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: Can we extract one more generic function (kind of inside-out approach to the current proposal), i.e.:
useSendGenericTransaction(() => Promise<TransactionResponse>, options?: Options) {
...
}
So that useSendTransaction
would be something like:
function useSendTransaction(...) {
return useSendGenericTransaction(() =>
signer.sendTransaction(transactionRequest)
)
}
and useContractFunction
would be something like:
function useContractFunction(...) {
return useSendGenericTransaction(() =>
contractWithSigner[functionName](...args)
)
}
4b799f0
to
4142523
Compare
4142523
to
f005bcb
Compare
const [spender, receiver, secondReceiver] = mockProvider.getWallets() | ||
|
||
it('success', async () => { | ||
const spenderBalance = await receiver.getBalance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
receiver.getBalance() -> spender.getBalance()
Hey Guys! not sure if this is related, but I'm not able to call a contract function because I get this error: And here a more detailed output: I literally followed your documentations step by step, I defined contract and everything else exactly like it's shown in the docs.. It should work but it does not :( Signer should be an optional variable in Transaction... Why is it interrupting the function execution? Where do I even look for Signer? Why is all this not explained in the docs? There is only a link to the ethersjs documentation but I have no clue how that ethers object fits into the useDapp framework :/ Also why should I define and create another signer object with ethers if I already have useDapp that injected a wallet instance into the web app state? We have to update the docs asap, can you please provide an example on how to call a contract function? Thank you so much for this clarification! |
Try: const {activate, account, library} = useEthers();
const {state, send} = useContractFunction(contract, 'addNewOpera', library);
.... |
Propably wallet is not connected did you try:
Before using |
Thanks for your reply @marekkirejczyk Unfortunately I still get the error: Terminal: I realized that the issue might be that I'm using NextJS, and the code is being run also on server-side. What could be a nextJS-friendly approach? @Szymx95 thanks for your reply! Good observation, yes I do have the |
No description provided.