Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
Swt transfer verification of balance , #102 #88
Browse files Browse the repository at this point in the history
  • Loading branch information
sponnet committed Feb 8, 2017
1 parent 5c642ac commit 7fec173
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/ac-balance.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ <h1 class="yellow bold">{{formatpong(swtbalance)}}</h1><h1 class="yellow bold"><

properties: {
swtbalance: {
type: Number,
type: Object,
observer: '_swtbalance'
},
balanceref: {
Expand All @@ -147,7 +147,7 @@ <h1 class="yellow bold">{{formatpong(swtbalance)}}</h1><h1 class="yellow bold"><


formatpong: function(val){
return (0 + (val / 1e18)).toFixed(2);
return val.dividedBy(1e18).toFormat(2);
},

ready: function() {
Expand Down
43 changes: 22 additions & 21 deletions src/ac-swtconversion.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,21 @@
<div class="totalwidth vertic start paddingsides basestructure">
<div class="whitespace"></div>
<div class="whitespace"></div>
<template is="dom-if" if="{{!needstoconvert}}">
<div class="total vertic start startjust ">
<h1 class="maxwidth white bold">Oops!</h1>
<div class="whitespace"></div>
<p class="reg maxwidth">No ARC-balance was found on <span class="bold account">{{account}}</span>. Make sure you are trying to import the right wallet and try again.</p>
<div class="tenspace"></div>
<paper-icon-button noink icon="sc-icons:arrowleft" class="shadow big grey1back" on-tap="back">Back</paper-icon-button>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
<template is="dom-if" if="{{arcbalance}}">
<template is="dom-if" if="{{!needstoconvert}}">
<div class="total vertic start startjust ">
<h1 class="maxwidth white bold">Oops!</h1>
<div class="whitespace"></div>
<p class="reg maxwidth">No ARC-balance was found on <span class="bold account">{{account}}</span>. Make sure you are trying to import the right wallet and try again.</p>
<div class="tenspace"></div>
<paper-icon-button noink icon="sc-icons:arrowleft" class="shadow big grey1back" on-tap="back">Back</paper-icon-button>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
<div class="whitespace"></div>
</template>
</template>
<template is="dom-if" if="{{needstoconvert}}">

Expand Down Expand Up @@ -653,19 +655,19 @@ <h1 class="bold centertxt yellow bigh">{{formatpong(swtbalance)}}</h1>
}

this.getAllowance(function(err, allowance) {

if (false && allowance > self.arcbalance) {
console.log('allowance is OK (', allowance.toString(10), '>=', self.arcbalance.toString(10), ')');
console.log('allowance=', allowance.toString(10), ' ARC balance=', self.arcbalance.toString(10), ')');
if (allowance >= self.arcbalance) {
console.log('allowance is OK');
return callback();
}
console.log('need to get allowance');

var requiredallowance = 0; //self.arcbalanceBN + 1;
var requiredallowance = self.arcbalance;

self.gasforapprove = self.ARCTokenInstance.approve.estimateGas(self.config.swtconversioncontractaddress, requiredallowance, {
from: self.$.helpers.fixaddress(self.account),
//gasPrice: self.gasPrice,
//gas: 100000
});
console.log('gas needed for approval=',self.gasforapprove);

self.ARCTokenInstance.approve.sendTransaction(self.config.swtconversioncontractaddress, requiredallowance, {
from: self.$.helpers.fixaddress(self.account),
Expand Down Expand Up @@ -697,9 +699,8 @@ <h1 class="bold centertxt yellow bigh">{{formatpong(swtbalance)}}</h1>

this.gasforconvert = this.SWTConverterInstance.convert.estimateGas(this.arcbalance, {
from: this.$.helpers.fixaddress(this.account),
//gasPrice: this.gasPrice,
//gas: 100000
});
console.log('gas needed for convert=',self.gasforconvert);

self.SWTConverterInstance.convert.sendTransaction(self.arcbalance, {
from: self.$.helpers.fixaddress(self.account),
Expand Down
91 changes: 51 additions & 40 deletions src/ac-tokensend.html
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@
value: true
},

swtbalance:{
type: Object
},

receivecollsclosed: {
type: Boolean,
value: true
Expand All @@ -616,40 +620,26 @@
},

_pincode: function() {
// console.log(this.pincode);
},

ready: function(){
// this._getARCbalance();
var self = this;

// window.setInterval(function(){
// self._getARCbalance();
// }, 5000);


this.sendcoinstate = 'init';
this.password = sessionStorage.getItem('ac-password');
},


tosendform: function(){
this.sendcoinstate = 'sendform';
this.fire('activated');
if (this.swtbalance){
this.sendcoinstate = 'sendform';
console.log('you haz',this.swtbalance.toString(10),'coiners');
this.fire('activated');
}else{
console.log('no swt balance available yet.');
}
},

// activatereceivecoins: function(){
// this.listeninterval = 60;
// },

// deactivatereceivecoins: function(){
// this.listeninterval = 0;
// },

attached: function(){
// var self=this;
// console.log('ac-tokensend attached');
// console.log('my account',this.account);
},

cancelsend: function(){
Expand All @@ -662,11 +652,11 @@
this.amount = '';
this.pincode = '';
this.receiver = null;
this.$.whisper.closeallchannels();
},

tosendcoins: function() {
var self = this;
//this.sendcoinstate = 'sendcoins';
this.transfer(this.amount * 1e18, this.$.helpers.fixaddress(self.receiver.account), function(err, result) {

if (err) {
Expand Down Expand Up @@ -727,6 +717,45 @@
},

tosearchingforpeer: function(){

// Verify amount syntax
var amount;
try{
amount = new this.web3.BigNumber(this.amount).times(1e18);
}catch(e){
return console.log('amount unreadable',this.amount);
amount = new this.web3.BigNumber(0);
}

if (amount.equals(0)){
return console.log('amount = 0');
}

// Verify sufficient funds
if (amount.greaterThan(this.swtbalance)){
this.sendcoinstate = 'balancelow';
return;
}else{
// console.log('amount=',amount.toString(10),'balance=',this.swtbalance.toString(10));
}

if (!this.pincode || this.pincode.length !== 5){
console.log('pincode too short.');
return;
}

try{
this.pincode = parseInt(this.pincode);
}catch(e){
console.log('pincode incorrect.');
return;
}


console.log(amount.toString(10));
console.log(this.swtbalance.toString(10));
//debugger;

var self = this;
this.$.whisper.whisperpost(this.pincode, JSON.stringify({
'command': 'requestuserinfo',
Expand All @@ -739,8 +768,6 @@
this.amount = '';
},



_is: function(a, b) {
if (b === undefined){
b = true;
Expand All @@ -759,12 +786,10 @@
closetokensendcollapser: function() {
this.sendcoinstate= 'init';
this.fire('deactivated');

},


transfer: function(amount, pubkey, cb) {

var self = this;
this.sendcoinstate = 'sending';
this.contracturl = this.resolveUrl('./contracts/ARCToken.json');
Expand Down Expand Up @@ -792,34 +817,20 @@
self.currenttxhash = result;
self.$.whisper.whisperpost(self.receiver.from, JSON.stringify({
'command': 'waitfortx',
//'amount': self.amount,
'txhash': result,
// 'username': self.identity.username,
//'txhash': result
}));


self.waitTx(result, function(success) {
console.log('TX mined!');
self.fire('tokenssent');
self.currenttxhash = '';
// var coinbalance = myContractInstance.balanceOf(self.$.helpers.fixaddress(self.account));
// self.arcbalance = coinbalance;
if (cb) {
cb(err, result);
}
});

});

});
});

//this.clearInputs();
//var sendcoins = self.$.sendcoins;
//sendcoins.toggle();
//this.collsclosed = !this.collsclosed;
//this.sendcoinstate = 'first';
},

waitTx: function(txHash, callback) {
Expand Down
8 changes: 4 additions & 4 deletions src/ac-wallet.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
notify: true
},
arcbalance: {
type: Number,
type: Object,
notify: true,
observer: '_arc'
},
Expand Down Expand Up @@ -133,8 +133,8 @@
var self = this;
this.debounce('_readARCBalance', function() {
self.updating = true;
self.ethbalance = self.web3.eth.getBalance(self.$.helpers.fixaddress(self.pubkey)).toNumber();
self.arcbalance = self.ARCTokeninstance.balanceOf(self.$.helpers.fixaddress(self.pubkey)).toNumber();
self.ethbalance = self.web3.eth.getBalance(self.$.helpers.fixaddress(self.pubkey));
self.arcbalance = self.ARCTokeninstance.balanceOf(self.$.helpers.fixaddress(self.pubkey));
self.updating = false;
console.log('ETH balance is', self.ethbalance);
console.log('ARC balance is', self.arcbalance);
Expand All @@ -154,7 +154,7 @@
var self = this;
this.debounce('_readSWTBalance', function() {
this.updating = true;
self.swtbalance = self.SWTTokeninstance.balanceOf(self.$.helpers.fixaddress(self.pubkey)).toNumber();
self.swtbalance = self.SWTTokeninstance.balanceOf(self.$.helpers.fixaddress(self.pubkey));
self.updating = false;
console.log('SWT balance is', this.swtbalance);
if (cb){
Expand Down
2 changes: 2 additions & 0 deletions src/ac-walletview.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
on-deactivated="showReceivebutton"
on-tokenssent="refreshbalance"
on-addlog="receivelog"
swtbalance="[[swtbalance]]"
on-tokenssent="refreshbalance"
sizeview="{{sizeview}}">
</ac-tokensend>
</template>
Expand Down

0 comments on commit 7fec173

Please sign in to comment.