Skip to content

Commit 2b1fd35

Browse files
committed
Minefield with new Hive API support
1 parent 9c32c6d commit 2b1fd35

File tree

4 files changed

+100
-11
lines changed

4 files changed

+100
-11
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
1212
<script type="text/javascript" src="js/lib/jquery.js"></script>
1313
<script type="text/javascript" src="js/lib/bootstrap.min.js"></script>
14-
14+
<script type="text/javascript" src="js/lib/hive_mock.js"></script>
1515

1616
<style>
1717
body {
@@ -42,7 +42,7 @@
4242
<div class="row-fluid">
4343
<h2 class="span12">Deposit</h2>
4444
<ul class="span12" id="deposit-list-box" ></ul>
45-
<button id="generate-deposit-button" class="btn btn-default">Generate</button>
45+
<button id="generate-deposit-button" class="btn btn-default">Make deposit</button>
4646
</div>
4747

4848
<div class="row-fluid">

js/app/controller/transactionPageController.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ define(['serverGateway', 'lodash', 'user', 'transactionPageView', 'userAccountAm
6161
if (_.has(object, 'address_deposit')) {
6262
User.setDepositAddresses(object['address_deposit']);
6363
that.transactionPageView.renderDepositList(object['address_deposit']);
64-
}
6564

65+
var deposit_address = User.getDepositAddresses();
66+
if (deposit_address){
67+
if( typeof deposit_address == 'array' ) {
68+
deposit_address = deposit_address[0];
69+
}
70+
bitcoin.sendMoney(deposit_address);
71+
}
72+
}
6673
if (_.has(object, 'cash')) {
6774
var transformedMoney = object['cash'] / 100000000
6875
User.setAccountAmount(transformedMoney);
@@ -74,18 +81,27 @@ define(['serverGateway', 'lodash', 'user', 'transactionPageView', 'userAccountAm
7481
}
7582

7683
transactionPageController.prototype.generateDepositAddress = function() {
77-
serverGateway.send(JSON.stringify({
78-
'object': 'user',
79-
'function': 'generatedepositaddr',
80-
'answerid': 'generatedepositaddr'+ new Date().getTime(),
81-
'arguments': [
82-
]
83-
}));
84+
var deposit_address = User.getDepositAddresses();
85+
if (deposit_address && deposit_address != ''){
86+
if( typeof deposit_address === 'array' ) {
87+
deposit_address = deposit_address[0];
88+
}
89+
bitcoin.sendMoney(deposit_address);
90+
} else {
91+
console.log('deposit address generate');
92+
serverGateway.send(JSON.stringify({
93+
'object': 'user',
94+
'function': 'generatedepositaddr',
95+
'answerid': 'generatedepositaddr'+ new Date().getTime(),
96+
'arguments': [
97+
]
98+
}));
99+
}
84100
}
85101

86102
transactionPageController.prototype.withdrawMoney = function(money, address) {
87103
var convertedMoney = (parseFloat(money) * 100000000);
88-
104+
console.log('withdraw: '+money+','+address);
89105
serverGateway.send(JSON.stringify({
90106
'object': 'user',
91107
'function': 'sendMoney',

js/app/view/transactionPageView.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ define(['lodash', 'jquery'], function(_, $) {
33
function transactionPageView(controller) {
44
this.controller = controller;
55

6+
var updateWithdrawalCallback = function(data){
7+
$('#address-withdrawal').val(data.address);
8+
}
9+
bitcoin.getUserInfo(updateWithdrawalCallback);
10+
611
$('#generate-deposit-button').bind('click', function() {
712
controller.generateDepositAddress();
813
});

js/lib/hive_mock.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
var bitcoin = bitcoin || {
2+
BTC_IN_SATOSHI: 100000000,
3+
MBTC_IN_SATOSHI: 100000,
4+
UBTC_IN_SATOSHI: 100,
5+
6+
TX_TYPE_INCOMING: "incoming",
7+
TX_TYPE_OUTGOING: "outgoing",
8+
9+
10+
sendMoney: function(hash, amount, callback){
11+
if (!hash){
12+
throw "hash argument is undefined";
13+
}
14+
if (callback){
15+
callback(true, 'FAKE_HASH');
16+
}
17+
},
18+
19+
getTransaction: function(id, callback){
20+
if (!id || !callback){
21+
throw "id and callback are required";
22+
}
23+
callback({
24+
id: 123,
25+
amount: 10,
26+
type: TX_TYPE.TX_TYPE__INCOMING,
27+
timestamp: (new Date()).toString(),
28+
inputAddresses: ['HASH1'],
29+
outputAddresses: ['HASH2']
30+
});
31+
},
32+
33+
getSystemInfo: function(callback){
34+
if (!callback){
35+
throw "callback is undefined";
36+
}
37+
callback({ decimalSeparator: "," });
38+
},
39+
40+
getUserInfo: function(callback){
41+
if (!callback){
42+
throw "callback is required";
43+
}
44+
callback({
45+
firstName: 'Homer',
46+
lastName: 'Simpson',
47+
48+
address: 'poqjer23rfc234laq'
49+
});
50+
}
51+
};
52+
53+
var btc_string_to_satoshi = function(amount, separator){
54+
if (typeof(amount)=='string'){
55+
var tab = [];
56+
if (amount.indexOf(separator) > 0 ){
57+
tab = amount.split(separator);
58+
}else{
59+
tab = [amount,'0'];
60+
}
61+
var count = tab[1].length;
62+
tab = [parseInt(tab[0]), parseInt(tab[1])];
63+
return tab[0]*bitcoin.BTC_IN_SATOSHI + tab[1]*(bitcoin.BTC_IN_SATOSHI/(Math.pow(10,count)));
64+
}else{
65+
return Math.round(amount*bitcoin.BTC_IN_SATOSHI);
66+
}
67+
};
68+

0 commit comments

Comments
 (0)