ScatterWebExtension icon indicating copy to clipboard operation
ScatterWebExtension copied to clipboard

Only the first promise of multiple failing scatter calls gives an error

Open LarsVader opened this issue 7 years ago • 1 comments

console.log("suggesting network"); 
scatter.suggestNetwork().catch(error => { 
     console.log("error suggesting network");
 });

console.log("requesting identity"); 
const requirements = ['account'];
scatter.getIdentity(requirements).then(identity => { 
    console.log("got identity"); 
}).catch(error => { 
     console.log("error in getIdentity"); 
});

The call to getIdentity will print nothing neither got identity nor error in getIdentity if scatter is locked. But if the call to suggestNetwork is removed

the console log is: requesting identity error suggesting network

i would expect this console log: requesting identity error suggesting network error in getIdentity

It is probably not good to call these methods in this progression anyway. It is though a bit confusing to get neither an error nor a success on this getIdentity call. Like the title suggest what scatter methods are called does not actually matter. Two calls to getIdentity would also do then the second call would be silent.

LarsVader avatar Mar 18 '18 18:03 LarsVader

How about this? async/await simplify using promises:

(async () => {
    try {
        console.log("suggesting network"); 
        await scatter.suggestNetwork();

        console.log("requesting identity"); 
        const requirements = ['account'];
        let identity = await scatter.getIdentity(requirements);

        console.log("got identity"); 
    } catch(error) {
        console.log("oops");
    }
})();

tbfleming avatar Apr 19 '18 14:04 tbfleming