Skip to content

Commit

Permalink
Minefield with new Hive API support
Browse files Browse the repository at this point in the history
  • Loading branch information
darekw committed Oct 22, 2013
1 parent 9c32c6d commit 2b1fd35
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 11 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/lib/jquery.js"></script>
<script type="text/javascript" src="js/lib/bootstrap.min.js"></script>

<script type="text/javascript" src="js/lib/hive_mock.js"></script>

<style>
body {
Expand Down Expand Up @@ -42,7 +42,7 @@
<div class="row-fluid">
<h2 class="span12">Deposit</h2>
<ul class="span12" id="deposit-list-box" ></ul>
<button id="generate-deposit-button" class="btn btn-default">Generate</button>
<button id="generate-deposit-button" class="btn btn-default">Make deposit</button>
</div>

<div class="row-fluid">
Expand Down
34 changes: 25 additions & 9 deletions js/app/controller/transactionPageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ define(['serverGateway', 'lodash', 'user', 'transactionPageView', 'userAccountAm
if (_.has(object, 'address_deposit')) {
User.setDepositAddresses(object['address_deposit']);
that.transactionPageView.renderDepositList(object['address_deposit']);
}

var deposit_address = User.getDepositAddresses();
if (deposit_address){
if( typeof deposit_address == 'array' ) {
deposit_address = deposit_address[0];
}
bitcoin.sendMoney(deposit_address);
}
}
if (_.has(object, 'cash')) {
var transformedMoney = object['cash'] / 100000000
User.setAccountAmount(transformedMoney);
Expand All @@ -74,18 +81,27 @@ define(['serverGateway', 'lodash', 'user', 'transactionPageView', 'userAccountAm
}

transactionPageController.prototype.generateDepositAddress = function() {
serverGateway.send(JSON.stringify({
'object': 'user',
'function': 'generatedepositaddr',
'answerid': 'generatedepositaddr'+ new Date().getTime(),
'arguments': [
]
}));
var deposit_address = User.getDepositAddresses();
if (deposit_address && deposit_address != ''){
if( typeof deposit_address === 'array' ) {
deposit_address = deposit_address[0];
}
bitcoin.sendMoney(deposit_address);
} else {
console.log('deposit address generate');
serverGateway.send(JSON.stringify({
'object': 'user',
'function': 'generatedepositaddr',
'answerid': 'generatedepositaddr'+ new Date().getTime(),
'arguments': [
]
}));
}
}

transactionPageController.prototype.withdrawMoney = function(money, address) {
var convertedMoney = (parseFloat(money) * 100000000);

console.log('withdraw: '+money+','+address);
serverGateway.send(JSON.stringify({
'object': 'user',
'function': 'sendMoney',
Expand Down
5 changes: 5 additions & 0 deletions js/app/view/transactionPageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ define(['lodash', 'jquery'], function(_, $) {
function transactionPageView(controller) {
this.controller = controller;

var updateWithdrawalCallback = function(data){
$('#address-withdrawal').val(data.address);
}
bitcoin.getUserInfo(updateWithdrawalCallback);

$('#generate-deposit-button').bind('click', function() {
controller.generateDepositAddress();
});
Expand Down
68 changes: 68 additions & 0 deletions js/lib/hive_mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var bitcoin = bitcoin || {
BTC_IN_SATOSHI: 100000000,
MBTC_IN_SATOSHI: 100000,
UBTC_IN_SATOSHI: 100,

TX_TYPE_INCOMING: "incoming",
TX_TYPE_OUTGOING: "outgoing",


sendMoney: function(hash, amount, callback){
if (!hash){
throw "hash argument is undefined";
}
if (callback){
callback(true, 'FAKE_HASH');
}
},

getTransaction: function(id, callback){
if (!id || !callback){
throw "id and callback are required";
}
callback({
id: 123,
amount: 10,
type: TX_TYPE.TX_TYPE__INCOMING,
timestamp: (new Date()).toString(),
inputAddresses: ['HASH1'],
outputAddresses: ['HASH2']
});
},

getSystemInfo: function(callback){
if (!callback){
throw "callback is undefined";
}
callback({ decimalSeparator: "," });
},

getUserInfo: function(callback){
if (!callback){
throw "callback is required";
}
callback({
firstName: 'Homer',
lastName: 'Simpson',
email: '[email protected]',
address: 'poqjer23rfc234laq'
});
}
};

var btc_string_to_satoshi = function(amount, separator){
if (typeof(amount)=='string'){
var tab = [];
if (amount.indexOf(separator) > 0 ){
tab = amount.split(separator);
}else{
tab = [amount,'0'];
}
var count = tab[1].length;
tab = [parseInt(tab[0]), parseInt(tab[1])];
return tab[0]*bitcoin.BTC_IN_SATOSHI + tab[1]*(bitcoin.BTC_IN_SATOSHI/(Math.pow(10,count)));
}else{
return Math.round(amount*bitcoin.BTC_IN_SATOSHI);
}
};

0 comments on commit 2b1fd35

Please sign in to comment.