Steem Keychain Promise Wrapper

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@therealwolf·
0.000 HBD
Steem Keychain Promise Wrapper
If you've integrated [Steem Keychain](https://github.com/MattyIce/steem-keychain) into your project/business/website and are like me: you've probably been a bit annoyed with the use of callbacks, instead of promises.

Which is why I've written myself a small basic wrapper that converts the callback Keychain normally returns, into a promise. Since I'm an avid user of typescript, I also added some types. The types for arguments are still missing, I'll probably add them sometime in the future.

Nevertheless, I thought some of my fellow devs might be in need of it, so here you go:

https://gist.github.com/therealwolf42/968db625aea6b45beffaae8283911062

*Info: This code snippet is using ES6 code syntax and types. Latter can be removed if you're not using typescript/flow.*

Example usage:

```
// Original Usage
steem_keychain.requestDelegation(username, delegatee, amount, unit, function(response) {
    console.log(response);
});

// Promise Wrapper Usage

import {keychain} from '../yourcode'

const {success, msg, cancel} = await keychain(window, 'requestDelegation', username, delegatee, amount, unit)
if('cancel') // Do nothing
if(success) {
  alert('Successful delegation!')
}
alert(`Error: ${msg}`)

```

If you've got improvements/found bugs, feel free to let me know!

*Wolf*

👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,