[Steemjs+Steemconnect+Php+Json] Withdraw vesting Routes Remove tools - part-4 & Live open source website

in #utopian-io5 years ago

Repository

https://github.com/nawab69/steemtools

What will you learn-

  • How to use SteemJs
  • How to use SteemConnect
  • How to make web app with php language
  • How to Check, Add & Remove withdraw vesting Route.

Requirements

  • Web Hosting
  • Text Editor
  • knowledge on php, JSON & html

Difficulty

  • Intermediate

Description

Hello everybody, I am Nawab. A full stack web developer in opensource community. Currently I am working on a project. My project is teaching everybody about app development. I am not good in English Language. I am living in UK from five years. Please forgive me if I write any grammatical errors.

In my previous tutorials you have learned how to check & Change withdraw route by php+steemjs+steemconnect.

Today I will teach you how to remove withdraw routes with PHP+STEEMJS+STEEMCONNECT

Before read this tutorial, please read my previous tutorials.

In my 1st & 2nd tutorial, I taught you creating check.php and change.php. I will use both these system to remove withdraw routes.

If you want to change or remove your withdraw route, you have to input 4 data. These are-

  • From Account
  • To Account
  • Percentage
  • Auto Vest

If you want to remove your withdraw routes you have to use these values,

parametersvalues
from_accountyour steemit account username
to_accountyour exists withdraw route's steemit username
percent0
autofalse

Here is the flow-chart of this tools;

  • Remove.php

  • confirmremove.php

How it works
  • Remove.php

First we input 'from_account' and submit it. Then it will connect to SteemJs API and get output of 'to_account'. Finally, it will send data to confirmremove.php page and redirect to that page.

  • ConfirmRemove.php

First it get value of 'form_account' and 'to_account'. Then the data will show in a form but remain readonly. and other input 'percent' & 'auto' will remain hidden. When user confirm the value & press 'remove' (submit button) , it will redirect to steemconnect.

Tutorial

First create remove.php file. Then insert header files.

<?php
include ('include/header.php'); // Include header
include ('include/nav.php'); // Include Navigation bar
?>

Create a form to input username. I use bootstrap form and at input tag name attribute value is user

 <form action="" method="post" >
           <div class="form-group">
             <label class="sr-only">Username</label> 
                <div class="input-group mb-2 mr-sm-2"> 
                   <div class="input-group-prepend">
                     <div class="input-group-text">@</div>
                   </div> 
                     <input type="text" class="form-control" name="user" placeholder="Enter your username">
               </div> 
           </div>
               <br>
                 <div class="form-group">
                   <button align="center" name="submit" class="btn btn-primary mb-2">Next</button> 
                 </div>
           </form>

Then write php code to connect with SteemJs and get data form it. I have described it in Tutorial-2 of these series.

<?php 
if($_POST)
{
  $username = $_POST["user"];
  $data = file_get_contents('https://api.steemjs.com/get_withdraw_routes?account='.$username.'&withdrawRouteType=true');         // steemjs Api
  $info = json_decode($data,true);            // decode from json to php strings                   
  $to = $info[0][to_account];                 // keep 'to_account' string's value at variable
    header("Location: confirmremove.php?user=$username&to=$to");   // redirect to confirmremove.php 
}
?>
Explanation

Here I use If condition. If someone post username with these form, the code inside the 2nd bracket will run.

First inputed username from form will store in $username variable.
Then withdraw route json data will be taken by steemjs API and store at $data variable.
JSON will be decoded to strings at next line and stored at $info variable. $to variable only select to_account value.
Last line I have used header() php function to redirect it to confirmremove.php and give two parameters. One is user and the other is to. And gives their values $username & $to.

Example

For example, If I put my username nawab69 and press submit/next button. It will get my withdraw routes details by STEEMJS API.

Suppose, My withdraw route is utopian-io.
What will happen if I press submit/next button?

The page will redirect to /confirmremove.php?user=nawab69&to=utopian-io


Step-2

Now create another file confirm.php

Include the header file same as remove.php

<?php
include ('include/header.php'); // Include header
include ('include/nav.php'); // Include Navigation bar
?>

In step-1, user & to parameters' value has sent to this page. Now write this code to get this values and keep them at variables.

<?php
$usname = $_GET["user"];    // get data from user
$touser = $_GET["to"];      // get data from to
?>

Then create a form with these formula,

namevalueattribute
user$usnamereadonly
to$toreadonly
percent0hidden
autofalsehidden

Write down these code to create the form.

  <form action="" method="post" >
(html comment removed:  Username Input box )
        <div class="form-group">
             <div class="input-group mb-2 mr-sm-2"> 
            <div class="input-group-prepend">
              <div class="input-group-text">From</div> 
            </div>         
      <input type="text" class="form-control" value="<?php echo $usname; ?>" name="user"  placeholder="Username" readonly> 
         </div>
        </div>
(html comment removed:  Withdraw To input box )
        <div class="form-group">
          <div class="input-group mb-2 mr-sm-2"> 
            <div class="input-group-prepend">
             <div class="input-group-text">To</div>
            </div> 
              <input type="text" class="form-control" name="to"  placeholder="Withdraw To" value="<?php echo $touser; ?>" readonly>
          </div>
       </div>
(html comment removed:  Percent =0  Input box )
    <input type="text" class="form-control" name="percent" value="0" hidden>
(html comment removed:  Auto Vesting Withdraw select box )
    <input type="text" class="form-control" name="auto" value="false" hidden>
<br>
(html comment removed:  Remove Button )
      <div class="form-group">
        <button align="center" name="submit" class="btn btn-primary mb-2">Remove</button> 
      </div>
  </form>

The red mark of this image is hidden attribute. It hide input box from user but still work.

Because of using readonly attribute at first two box, they aren't be editable any more. And because of using hidden attribute at last two input box, they will be hidden.

Now, write this php code to run this.

<?php
if($_POST)
{
$from = $_POST["user"];   // store username from Form using post method
$to = $_POST["to"];     // store withdraw to username from Form using post method
$percent = $_POST["percent"];  // store percentage from Form using post method
$auto = $_POST["auto"]; //   store auto vest boolian from Form using post method
$api = "https://steemconnect.com/sign/set_withdraw_vesting_route?from_account=$from&to_account=$to&percent=$percent&auto_vest=$auto";   // steemconnect Api for changing withdraw routes
header("Location: $api");   // redirect to steemconnect
}
?>

It is same as change.php file's function. Read it from my previous tutorial from here

now save this file. And run remove.php from server.

Here is the live of this tool...

How to remove withdraw Route

  • open yoursite/remove.php

  • Input your username & press next.

  • Now You will see your existing "withdraw route". Press remove. It will be redirected to steemconnect.

  • Now click on "continue" and fill the login from and login.

  • You would get a success message if your withdraw route successfully removed.

  • Lets check your withdraw route by check.php

All the files and codes of these tutorial.

Curriculum

Development

I have just completed Withdraw Route tools. It contains-

  • Check Current Withdraw Route
  • Change Withdraw Route
  • Remove Withdraw Route

The website is now live and open for everyone. It is open source.

Site Url : http://steemtools.cf (updated)
Github Repository : https://github.com/nawab69/steemtools

Prove of work done

https://github.com/nawab69/steemtools/blob/master/remove.php
https://github.com/nawab69/steemtools/blob/master/confirmremove.php
https://steemtools.cf/remove.php

Sort:  

Thank you for your contribution @nawab69.
After analyzing your tutorial we suggest the following points listed below:

  • Try to improve your flowcharts a bit. They got very big.

  • We suggest instead of putting multiple images with the remove withdraw Route process that put a gif with your demonstration of the process.

  • Put your code ident, the code sections of your tutorial are a bit difficult to read.

  • Pay more attention to the structure of your tutorial. Your tutorial seems pretty confusing.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thank you for your review, @portugalcoin! Keep up the good work!

Hi @nawab69!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @nawab69!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 63816.85
ETH 3134.82
USDT 1.00
SBD 3.86