Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Safe-Proofing delayedPromise #162

Open
andrewpeters9 opened this issue Feb 12, 2023 · 0 comments
Open

Safe-Proofing delayedPromise #162

andrewpeters9 opened this issue Feb 12, 2023 · 0 comments

Comments

@andrewpeters9
Copy link

If someone init's the keyring twice, or calls updateTransportMethod twice quickly while the iframe is loading then you could run into situations where this if block runs (see here) but when this.delayedPromise.resolve(result) or this.delayedPromise.reject(e) is called the object is deleted by a separate execution context.

Ways that this could be fixed:

  • change this.delayedPromise to this.delayedPromises: Array<Object> = [], and then run something like:
for (const delayedPromise of this.delayedPromises) {
    this.updateTransportMethod(delayedPromise.transportType)
         .then((res) => delayedPromise.resolve(res))
         .catch(e => delayedPromise.reject(e))
}

this.delayedPromises = [];

// and then when the promise is added we do 
this.delayedPromises.push({
 // ...
})
  • or, to allow for more flexibility, this.delayedPromise could be changed to something like this.iframeOnloadHooks: Array<Promise> and the whole this.updateTransportMethod could be contained in the array, in case someone needs to add in a different onload call in later?
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant