iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 30
0
Blockchain

區塊鏈應用開發實戰系列 第 30

30. 去中心化交易所用戶前端存提代幣功能實作

  • 分享至 

  • xImage
  •  

小明今天繼續完成用戶存提代幣的前端功能

https://ithelp.ithome.com.tw/upload/images/20181105/20111706wWM5JZeqSG.png

存入代幣 HTML

<div class="col-lg-6">
    <div class="panel panel-default panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">存入代幣</h3>
        </div>
        <div class="panel-body">
            <form>
                <div class="form-group">
                    <label for="inputNameDepositToken">代幣名稱</label>
                    <input type="text" name="inputNameDepositToken" class="form-control" id="inputNameDepositToken" placeholder="e.g. FIXED">
                </div>
                <div class="form-group">
                    <label for="inputAmountDepositToken">代幣數量</label>
                    <input type="number" name="inputAmountDepositToken" class="form-control" id="inputAmountDepositToken" placeholder="e.g., 95">
                </div>

            </form>
        </div>

        <div class="panel-footer">
            <button type="button" class="btn btn-default" onclick="App.depositToken();return false;">確認</button>
        </div>
    </div>
</div>

存入代幣 JavaScript

depositToken: function() {
  //deposit token function

  var amountToken = document.getElementById("inputAmountDepositToken").value;
  var nameToken = document.getElementById("inputNameDepositToken").value;
  var exchangeInstance;
  ExchangeContract.deployed().then(function(instance) {
    exchangeInstance = instance;
    return exchangeInstance.depositToken(nameToken, amountToken, {from: account, gas: 4500000});
  }).then(function(txResult) {
    console.log(txResult);
    App.refreshBalanceExchange();
  }).catch(function(e) {
    console.log(e);
    self.setStatus("Error getting balance; see log.");
  });
}

https://ithelp.ithome.com.tw/upload/images/20181105/201117067NXV3vbwtq.png

提領代幣 HTML

<div class="col-lg-6">
    <div class="panel panel-default panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">提領代幣</h3>
        </div>
        <div class="panel-body">
            <form>
                <div class="form-group">
                    <label for="inputNameWithdrawalToken">代幣名稱</label>
                    <input type="text" name="inputNameWithdrawalToken" class="form-control" id="inputNameWithdrawalToken" placeholder="e.g. FIXED">
                </div>
                <div class="form-group">
                    <label for="inputAmountWithdrawalToken">代幣數量</label>
                    <input type="number" name="inputAmountWithdrawalToken" class="form-control" id="inputAmountWithdrawalToken" placeholder="e.g., 95">
                </div>
            </form>
        </div>
            <div class="panel-footer">
                <button type="button" class="btn btn-default" onclick="App.withdrawToken();return false;">確認</button>
            </div>
    </div>
</div>

提領代幣 JavaScript

withdrawToken: function() {
  //The Withdraw Token function

  var nameToken = document.getElementById("inputNameWithdrawalToken").value;
  var amountTokens = document.getElementById("inputAmountWithdrawalToken").value;
  var exchangeInstance;
  ExchangeContract.deployed().then(function(instance) {
    exchangeInstance = instance;

    App.setStatus("Initiating Withdrawal...");
    return exchangeInstance.withdrawToken(nameToken, amountTokens,  {from: account});
  }).then(function() {
    document.getElementById("inputNameWithdrawalToken").value = "";
    document.getElementById("inputAmountWithdrawalToken").value = "";
    App.refreshBalanceExchange();

    App.setStatus("Withdrawal complete.");
  }).catch(function(e) {
    console.log(e);
    App.setStatus("Error getting balance; see log.");
  });
}

本文同時發佈於作者部落格:https://www.bdetw.com/blog


/images/emoticon/emoticon34.gif想找區塊鏈人才或想學習區塊鏈知識的夥伴。歡迎參加社群小聚,一起來輕鬆交流、互相學習成長、認識新朋友、發現新機會!
 
台北區塊鏈社群
https://bitlly.co/Q4dIK
 
BDE 區塊鏈學院 - 提供專業的區塊鏈培訓與顧問服務。
https://bitlly.co/mbDwX


上一篇
29. 去中心化交易所管理者前端功能實作
系列文
區塊鏈應用開發實戰30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言