-
Notifications
You must be signed in to change notification settings - Fork 107
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/fix: wait for tx to resolve/reject using resolversMap #658
base: main
Are you sure you want to change the base?
Conversation
Changelog
To-do list
Appendix
|
Alright, pooh! Think this now has most of the logic I wanted to implement. It's sometimes difficult to navigate inside other people's code 😅! Hope I didn't make a mess. Tell me if I did! To explain this PR in simple terms:
|
Thanks for the contribution and detailed explanation! I should hopefully be able to review this next week if no one else gets there first. One thing to mention is that it is already possible to know if a transaction has completed, because the extension fires an event ( |
Ah interesting, didn't know this! That's also indeed a way to go at it! Take your time and no pressure/biggy if you decide this won't make the cut :)! UPDATE: Due to the thought process below, I may need to rephrase this PR. It's more so about knowing whether a tx we initiated got submitted correctly or not. It might also be a good thing to consider the direction or options given to the front-end developer: do we listen to every tx event fired or do we selectively wait for the result of a transaction we initiated? But I actually think it's possible to have both ways implemented without loss of performance or anything! Plus it's consistent that way, considering signatures already had promises! (unless it was planned to remove this!) |
Just a small post-refactoring I'll do. I think it's better to separate the logic of creating a window/popup and attaching a resolver to it. Will commit this after getting out of bed 😴. |
Alright done.
But yes, just a couple of contemplations. In my opinion the check seems a bit overkill, could perhaps remove the PS: It might actually be necessary to not include this check if I think of this TODO comment: |
Okay final option lol, which may solve ths whole TODO-issue while still including the error throwing if the tabId isn't around: private resolve(popupTabId: number, result?: unknown) {
if (popupTabId in this.resolverMap) {
this.resolverMap[popupTabId].resolve(result);
delete this.resolverMap[popupTabId];
} else {
throw new Error(`no resolvers found for tab ID ${popupTabId}`);
}
}
private reject(popupTabId: number, message?: any) {
if (popupTabId in this.resolverMap) {
this.resolverMap[popupTabId].reject(message ?? new Error("Request rejected"));
delete this.resolverMap[popupTabId];
} else {
throw new Error(`no resolvers found for tab ID ${popupTabId}`);
}
} For this to work, it does require the resolving or rejecting to always happen AFTER clearing pending data.. Choices, choices 😅, I hope the bombardment of details doesn't make ya go nuts. |
Merged latest into this PR. Luckily already fixed the things that got pushed to main. |
Hi there!
So I'm currently working on the IBC shielded transfer app, which communicates with the Namada extension and stumbled upon the following problem:
Sent transactions to the extension immediately resolve/reject, which make it impossible for the browser to wait for a result and decide whether the tx failed or not.
This PR solves this and also optimizes/fixes/restructures/refactors some of the resolver logic; see more technical details below.
With this fix the frontend is capable of awaiting sent transactions and also able to see whether the user approves or declines the transaction (or closes the window). Declining makes the browser aware of the promises' rejection with an optional message field, while a successful transaction resolves with optional additional details.
ZEN