Skip to content

Commit

Permalink
Add direct transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
stoodkev committed Jan 17, 2018
1 parent 2df68df commit 1181a22
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 7 deletions.
7 changes: 6 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steem.api.getDynamicGlobalProperties( function(err,globalProp)
const totalSteem = Number(globalProp.total_vesting_fund_steem.split(' ')[0]);
const totalVests = Number(globalProp.total_vesting_shares.split(' ')[0]);
updateSteemPrice();
chrome.storage.local.get(['weight','del','acc_v','ben','drop','badge','username', 'nb_posts','resteem','sort','tag','list_tags','voted_check', 'rep_feed', 'rep_feed_check', 'whitelist', 'blacklist','feedp','sessionToken','tokenExpire'], function (items) {
chrome.storage.local.get(['weight','del','transfers','acc_v','ben','drop','badge','username', 'nb_posts','resteem','sort','tag','list_tags','voted_check', 'rep_feed', 'rep_feed_check', 'whitelist', 'blacklist','feedp','sessionToken','tokenExpire'], function (items) {
const token=makeToken();
var steemConnect=(items.sessionToken===undefined||items.tokenExpire===undefined)?{connect:false}:{connect:true,sessionToken:items.sessionToken,tokenExpire:items.tokenExpire};
chrome.runtime.sendMessage({ token:token, to: 'steemConnect', order: 'start',data:{steemConnect:steemConnect,steemit:steemit,busy:busy}} );
Expand All @@ -24,6 +24,7 @@ steem.api.getDynamicGlobalProperties( function(err,globalProp)
const account=me.account;
const user=me.name;
const delegation=(items.del==undefined||items.del=="show");
const transfers=(items.transfers==undefined||items.transfers=="show");
const account_value=(items.acc_v==undefined||items.acc_v=="show");
const beneficiaries=(items.ben==undefined||items.ben=="show");
const dropdown=(items.drop==undefined||items.drop=="show");
Expand All @@ -43,6 +44,8 @@ steem.api.getDynamicGlobalProperties( function(err,globalProp)
console.log(steemConnect);
if(delegation)
chrome.runtime.sendMessage({ token:token, to: 'delegation', order: 'start',data:{steemit:steemit,busy:busy,global:{totalSteem:totalSteem,totalVests:totalVests},user:user} });
if(transfers)
chrome.runtime.sendMessage({ token:token, to: 'transfers', order: 'start',data:{steemit:steemit,busy:busy,user:user,balance:{steem:account.balance.split(' ')[0],sbd:account.sbd_balance.split(' ')[0]}} });
if(account_value)
chrome.runtime.sendMessage({ token:token, to: 'acc_v', order: 'start',data:{steemit:steemit,busy:busy,global:{totalSteem:totalSteem,totalVests:totalVests},market:market}});
if(beneficiaries&&steemit)
Expand All @@ -60,6 +63,8 @@ steem.api.getDynamicGlobalProperties( function(err,globalProp)
{
if(delegation)
chrome.runtime.sendMessage({token:token, to: 'delegation', order: 'click',data:{steemit:steemit,busy:busy,global:{totalSteem:totalSteem,totalVests:totalVests},user:user} });
if(transfers)
chrome.runtime.sendMessage({token:token, to: 'transfers', order: 'click',data:{steemit:steemit,user:user,balance:{steem:account.balance.split(' ')[0],sbd:account.sbd_balance.split(' ')[0]}}} );
if(account_value)
chrome.runtime.sendMessage({ token:token, to: 'acc_v', order: 'click',data:{steemit:steemit,busy:busy,global:{totalSteem:totalSteem,totalVests:totalVests},market:market} });
if(beneficiaries&&steemit)
Expand Down
8 changes: 5 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "SteemPlus",
"description": "Lightweight toolbox for Steemit",
"version": "2.1.4.0",
"version": "2.2.0.0",

"browser_action": {
"default_icon": "src/img/logo.png",
Expand Down Expand Up @@ -54,15 +54,17 @@
"src/js/dropdown.js",
"src/js/rank.js",
"src/js/resteem.js",
"src/js/feedplus.js"],
"src/js/feedplus.js",
"src/js/transferTo.js"],
"css":["vendor/bootstrap.css",
"src/css/delegate.css",
"src/css/account_val.css",
"src/css/beneficiaries.css",
"src/css/rank.css",
"src/css/resteem.css",
"src/css/feedplus.css",
"src/css/loginSteemPlus.css"],
"src/css/loginSteemPlus.css",
"src/css/transferTo.css"],
"permissions": [
"activeTab",
"storage",
Expand Down
3 changes: 3 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ <h4>Feed+</h4>
<h4>Delegation</h4>
<input type="radio" name="del" value="show" id="show"> <label for="show">Show</label> <br>
<input type="radio" name="del" value="hide" id="hide"> <label for="hide">Hide</label> <br>
<h4>Transfers</h4>
<input type="radio" name="transfers" value="show" id="show"> <label for="show">Show</label> <br>
<input type="radio" name="transfers" value="hide" id="hide"> <label for="hide">Hide</label> <br>
<h4>Beneficiaries</h4>
<input type="radio" name="ben" value="show" id="show"> <label for="show">Show</label> <br>
<input type="radio" name="ben" value="hide" id="hide"> <label for="hide">Hide</label> <br>
Expand Down
11 changes: 9 additions & 2 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ document.getElementById('vote').addEventListener("click", Upvote);
var weight;
var vpow;
var width=0;
var badge,ben,feedp,del,drop,acc_v;
var badge,ben,feedp,del,drop,acc_v,transfers;
var me,acc;
var menus=document.getElementsByClassName("menu");
var content=document.getElementsByClassName("content");
var back=document.getElementsByClassName("back_menu");
// Get local parameters stored using Chrome Storage API
chrome.storage.local.get(['sessionToken','tokenExpire','weight','resteem','blacklist','whitelist','reputation','rep','badge','del','ben','feedp','drop','acc_v'], function (items) {
chrome.storage.local.get(['sessionToken','tokenExpire','weight','resteem','blacklist','whitelist','reputation','rep','badge','del','ben','feedp','drop','acc_v','transfers'], function (items) {
var steemConnect=(items.sessionToken===undefined||items.tokenExpire===undefined||items.tokenExpire<Date.now())?{connect:false}:{connect:true,sessionToken:items.sessionToken,tokenExpire:items.tokenExpire};

if(steemConnect.connect===true)
Expand Down Expand Up @@ -46,6 +46,7 @@ chrome.storage.local.get(['sessionToken','tokenExpire','weight','resteem','black
feedp=items.feedp==undefined?'show':items.feedp;
ben=items.ben==undefined?'show':items.ben;
del=items.del==undefined?'show':items.del;
transfers=items.transfers==undefined?'show':items.transfers;
acc_v=items.acc_v==undefined?'show':items.acc_v;
drop=items.drop==undefined?'show':items.drop;
//console.log(items.resteem);
Expand All @@ -61,6 +62,7 @@ chrome.storage.local.get(['sessionToken','tokenExpire','weight','resteem','black
$('input[name=ben][value='+ben+']').prop('checked',true);
$('input[name=drop][value='+drop+']').prop('checked',true);
$('input[name=acc_v][value='+acc_v+']').prop('checked',true);
$('input[name=transfers][value='+transfers+']').prop('checked',true);

});

Expand Down Expand Up @@ -124,6 +126,11 @@ $(document).on("change","input[name=del]",function(){
del:$("input[name=del]:checked").val()
});
});
$(document).on("change","input[name=transfers]",function(){
chrome.storage.local.set({
transfers:$("input[name=transfers]:checked").val()
});
});

$(document).on("change","input[name=drop]",function(){
chrome.storage.local.set({
Expand Down
13 changes: 13 additions & 0 deletions src/css/transferTo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.divTransfer
{
display: inline-block;

}
.transfer_to
{
display: inline-block;

}
.currency{
cursor: pointer;
}
1 change: 1 addition & 0 deletions src/js/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var ii=0;
function createButton(isSteemit,busy,globalP,account) {
console.log('Create Delegation Button');
if($('.delegate').length===0) {
if($('.transfer_to').length!==0) $('.transfer_to').remove();
var delegate_div = document.createElement('div');
delegate_div.style.width = '100%';
delegate_div.style.textAlign = 'right';
Expand Down
136 changes: 136 additions & 0 deletions src/js/transferTo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* Created by @stoodkev on 10/23/2017.
*/

var createdt=false;
var load_checkt='';
var wallet_elt_t;
var classButtonT;
var timeoutT=2000;
var token_tr=null;
var indexT=0;
var currency='STEEM';
var max=0;

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if(request.to==='transfers'&&request.order==='start'&&token_tr==null)
{
token_tr=request.token;
startTransfer(request.data.steemit,request.data.busy,request.data.user,request.data.balance);
max=request.data.balance.steem;
}

if(request.to==='transfers'&&request.order==='click'&&token_tr===request.token)
onClickTr(request.data.steemit,request.data.busy,request.data.user,request.data.balance);
});


function startTransfer(isSteemit,busy,account,balance)
{
if(isSteemit) {
load_checkt=/transfers/;
wallet_elt_t=".FoundationDropdownMenu__label";
classButtonT="'UserWallet__buysp button hollow transfer_to";
}

if(window.location.href.match(load_checkt))
checkLoadTr(isSteemit,busy,account,balance);

}

function onClickTr(isSteemit,busy,account,balance){
setTimeout(function() {
if (window.location.href.match(load_checkt) && !createdt) {
createdt = true;
checkLoadTr(isSteemit,busy,account,balance);
}
if (!window.location.href.match(load_checkt)) {
createdt = false;
}
},timeoutT);
}

function checkLoadTr(isSteemit,busy,account,balance){
indexT++;

if($(wallet_elt_t).length===0){
createButtonT(isSteemit,busy,account,balance);
}
else {
if(indexT<5)
setTimeout(checkLoadTr, 2000);
}
}

function createButtonT(isSteemit,busy,account,balance) {
console.log('Create Transfer Button');
if($('.transfer_to').length===0) {
var transfer_to = document.createElement('div');
transfer_to.style.textAlign = 'right';
transfer_to.className = 'divTransfer';
var transfer_button = document.createElement('button');
transfer_button.innerHTML = 'Transfer to user';
transfer_button.className = classButtonT;
transfer_button.id = 'transferButton';
transfer_button.style.marginTop='15px';
transfer_button.style.display = 'block';
transfer_button.style.float = 'right';
transfer_to.appendChild(transfer_button);
$('.UserWallet .small-10 h4')[0].after(transfer_to);
const receiver=window.location.href.split('@')[1].split('/')[0];

$('.transfer_to').click(function(){
var div = document.createElement('div');
div.id = 'overlay_transfer';
var inner="";
inner = '<div data-reactroot="" role="dialog" style="bottom: 0px; left: 0px; overflow-y: scroll; position: fixed; right: 0px; top: 0px;"><div class="reveal-overlay fade in" style="display: block;"></div><div class="reveal fade in" role="document" tabindex="-1" style="display: block;"><button class="close-button" type="button"><span aria-hidden="true" class="">×</span></button><div><div class="row"><h3 class="column">Transfer</h3>' +
'</div><form ><div><div class="row"><div class="column small-12">Transfer Steem or SBD from @'+account+' to @'+receiver+'.</div></div><br></div><div class="row"><div class="column small-2" style="padding-top: 5px;">' +
'Amount</div><div class="column small-10"><div class="input-group" style="margin-bottom: 5px;"><input type="text" placeholder="Amount" name="amount" value="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"><span class="input-group-label currency" style="padding-left: 0px; padding-right: 0px; border:#1A5099 1px solid; border-radius:5px; background:white;">' +
'<span style="min-width: 5rem; height: inherit; background-color: transparent; border: none;">STEEM</span></span><span class=" input-group-label currency" style="padding-left: 0px; padding-right: 0px;" >' +
'<span style="min-width: 5rem; height: inherit; background-color: transparent; border: none;" >SBD</span></span></div><div style="margin-bottom: 0.6rem;"><a id="max_b" style="border-bottom: 1px dotted rgb(160, 159, 159); cursor: pointer;">' +
'Balance: <span class="maxbalance">'+max+'</span> <span class="maxbalance_currency">STEEM</span></a></div></div></div><div class="row"><div class="column small-2" style="padding-top: 33px;">Memo</div><div class="column small-10"><small>This memo is public</small><input type="text" placeholder="Memo" name="memo" value="" autocomplete="on" autocorrect="off" autocapitalize="off" spellcheck="false"><div class="error"><!-- react-text: 45 -->&nbsp;<!-- /react-text --></div></div></div>';

inner +='<div class="row"><div class="column"><span><input type="button" disabled="" class="UserWallet__buysp button hollow transfer_to" id="bd" value="Submit"/></span></div></div></form></div></div></div>';
div.innerHTML=inner;


$('body').append(div);
$('.currency').click(function(){
$(this).css('background','white');
$(this).css('border','#1A5099 1px solid');
$(this).css('border-radius','5px');
const index=$('.currency').index($(this));
currency=index==0?'STEEM':'SBD';
max=currency=='STEEM'?balance.steem:balance.sbd;
$('.maxbalance').html(max);
$('.maxbalance_currency').html(currency);

$('.currency').each(function(i,e,a){
if(index!==i)
{
$(e).css('background','#e6e6e6');
$(e).css('border','#cacaca 1px solid');
$(e).css('border-radius','0');
}
});
});
$('.close-button').click(function(){$('#overlay_transfer').remove();});
$('#max_b').click(function(){$('input[name=amount]').val(max); checkSubmit();});
$('form input').blur(function () {
checkSubmit();

});
function checkSubmit(){
if(parseFloat($('input[name=amount]').val())>=0&&parseFloat($('input[name=amount]').val())<=max)
{$('#bd').prop("disabled",false); }
else
{$('#bd').prop("disabled",true); }
}
$('#bd').click(function () {

var url = 'https://v2.steemconnect.com/sign/transfer?from='+account+'&to='+receiver+'&amount='+$('input[name=amount]').val()+'%20'+currency+'&memo='+$('input[name=memo]').val();
window.open(url, '_blank');
});
});
}
}
Loading

0 comments on commit 1181a22

Please sign in to comment.