Steem Keychain Promise Wrapper

avatar
(Edited)

If you've integrated 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



0
0
0.000
11 comments
avatar

Thanks! Will smartsteem be moving to keychain at some point?

0
0
0.000
avatar

The current version of Smartsteem is already using keychain. The only thing not supported is login via keychain. This, however, will be supported with the redesign & relaunch, coming soon.

0
0
0.000
avatar

Great @therealwolf ...

"The only thing not supported is login via keychain. This, however, will be supported with the redesign & relaunch, coming soon."

... to hear! 👍

Posted using Partiko Android

0
0
0.000
avatar

Hi! this is awesome, I think you are Wolfinator in Splinterlands? If so, You are an amazing player! Awesome name too! :-) I bought up all the gold Alpha wolfs long ago and maxed him out first. It is a great card too!

0
0
0.000
avatar

Hi, @therealwolf!

You just got a 0.27% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

0
0
0.000
avatar

This post has been included in the latest edition of The Steem News - a compilation of the key news stories on the Steem blockchain.

0
0
0.000