SteemConnect support for SRD and bug fix

Words
190
Reading
1 min
Listen
Play
8y

SteemRandomDraw is application that automate the draw.

SteemConnect support

Сonnecting the app with steemconnect seemed like something beyond possibilities. But thanks to steem developer portal, steemconnect sdk and this example I wrote test version of connection to steemconnect that was finalized by deadzy@deadzy.
It is steemlogin.js where I wrote all that needed to connection.

+function getQueryVariable(variable)
+{
+       var query = window.location.search.substring(1);
+       var vars = query.split("&");
+       for (var i=0;i<vars.length;i++) {
+               var pair = vars[i].split("=");
+               if(pair[0] == variable){return pair[1];}
+       }
+       return(false);
+}
+
+sc2.init({
+    app:'delayed-upvotes',
+    callbackURL: 'https://deadz.github.io/SteemRandomDraw/',
+    accessToken: 'access_token',
+    scope: ['comment']
+})
+
+//authentication
+var link = sc2.getLoginURL();
+if (window.location.search == "")
+   window.location.replace(link);
+//
+
+sc2.setAccessToken(getQueryVariable('access_token'));
+
+function commentWinnerList(author, authorPermlink, winners)
+{
+   var permlink = steem.formatter.commentPermlink(author, authorPermlink);
+   console.log(permlink);
+   console.log(winners);
+   var message = "test";
+    sc2.comment(author, authorPermlink, author, permlink, '', message, '', function(err, result) {
+      console.log(err, result);
+    });
+} 

Bug with the multiple contest links

Desription

This bug appeared when you enter two different links in one session like with different authors or/and different permlink. The winner from the first contest was keeped in the list as well as the winner from second contest was added to the same list.

Solution

I added two boolean variables flag1 and flag2 one for sessionStorage.author and other for sessionStorage.permlink.

var flag1 = true;
var flag2 = true;

In the function getAuthorPermlink I added this lines:

flag1 = (sessionStorage.author == link_split.split(regex_v2)[0]);
flag2 = (sessionStorage.permlink == link_split.split(regex_v2)[1]);

Here I check if previous value of sessionStorage.author and sessionStorage.permlink were the same as in new contest link.
And finally:

if (!(flag1 && flag2)) 
{
    win_list = [];
    number_of_draws="1";
}

Here I set variables to their init value.

Contact

if you have some suggestions write it here or contact me on discord CleverShovel#7855




Posted on Utopian.io - Rewarding Open Source Contributors

SteemConnect support for SRD and bug fix | Ecency