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

feat: afterConfirmTx #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Tarnadas
Copy link

@Tarnadas Tarnadas commented Jun 23, 2023

Introduces a new function afterConfirmTx for the VM to run a callback every time a tx has been confirmed.

Example BOS code from my chess game component:

afterConfirmTx((txConfirmations) => {
  console.log("afterConfirmTx", txConfirmations);
  for (const tx of txConfirmations) {
    const actions = tx?.transaction?.actions;
    if (Array.isArray(actions)) {
      for (const action of actions) {
        console.log("action", action);
        const methodName = action.FunctionCall?.method_name;
        console.log("methodName", methodName);
        if (!methodName) continue;
        if (
          methodName === "challenge" ||
          methodName === "accept_challenge" ||
          methodName === "reject_challenge"
        ) {
          // DO STUFF
        }
      }
    }
  }
});
2023-06-23.13-19-34.mp4

introduces a new function `afterConfirmTx` for the VM to run a callback
every time a tx has been confirmed
@evgenykuzyakov
Copy link
Contributor

I think it's better to convert Near.call to return a promise instead of having a global callback.

@evgenykuzyakov
Copy link
Contributor

Also please rebase from master to dev

@evgenykuzyakov evgenykuzyakov self-requested a review July 7, 2023 17:49
@shelegdmitriy
Copy link
Contributor

Hi @evgenykuzyakov! I'd like to participate in this PR but I wonder what is your vision this feature?

@petersalomonsen
Copy link
Contributor

@Tarnadas How have you handled function access keys in order to avoid confirmation with the wallet? I'm into a similar thing with DevHub to solve this issue here: NEAR-DevHub/neardevhub-bos#137

I've solved access to multiple contracts by adding multiple keystores as you can see in the onging PR here ( there's a video in it): near/wallet-selector#887

But the remaining issue now is that in order to close the editor in DevHub, and also show Likes after transaction complete, a callback like you've created here is needed. It seems to me your PR will solve that part.

@Tarnadas
Copy link
Author

Tarnadas commented Sep 5, 2023

Hey @petersalomonsen,
this is awesome and exactly what I would also need! I don't have any function access keys handling and users always need to confirm a tx, which is especially bad, if you're e.g. playing a game.

Yeah my PR would fix this. I wanted to get back to it and try to convert Near.call to return a promise, just like @evgenykuzyakov suggested, but I did not yet have the time.

@petersalomonsen
Copy link
Contributor

Sounds good, but why return a Promise @evgenykuzyakov? A similar function like Social.set is also callback based and does not return a promise https://docs.near.org/bos/api/social#socialset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants